You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Add UNARY convert; improve 2.1 imports
This commit is contained in:
BIN
test/bytecode_2.7/02_unary_convert.pyc
Normal file
BIN
test/bytecode_2.7/02_unary_convert.pyc
Normal file
Binary file not shown.
2
test/simple_source/bug25/02_unary_convert.py
Normal file
2
test/simple_source/bug25/02_unary_convert.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# Python 2's deprecated unary convert (akin to "repr()"
|
||||||
|
`abc`
|
@@ -38,6 +38,7 @@ class PythonParser(GenericASTBuilder):
|
|||||||
# Python < 3
|
# Python < 3
|
||||||
'print_items',
|
'print_items',
|
||||||
# PyPy:
|
# PyPy:
|
||||||
|
'imports_cont',
|
||||||
'kvlist_n']
|
'kvlist_n']
|
||||||
self.collect = frozenset(nt_list)
|
self.collect = frozenset(nt_list)
|
||||||
|
|
||||||
|
@@ -302,11 +302,21 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
offset=3, has_arg=True)])
|
offset=3, has_arg=True)])
|
||||||
])])
|
])])
|
||||||
pass
|
pass
|
||||||
if version <= 2.3:
|
if version <= 2.3:
|
||||||
TABLE_DIRECT.update({
|
TABLE_DIRECT.update({
|
||||||
'tryfinallystmt': ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n', 1, 4 )
|
'tryfinallystmt': ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n', 1, 4 )
|
||||||
})
|
})
|
||||||
|
if version <= 2.1:
|
||||||
|
TABLE_DIRECT.update({
|
||||||
|
'importmultiple': ( '%c', 2 ),
|
||||||
|
'imports_cont': ( '%c', 2 ),
|
||||||
|
# FIXME: not quite right. We have indiividual imports
|
||||||
|
# when there is in fact one: "import a, b, ..."
|
||||||
|
'imports_cont': ( '%C%,', (1, 100, '\n') ),
|
||||||
|
})
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
pass
|
||||||
elif version >= 2.5:
|
elif version >= 2.5:
|
||||||
########################
|
########################
|
||||||
# Import style for 2.5+
|
# Import style for 2.5+
|
||||||
@@ -980,6 +990,20 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
self.prune()
|
self.prune()
|
||||||
|
|
||||||
def n_import_as(self, node):
|
def n_import_as(self, node):
|
||||||
|
if self.version <= 2.1:
|
||||||
|
if len(node) == 2:
|
||||||
|
designator = node[1]
|
||||||
|
assert designator == 'designator'
|
||||||
|
if designator[0].pattr == node[0].pattr:
|
||||||
|
self.write("import %s\n" % node[0].pattr)
|
||||||
|
else:
|
||||||
|
self.write("import %s as %s\n" %
|
||||||
|
(node[0].pattr, designator[0].pattr))
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
self.prune() # stop recursing
|
||||||
|
|
||||||
|
|
||||||
store_node = node[-1][-1]
|
store_node = node[-1][-1]
|
||||||
assert store_node.kind.startswith('STORE_')
|
assert store_node.kind.startswith('STORE_')
|
||||||
iname = node[0].pattr # import name
|
iname = node[0].pattr # import name
|
||||||
|
Reference in New Issue
Block a user