
    Fg_              	           S SK r S SKrS SKrS SKJrJr  \R                  " S5      rS\4S jr	S r
S rS rS	\\   S
\S\\   4S jrS\S\4S jrS\SS4S jr SS\S\S\S\4S jjr SS\\\4   S\S\4S jjrg)    N)DictOptionaldeeplmodule_namec                 T     [         R                  " U 5      nU$ ! [         a     gf = f)a^  Tries importing the specified module and returns it if successful,
else None.
Example:

keyring = _optional_import('keyring')
if keyring:
    keyring.get_password(...)
else:
    # Code to handle the module not being present
    pass

:param module_name: str containing the exact module name
:return: The module, if the import was successful, or None
N)	importlibimport_moduleImportError)r   modules     [/Users/admin/workspace/ai/PDFMathTranslate/myenv/lib/python3.13/site-packages/deepl/util.py_optional_importr      s.    ((5 s    
''c                 l    U S-   SR                  S [        UR                  5       5       5       5      -   $ )N c              3   4   #    U  H  u  pU S U 3v   M     g7f)=N ).0keyvalues      r   	<genexpr> _get_log_text.<locals>.<genexpr>&   s     M6L
cU!E7#6Ls   )joinsorteditems)messagekwargss     r   _get_log_textr   "   s5    
	
((MfV\\^6LM
M	N    c                 F    [        U 40 UD6n[        R                  U5        g N)r   loggerdebugr   r   texts      r   	log_debugr%   *   s    +F+D
LLr   c                 F    [        U 40 UD6n[        R                  U5        g r    )r   r!   infor#   s      r   log_infor(   /   s    +F+D
KKr   dr   returnc                 ~     [        U (       a  U R                  U5      5      $ S5      $ ! [        [        4 a     gf = f)z;Returns value in dictionary with given key as int, or None.N)intget	TypeError
ValueError)r)   r   s     r   get_int_safer0   4   s;    155:----z" s    ) ) <<auth_keyc                 $    U R                  S5      $ )zbReturns True if the given authentication key belongs to a DeepL API Free
account, otherwise False.z:fx)endswith)r1   s    r   auth_key_is_free_accountr4   <   s     U##r   termc                     [        U 5      S:X  a  [        SU  S35      e[        S U  5       5      (       a  [        SU  S35      eg)zChecks if the given glossary term contains any disallowed characters.

:param term: Glossary term to check for validity.
:raises ValueError: If the term is not valid or a disallowed character is
found.r   zTerm "z" is not a valid stringc              3      #    U  HT  nS [        U5      s=:*  =(       a    S:*  Os  =(       d*    S[        U5      s=:*  =(       a    S:*  Os  =(       d    US;   v   MV     g7f)r            u     N)ord)r   chars     r   r   )validate_glossary_term.<locals>.<genexpr>J   sW       D	 T  b  &c$i&&3&&~%& s   AAz" contains invalid characterN)lenr/   any)r5   s    r   validate_glossary_termr@   B   s\     4yA~6$'>?@@
     6$'CDEEr   tsvterm_separatorskip_checksc                    0 n[        U R                  5       [        R                  " S5      5       H  u  pEU(       d  M  X;  a  [	        SU SU 35      eUR                  US5      u  pgUR                  5       UR                  5       pvXc;   a  [	        SU SU S35      eX;   a  [	        SU SU 35      eU(       d  [        U5        [        U5        XsU'   M     U$ )a  Converts the given tab-separated values (TSV) string to an entries
dictionary for use in a glossary. Each line should contain a source and
target term separated by a tab. Empty lines are ignored.

:param tsv: string containing TSV to parse.
:param term_separator: optional term separator to use.
:param skip_checks: set to True to override entry validation.
:return: dictionary containing parsed entries.
   zEntry z does not contain separator: z duplicates source term ""z( contains more than one term separator: )zip
splitlines	itertoolscountr/   splitstripr@   )rA   rB   rC   entries_dictlineindexsourcetargets           r   convert_tsv_to_dictrR   U   s     L3>>+Y__Q-?@%<TFC  NA6!8B  #GvN  "6*"6*%V) A* r   
entry_dictc                     U(       dK  U R                  5        H7  u  p#[        UR                  5       5        [        UR                  5       5        M9     SR                  S U R                  5        5       5      $ )a  Converts the given glossary entries dictionary to a tab-separated values
(TSV) string.

:param entry_dict: dictionary containing glossary entries.
:param skip_checks: set to True to override entry validation.
:return: string containing entries in TSV format.

c              3   l   #    U  H*  u  pUR                  5        S UR                  5        3v   M,     g7f)	N)rL   )r   sts      r   r   &convert_dict_to_tsv.<locals>.<genexpr>   s-      0B1779+R	{#0Bs   24)r   r@   rL   r   )rS   rC   rP   rQ   s       r   convert_dict_to_tsvr[   z   sa     (..0NF"6<<>2"6<<>2 1 99 0:0@0@0B  r   )rW   F)F)r   rI   loggingtypingr   r   	getLoggerr!   strr   r   r%   r(   dictr,   r0   boolr4   r@   rR   r[   r   r   r   <module>rb      s       !			7	## ,

HTN  # $s $t $F F F( ?D"	"!"7;"	"L 5:S#X-1r   