diff --git a/test/bytecode_2.4/02_unary_convert.pyc b/test/bytecode_2.4/02_unary_convert.pyc new file mode 100644 index 00000000..1cc0de2c Binary files /dev/null and b/test/bytecode_2.4/02_unary_convert.pyc differ diff --git a/test/bytecode_2.7/02_unary_convert.pyc b/test/bytecode_2.7/02_unary_convert.pyc new file mode 100644 index 00000000..27fd86d5 Binary files /dev/null and b/test/bytecode_2.7/02_unary_convert.pyc differ diff --git a/test/simple_source/bug25/02_unary_convert.py b/test/simple_source/bug25/02_unary_convert.py new file mode 100644 index 00000000..9aca355e --- /dev/null +++ b/test/simple_source/bug25/02_unary_convert.py @@ -0,0 +1,2 @@ +# Python 2's deprecated unary convert (akin to "repr()" +`abc` diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index 6c160ec3..7b84858e 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -36,6 +36,7 @@ class PythonParser(GenericASTBuilder): # Python < 3 'print_items', # PyPy: + 'imports_cont', 'kvlist_n'] self.collect = frozenset(nt_list) diff --git a/uncompyle6/parsers/parse33.py b/uncompyle6/parsers/parse33.py index d4a8e1ad..89ba40e1 100644 --- a/uncompyle6/parsers/parse33.py +++ b/uncompyle6/parsers/parse33.py @@ -33,7 +33,6 @@ class Python33Parser(Python32Parser): self.remove_rules(""" # 3.3+ adds POP_BLOCKS whileTruestmt ::= SETUP_LOOP l_stmts JUMP_ABSOLUTE JUMP_BACK COME_FROM_LOOP - whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK COME_FROM_LOOP whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK NOP COME_FROM_LOOP whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK NOP COME_FROM_LOOP whilestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 00992811..723812dd 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -300,11 +300,21 @@ class SourceWalker(GenericASTTraversal, object): offset=3, has_arg=True)]) ])]) pass - if version <= 2.3: - TABLE_DIRECT.update({ - 'tryfinallystmt': ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n', 1, 4 ) - }) - + if version <= 2.3: + TABLE_DIRECT.update({ + '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: ######################## # Import style for 2.5+ @@ -978,6 +988,20 @@ class SourceWalker(GenericASTTraversal, object): self.prune() 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] assert store_node.kind.startswith('STORE_') iname = node[0].pattr # import name