
    Fgݟ                         S SK JrJrJrJrJrJrJrJrJ	r	  SSK
JrJr  SSKJrJrJrJrJrJrJr  S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&  S SK'r( " S S5      r)g)	    )	DocumentHandleDocumentStatus	FormalityGlossaryInfoGlossaryLanguagePairLanguageSplitSentences
TextResultUsage   )http_clientutil)DocumentNotReadyExceptionGlossaryNotFoundExceptionQuotaExceededExceptionTooManyRequestsExceptionDeepLExceptionAuthorizationExceptionDocumentTranslationExceptionN)	AnyBinaryIODictIterableListOptionalTextIOTupleUnionc                       \ rS rSrSrSrSrSrSSSSSS	.S
\S\	\   S\
\\S4   S\S\
\\S4   S\4S jjrS rSSSSSS.S\S\S\	\   S\	\   S\S\	\   S\\\
\\R&                  4   \4   4S jjr  SYS\S\
\\R&                  4   S\S\S\4
S  jjrS!\	\   S"\4S# jr SZS!\
\\S4   S"\
\\4   S$\
\\S4   S\
\\S4   S\4
S% jjrS&\S!\
\\4   S"\
\\4   S'\S(\
\\4   S\4S) jrS* rS+\S,\4S- jr\ S. 5       r!SSSSSSSSSSSS/.S0\
\\"\   4   S!\
\\S4   S"\
\\4   S1\	\   S2\
\\#S4   S3\	\   S$\
\\S4   S\
\\S4   S4\	\   S5\	\   S6\
\\$\   S4   S7\
\\$\   S4   S8\
\\$\   S4   S\
\%\$\%   4   4S9 jjr& SZS0\
\\"\   4   S\S"\
\\S4   S\
\%\$\%   4   4S: jjr'S\RP                  SS;.S<\
\\)RT                  4   S=\
\\)RT                  4   S!\	\   S"\S$\
\\4   S\
\\S4   S\+4S> jjr,S\RP                  SSSS?.S@\
\-\.\4   SA\
\-\.\4   S!\	\   S"\S$\
\\4   S\
\\S4   SB\	\   SC\	\   S\+4SD jjr/SSSSSS?.S@\
\-\.\\\4   S!\	\   S"\S$\
\\S4   S\
\\S4   SB\	\   SC\	\   S\04SE jjr1SF\0S\+4SG jr2SF\0S\+4SH jr3  S[SF\0SI\
\-\.\S4   SJ\S\	\R&                     4SK jjr4S\S\$\   4SL jjr5S\S\$\   4SM jjr6S\$\7   4SN jr8S\94SO jr:S&\S!\
\\4   S"\
\\4   S(\\\4   S\4
SP jr;S&\S!\
\\4   S"\
\\4   SQ\
\-\.\\\4   S\4
SR jr<SS\S\4ST jr=S\$\   4SU jr>S\
\\4   S\4SV jr?S\
\\4   SS4SW jr@SXrAg)]
Translator/   a  Wrapper for the DeepL API for language translation.

You must create an instance of Translator to use the DeepL API.

:param auth_key: Authentication key as found in your DeepL API account.
:param server_url: (Optional) Base URL of DeepL API, can be overridden e.g.
    for testing purposes.
:param proxy: (Optional) Proxy server URL string or dictionary containing
    URL strings for the 'http' and 'https' keys. This is passed to the
    underlying requests session, see the requests proxy documentation for
    more information.
:param send_platform_info: (Optional) boolean that indicates if the client
    library can send basic platform info (python version, OS, http library
    version) to the DeepL API. True = send info, False = only send client
    library version
:param verify_ssl: (Optional) Controls how requests verifies SSL
    certificates. This is passed to the underlying requests session, see
    the requests verify documentation for more information.
:param skip_language_check: Deprecated, and now has no effect as the
    corresponding internal functionality has been removed. This parameter
    will be removed in a future version.

All functions may raise DeepLException or a subclass if a connection error
occurs.
zhttps://api.deepl.comzhttps://api-free.deepl.comi  NTF)
server_urlproxysend_platform_info
verify_sslskip_language_checkauth_keyr"   r#   r$   r%   r&   c                    U(       d  [        S5      eUc3  [        R                  " U5      (       a  U R                  OU R                  nX l        [        R                  " X4U5      U l        SSU 30U l	        g )Nzauth_key must not be emptyAuthorizationzDeepL-Auth-Key )

ValueErrorr   auth_key_is_free_account_DEEPL_SERVER_URL_FREE_DEEPL_SERVER_URL_server_urlr   
HttpClient_clientheaders)selfr'   r"   r#   r$   r%   r&   s          a/Users/admin/workspace/ai/PDFMathTranslate/myenv/lib/python3.13/site-packages/deepl/translator.py__init__Translator.__init__Q   sy     9:: 00:: ++++  &"--z
 (?8*)EF    c                 $    U R                  5         g N)closer2   s    r3   __del__Translator.__del__k   s    

r6   POST)methoddatajsonstreamr1   urlr>   r?   r@   rA   r1   returnc                   Ub  Ub  [        S5      eUc  0 n[        R                  R                  U R                  U5      n[
        R                  " SX!S9  [
        R                  " SX4S9  Uc
  [        5       nUR                  U R                  R                  5        VV	s0 s H  u  pX;  d  M  X_M     sn	n5        U R                  R                  " UU4UUUUS.UD6u  pSn[        U[        5      (       a  Un [         R"                  " U5      nOUR&                  n[
        R                  " SXS	9  [
        R                  " S
US9  XU4$ s  sn	nf ! [         R$                   a     NJf = f)z[
Makes a request to the API, and returns response as status code,
content and JSON object.
Nz cannot accept both json and datazRequest to DeepL API)r>   rB   zRequest details)r?   r@   )r?   r@   rA   r1   zDeepL API response)rB   status_codezResponse details)content)r*   urllibparseurljoinr.   r   log_info	log_debugdictupdater1   itemsr0   request_with_backoff
isinstancestrjson_moduleloadsJSONDecodeErrortext)r2   rB   r>   r?   r@   rA   r1   kwargskvrE   rF   content_strs                r3   	_api_callTranslator._api_calln   sa     0?@@<Dll""4#3#3S9,VE(t??fG"ll002G2daa6FTQT2G	
  $||@@ 
  
  
 gs##!K"((1 ",,K*M);?T))5 H$ .. s    E
/E
<E E*)E*rE   rF   glossarydownloading_documentc           	         SnUb&  [        U[        5      (       a  SU;   a  USUS   -   -  nUb&  [        U[        5      (       a  SU;   a  USUS   -   -  nSUs=::  a  S:  a   g   U[        R                  R                  :X  a  [        SU 3US	9eXR                  :X  a  [        S
U 3US	9eU[        R                  R                  :X  a!  U(       a  [        SU 3US	9e[        SU 3US	9eU[        R                  R                  :X  a  [        SU 3US	9eU[        R                  R                  :X  a  [        SU 3SUS9eU[        R                  R                  :X  a#  U(       a  [        SU 3SUS9e[        SU 3SUS9eU[        R                   R"                  ;   a  [        R                   R"                  U   OSn[        U[$        5      (       a  UOUR&                  n[        SU SU SU S3SUS9e)N messagez, message: detailz
, detail:    i  z%Authorization failure, check auth_keyhttp_status_codez/Quota for this billing period has been exceededzGlossary not foundzNot found, check server_urlzBad requestzEToo many requests, DeepL servers are currently experiencing high loadT)should_retryrd   zDocument not readyzService unavailableUnknownzUnexpected status code:  z, content: .F)rP   rL   http
HTTPStatus	FORBIDDENr   _HTTP_STATUS_QUOTA_EXCEEDEDr   	NOT_FOUNDr   r   BAD_REQUESTTOO_MANY_REQUESTSr   SERVICE_UNAVAILABLEr   client	responsesrQ   rU   )	r2   rE   rF   r@   r\   r]   r`   status_namerY   s	            r3   _raise_for_statusTranslator._raise_for_status   sH    
4 6 69;L}tI66G
4 6 68t;K|d8n44G+## $DOO555(7yA!,  <<<(A'K!,  DOO555/(	2%0  !-gY7!,  DOO777 gY'+  DOO===*#9&!!,	  DOO???#/(	2!%%0  %)'3!%%0  $++"7"77 %%k2 
 &0%=%='7<<K *;-q F'=+"!,	 r6   source_langtarget_langc                 H    US:X  a  [        S5      eUS:X  a  [        S5      eg)z5Internal function to check given languages are valid.ENzEtarget_lang="EN" is deprecated, please use "EN-GB" or "EN-US"instead.PTzEtarget_lang="PT" is deprecated, please use "PT-PT" or "PT-BR"instead.N)r   )r2   rv   rw   s      r3   _check_valid_languages!Translator._check_valid_languages   s?     $   D    !r6   	formalityc                    [        U5      R                  5       nUb  [        U5      R                  5       nUb  Uc  [        S5      e[        U[        5      (       a>  [
        R                  " U5      UR                  :w  d  XR                  :w  a  [        S5      eU R                  X5        SU0nUb  XS'   Ub  [        U5      R                  5       US'   [        U[        5      (       a  UR                  US'   U$ Ub  XES'   U$ )Nz+source_lang is required if using a glossaryz/source_lang and target_lang must match glossaryrw   rv   r}   glossary_id)rQ   upperr*   rP   r   r   remove_regional_variantrw   rv   r{   lowerr   )r2   rv   rw   r}   r\   request_datas         r3   _check_language_and_formality(Translator._check_language_and_formality   s    +&,,."k*002KK$7JKKh--00=''("6"66 E  	##K=%{3"*5' (+I(<(<(>L%h--*2*>*>L'  !*2'r6   nameentries_formatentriesc                    [         R                  " U5      n[         R                  " U5      nU(       d  [        S5      eUUUUUS.nU R                  SUS9u  pxn	U R	                  XxU	SS9  [
        R                  " U	5      $ )Nzglossary name must not be empty)r   rv   rw   r   r   v2/glossariesr@   Tr\   )r   r   r*   rZ   rt   r   	from_json)
r2   r   rv   rw   r   r   r   statusrF   r@   s
             r3   _create_glossaryTranslator._create_glossary%  s     66{C66{C>?? &&,
 !%, !/ !
 	vtD%%d++r6   c                 \    [        U S5      (       a  U R                  R                  5         g g )Nr0   )hasattrr0   r9   r:   s    r3   r9   Translator.closeB  s$    4##LL  $r6   app_info_nameapp_info_versionc                 <    U R                   R                  X5        U $ r8   )r0   set_app_info)r2   r   r   s      r3   r   Translator.set_app_infoF  s    !!-Br6   c                     U R                   $ r8   )r.   r:   s    r3   r"   Translator.server_urlJ  s    r6   )rv   contextsplit_sentencespreserve_formattingr}   r\   tag_handlingoutline_detectionnon_splitting_tagssplitting_tagsignore_tagsrU   r   r   r   r   r   r   r   r   c                   [        U[        5      (       a   [        U5      S:X  a  [        S5      eU/nSnO*[	        US5      (       a  Sn[        U5      nO[        S5      eU R                  UUUU5      nXS'   Ub  XOS'   Ub  [        U5      US	'   Ub  [        U5      US
'   U	b  XS'   U
b  [        U
5      US'   S[        [        [        [           4   S[        [           4S jnUb  U" U5      US'   Ub  U" U5      US'   Ub  U" U5      US'   U R                  SUS9u  nnnU R                  UUU5        U(       a'  [        U[        5      (       a  UR                  S/ 5      O/ n/ nU HR  nU(       a  UR                  SS5      OSnU(       a  UR                  SS5      OSnUR!                  [#        UUS95        MT     U(       a  U$ US   $ )a  Translate text(s) into the target language.

:param text: Text to translate.
:type text: UTF-8 :class:`str`; string sequence (list, tuple, iterator,
    generator)
:param source_lang: (Optional) Language code of input text, for example
    "DE", "EN", "FR". If omitted, DeepL will auto-detect the input
    language. If a glossary is used, source_lang must be specified.
:param target_lang: language code to translate text into, for example
    "DE", "EN-US", "FR".
:param context: (Optional) Additional contextual text to influence
    translations, that is not translated itself. Note: this is an alpha
    feature: it may be deprecated at any time, or incur charges if it
    becomes generally available. See the API documentation for more
    information and example usage.
:param split_sentences: (Optional) Controls how the translation engine
    should split input into sentences before translation, see
    :class:`SplitSentences`.
:param preserve_formatting: (Optional) Set to True to prevent the
    translation engine from correcting some formatting aspects, and
    instead leave the formatting unchanged.
:param formality: (Optional) Desired formality for translation, as
    Formality enum, "less", "more", "prefer_less", "prefer_more", or
    "default".
:param glossary: (Optional) glossary or glossary ID to use for
    translation. Must match specified source_lang and target_lang.
:param tag_handling: (Optional) Type of tags to parse before
    translation, only "xml" and "html" are currently available.
:param outline_detection: (Optional) Set to False to disable automatic
    tag detection.
:param non_splitting_tags: (Optional) XML tags that should not split a
    sentence.
:type non_splitting_tags: List of XML tags or comma-separated-list of
    tags.
:param splitting_tags: (Optional) XML tags that should split a
    sentence.
:type splitting_tags: List of XML tags or comma-separated-list of tags.
:param ignore_tags: (Optional) XML tags containing text that should not
    be translated.
:type ignore_tags: List of XML tags or comma-separated-list of tags.
:return: List of TextResult objects containing results, unless input
    text was one string, then a single TextResult object is returned.
r   ztext must not be emptyF__iter__Tz9text parameter must be a string or an iterable of stringsrU   r   r   r   r   r   tag_argumentrC   c                     [        U [        5      (       a  U /n U  VVs/ s H  nUR                  S5        H  nUPM     M      snn$ s  snnf )N,)rP   rQ   split)r   
arg_stringtags      r3   	join_tags,Translator.translate_text.<locals>.join_tags  sU    ,,, ,~ #/".J%++C0C 0 ".  s   %Ar   r   r   zv2/translater   translationsr_   detected_source_language)detected_source_lang)rP   rQ   lenr*   r   list	TypeErrorr   boolr   r   r   rZ   rt   rL   getappendr
   )r2   rU   rv   rw   r   r   r   r}   r\   r   r   r   r   r   multi_inputr   r   r   rF   r@   r   outputtranslationlangs                           r3   translate_textTranslator.translate_textN  s   x dC  4yA~ !9::6DKT:&&K:DK  99	
  $V&-#&.1/.BL*+*267J2KL./#+7((045F0GL,-	E#x}*<$= 	$s) 	 )1:;M1NL-.%-6~-FL)*"*3K*@L' $ !/ !
 	vw5 D$// HH^R( 	
 'K2=;??62.2D   :B? 
 MM*TEF ( %v3&)3r6   c                     [        U[        5      (       d  Sn[        U5      eUc  UR                  nUS:X  a  SnU R                  " U4UR
                  UUS.UD6$ )a  Translate text(s) using given glossary. The source and target
languages are assumed to match the glossary languages.

Note that if the glossary target language is English (EN), the text
will be translated into British English (EN-GB). To instead translate
into American English specify target_lang="EN-US".

:param text: Text to translate.
:type text: UTF-8 :class:`str`; string sequence (list, tuple, iterator,
    generator)
:param glossary: glossary to use for translation.
:type glossary: :class:`GlossaryInfo`.
:param target_lang: override target language of glossary.
:return: List of TextResult objects containing results, unless input
    text was one string, then a single TextResult object is returned.
a	  This function expects the glossary parameter to be an instance of GlossaryInfo. Use get_glossary() to obtain a GlossaryInfo using the glossary ID of an existing glossary. Alternatively, use translate_text() and specify the glossary ID using the glossary parameter. ry   zEN-GB)rv   rw   r\   )rP   r   r*   rw   r   rv   )r2   rU   r\   rw   rV   msgs         r3   translate_text_with_glossary'Translator.translate_text_with_glossary  sz    0 (L11I  S/!"..Kd"%""
 ,,#	

 
 	
r6   )rv   r}   r\   
input_pathoutput_pathc                "   [         R                  " U5      R                  R                  5       n[         R                  " U5      R                  R                  5       nXx:X  a  SOUSS n	[	        US5       n
[	        US5       n U R                  U
UUUUUU	S9sSSS5        sSSS5        $ ! [         a-  nUR                  5         [        R                  " U5        UeSnAff = f! , (       d  f       O= f SSS5        g! , (       d  f       g= f)a  Upload document at given input path, translate it into the target
language, and download result to given output path.

:param input_path: Path to document to be translated.
:param output_path: Path to store translated document.
:param source_lang: (Optional) Language code of input document, for
    example "DE", "EN", "FR". If omitted, DeepL will auto-detect the
    input language.
:param target_lang: Language code to translate document into, for
    example "DE", "EN-US", "FR".
:param formality: (Optional) Desired formality for translation, as
    Formality enum, "less", "more", "prefer_less", or "prefer_more".
:param glossary: (Optional) glossary or glossary ID to use for
    translation. Must match specified source_lang and target_lang.
:return: DocumentStatus when document translation completed, this
    allows the number of billed characters to be queried.

:raises DocumentTranslationException: If an error occurs during
    translation. The exception includes information about the document
    request.
Nr   rbwb)rw   rv   r}   r\   output_format)
pathlibPurePathsuffixr   opentranslate_document	Exceptionr9   osunlink)r2   r   r   rv   rw   r}   r\   in_extout_extr   in_fileout_filees                r3    translate_document_from_filepath+Translator.translate_document_from_filepath   s    @ !!*-44::<"";/66<<> & 1wqr{*d#wk4(H22 $/$/"+!)&3 3  )( $# ! NN$IIk*G )(( $##sB   5D C%B+	D +
C"5(CC""C%%
C3	/D  
D)rv   r}   r\   filenamer   input_documentoutput_documentr   r   c          
      R   U R                  UUUUUUUS9n	 U R                  U	5      n
U
R                  (       a  U R                  X5        U
R                  (       d$  U
R                  =(       d    Sn[        SU 3U	5      eU
$ ! [         a  n[        [        U5      U	5      UeSnAff = f)a  Upload document, translate it into the target language, and download
result.

:param input_document: Document to translate as a file-like object. It
    is recommended to open files in binary mode.
:param output_document: File-like object to receive translated
    document.
:param source_lang: (Optional) Language code of input document, for
    example "DE", "EN", "FR". If omitted, DeepL will auto-detect the
    input language.
:param target_lang: Language code to translate document into, for
    example "DE", "EN-US", "FR".
:param formality: (Optional) Desired formality for translation, as
    Formality enum, "less", "more", "prefer_less", or "prefer_more".
:param glossary: (Optional) glossary or glossary ID to use for
    translation. Must match specified source_lang and target_lang.
:param filename: (Optional) Filename including extension, only required
    if uploading string or bytes containing file content.
:param output_format: (Optional) Desired output file extension, if
    it differs from the input file format.
:return: DocumentStatus when document translation completed, this
    allows the number of billed characters to be queried.

:raises DocumentTranslationException: If an error occurs during
    translation, the exception includes the document handle.
)rw   rv   r}   r\   r   r   Nzunknown errorz+Error occurred while translating document: )translate_document_upload"translate_document_wait_until_doneoktranslate_document_downloadr   r   rQ   error_message)r2   r   r   rv   rw   r}   r\   r   r   handler   r   r   s                r3   r   Translator.translate_document5  s    N //##' 0 
	F<<VDFyy00I yy"00COM.=m_M    	F.s1vv>AE	Fs   3B 
B&B!!B&c                Z   U R                  X#XE5      nU(       a  XxS'   0 n	[        U[        [        45      (       a  Uc  [	        S5      eSXa40n	OSU0n	U R                  SXS9u  pnU R                  XU5        U(       d  0 n[        UR                  SS5      UR                  SS5      5      $ )	a  Upload document to be translated and return handle associated with
request.

:param input_document: Document to translate as a file-like object, or
    string or bytes containing file content.
:param source_lang: (Optional) Language code of input document, for
    example "DE", "EN", "FR". If omitted, DeepL will auto-detect the
    input language.
:param target_lang: Language code to translate document into, for
    example "DE", "EN-US", "FR".
:param formality: (Optional) Desired formality for translation, as
    Formality enum, "less", "more", "prefer_less", or "prefer_more".
:param glossary: (Optional) glossary or glossary ID to use for
    translation. Must match specified source_lang and target_lang.
:param filename: (Optional) Filename including extension, only required
    if uploading string or bytes containing file content.
:param output_format: (Optional) Desired output file extension, if
    it differs from the input file format.
:return: DocumentHandle with ID and key identifying document.
r   zAfilename is required if uploading file content as string or bytesfilezv2/document)r?   filesdocument_idr_   document_key)	r   rP   rQ   bytesr*   rZ   rt   r   r   )r2   r   rv   rw   r}   r\   r   r   r   r   r   rF   r@   s                r3   r   $Translator.translate_document_uploadu  s    @ 99i
 ,9) "nsEl33   h78E^,E $ !/ !
 	v5DHH]B'.")E
 	
r6   r   c                 B   SUR                   0nSUR                   3nU R                  X2S9u  pEnU R                  XEU5        U(       a'  [	        U[
        5      (       a  UR                  SS5      OSnU(       d  [        SU5      eU(       a'  [	        U[
        5      (       a  UR                  SS5      OSnU(       a'  [	        U[
        5      (       a  UR                  SS5      OSn	U(       a'  [	        U[
        5      (       a  UR                  S	S5      OSn
[        XxX5      $ )
aJ  Gets the status of the document translation request associated with
 given handle.

:param handle: DocumentHandle to the request to check.
:return: DocumentStatus containing the request status.

:raises DocumentTranslationException: If an error occurs during
    querying the document, the exception includes the document handle.
r   v2/document/r   r   Nz/Querying document status gave an empty responseseconds_remainingbilled_charactersr   )	r   r   rZ   rt   rP   rL   r   r   r   )r2   r   r?   rB   rE   rF   r@   r   r   r   r   s              r3   translate_document_get_status(Translator.translate_document_get_status  s     3 34V//01%)^^C^%C"d{T: D$// HHXt$ 	
 .A6 
 D$// HH($/ 	 D$// HH($/ 	 D$// HH_d+ 	
 '8
 	
r6   c                 <   U R                  U5      nUR                  (       ay  UR                  (       dh  Sn[        R                  " SUS S35        [
        R                  " U5        U R                  U5      nUR                  (       a  UR                  (       d  Mh  U$ )aX  
Continually polls the status of the document translation associated
with the given handle, sleeping in between requests, and returns the
final status when the translation completes (whether successful or
not).

:param handle: DocumentHandle to the document translation to wait on.
:return: DocumentStatus containing the status when completed.
g      @z:Rechecking document translation status after sleeping for z.3fz	 seconds.)r   r   doner   rJ   timesleep)r2   r   r   secss       r3   r   -Translator.translate_document_wait_until_done  s{     33F;iiDMM&&*3Zy: JJt77?F ii r6   output_file
chunk_sizec                 0   SUR                   0nSUR                   S3nU R                  XTSS9u  pgn[        U[        R
                  5      (       d   eU R                  USUSS9  U(       a*  UR                  US9n	U	 H  n
UR                  U
5        M     g	U$ )
a  Downloads the translated document for the request associated with
given handle and returns a response object for streaming the data. Call
iter_content() on the response object to read streamed file data.
Alternatively, a file-like object may be given as output_file where the
complete file will be downloaded and written to.

:param handle: DocumentHandle associated with request.
:param output_file: (Optional) File-like object to store downloaded
    document. If not provided, use iter_content() on the returned
    response object to read streamed file data.
:param chunk_size: (Optional) Size of chunk in bytes for streaming.
    Only used if output_file is specified.
:return: None if output_file is specified, otherwise the
    requests.Response will be returned.
r   r   z/resultT)r@   rA   z<file>)r]   )r   N)	r   r   rZ   rP   requestsResponsert   iter_contentwrite)r2   r   r   r   r?   rB   rE   responser@   chunkschunks              r3   r   &Translator.translate_document_download  s    ,  3 34V//08&*nn4 '5 '
#t (H$5$566664d 	 	
 **j*AF!!%(  Or6   c                     U R                  SSS9u  p#nU R                  X#U5        U(       a  [        U[        5      (       a  UO/ nU Vs/ s H  n[	        US   US   5      PM     sn$ s  snf )a  Request the list of available source languages.

:param skip_cache: Deprecated, and now has no effect as the
    corresponding internal functionality has been removed. This
    parameter will be removed in a future version.
:return: List of supported source languages.
v2/languagesGETr>   languager   )rZ   rt   rP   r   r   )r2   
skip_cacher   rF   r@   	languagesr  s          r3   get_source_languagesTranslator.get_source_languages'  s     !%~e Lv5!jt&<&<D2	 &

 &	 $  &
 	
 
s   
A)c                    SS0nU R                  SSUS9u  p4nU R                  X4U5        U(       a  [        U[        5      (       a  UO/ nU Vs/ s H&  n[	        US   US   UR                  SS	5      5      PM(     sn$ s  snf )
a  Request the list of available target languages.

:param skip_cache: Deprecated, and now has no effect as the
    corresponding internal functionality has been removed. This
    parameter will be removed in a future version.
:return: List of supported target languages.
typetargetr   r   )r>   r?   r  r   supports_formalityN)rZ   rt   rP   r   r   r   )r2   r  r?   r   rF   r@   r  r  s           r3   get_target_languagesTranslator.get_target_languages:  s     ! $5t !/ !
 	v5!jt&<&<D2	 &
 & $ 148
 &
 	
 
s   -A?c                     U R                  SSS9u  pnU R                  XU5        U(       a'  [        U[        5      (       a  UR	                  S/ 5      O/ nU Vs/ s H  n[        US   US   5      PM     sn$ s  snf )z<Request the list of language pairs supported for glossaries.zv2/glossary-language-pairsr   r  supported_languagesrv   rw   )rZ   rt   rP   rL   r   r   )r2   r   rF   r@   r  language_pairs         r3   get_glossary_languages!Translator.get_glossary_languagesQ  s     $( !/ !
 	v5 D$// HH*B/ 	 "5	
 "5 !m,mM.J "5	
 	
 
s   A9c                     U R                  SSS9u  pnU R                  XU5        [        U[        5      (       d  0 n[	        U5      $ )zRequests the current API usage.zv2/usager   r  )rZ   rt   rP   rL   r   )r2   r   rF   r@   s       r3   	get_usageTranslator.get_usagee  sE     $z% Hv5$%%DT{r6   c           	      x    U(       d  [        S5      eU R                  UUUS[        R                  " U5      5      $ )a  Creates a glossary with given name for the source and target
languages, containing the entries in dictionary. The glossary may be
used in the translate_text functions.

Only certain language pairs are supported. The available language pairs
can be queried using get_glossary_languages(). Glossaries are not
regional specific: a glossary with target language EN may be used to
translate texts into both EN-US and EN-GB.

This function requires the glossary entries to be provided as a
dictionary of source-target terms. To create a glossary from a CSV file
downloaded from the DeepL website, see create_glossary_from_csv().

:param name: user-defined name to attach to glossary.
:param source_lang: Language of source terms.
:param target_lang: Language of target terms.
:param entries: dictionary of terms to insert in glossary, with the
    keys and values representing source and target terms respectively.
:return: GlossaryInfo containing information about created glossary.

:raises ValueError: If the glossary name is empty, or entries are
    empty or invalid.
:raises DeepLException: If source and target language pair are not
    supported for glossaries.
z"glossary entries must not be emptytsv)r*   r   r   convert_dict_to_tsv)r2   r   rv   rw   r   s        r3   create_glossaryTranslator.create_glossaryo  sA    @ ABB$$$$W-
 	
r6   csv_datac                     [        U[        [        45      (       a  UOUR                  5       n[        U[        [        45      (       d  [	        S5      eU R                  XUSU5      $ )a  Creates a glossary with given name for the source and target
languages, containing the entries in the given CSV data.
The glossary may be used in the translate_text functions.

Only certain language pairs are supported. The available language pairs
can be queried using get_glossary_languages(). Glossaries are not
regional specific: a glossary with target language EN may be used to
translate texts into both EN-US and EN-GB.

This function allows you to upload a glossary CSV file that you have
downloaded from the DeepL website.

Information about the expected CSV format can be found in the API
documentation: https://www.deepl.com/docs-api/managing-glossaries/supported-glossary-formats/  # noqa

:param name: user-defined name to attach to glossary.
:param source_lang: Language of source terms.
:param target_lang: Language of target terms.
:param csv_data: CSV data containing glossary entries, either as a
    file-like object or string or bytes containing file content.
:return: GlossaryInfo containing information about created glossary.

:raises ValueError: If the glossary name is empty, or entries are
    empty or invalid.
:raises DeepLException: If source and target language pair are not
    supported for glossaries.
z#Entries of the glossary are invalidcsv)rP   rQ   r   readr*   r   )r2   r   rv   rw   r  r   s         r3   create_glossary_from_csv#Translator.create_glossary_from_csv  s`    H #8c5\::H 	 'E3<00BCC$${E7
 	
r6   r   c                 |    U R                  SU 3SS9u  p#nU R                  X#USS9  [        R                  " U5      $ )zRetrieves GlossaryInfo for the glossary with specified ID.

:param glossary_id: ID of glossary to retrieve.
:return: GlossaryInfo with information about specified glossary.
:raises GlossaryNotFoundException: If no glossary with given ID is
    found.
v2/glossaries/r   r  Tr   )rZ   rt   r   r   )r2   r   r   rF   r@   s        r3   get_glossaryTranslator.get_glossary  sP     !%[M*5 !/ !
 	vtD%%d++r6   c                    U R                  SSS9u  pnU R                  XUSS9  U(       a'  [        U[        5      (       a  UR	                  S/ 5      O/ nU Vs/ s H  n[
        R                  " U5      PM     sn$ s  snf )zrRetrieves GlossaryInfo for all available glossaries.

:return: list of GlossaryInfo for all available glossaries.
r   r   r  Tr   
glossaries)rZ   rt   rP   rL   r   r   r   )r2   r   rF   r@   r%  r\   s         r3   list_glossariesTranslator.list_glossaries  s    
 !%u MvtD D$// HH\2& 	
 BLLX&&x0LLLs    A<c                 
   [        U[        5      (       a  UR                  nOUnU R                  SU S3SSS0S9u  p4nU R	                  X4USS9  [        U[
        5      (       d
  [        S	US
9e[        R                  " U5      $ )a_  Retrieves the entries of the specified glossary and returns them as
a dictionary.

:param glossary: GlossaryInfo or ID of glossary to retrieve.
:return: dictionary of glossary entries.
:raises GlossaryNotFoundException: If no glossary with given ID is
    found.
:raises DeepLException: If the glossary could not be retrieved
    in the right format.
r!  z/entriesr   Acceptztext/tab-separated-values)r>   r1   Tr   z.Could not get the glossary content as a stringrc   )	rP   r   r   rZ   rt   rQ   r   r   convert_tsv_to_dictr2   r\   r   r   rF   r@   s         r3   get_glossary_entriesTranslator.get_glossary_entries  s     h--"..K"K $[M2:; !/ !

 	vtD'3'' @!'  ''00r6   c                     [        U[        5      (       a  UR                  nOUnU R                  SU 3SS9u  p4nU R	                  X4USS9  g)zDeletes specified glossary.

:param glossary: GlossaryInfo or ID of glossary to delete.
:raises GlossaryNotFoundException: If no glossary with given ID is
    found.
r!  DELETEr  Tr   N)rP   r   r   rZ   rt   r+  s         r3   delete_glossaryTranslator.delete_glossary   s]     h--"..K"K $[M* !/ !
 	vtDr6   )r0   r.   r1   )FFr8   )Nr   )F)B__name__
__module____qualname____firstlineno____doc__r-   r,   rl   rQ   r   r   r   r   r4   r;   rL   r   intr   r   r   rZ   rt   r{   r   r   r   r   r   r   r9   r   propertyr"   r   r	   r   r
   r   r   DEFAULTr   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r  r   r  r  r  r"  r&  r,  r0  __static_attributes__ r6   r3   r    r    /   s   4 09 #& %)(,#'-1$)GG SM	G
 T3_%G !G $T/*G "G4 ##"&6*6* 	6*
 tn6* tn6* 6* $6* 
sE#x000136	76*z %*HH sH---.H 	H
 H #HT#C=7:( 48$3$./$ 3=)$ i-.	$
 \4/0$ 
$L,, 3=), 3=)	,
 , sEz", 
,:!#       37!%<@.21537&*,0:>6:37A4C#&'A4 3$./	A4
 3=)A4 #A4 sND89A4 &d^A4 i-.A4 \4/0A4 smA4 $D>A4 "#tCy$"67A4 c49d23A4 3S	4/0A4  
z4
++	,!A4N 37	-
C#&'-
 -
 3$./	-
 
z4
++	,-
h &*+4+<+<373#w///03 3 0 0013
 c]3 3 i(3 \4/03 
3t &*+4+<+<37"&'+>fh34> vx45>
 c]> > i(> \4/0> 3->  }> 
>H &*1537"&'+9
fhUC?@9
 c]	9

 9
 i-.9
 \4/09
 3-9
  }9
 
9
v.
$.
	.
`$	6 ;?	-- 68S$67- 	-
 
(##	$-^
X 
&
X 
.
-A(B 
(5 )
)
 3=))
 3=)	)

 c3h)
 
)
V+
+
 3=)+
 3=)	+

 #uc9:+
 
+
Z, , ,Ml!3 M1U33D-E 1$ 1:Ec<.?(@ ET Er6   r    )*deepl.api_datar   r   r   r   r   r   r	   r
   r   r_   r   r   
exceptionsr   r   r   r   r   r   r   ri   http.clientr@   rR   r   r   r   r   typingr   r   r   r   r   r   r   r   r   urllib.parserG   r    r;  r6   r3   <module>rA     sa   

 
 
        	   
 
 
 aE aEr6   