diff --git a/__pkginfo__.py b/__pkginfo__.py index 5869b595..9e218966 100644 --- a/__pkginfo__.py +++ b/__pkginfo__.py @@ -38,7 +38,7 @@ entry_points={ ]} ftp_url = None install_requires = ['spark-parser >= 1.4.0', - 'xdis >= 2.3.0'] + 'xdis >= 2.3.1'] license = 'MIT' mailing_list = 'python-debugger@googlegroups.com' modname = 'uncompyle6' diff --git a/test/bytecode_2.1/applyEquiv.pyc b/test/bytecode_2.1/applyEquiv.pyc new file mode 100644 index 00000000..b7f026a9 Binary files /dev/null and b/test/bytecode_2.1/applyEquiv.pyc differ diff --git a/test/bytecode_2.1/augmentedAssign.pyc b/test/bytecode_2.1/augmentedAssign.pyc new file mode 100644 index 00000000..3f92c2a9 Binary files /dev/null and b/test/bytecode_2.1/augmentedAssign.pyc differ diff --git a/test/bytecode_2.1/docstring.pyc b/test/bytecode_2.1/docstring.pyc new file mode 100644 index 00000000..7589f672 Binary files /dev/null and b/test/bytecode_2.1/docstring.pyc differ diff --git a/test/bytecode_2.1/exceptions.pyc b/test/bytecode_2.1/exceptions.pyc new file mode 100644 index 00000000..28c72fac Binary files /dev/null and b/test/bytecode_2.1/exceptions.pyc differ diff --git a/test/bytecode_2.1/exec.pyc b/test/bytecode_2.1/exec.pyc new file mode 100644 index 00000000..435fa592 Binary files /dev/null and b/test/bytecode_2.1/exec.pyc differ diff --git a/test/bytecode_2.1/expressions.pyc b/test/bytecode_2.1/expressions.pyc new file mode 100644 index 00000000..97a263e4 Binary files /dev/null and b/test/bytecode_2.1/expressions.pyc differ diff --git a/test/bytecode_2.1/extendedImport.pyc b/test/bytecode_2.1/extendedImport.pyc new file mode 100644 index 00000000..dc1b81be Binary files /dev/null and b/test/bytecode_2.1/extendedImport.pyc differ diff --git a/test/bytecode_2.1/extendedPrint.pyc b/test/bytecode_2.1/extendedPrint.pyc new file mode 100644 index 00000000..0aad1d82 Binary files /dev/null and b/test/bytecode_2.1/extendedPrint.pyc differ diff --git a/test/bytecode_2.1/globals.pyc b/test/bytecode_2.1/globals.pyc new file mode 100644 index 00000000..22563628 Binary files /dev/null and b/test/bytecode_2.1/globals.pyc differ diff --git a/test/bytecode_2.1/import.pyc b/test/bytecode_2.1/import.pyc new file mode 100644 index 00000000..9e84210a Binary files /dev/null and b/test/bytecode_2.1/import.pyc differ diff --git a/test/bytecode_2.1/lambda.pyc b/test/bytecode_2.1/lambda.pyc new file mode 100644 index 00000000..95a2b7e2 Binary files /dev/null and b/test/bytecode_2.1/lambda.pyc differ diff --git a/test/bytecode_2.1/listComprehensions.pyc b/test/bytecode_2.1/listComprehensions.pyc new file mode 100644 index 00000000..44e997e2 Binary files /dev/null and b/test/bytecode_2.1/listComprehensions.pyc differ diff --git a/test/bytecode_2.1/misc.pyc b/test/bytecode_2.1/misc.pyc new file mode 100644 index 00000000..f293c4c0 Binary files /dev/null and b/test/bytecode_2.1/misc.pyc differ diff --git a/test/bytecode_2.1/nested_elif.pyc b/test/bytecode_2.1/nested_elif.pyc new file mode 100644 index 00000000..07fd94d1 Binary files /dev/null and b/test/bytecode_2.1/nested_elif.pyc differ diff --git a/test/bytecode_2.1/print.pyc b/test/bytecode_2.1/print.pyc new file mode 100644 index 00000000..2ac4c195 Binary files /dev/null and b/test/bytecode_2.1/print.pyc differ diff --git a/test/bytecode_2.1/slices.pyc b/test/bytecode_2.1/slices.pyc new file mode 100644 index 00000000..b31ece5d Binary files /dev/null and b/test/bytecode_2.1/slices.pyc differ diff --git a/test/bytecode_2.1/test_applyEquiv.pyc b/test/bytecode_2.1/test_applyEquiv.pyc new file mode 100644 index 00000000..b912916b Binary files /dev/null and b/test/bytecode_2.1/test_applyEquiv.pyc differ diff --git a/test/bytecode_2.1/test_applyEquiv.pyo b/test/bytecode_2.1/test_applyEquiv.pyo new file mode 100644 index 00000000..e4941baa Binary files /dev/null and b/test/bytecode_2.1/test_applyEquiv.pyo differ diff --git a/test/bytecode_2.1/test_augmentedAssign.pyc b/test/bytecode_2.1/test_augmentedAssign.pyc new file mode 100644 index 00000000..dadb8c79 Binary files /dev/null and b/test/bytecode_2.1/test_augmentedAssign.pyc differ diff --git a/test/bytecode_2.1/test_augmentedAssign.pyo b/test/bytecode_2.1/test_augmentedAssign.pyo new file mode 100644 index 00000000..645805b1 Binary files /dev/null and b/test/bytecode_2.1/test_augmentedAssign.pyo differ diff --git a/test/bytecode_2.1/test_class.pyc b/test/bytecode_2.1/test_class.pyc new file mode 100644 index 00000000..8fa9a87d Binary files /dev/null and b/test/bytecode_2.1/test_class.pyc differ diff --git a/test/bytecode_2.1/test_class.pyo b/test/bytecode_2.1/test_class.pyo new file mode 100644 index 00000000..87809f99 Binary files /dev/null and b/test/bytecode_2.1/test_class.pyo differ diff --git a/test/bytecode_2.1/test_del.pyc b/test/bytecode_2.1/test_del.pyc new file mode 100644 index 00000000..c236c7ec Binary files /dev/null and b/test/bytecode_2.1/test_del.pyc differ diff --git a/test/bytecode_2.1/test_del.pyo b/test/bytecode_2.1/test_del.pyo new file mode 100644 index 00000000..8e3838aa Binary files /dev/null and b/test/bytecode_2.1/test_del.pyo differ diff --git a/test/bytecode_2.1/test_docstring.pyc b/test/bytecode_2.1/test_docstring.pyc new file mode 100644 index 00000000..460e3062 Binary files /dev/null and b/test/bytecode_2.1/test_docstring.pyc differ diff --git a/test/bytecode_2.1/test_docstring.pyo b/test/bytecode_2.1/test_docstring.pyo new file mode 100644 index 00000000..a7c9a475 Binary files /dev/null and b/test/bytecode_2.1/test_docstring.pyo differ diff --git a/test/bytecode_2.1/test_empty.pyc b/test/bytecode_2.1/test_empty.pyc new file mode 100644 index 00000000..a9dff72f Binary files /dev/null and b/test/bytecode_2.1/test_empty.pyc differ diff --git a/test/bytecode_2.1/test_empty.pyo b/test/bytecode_2.1/test_empty.pyo new file mode 100644 index 00000000..3bebed09 Binary files /dev/null and b/test/bytecode_2.1/test_empty.pyo differ diff --git a/test/bytecode_2.1/test_exceptions.pyc b/test/bytecode_2.1/test_exceptions.pyc new file mode 100644 index 00000000..b1f3890e Binary files /dev/null and b/test/bytecode_2.1/test_exceptions.pyc differ diff --git a/test/bytecode_2.1/test_exceptions.pyo b/test/bytecode_2.1/test_exceptions.pyo new file mode 100644 index 00000000..79c9f394 Binary files /dev/null and b/test/bytecode_2.1/test_exceptions.pyo differ diff --git a/test/bytecode_2.1/test_exec.pyc b/test/bytecode_2.1/test_exec.pyc new file mode 100644 index 00000000..af12bdf3 Binary files /dev/null and b/test/bytecode_2.1/test_exec.pyc differ diff --git a/test/bytecode_2.1/test_exec.pyo b/test/bytecode_2.1/test_exec.pyo new file mode 100644 index 00000000..93011d79 Binary files /dev/null and b/test/bytecode_2.1/test_exec.pyo differ diff --git a/test/bytecode_2.1/test_expressions.pyc b/test/bytecode_2.1/test_expressions.pyc new file mode 100644 index 00000000..fe8bf9ee Binary files /dev/null and b/test/bytecode_2.1/test_expressions.pyc differ diff --git a/test/bytecode_2.1/test_expressions.pyo b/test/bytecode_2.1/test_expressions.pyo new file mode 100644 index 00000000..97bcf342 Binary files /dev/null and b/test/bytecode_2.1/test_expressions.pyo differ diff --git a/test/bytecode_2.1/test_extendedImport.pyc b/test/bytecode_2.1/test_extendedImport.pyc new file mode 100644 index 00000000..a7fbc84f Binary files /dev/null and b/test/bytecode_2.1/test_extendedImport.pyc differ diff --git a/test/bytecode_2.1/test_extendedImport.pyo b/test/bytecode_2.1/test_extendedImport.pyo new file mode 100644 index 00000000..cd945cbe Binary files /dev/null and b/test/bytecode_2.1/test_extendedImport.pyo differ diff --git a/test/bytecode_2.1/test_extendedPrint.pyc b/test/bytecode_2.1/test_extendedPrint.pyc new file mode 100644 index 00000000..181d3414 Binary files /dev/null and b/test/bytecode_2.1/test_extendedPrint.pyc differ diff --git a/test/bytecode_2.1/test_extendedPrint.pyo b/test/bytecode_2.1/test_extendedPrint.pyo new file mode 100644 index 00000000..bf8f0417 Binary files /dev/null and b/test/bytecode_2.1/test_extendedPrint.pyo differ diff --git a/test/bytecode_2.1/test_functions.pyc b/test/bytecode_2.1/test_functions.pyc new file mode 100644 index 00000000..c55239f3 Binary files /dev/null and b/test/bytecode_2.1/test_functions.pyc differ diff --git a/test/bytecode_2.1/test_functions.pyo b/test/bytecode_2.1/test_functions.pyo new file mode 100644 index 00000000..f7b24cd1 Binary files /dev/null and b/test/bytecode_2.1/test_functions.pyo differ diff --git a/test/bytecode_2.1/test_global.pyc b/test/bytecode_2.1/test_global.pyc new file mode 100644 index 00000000..27592658 Binary files /dev/null and b/test/bytecode_2.1/test_global.pyc differ diff --git a/test/bytecode_2.1/test_global.pyo b/test/bytecode_2.1/test_global.pyo new file mode 100644 index 00000000..62108c0e Binary files /dev/null and b/test/bytecode_2.1/test_global.pyo differ diff --git a/test/bytecode_2.1/test_globals.pyc b/test/bytecode_2.1/test_globals.pyc new file mode 100644 index 00000000..b9949ba5 Binary files /dev/null and b/test/bytecode_2.1/test_globals.pyc differ diff --git a/test/bytecode_2.1/test_globals.pyo b/test/bytecode_2.1/test_globals.pyo new file mode 100644 index 00000000..d9980589 Binary files /dev/null and b/test/bytecode_2.1/test_globals.pyo differ diff --git a/test/bytecode_2.1/test_import.pyc b/test/bytecode_2.1/test_import.pyc new file mode 100644 index 00000000..59ee04e2 Binary files /dev/null and b/test/bytecode_2.1/test_import.pyc differ diff --git a/test/bytecode_2.1/test_import.pyo b/test/bytecode_2.1/test_import.pyo new file mode 100644 index 00000000..e626de0e Binary files /dev/null and b/test/bytecode_2.1/test_import.pyo differ diff --git a/test/bytecode_2.1/test_import_as.pyc b/test/bytecode_2.1/test_import_as.pyc new file mode 100644 index 00000000..dc705aa8 Binary files /dev/null and b/test/bytecode_2.1/test_import_as.pyc differ diff --git a/test/bytecode_2.1/test_import_as.pyo b/test/bytecode_2.1/test_import_as.pyo new file mode 100644 index 00000000..c8f26fe4 Binary files /dev/null and b/test/bytecode_2.1/test_import_as.pyo differ diff --git a/test/bytecode_2.1/test_integers.pyc b/test/bytecode_2.1/test_integers.pyc new file mode 100644 index 00000000..97e27b36 Binary files /dev/null and b/test/bytecode_2.1/test_integers.pyc differ diff --git a/test/bytecode_2.1/test_integers.pyo b/test/bytecode_2.1/test_integers.pyo new file mode 100644 index 00000000..8cf47322 Binary files /dev/null and b/test/bytecode_2.1/test_integers.pyo differ diff --git a/test/bytecode_2.1/test_lambda.pyc b/test/bytecode_2.1/test_lambda.pyc new file mode 100644 index 00000000..472084c7 Binary files /dev/null and b/test/bytecode_2.1/test_lambda.pyc differ diff --git a/test/bytecode_2.1/test_lambda.pyo b/test/bytecode_2.1/test_lambda.pyo new file mode 100644 index 00000000..6d01a1f9 Binary files /dev/null and b/test/bytecode_2.1/test_lambda.pyo differ diff --git a/test/bytecode_2.1/test_listComprehensions.pyc b/test/bytecode_2.1/test_listComprehensions.pyc new file mode 100644 index 00000000..927205af Binary files /dev/null and b/test/bytecode_2.1/test_listComprehensions.pyc differ diff --git a/test/bytecode_2.1/test_listComprehensions.pyo b/test/bytecode_2.1/test_listComprehensions.pyo new file mode 100644 index 00000000..33cc40c4 Binary files /dev/null and b/test/bytecode_2.1/test_listComprehensions.pyo differ diff --git a/test/bytecode_2.1/test_loops.pyc b/test/bytecode_2.1/test_loops.pyc new file mode 100644 index 00000000..a773d332 Binary files /dev/null and b/test/bytecode_2.1/test_loops.pyc differ diff --git a/test/bytecode_2.1/test_loops.pyo b/test/bytecode_2.1/test_loops.pyo new file mode 100644 index 00000000..52353b11 Binary files /dev/null and b/test/bytecode_2.1/test_loops.pyo differ diff --git a/test/bytecode_2.1/test_loops2.pyc b/test/bytecode_2.1/test_loops2.pyc new file mode 100644 index 00000000..4eb829d8 Binary files /dev/null and b/test/bytecode_2.1/test_loops2.pyc differ diff --git a/test/bytecode_2.1/test_loops2.pyo b/test/bytecode_2.1/test_loops2.pyo new file mode 100644 index 00000000..aa59d290 Binary files /dev/null and b/test/bytecode_2.1/test_loops2.pyo differ diff --git a/test/bytecode_2.1/test_misc.pyc b/test/bytecode_2.1/test_misc.pyc new file mode 100644 index 00000000..75e87ab3 Binary files /dev/null and b/test/bytecode_2.1/test_misc.pyc differ diff --git a/test/bytecode_2.1/test_misc.pyo b/test/bytecode_2.1/test_misc.pyo new file mode 100644 index 00000000..e6a8c9fa Binary files /dev/null and b/test/bytecode_2.1/test_misc.pyo differ diff --git a/test/bytecode_2.1/test_nested_elif.pyc b/test/bytecode_2.1/test_nested_elif.pyc new file mode 100644 index 00000000..6ac021f4 Binary files /dev/null and b/test/bytecode_2.1/test_nested_elif.pyc differ diff --git a/test/bytecode_2.1/test_nested_elif.pyo b/test/bytecode_2.1/test_nested_elif.pyo new file mode 100644 index 00000000..d65baf7d Binary files /dev/null and b/test/bytecode_2.1/test_nested_elif.pyo differ diff --git a/test/bytecode_2.1/test_nested_scopes.pyc b/test/bytecode_2.1/test_nested_scopes.pyc new file mode 100644 index 00000000..c6755616 Binary files /dev/null and b/test/bytecode_2.1/test_nested_scopes.pyc differ diff --git a/test/bytecode_2.1/test_nested_scopes.pyo b/test/bytecode_2.1/test_nested_scopes.pyo new file mode 100644 index 00000000..33a09c90 Binary files /dev/null and b/test/bytecode_2.1/test_nested_scopes.pyo differ diff --git a/test/bytecode_2.1/test_prettyprint.pyc b/test/bytecode_2.1/test_prettyprint.pyc new file mode 100644 index 00000000..cb6a305c Binary files /dev/null and b/test/bytecode_2.1/test_prettyprint.pyc differ diff --git a/test/bytecode_2.1/test_prettyprint.pyo b/test/bytecode_2.1/test_prettyprint.pyo new file mode 100644 index 00000000..b6156f2c Binary files /dev/null and b/test/bytecode_2.1/test_prettyprint.pyo differ diff --git a/test/bytecode_2.1/test_print.pyc b/test/bytecode_2.1/test_print.pyc new file mode 100644 index 00000000..931c75e1 Binary files /dev/null and b/test/bytecode_2.1/test_print.pyc differ diff --git a/test/bytecode_2.1/test_print.pyo b/test/bytecode_2.1/test_print.pyo new file mode 100644 index 00000000..7dffcdf8 Binary files /dev/null and b/test/bytecode_2.1/test_print.pyo differ diff --git a/test/bytecode_2.1/test_print_to.pyc b/test/bytecode_2.1/test_print_to.pyc new file mode 100644 index 00000000..93e354a5 Binary files /dev/null and b/test/bytecode_2.1/test_print_to.pyc differ diff --git a/test/bytecode_2.1/test_print_to.pyo b/test/bytecode_2.1/test_print_to.pyo new file mode 100644 index 00000000..f87b898e Binary files /dev/null and b/test/bytecode_2.1/test_print_to.pyo differ diff --git a/test/bytecode_2.1/test_single_stmt.pyc b/test/bytecode_2.1/test_single_stmt.pyc new file mode 100644 index 00000000..9befedcc Binary files /dev/null and b/test/bytecode_2.1/test_single_stmt.pyc differ diff --git a/test/bytecode_2.1/test_single_stmt.pyo b/test/bytecode_2.1/test_single_stmt.pyo new file mode 100644 index 00000000..904f25a5 Binary files /dev/null and b/test/bytecode_2.1/test_single_stmt.pyo differ diff --git a/test/bytecode_2.1/test_slices.pyc b/test/bytecode_2.1/test_slices.pyc new file mode 100644 index 00000000..21e623a0 Binary files /dev/null and b/test/bytecode_2.1/test_slices.pyc differ diff --git a/test/bytecode_2.1/test_slices.pyo b/test/bytecode_2.1/test_slices.pyo new file mode 100644 index 00000000..cbdc1590 Binary files /dev/null and b/test/bytecode_2.1/test_slices.pyo differ diff --git a/test/bytecode_2.1/test_tuple_params.pyc b/test/bytecode_2.1/test_tuple_params.pyc new file mode 100644 index 00000000..f691e53a Binary files /dev/null and b/test/bytecode_2.1/test_tuple_params.pyc differ diff --git a/test/bytecode_2.1/test_tuple_params.pyo b/test/bytecode_2.1/test_tuple_params.pyo new file mode 100644 index 00000000..641a9c89 Binary files /dev/null and b/test/bytecode_2.1/test_tuple_params.pyo differ diff --git a/test/bytecode_2.1/test_tuples.pyc b/test/bytecode_2.1/test_tuples.pyc new file mode 100644 index 00000000..445a4bfb Binary files /dev/null and b/test/bytecode_2.1/test_tuples.pyc differ diff --git a/test/bytecode_2.1/test_tuples.pyo b/test/bytecode_2.1/test_tuples.pyo new file mode 100644 index 00000000..f548b6ee Binary files /dev/null and b/test/bytecode_2.1/test_tuples.pyo differ diff --git a/test/bytecode_2.1/tuple_params.pyc b/test/bytecode_2.1/tuple_params.pyc new file mode 100644 index 00000000..044558b8 Binary files /dev/null and b/test/bytecode_2.1/tuple_params.pyc differ diff --git a/test/test_pythonlib.py b/test/test_pythonlib.py index 0ca68842..503e5cdf 100755 --- a/test/test_pythonlib.py +++ b/test/test_pythonlib.py @@ -78,7 +78,7 @@ for vers in (2.7, 3.4, 3.5, 3.6): test_options[key] = (os.path.join(src_dir, pythonlib), PYOC, key, vers) pass -for vers in (2.2, 2.3, 2.4, 2.5, 2.6, 2.7, +for vers in (2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 'pypy3.2', 'pypy2.7'): bytecode = "bytecode_%s" % vers diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index e455afc2..91a5c76e 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -553,7 +553,13 @@ def get_python_parser( # FIXME: there has to be a better way... if version < 3.0: - if version == 2.2: + if version == 2.1: + import uncompyle6.parsers.parse21 as parse21 + if compile_mode == 'exec': + p = parse21.Python21Parser(debug_parser) + else: + p = parse21.Python21ParserSingle(debug_parser) + elif version == 2.2: import uncompyle6.parsers.parse22 as parse22 if compile_mode == 'exec': p = parse22.Python22Parser(debug_parser) diff --git a/uncompyle6/parsers/parse2.py b/uncompyle6/parsers/parse2.py index 7267d98a..8b49b607 100644 --- a/uncompyle6/parsers/parse2.py +++ b/uncompyle6/parsers/parse2.py @@ -196,16 +196,18 @@ class Python2Parser(PythonParser): genexpr ::= LOAD_GENEXPR MAKE_FUNCTION_0 expr GET_ITER CALL_FUNCTION_1 ''' - # def p_import2(self, args): - # ''' - # # These might be relevant for only Python 2.0 or so. - # importstar ::= LOAD_CONST LOAD_CONST IMPORT_NAME_CONT IMPORT_STAR - # importfrom ::= LOAD_CONST LOAD_CONST IMPORT_NAME_CONT importlist2 POP_TOP - # import_as_cont ::= IMPORT_NAME_CONT designator - # import_as_cont ::= IMPORT_NAME_CONT load_attrs designator - # ''' + def p_import15(self, args): + ''' + stmt ::= importstmt + stmt ::= importfrom + importstmt ::= IMPORT_NAME STORE_FAST + importstmt ::= IMPORT_NAME STORE_NAME + importfrom ::= IMPORT_NAME importlist + importlist ::= importlist IMPORT_FROM + importlist ::= IMPORT_FROM + ''' def p_expr2(self, args): """ expr ::= LOAD_LOCALS diff --git a/uncompyle6/parsers/parse21.py b/uncompyle6/parsers/parse21.py new file mode 100644 index 00000000..7fe06d71 --- /dev/null +++ b/uncompyle6/parsers/parse21.py @@ -0,0 +1,57 @@ +# Copyright (c) 2016 Rocky Bernstein +# Copyright (c) 2000-2002 by hartmut Goebel + +from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG +from uncompyle6.parser import PythonParserSingle +from uncompyle6.parsers.parse22 import Python22Parser + +class Python21Parser(Python22Parser): + + def __init__(self, debug_parser=PARSER_DEFAULT_DEBUG): + super(Python22Parser, self).__init__(debug_parser) + self.customized = {} + + def p_forstmt21(self, args): + """ + _for ::= LOAD_CONST FOR_LOOP + forstmt ::= SETUP_LOOP expr _for designator + return_stmts + POP_BLOCK COME_FROM + forstmt ::= SETUP_LOOP expr _for designator + l_stmts_opt _jump_back + POP_BLOCK COME_FROM + """ + + def p_import21(self, args): + ''' + # These are be relevant for only Python 2.0 and 2.1 + stmt ::= importstmt2 + stmt ::= importfrom2 + stmt ::= importstar + stmt ::= import_as_cont + stmt ::= import_as + importfrom2 ::= LOAD_CONST IMPORT_NAME importlist2 POP_TOP + importlist2 ::= importlist2 import_as + importstmt2 ::= LOAD_CONST IMPORT_NAME designator + importstmt2 ::= LOAD_CONST IMPORT_NAME IMPORT_FROM designator POP_TOP + importstar ::= LOAD_CONST LOAD_CONST IMPORT_NAME_CONT IMPORT_STAR + importfrom ::= LOAD_CONST LOAD_CONST IMPORT_NAME_CONT importlist2 POP_TOP + import_as ::= LOAD_CONST IMPORT_NAME LOAD_ATTR designator + import_as ::= LOAD_CONST IMPORT_NAME LOAD_ATTR LOAD_ATTR designator + import_as ::= LOAD_CONST IMPORT_NAME LOAD_ATTR LOAD_ATTR LOAD_ATTR designator + import_as ::= IMPORT_FROM designator + import_as_cont ::= LOAD_CONST IMPORT_NAME_CONT designator + import_as_cont ::= IMPORT_NAME_CONT load_attrs designator + ''' + +class Python21ParserSingle(Python22Parser, PythonParserSingle): + pass + +if __name__ == '__main__': + # Check grammar + p = Python21Parser() + p.checkGrammar() + p.dumpGrammar() + +# local variables: +# tab-width: 4 diff --git a/uncompyle6/scanner.py b/uncompyle6/scanner.py index 26d82580..2dd3a4f3 100755 --- a/uncompyle6/scanner.py +++ b/uncompyle6/scanner.py @@ -18,7 +18,7 @@ from uncompyle6 import PYTHON3, IS_PYPY from uncompyle6.scanners.tok import Token # The byte code versions we support -PYTHON_VERSIONS = (2.2, 2.3, 2.4, 2.5, 2.6, 2.7, +PYTHON_VERSIONS = (2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6) # FIXME: DRY diff --git a/uncompyle6/scanners/scanner21.py b/uncompyle6/scanners/scanner21.py new file mode 100644 index 00000000..ce60c801 --- /dev/null +++ b/uncompyle6/scanners/scanner21.py @@ -0,0 +1,27 @@ +# Copyright (c) 2016 by Rocky Bernstein +""" +Python 2.1 bytecode scanner/deparser + +This massages tokenized 2.1 bytecode to make it more amenable for +grammar parsing. +""" + +import uncompyle6.scanners.scanner22 as scan +# from uncompyle6.scanners.scanner26 import ingest as ingest26 + +# bytecode verification, verify(), uses JUMP_OPs from here +from xdis.opcodes import opcode_21 +JUMP_OPs = opcode_21.JUMP_OPs + +# We base this off of 2.2 instead of the other way around +# because we cleaned things up this way. +# The history is that 2.7 support is the cleanest, +# then from that we got 2.6 and so on. +class Scanner21(scan.Scanner22): + def __init__(self, show_asm=False): + scan.Scanner22.__init__(self, show_asm) + self.opc = opcode_21 + self.opname = opcode_21.opname + self.version = 2.1 + self.genexpr_name = ''; + return diff --git a/uncompyle6/scanners/scanner22.py b/uncompyle6/scanners/scanner22.py index 0c1840c9..8f740dba 100644 --- a/uncompyle6/scanners/scanner22.py +++ b/uncompyle6/scanners/scanner22.py @@ -1,10 +1,9 @@ # Copyright (c) 2016 by Rocky Bernstein """ -Python 2.2 bytecode scanner/deparser +Python 2.2 bytecode ingester. -This overlaps Python's 2.2's dis module, but it can be run from -Python 3 and other versions of Python. Also, we save token -information for later use in deparsing. +This massages tokenized 2.2 bytecode to make it more amenable for +grammar parsing. """ import uncompyle6.scanners.scanner23 as scan diff --git a/uncompyle6/scanners/scanner27.py b/uncompyle6/scanners/scanner27.py index 57eaeebd..885be81e 100755 --- a/uncompyle6/scanners/scanner27.py +++ b/uncompyle6/scanners/scanner27.py @@ -1,10 +1,9 @@ # Copyright (c) 2015, 2016 by Rocky Bernstein """ -Python 2.7 bytecode scanner/deparser +Python 2.7 bytecode ingester. -This overlaps Python's 2.7's dis module, but it can be run from -Python 3 and other versions of Python. Also, we save token information -for later use in deparsing. +This massages tokenized 2.7 bytecode to make it more amenable for +grammar parsing. """ diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 946efcf9..695e50ba 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -564,14 +564,18 @@ class SourceWalker(GenericASTTraversal, object): TABLE_DIRECT.update({ 'tryfinallystmt': ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n', 1, 4 ) }) - ########################### - # Import style for 2.0-2.3 - ########################### - TABLE_DIRECT.update({ - 'importstmt20': ( '%|import %c\n', 1), - 'importstar20': ( '%|from %[1]{pattr} import *\n', ), - 'importfrom20': ( '%|from %[1]{pattr} import %c\n', 2 ), - 'importlist20': ( '%C', (0, maxint, ', ') ), + if version == 2.1: + ########################### + # Import style for 2.0-2.3 + ########################### + TABLE_DIRECT.update({ + 'importstmt2': ( '%|import %c\n', 1), + 'import_as_cont': ( '%|import %c as %c\n', 1, 2), + 'importstar2': ( '%|from %[1]{pattr} import *\n', ), + 'importfrom2': ( '%|from %[1]{pattr} import %c\n', 2 ), + 'importlist2': ( '%C', (0, maxint, ', ') ), + 'IMPORT_NAME': ( '%{pattr}', ), + 'IMPORT_NAME_CONT': ( '%{pattr}', ), }) elif version >= 2.5: @@ -1055,13 +1059,17 @@ class SourceWalker(GenericASTTraversal, object): self.prune() def n_import_as(self, node): - iname = node[0].pattr + if self.version == 2.1 and node == 'import_as_cont': + self.write("\n", self.indent, "import ") + iname = node[1].pattr if node[0] == 'LOAD_CONST' else node[0].pattr assert node[-1][-1].type.startswith('STORE_') sname = node[-1][-1].pattr # assume one of STORE_.... here - if iname == sname or iname.startswith(sname + '.'): + if iname and iname == sname or iname.startswith(sname + '.'): self.write(iname) else: self.write(iname, ' as ', sname) + if self.version == 2.1 and node == 'import_as_cont': + self.write("\n") self.prune() # stop recursing n_import_as_cont = n_import_as @@ -1794,7 +1802,6 @@ class SourceWalker(GenericASTTraversal, object): """ # self.println("----> ", startnode.type) - fmt = entry[0] arg = 1 i = 0