You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 09:22:40 +08:00
Merge branch 'master' into python-2.4
This commit is contained in:
BIN
test/bytecode_3.5/02_async.pyc
Normal file
BIN
test/bytecode_3.5/02_async.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.7/02_async.pyc
Normal file
BIN
test/bytecode_3.7/02_async.pyc
Normal file
Binary file not shown.
17
test/simple_source/bug35/02_async.py
Normal file
17
test/simple_source/bug35/02_async.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# From 3.7.3 asyncio/base_events.py
|
||||||
|
# We had (still have) screwy logic. Python 3.5 code node detection was off too.
|
||||||
|
|
||||||
|
async def create_connection(self):
|
||||||
|
infos = await self._ensure_resolved()
|
||||||
|
|
||||||
|
laddr_infos = await self._ensure_resolved()
|
||||||
|
for family in infos:
|
||||||
|
for laddr in laddr_infos:
|
||||||
|
family = 1
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
await self.sock_connect()
|
||||||
|
else:
|
||||||
|
raise OSError('Multiple exceptions: {}' for exc in family)
|
||||||
|
|
||||||
|
return
|
@@ -598,16 +598,9 @@ class Python3Parser(PythonParser):
|
|||||||
|
|
||||||
# Determine if we have an iteration CALL_FUNCTION_1.
|
# Determine if we have an iteration CALL_FUNCTION_1.
|
||||||
has_get_iter_call_function1 = False
|
has_get_iter_call_function1 = False
|
||||||
max_branches = 0
|
|
||||||
for i, token in enumerate(tokens):
|
for i, token in enumerate(tokens):
|
||||||
if token == 'GET_ITER' and i < n-2 and self.call_fn_name(tokens[i+1]) == 'CALL_FUNCTION_1':
|
if token == 'GET_ITER' and i < n-2 and self.call_fn_name(tokens[i+1]) == 'CALL_FUNCTION_1':
|
||||||
has_get_iter_call_function1 = True
|
has_get_iter_call_function1 = True
|
||||||
max_branches += 1
|
|
||||||
elif (token == 'GET_AWAITABLE' and i < n-3
|
|
||||||
and tokens[i+1] == 'LOAD_CONST' and tokens[i+2] == 'YIELD_FROM'):
|
|
||||||
max_branches += 1
|
|
||||||
if max_branches > 2:
|
|
||||||
break
|
|
||||||
|
|
||||||
for i, token in enumerate(tokens):
|
for i, token in enumerate(tokens):
|
||||||
opname = token.kind
|
opname = token.kind
|
||||||
|
@@ -49,11 +49,6 @@ def customize_for_version(self, is_pypy, version):
|
|||||||
5, 6, 7, 0, 1, 2 ),
|
5, 6, 7, 0, 1, 2 ),
|
||||||
})
|
})
|
||||||
if version >= 3.0:
|
if version >= 3.0:
|
||||||
TABLE_DIRECT.update({
|
|
||||||
# Gotta love Python for its futzing around with syntax like this
|
|
||||||
'raise_stmt2': ( '%|raise %c from %c\n', 0, 1),
|
|
||||||
})
|
|
||||||
|
|
||||||
if version >= 3.2:
|
if version >= 3.2:
|
||||||
TABLE_DIRECT.update({
|
TABLE_DIRECT.update({
|
||||||
'del_deref_stmt': ( '%|del %c\n', 0),
|
'del_deref_stmt': ( '%|del %c\n', 0),
|
||||||
|
@@ -31,9 +31,31 @@ def customize_for_version26_27(self, version):
|
|||||||
if version > 2.6:
|
if version > 2.6:
|
||||||
TABLE_DIRECT.update({
|
TABLE_DIRECT.update({
|
||||||
'except_cond2': ( '%|except %c as %c:\n', 1, 5 ),
|
'except_cond2': ( '%|except %c as %c:\n', 1, 5 ),
|
||||||
|
# When a generator is a single parameter of a function,
|
||||||
|
# it doesn't need the surrounding parenethesis.
|
||||||
|
'call_generator': ('%c%P', 0, (1, -1, ', ', 100)),
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
TABLE_DIRECT.update({
|
TABLE_DIRECT.update({
|
||||||
'testtrue_then': ( 'not %p', (0, 22) ),
|
'testtrue_then': ( 'not %p', (0, 22) ),
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def n_call(node):
|
||||||
|
mapping = self._get_mapping(node)
|
||||||
|
key = node
|
||||||
|
for i in mapping[1:]:
|
||||||
|
key = key[i]
|
||||||
|
pass
|
||||||
|
if key.kind == 'CALL_FUNCTION_1':
|
||||||
|
# A function with one argument. If this is a generator,
|
||||||
|
# no parenthesis is needed.
|
||||||
|
args_node = node[-2]
|
||||||
|
if args_node == 'expr':
|
||||||
|
n = args_node[0]
|
||||||
|
if n == 'generator_exp':
|
||||||
|
node.kind = 'call_generator'
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
|
||||||
|
self.default(node)
|
||||||
|
self.n_call = n_call
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
from uncompyle6.semantics.consts import TABLE_DIRECT
|
from uncompyle6.semantics.consts import TABLE_DIRECT
|
||||||
|
|
||||||
from xdis.code import iscode
|
from xdis.code import iscode
|
||||||
|
from uncompyle6.semantics.helper import gen_function_parens_adjust
|
||||||
from uncompyle6.semantics.make_function import make_function3_annotate
|
from uncompyle6.semantics.make_function import make_function3_annotate
|
||||||
from uncompyle6.semantics.customize35 import customize_for_version35
|
from uncompyle6.semantics.customize35 import customize_for_version35
|
||||||
from uncompyle6.semantics.customize36 import customize_for_version36
|
from uncompyle6.semantics.customize36 import customize_for_version36
|
||||||
@@ -33,8 +34,14 @@ def customize_for_version3(self, version):
|
|||||||
(2, 'expr') , (0, 'expr'), (4, 'expr') ),
|
(2, 'expr') , (0, 'expr'), (4, 'expr') ),
|
||||||
'except_cond2' : ( '%|except %c as %c:\n', 1, 5 ),
|
'except_cond2' : ( '%|except %c as %c:\n', 1, 5 ),
|
||||||
'function_def_annotate': ( '\n\n%|def %c%c\n', -1, 0),
|
'function_def_annotate': ( '\n\n%|def %c%c\n', -1, 0),
|
||||||
|
|
||||||
|
# When a generator is a single parameter of a function,
|
||||||
|
# it doesn't need the surrounding parenethesis.
|
||||||
|
'call_generator' : ('%c%P', 0, (1, -1, ', ', 100)),
|
||||||
|
|
||||||
'importmultiple' : ( '%|import %c%c\n', 2, 3 ),
|
'importmultiple' : ( '%|import %c%c\n', 2, 3 ),
|
||||||
'import_cont' : ( ', %c', 2 ),
|
'import_cont' : ( ', %c', 2 ),
|
||||||
|
'raise_stmt2' : ( '%|raise %c from %c\n', 0, 1),
|
||||||
'store_locals' : ( '%|# inspect.currentframe().f_locals = __locals__\n', ),
|
'store_locals' : ( '%|# inspect.currentframe().f_locals = __locals__\n', ),
|
||||||
'withstmt' : ( '%|with %c:\n%+%c%-', 0, 3),
|
'withstmt' : ( '%|with %c:\n%+%c%-', 0, 3),
|
||||||
'withasstmt' : ( '%|with %c as (%c):\n%+%c%-', 0, 2, 3),
|
'withasstmt' : ( '%|with %c as (%c):\n%+%c%-', 0, 2, 3),
|
||||||
@@ -195,7 +202,9 @@ def customize_for_version3(self, version):
|
|||||||
self.n_yield_from = n_yield_from
|
self.n_yield_from = n_yield_from
|
||||||
|
|
||||||
if 3.2 <= version <= 3.4:
|
if 3.2 <= version <= 3.4:
|
||||||
|
|
||||||
def n_call(node):
|
def n_call(node):
|
||||||
|
|
||||||
mapping = self._get_mapping(node)
|
mapping = self._get_mapping(node)
|
||||||
key = node
|
key = node
|
||||||
for i in mapping[1:]:
|
for i in mapping[1:]:
|
||||||
@@ -227,11 +236,22 @@ def customize_for_version3(self, version):
|
|||||||
-2, (-2-kwargs, -2, ', '))
|
-2, (-2-kwargs, -2, ', '))
|
||||||
self.template_engine(template, node)
|
self.template_engine(template, node)
|
||||||
self.prune()
|
self.prune()
|
||||||
|
else:
|
||||||
|
gen_function_parens_adjust(key, node)
|
||||||
|
self.default(node)
|
||||||
|
|
||||||
|
self.n_call = n_call
|
||||||
|
elif version < 3.2:
|
||||||
|
def n_call(node):
|
||||||
|
mapping = self._get_mapping(node)
|
||||||
|
key = node
|
||||||
|
for i in mapping[1:]:
|
||||||
|
key = key[i]
|
||||||
|
pass
|
||||||
|
gen_function_parens_adjust(key, node)
|
||||||
self.default(node)
|
self.default(node)
|
||||||
self.n_call = n_call
|
self.n_call = n_call
|
||||||
|
|
||||||
|
|
||||||
def n_mkfunc_annotate(node):
|
def n_mkfunc_annotate(node):
|
||||||
|
|
||||||
if self.version >= 3.3 or node[-2] == 'kwargs':
|
if self.version >= 3.3 or node[-2] == 'kwargs':
|
||||||
|
@@ -19,7 +19,8 @@ from xdis.code import iscode
|
|||||||
from xdis.util import COMPILER_FLAG_BIT
|
from xdis.util import COMPILER_FLAG_BIT
|
||||||
from uncompyle6.semantics.consts import (
|
from uncompyle6.semantics.consts import (
|
||||||
INDENT_PER_LEVEL, TABLE_DIRECT)
|
INDENT_PER_LEVEL, TABLE_DIRECT)
|
||||||
from uncompyle6.semantics.helper import flatten_list
|
from uncompyle6.semantics.helper import (
|
||||||
|
flatten_list, gen_function_parens_adjust)
|
||||||
|
|
||||||
#######################
|
#######################
|
||||||
# Python 3.5+ Changes #
|
# Python 3.5+ Changes #
|
||||||
@@ -112,23 +113,21 @@ def customize_for_version35(self, version):
|
|||||||
template = ('*%c)', nargs+1)
|
template = ('*%c)', nargs+1)
|
||||||
self.template_engine(template, node)
|
self.template_engine(template, node)
|
||||||
self.prune()
|
self.prune()
|
||||||
|
else:
|
||||||
|
gen_function_parens_adjust(key, node)
|
||||||
|
|
||||||
self.default(node)
|
self.default(node)
|
||||||
self.n_call = n_call
|
self.n_call = n_call
|
||||||
|
|
||||||
def n_function_def(node):
|
def n_function_def(node):
|
||||||
if self.version >= 3.6:
|
n0 = node[0]
|
||||||
code_node = node[0][0]
|
is_code = False
|
||||||
for n in node[0]:
|
for i in list(range(len(n0)-2, -1, -1)):
|
||||||
if hasattr(n, 'attr') and iscode(n.attr):
|
code_node = n0[i]
|
||||||
code_node = n
|
if hasattr(code_node, 'attr') and iscode(code_node.attr):
|
||||||
break
|
is_code = True
|
||||||
pass
|
break
|
||||||
pass
|
|
||||||
else:
|
|
||||||
code_node = node[0][1]
|
|
||||||
|
|
||||||
is_code = hasattr(code_node, 'attr') and iscode(code_node.attr)
|
|
||||||
if (is_code and
|
if (is_code and
|
||||||
(code_node.attr.co_flags & COMPILER_FLAG_BIT['COROUTINE'])):
|
(code_node.attr.co_flags & COMPILER_FLAG_BIT['COROUTINE'])):
|
||||||
self.template_engine(('\n\n%|async def %c\n',
|
self.template_engine(('\n\n%|async def %c\n',
|
||||||
|
@@ -196,6 +196,26 @@ def flatten_list(node):
|
|||||||
pass
|
pass
|
||||||
return flat_elems
|
return flat_elems
|
||||||
|
|
||||||
|
# Note: this is only used in Python > 3.0
|
||||||
|
# Should move this somewhere more specific?
|
||||||
|
def gen_function_parens_adjust(mapping_key, node):
|
||||||
|
"""If we can avoid the outer parenthesis
|
||||||
|
of a generator function, set the node key to
|
||||||
|
'call_generator' and the caller will do the default
|
||||||
|
action on that. Otherwise we do nothing.
|
||||||
|
"""
|
||||||
|
if mapping_key.kind != 'CALL_FUNCTION_1':
|
||||||
|
return
|
||||||
|
|
||||||
|
args_node = node[-2]
|
||||||
|
if args_node == 'pos_arg':
|
||||||
|
assert args_node[0] == 'expr'
|
||||||
|
n = args_node[0][0]
|
||||||
|
if n == 'generator_exp':
|
||||||
|
node.kind = 'call_generator'
|
||||||
|
pass
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
# if __name__ == '__main__':
|
# if __name__ == '__main__':
|
||||||
# if PYTHON3:
|
# if PYTHON3:
|
||||||
|
Reference in New Issue
Block a user