Files
old-nlp/venv/lib/python3.7/site-packages/googletrans/__pycache__/client.cpython-37.pyc

145 lines
8.5 KiB
Plaintext
Raw Normal View History

2019-10-20 13:16:49 +02:00
B
Z'<27>]p'<00>@s<>dZddlZddlZddlmZmZddlmZddlm Z ddl
m Z ddl m Z mZmZmZddlmZmZd ZGd
d <0B>d e<15>ZdS) zB
A Translation module.
You can translate text using this module.
<EFBFBD>N)<02>urls<6C>utils)<01>TimeoutAdapter)<01>PY3)<01> TokenAcquirer)<04>DEFAULT_USER_AGENT<4E> LANGCODES<45> LANGUAGES<45> SPECIAL_CASES)<02>
Translated<EFBFBD>Detected)<03>en<65>ca<63>frc@sLeZdZdZdeddfdd<04>Zdd<06>Zdd<08>Zd d
<EFBFBD>Zdd d<0E>Z dd<10>Z
dS)<12>
TranslatoranGoogle Translate ajax API implementation class
You have to create an instance of Translator to use this API
:param service_urls: google translate url list. URLs will be used randomly.
For example ``['translate.google.com', 'translate.google.co.kr']``
:type service_urls: a sequence of strings
:param user_agent: the User-Agent header to send when making requests.
:type user_agent: :class:`str`
:param proxies: proxies configuration.
Dictionary mapping protocol or protocol and host to the URL of the proxy
For example ``{'http': 'foo.bar:3128', 'http://host.name': 'foo.bar:4012'}``
:type proxies: dictionary
:param timeout: Definition of timeout for Requests library.
Will be used by every request.
:type timeout: number or a double of numbers
NcCs<>t<00><01>|_|dk r||j_|jj<04>d|i<01>|dk rX|j<02>dt|<04><01>|j<02>dt|<04><01>|p`dg|_t |j|jdd<06>|_
y"ddl m }|j<02>t j|<05><00>Wntk
r<EFBFBD>YnXdS)Nz
User-Agentzhttps://zhttp://ztranslate.google.comr)<02>session<6F>host)<01> HTTP20Adapter)<10>requests<74>Sessionr<00>proxies<65>headers<72>update<74>mountr<00> service_urlsr<00>token_acquirerZ hyper.contribrrZBASE<53> ImportError)<06>selfr<00>
user_agentr<00>timeoutr<00>r <00>;/tmp/pip-install-irokppfq/googletrans/googletrans/client.py<70>__init__+s

  zTranslator.__init__cCs$t|j<01>dkr|jdSt<02>|j<01>S)N<>r)<04>lenr<00>random<6F>choice)rr r r!<00>_pick_service_urlBs
zTranslator._pick_service_urlc Cshtst|t<02>r|<01>d<01>}|j<04>|<01>}tj||||d<02>}tj j
|<00> <0B>d<03>}|j j ||d<04>}t<06>|j<0F>}|S)Nzutf-8)<04>query<72>src<72>dest<73>token)r)<01>params)r<00>
isinstance<EFBFBD>str<74>decoderZdorZ build_paramsrZ TRANSLATE<54>formatr'r<00>getZ format_json<6F>text) rr2r*r)r+r,<00>url<72>r<>datar r r!<00>
_translateGs
 
 zTranslator._translatec Cs^ddddddddd d
d d <0C> }i}x8|<02><00>D],\}}|t|<01>krN||rN||nd||<q*W|S) N<> translationzall-translationszoriginal-languagezpossible-translations<6E>
confidencezpossible-mistakes<65>languageZsynonymsZ definitionsZexampleszsee-also) rr#<00><00><00><00><00><00> <00> <00> <00>)<02>itemsr$)rr5Zresponse_parts_name_mapping<6E>extra<72>index<65>categoryr r r!<00>_parse_extra_dataTs(zTranslator._parse_extra_datar <00>autoc Cs<>|<02><00><00>dd<02>d}|<03><00><00>dd<02>d}|dkrd|tkrd|tkrJt|}n|tkr\t|}ntd<05><01>|tkr<>|tkr~t|}n|tkr<>t|}ntd<06><01>t|t<07>r<>g}x&|D]}|j|||d<07>}|<04> |<06>q<>W|S|}|<00>
|||<03>}d<08> d d
<EFBFBD>|dD<00><01>}|<00> |<08>} y |d }Wnt k
<EFBFBD>r(YnX|}
y|ddd }
Wnt k
<EFBFBD>rXYnXt<0E>s<>t|
t<0F><02>r<>t|t<10><02>r<>|<07>d <0A>}|tk<06>r<>|
|k<02>r<>|}
t<0E>s<>t|t<10><02>r<>|<03>d <0A>}t|t<10><02>r<>|<02>d <0A>}t|t<10><02>r<>|<06>d <0A>}t|||||
| d<0E>}|S)uSTranslate text from source language to destination language
:param text: The source text(s) to be translated. Batch translation is supported via sequence input.
:type text: UTF-8 :class:`str`; :class:`unicode`; string sequence (list, tuple, iterator, generator)
:param dest: The language to translate the source text into.
The value should be one of the language codes listed in :const:`googletrans.LANGUAGES`
or one of the language names listed in :const:`googletrans.LANGCODES`.
:param dest: :class:`str`; :class:`unicode`
:param src: The language of the source text.
The value should be one of the language codes listed in :const:`googletrans.LANGUAGES`
or one of the language names listed in :const:`googletrans.LANGCODES`.
If a language is not specified,
the system will attempt to identify the source language automatically.
:param src: :class:`str`; :class:`unicode`
:rtype: Translated
:rtype: :class:`list` (when a list is passed)
Basic usage:
>>> from googletrans import Translator
>>> translator = Translator()
>>> translator.translate('안녕하세요.')
<Translated src=ko dest=en text=Good evening. pronunciation=Good evening.>
>>> translator.translate('안녕하세요.', dest='ja')
<Translated src=ko dest=ja text=こんにちは。 pronunciation=Kon'nichiwa.>
>>> translator.translate('veritas lux mea', src='la')
<Translated src=la dest=en text=The truth is my light pronunciation=The truth is my light>
Advanced usage:
>>> translations = translator.translate(['The quick brown fox', 'jumps over', 'the lazy dog'], dest='ko')
>>> for translation in translations:
... print(translation.origin, ' -> ', translation.text)
The quick brown fox -> 빠른 갈색 여우
jumps over -> 이상 점프
the lazy dog -> 게으른 개
<20>_r#rrHzinvalid source languagezinvalid destination language)r*r)<00>cSs g|]}|dr|dnd<01>qS)rrJr )<02>.0<EFBFBD>dr r r!<00>
<listcomp><3E>sz(Translator.translate.<locals>.<listcomp>r:<00><><EFBFBD><EFBFBD><EFBFBD>zutf-8)r)r*<00>originr2Z pronunciation<6F>
extra_data)<14>lower<65>splitr r
r<00>
ValueErrorr-<00>list<73> translate<74>appendr6<00>joinrG<00> Exceptionr<00>unicoder.r/<00>EXCLUDESr ) rr2r*r)<00>result<6C>itemZ
translatedrOr5rPZpronr r r!rUjs^'






 
 
 
 
 zTranslator.translatecCs<>t|t<01>r4g}x |D]}|<00>|<03>}|<02>|<04>qW|S|j|ddd<03>}d}d}y&d<04>|dd<00>}|ddd}Wntk
r<EFBFBD>YnXt||d <09>}|S)
u1Detect language of the input text
:param text: The source text(s) whose language you want to identify.
Batch detection is supported via sequence input.
:type text: UTF-8 :class:`str`; :class:`unicode`; string sequence (list, tuple, iterator, generator)
:rtype: Detected
:rtype: :class:`list` (when a list is passed)
Basic usage:
>>> from googletrans import Translator
>>> translator = Translator()
>>> translator.detect('이 문장은 한글로 쓰여졌습니다.')
<Detected lang=ko confidence=0.27041003>
>>> translator.detect('この文章は日本語で書かれました。')
<Detected lang=ja confidence=0.64889508>
>>> translator.detect('This sentence is written in English.')
<Detected lang=en confidence=0.22348526>
>>> translator.detect('Tiu frazo estas skribita en Esperanto.')
<Detected lang=eo confidence=0.10538048>
Advanced usage:
>>> langs = translator.detect(['한국어', '日本語', 'English', 'le français'])
>>> for lang in langs:
... print(lang.lang, lang.confidence)
ko 1
ja 0.92929292
en 0.96954316
fr 0.043500196
r rH)r*r)rJgr>rrN)<02>langr8)r-rT<00>detectrVr6rWrXr )rr2r[r\r]r5r)r8r r r!r^<00>s 


 zTranslator.detect)r rH) <0B>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__rr"r'r6rGrUr^r r r r!rs 
ir)rbrr%Z googletransrrZgoogletrans.adaptersrZgoogletrans.compatrZgoogletrans.gtokenrZgoogletrans.constantsrrr r
Zgoogletrans.modelsr r rZ<00>objectrr r r r!<00><module>s