PEP8
This commit is contained in:
parent
791e32a23b
commit
dda50305b7
@ -33,21 +33,24 @@ class Translator(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def _translate(self, text, dest='en', src='auto'):
|
def _translate(self, text, dest='en', src='auto'):
|
||||||
if src != 'auto' and src not in LANGUAGES.keys() and src in SPECIAL_CASES.keys():
|
if src != 'auto':
|
||||||
src = SPECIAL_CASES[src]
|
if src not in LANGUAGES.keys() and src in SPECIAL_CASES.keys():
|
||||||
elif src != 'auto' and src not in LANGUAGES.keys():
|
src = SPECIAL_CASES[src]
|
||||||
raise ValueError('invalid source language')
|
elif src not in LANGUAGES.keys():
|
||||||
|
raise ValueError('invalid source language')
|
||||||
|
|
||||||
if dest not in LANGUAGES.keys() and dest in SPECIAL_CASES.keys():
|
if dest not in LANGUAGES.keys():
|
||||||
dest = SPECIAL_CASES[dest]
|
if dest in SPECIAL_CASES.keys():
|
||||||
elif dest not in LANGUAGES.keys():
|
dest = SPECIAL_CASES[dest]
|
||||||
raise ValueError('invalid destination language')
|
else:
|
||||||
|
raise ValueError('invalid destination language')
|
||||||
|
|
||||||
if not PY3 and isinstance(text, str): # pragma: nocover
|
if not PY3 and isinstance(text, str): # pragma: nocover
|
||||||
text = text.decode('utf-8')
|
text = text.decode('utf-8')
|
||||||
|
|
||||||
token = self.token_acquirer.do(text)
|
token = self.token_acquirer.do(text)
|
||||||
params = utils.build_params(query=text, src=src, dest=dest, token=token)
|
params = utils.build_params(query=text, src=src, dest=dest,
|
||||||
|
token=token)
|
||||||
r = self.session.get(urls.TRANSLATE, params=params)
|
r = self.session.get(urls.TRANSLATE, params=params)
|
||||||
|
|
||||||
data = utils.format_json(r.text)
|
data = utils.format_json(r.text)
|
||||||
|
@ -39,7 +39,8 @@ class TokenAcquirer(object):
|
|||||||
950629.577246
|
950629.577246
|
||||||
"""
|
"""
|
||||||
|
|
||||||
RE_TKK = re.compile(r'TKK=eval\(\'\(\(function\(\)\{(.+?)\}\)\(\)\)\'\);', re.DOTALL)
|
RE_TKK = re.compile(r'TKK=eval\(\'\(\(function\(\)\{(.+?)\}\)\(\)\)\'\);',
|
||||||
|
re.DOTALL)
|
||||||
|
|
||||||
def __init__(self, tkk='0', session=None):
|
def __init__(self, tkk='0', session=None):
|
||||||
self.session = session or requests.Session()
|
self.session = session or requests.Session()
|
||||||
@ -96,7 +97,8 @@ class TokenAcquirer(object):
|
|||||||
elif isinstance(node, ast.BitXor): # pragma: nocover
|
elif isinstance(node, ast.BitXor): # pragma: nocover
|
||||||
operator = '^'
|
operator = '^'
|
||||||
# a safety way to avoid Exceptions
|
# a safety way to avoid Exceptions
|
||||||
clause = compile('{1}{0}{2}'.format(operator, keys['a'], keys['b']), '', 'eval')
|
clause = compile('{1}{0}{2}'.format(
|
||||||
|
operator, keys['a'], keys['b']), '', 'eval')
|
||||||
value = eval(clause, dict(__builtin__={}))
|
value = eval(clause, dict(__builtin__={}))
|
||||||
result = '{}.{}'.format(n, value)
|
result = '{}.{}'.format(n, value)
|
||||||
|
|
||||||
@ -150,7 +152,8 @@ class TokenAcquirer(object):
|
|||||||
elif l < 2048:
|
elif l < 2048:
|
||||||
e.append(l >> 6 | 192)
|
e.append(l >> 6 | 192)
|
||||||
# append calculated value if l matches special condition
|
# append calculated value if l matches special condition
|
||||||
elif (l & 64512) == 55296 and g + 1 < size and ord(text[g + 1]) & 64512 == 56320:
|
elif (l & 64512) == 55296 and g + 1 < size and \
|
||||||
|
ord(text[g + 1]) & 64512 == 56320:
|
||||||
g += 1
|
g += 1
|
||||||
l = 65536 + ((l & 1023) << 10) + ord(text[g]) & 1023
|
l = 65536 + ((l & 1023) << 10) + ord(text[g]) & 1023
|
||||||
e.append(l >> 18 | 240)
|
e.append(l >> 18 | 240)
|
||||||
|
Loading…
Reference in New Issue
Block a user