diff --git a/test/bytecode_2.7/00_pass.pyc b/test/bytecode_2.7/00_pass.pyc new file mode 100644 index 00000000..d19d555f Binary files /dev/null and b/test/bytecode_2.7/00_pass.pyc differ diff --git a/test/bytecode_2.7/01_class.pyc b/test/bytecode_2.7/01_class.pyc index 543da485..f7babcd0 100644 Binary files a/test/bytecode_2.7/01_class.pyc and b/test/bytecode_2.7/01_class.pyc differ diff --git a/test/bytecode_3.4/00_import.pyc b/test/bytecode_3.4/00_import.pyc new file mode 100644 index 00000000..db26ac84 Binary files /dev/null and b/test/bytecode_3.4/00_import.pyc differ diff --git a/test/bytecode_3.4/00_pass.pyc b/test/bytecode_3.4/00_pass.pyc new file mode 100644 index 00000000..bb7c9806 Binary files /dev/null and b/test/bytecode_3.4/00_pass.pyc differ diff --git a/test/bytecode_3.4/01_class.pyc b/test/bytecode_3.4/01_class.pyc index a86f0663..71a91979 100644 Binary files a/test/bytecode_3.4/01_class.pyc and b/test/bytecode_3.4/01_class.pyc differ diff --git a/test/simple_source/simple_stmts/00_import.py b/test/simple_source/simple_stmts/00_import.py new file mode 100644 index 00000000..5c611426 --- /dev/null +++ b/test/simple_source/simple_stmts/00_import.py @@ -0,0 +1,4 @@ +# Tests: + +import sys +from os import path diff --git a/test/simple_source/simple_stmts/00_pass.py b/test/simple_source/simple_stmts/00_pass.py new file mode 100644 index 00000000..3deb4538 --- /dev/null +++ b/test/simple_source/simple_stmts/00_pass.py @@ -0,0 +1,3 @@ +# Tests: +# assign ::= expr designator +pass diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 0dca702e..3093a1b6 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -370,9 +370,12 @@ class Python3Parser(PythonParser): kwarg ::= LOAD_CONST expr + classdef ::= buildclass designator + # Python3 introduced LOAD_BUILD_CLASS - classdef ::= LOAD_BUILD_CLASS mkfunc LOAD_CONST - CALL_FUNCTION_2 designator + # FIXME: the below should be created by custom rules + buildclass ::= LOAD_BUILD_CLASS mkfunc LOAD_CONST LOAD_NAME CALL_FUNCTION_3 + buildclass ::= LOAD_BUILD_CLASS mkfunc LOAD_CONST CALL_FUNCTION_2 stmt ::= classdefdeco classdefdeco ::= classdefdeco1 designator diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index edf8475b..41f52727 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -1053,26 +1053,29 @@ class Walker(GenericASTTraversal, object): # class definition ('class X(A,B,C):') cclass = self.currentclass + if self.version > 3.0: buildclass = node[1] - self.currentclass = str(buildclass[1].pattr) + build_list = node[0] + subclass = build_list[1][0].attr else: buildclass = node[0] - self.currentclass = str(buildclass[0].pattr) + build_list = buildclass[1][0] + subclass = buildclass[-3][0].attr self.write('\n\n') + self.currentclass = str(buildclass[0].pattr) self.write(self.indent, 'class ', self.currentclass) - self.print_super_classes(buildclass) + if self.version > 3.0: + self.print_super_classes3(build_list) + else: + self.print_super_classes(build_list) self.print_(':') # class body self.indentMore() - - if self.version > 3.0: - self.build_class(buildclass[0].attr) - else: - self.build_class(buildclass[-3][0].attr) + self.build_class(subclass) self.indentLess() self.currentclass = cclass @@ -1086,7 +1089,6 @@ class Walker(GenericASTTraversal, object): n_classdefdeco2 = n_classdef def print_super_classes(self, node): - node = node[1][0] if not (node == 'build_list'): return @@ -1100,6 +1102,29 @@ class Walker(GenericASTTraversal, object): self.write(')') + def print_super_classes3(self, node): + + # FIXME: put blow logic into grammar + # as a custom rule + i = 0 + for i, n in enumerate(node[:-1]): + if n.type == 'LOAD_NAME': + break + pass + + if i == 0: + return + self.write('(') + line_separator = ', ' + sep = '' + while i <= len(node) - 2: + value = self.traverse(node[i]) + i += 1 + self.write(sep, value) + sep = line_separator + + self.write(')') + def n_mapexpr(self, node): """ prettyprint a mapexpr