You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Start Python 2.1 bytecode decompile
This commit is contained in:
@@ -38,7 +38,7 @@ entry_points={
|
|||||||
]}
|
]}
|
||||||
ftp_url = None
|
ftp_url = None
|
||||||
install_requires = ['spark-parser >= 1.4.0',
|
install_requires = ['spark-parser >= 1.4.0',
|
||||||
'xdis >= 2.3.0']
|
'xdis >= 2.3.1']
|
||||||
license = 'MIT'
|
license = 'MIT'
|
||||||
mailing_list = 'python-debugger@googlegroups.com'
|
mailing_list = 'python-debugger@googlegroups.com'
|
||||||
modname = 'uncompyle6'
|
modname = 'uncompyle6'
|
||||||
|
BIN
test/bytecode_2.1/applyEquiv.pyc
Normal file
BIN
test/bytecode_2.1/applyEquiv.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/augmentedAssign.pyc
Normal file
BIN
test/bytecode_2.1/augmentedAssign.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/docstring.pyc
Normal file
BIN
test/bytecode_2.1/docstring.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/exceptions.pyc
Normal file
BIN
test/bytecode_2.1/exceptions.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/exec.pyc
Normal file
BIN
test/bytecode_2.1/exec.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/expressions.pyc
Normal file
BIN
test/bytecode_2.1/expressions.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/extendedImport.pyc
Normal file
BIN
test/bytecode_2.1/extendedImport.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/extendedPrint.pyc
Normal file
BIN
test/bytecode_2.1/extendedPrint.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/globals.pyc
Normal file
BIN
test/bytecode_2.1/globals.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/import.pyc
Normal file
BIN
test/bytecode_2.1/import.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/lambda.pyc
Normal file
BIN
test/bytecode_2.1/lambda.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/listComprehensions.pyc
Normal file
BIN
test/bytecode_2.1/listComprehensions.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/misc.pyc
Normal file
BIN
test/bytecode_2.1/misc.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/nested_elif.pyc
Normal file
BIN
test/bytecode_2.1/nested_elif.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/print.pyc
Normal file
BIN
test/bytecode_2.1/print.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/slices.pyc
Normal file
BIN
test/bytecode_2.1/slices.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_applyEquiv.pyc
Normal file
BIN
test/bytecode_2.1/test_applyEquiv.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_applyEquiv.pyo
Normal file
BIN
test/bytecode_2.1/test_applyEquiv.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_augmentedAssign.pyc
Normal file
BIN
test/bytecode_2.1/test_augmentedAssign.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_augmentedAssign.pyo
Normal file
BIN
test/bytecode_2.1/test_augmentedAssign.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_class.pyc
Normal file
BIN
test/bytecode_2.1/test_class.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_class.pyo
Normal file
BIN
test/bytecode_2.1/test_class.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_del.pyc
Normal file
BIN
test/bytecode_2.1/test_del.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_del.pyo
Normal file
BIN
test/bytecode_2.1/test_del.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_docstring.pyc
Normal file
BIN
test/bytecode_2.1/test_docstring.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_docstring.pyo
Normal file
BIN
test/bytecode_2.1/test_docstring.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_empty.pyc
Normal file
BIN
test/bytecode_2.1/test_empty.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_empty.pyo
Normal file
BIN
test/bytecode_2.1/test_empty.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_exceptions.pyc
Normal file
BIN
test/bytecode_2.1/test_exceptions.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_exceptions.pyo
Normal file
BIN
test/bytecode_2.1/test_exceptions.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_exec.pyc
Normal file
BIN
test/bytecode_2.1/test_exec.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_exec.pyo
Normal file
BIN
test/bytecode_2.1/test_exec.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_expressions.pyc
Normal file
BIN
test/bytecode_2.1/test_expressions.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_expressions.pyo
Normal file
BIN
test/bytecode_2.1/test_expressions.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_extendedImport.pyc
Normal file
BIN
test/bytecode_2.1/test_extendedImport.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_extendedImport.pyo
Normal file
BIN
test/bytecode_2.1/test_extendedImport.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_extendedPrint.pyc
Normal file
BIN
test/bytecode_2.1/test_extendedPrint.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_extendedPrint.pyo
Normal file
BIN
test/bytecode_2.1/test_extendedPrint.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_functions.pyc
Normal file
BIN
test/bytecode_2.1/test_functions.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_functions.pyo
Normal file
BIN
test/bytecode_2.1/test_functions.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_global.pyc
Normal file
BIN
test/bytecode_2.1/test_global.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_global.pyo
Normal file
BIN
test/bytecode_2.1/test_global.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_globals.pyc
Normal file
BIN
test/bytecode_2.1/test_globals.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_globals.pyo
Normal file
BIN
test/bytecode_2.1/test_globals.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_import.pyc
Normal file
BIN
test/bytecode_2.1/test_import.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_import.pyo
Normal file
BIN
test/bytecode_2.1/test_import.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_import_as.pyc
Normal file
BIN
test/bytecode_2.1/test_import_as.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_import_as.pyo
Normal file
BIN
test/bytecode_2.1/test_import_as.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_integers.pyc
Normal file
BIN
test/bytecode_2.1/test_integers.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_integers.pyo
Normal file
BIN
test/bytecode_2.1/test_integers.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_lambda.pyc
Normal file
BIN
test/bytecode_2.1/test_lambda.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_lambda.pyo
Normal file
BIN
test/bytecode_2.1/test_lambda.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_listComprehensions.pyc
Normal file
BIN
test/bytecode_2.1/test_listComprehensions.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_listComprehensions.pyo
Normal file
BIN
test/bytecode_2.1/test_listComprehensions.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_loops.pyc
Normal file
BIN
test/bytecode_2.1/test_loops.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_loops.pyo
Normal file
BIN
test/bytecode_2.1/test_loops.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_loops2.pyc
Normal file
BIN
test/bytecode_2.1/test_loops2.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_loops2.pyo
Normal file
BIN
test/bytecode_2.1/test_loops2.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_misc.pyc
Normal file
BIN
test/bytecode_2.1/test_misc.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_misc.pyo
Normal file
BIN
test/bytecode_2.1/test_misc.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_nested_elif.pyc
Normal file
BIN
test/bytecode_2.1/test_nested_elif.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_nested_elif.pyo
Normal file
BIN
test/bytecode_2.1/test_nested_elif.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_nested_scopes.pyc
Normal file
BIN
test/bytecode_2.1/test_nested_scopes.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_nested_scopes.pyo
Normal file
BIN
test/bytecode_2.1/test_nested_scopes.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_prettyprint.pyc
Normal file
BIN
test/bytecode_2.1/test_prettyprint.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_prettyprint.pyo
Normal file
BIN
test/bytecode_2.1/test_prettyprint.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_print.pyc
Normal file
BIN
test/bytecode_2.1/test_print.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_print.pyo
Normal file
BIN
test/bytecode_2.1/test_print.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_print_to.pyc
Normal file
BIN
test/bytecode_2.1/test_print_to.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_print_to.pyo
Normal file
BIN
test/bytecode_2.1/test_print_to.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_single_stmt.pyc
Normal file
BIN
test/bytecode_2.1/test_single_stmt.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_single_stmt.pyo
Normal file
BIN
test/bytecode_2.1/test_single_stmt.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_slices.pyc
Normal file
BIN
test/bytecode_2.1/test_slices.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_slices.pyo
Normal file
BIN
test/bytecode_2.1/test_slices.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_tuple_params.pyc
Normal file
BIN
test/bytecode_2.1/test_tuple_params.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_tuple_params.pyo
Normal file
BIN
test/bytecode_2.1/test_tuple_params.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_tuples.pyc
Normal file
BIN
test/bytecode_2.1/test_tuples.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/test_tuples.pyo
Normal file
BIN
test/bytecode_2.1/test_tuples.pyo
Normal file
Binary file not shown.
BIN
test/bytecode_2.1/tuple_params.pyc
Normal file
BIN
test/bytecode_2.1/tuple_params.pyc
Normal file
Binary file not shown.
@@ -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)
|
test_options[key] = (os.path.join(src_dir, pythonlib), PYOC, key, vers)
|
||||||
pass
|
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.1, 3.2, 3.3,
|
||||||
3.4, 3.5, 3.6, 'pypy3.2', 'pypy2.7'):
|
3.4, 3.5, 3.6, 'pypy3.2', 'pypy2.7'):
|
||||||
bytecode = "bytecode_%s" % vers
|
bytecode = "bytecode_%s" % vers
|
||||||
|
@@ -553,7 +553,13 @@ def get_python_parser(
|
|||||||
|
|
||||||
# FIXME: there has to be a better way...
|
# FIXME: there has to be a better way...
|
||||||
if version < 3.0:
|
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
|
import uncompyle6.parsers.parse22 as parse22
|
||||||
if compile_mode == 'exec':
|
if compile_mode == 'exec':
|
||||||
p = parse22.Python22Parser(debug_parser)
|
p = parse22.Python22Parser(debug_parser)
|
||||||
|
@@ -196,16 +196,18 @@ class Python2Parser(PythonParser):
|
|||||||
genexpr ::= LOAD_GENEXPR MAKE_FUNCTION_0 expr GET_ITER CALL_FUNCTION_1
|
genexpr ::= LOAD_GENEXPR MAKE_FUNCTION_0 expr GET_ITER CALL_FUNCTION_1
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# def p_import2(self, args):
|
def p_import15(self, args):
|
||||||
# '''
|
'''
|
||||||
# # These might be relevant for only Python 2.0 or so.
|
stmt ::= importstmt
|
||||||
# importstar ::= LOAD_CONST LOAD_CONST IMPORT_NAME_CONT IMPORT_STAR
|
stmt ::= importfrom
|
||||||
# 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
|
|
||||||
# '''
|
|
||||||
|
|
||||||
|
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):
|
def p_expr2(self, args):
|
||||||
"""
|
"""
|
||||||
expr ::= LOAD_LOCALS
|
expr ::= LOAD_LOCALS
|
||||||
|
57
uncompyle6/parsers/parse21.py
Normal file
57
uncompyle6/parsers/parse21.py
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
# Copyright (c) 2016 Rocky Bernstein
|
||||||
|
# Copyright (c) 2000-2002 by hartmut Goebel <hartmut@goebel.noris.de>
|
||||||
|
|
||||||
|
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
|
@@ -18,7 +18,7 @@ from uncompyle6 import PYTHON3, IS_PYPY
|
|||||||
from uncompyle6.scanners.tok import Token
|
from uncompyle6.scanners.tok import Token
|
||||||
|
|
||||||
# The byte code versions we support
|
# 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)
|
3.1, 3.2, 3.3, 3.4, 3.5, 3.6)
|
||||||
|
|
||||||
# FIXME: DRY
|
# FIXME: DRY
|
||||||
|
27
uncompyle6/scanners/scanner21.py
Normal file
27
uncompyle6/scanners/scanner21.py
Normal file
@@ -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 = '<generator expression>';
|
||||||
|
return
|
@@ -1,10 +1,9 @@
|
|||||||
# Copyright (c) 2016 by Rocky Bernstein
|
# 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
|
This massages tokenized 2.2 bytecode to make it more amenable for
|
||||||
Python 3 and other versions of Python. Also, we save token
|
grammar parsing.
|
||||||
information for later use in deparsing.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import uncompyle6.scanners.scanner23 as scan
|
import uncompyle6.scanners.scanner23 as scan
|
||||||
|
@@ -1,10 +1,9 @@
|
|||||||
# Copyright (c) 2015, 2016 by Rocky Bernstein
|
# 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
|
This massages tokenized 2.7 bytecode to make it more amenable for
|
||||||
Python 3 and other versions of Python. Also, we save token information
|
grammar parsing.
|
||||||
for later use in deparsing.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@@ -564,14 +564,18 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
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:
|
||||||
# Import style for 2.0-2.3
|
###########################
|
||||||
###########################
|
# Import style for 2.0-2.3
|
||||||
TABLE_DIRECT.update({
|
###########################
|
||||||
'importstmt20': ( '%|import %c\n', 1),
|
TABLE_DIRECT.update({
|
||||||
'importstar20': ( '%|from %[1]{pattr} import *\n', ),
|
'importstmt2': ( '%|import %c\n', 1),
|
||||||
'importfrom20': ( '%|from %[1]{pattr} import %c\n', 2 ),
|
'import_as_cont': ( '%|import %c as %c\n', 1, 2),
|
||||||
'importlist20': ( '%C', (0, maxint, ', ') ),
|
'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:
|
elif version >= 2.5:
|
||||||
@@ -1055,13 +1059,17 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
self.prune()
|
self.prune()
|
||||||
|
|
||||||
def n_import_as(self, node):
|
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_')
|
assert node[-1][-1].type.startswith('STORE_')
|
||||||
sname = node[-1][-1].pattr # assume one of STORE_.... here
|
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)
|
self.write(iname)
|
||||||
else:
|
else:
|
||||||
self.write(iname, ' as ', sname)
|
self.write(iname, ' as ', sname)
|
||||||
|
if self.version == 2.1 and node == 'import_as_cont':
|
||||||
|
self.write("\n")
|
||||||
self.prune() # stop recursing
|
self.prune() # stop recursing
|
||||||
|
|
||||||
n_import_as_cont = n_import_as
|
n_import_as_cont = n_import_as
|
||||||
@@ -1794,7 +1802,6 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# self.println("----> ", startnode.type)
|
# self.println("----> ", startnode.type)
|
||||||
|
|
||||||
fmt = entry[0]
|
fmt = entry[0]
|
||||||
arg = 1
|
arg = 1
|
||||||
i = 0
|
i = 0
|
||||||
|
Reference in New Issue
Block a user