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 changing API to make version optional...
and use debug option dictionary
This commit is contained in:
@@ -55,7 +55,10 @@ from uncompyle6.main import decompile_file
|
|||||||
uncompyle_file = decompile_file
|
uncompyle_file = decompile_file
|
||||||
|
|
||||||
# Conventience functions so you can say:
|
# Conventience functions so you can say:
|
||||||
# from uncompyle6 import (deparse_code, deparse_code2str)
|
# from uncompyle6 import (code_deparse, deparse_code2str)
|
||||||
|
|
||||||
deparse_code = uncompyle6.semantics.pysource.deparse_code
|
code_deparse = uncompyle6.semantics.pysource.code_deparse
|
||||||
deparse_code2str = uncompyle6.semantics.pysource.deparse_code2str
|
deparse_code2str = uncompyle6.semantics.pysource.deparse_code2str
|
||||||
|
|
||||||
|
# This is deprecated:
|
||||||
|
deparse_code = uncompyle6.semantics.pysource.deparse_code
|
||||||
|
@@ -1,4 +1,17 @@
|
|||||||
# Copyright (c) 2015-2018 by Rocky Bernstein
|
# Copyright (c) 2015-2018 by Rocky Bernstein
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Creates Python source code from an uncompyle6 parse tree,
|
Creates Python source code from an uncompyle6 parse tree,
|
||||||
|
@@ -2630,9 +2630,27 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
return MAP.get(node, MAP_DIRECT)
|
return MAP.get(node, MAP_DIRECT)
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
DEFAULT_DEBUG_OPTS = {
|
||||||
|
'asm': False,
|
||||||
|
'tree': False,
|
||||||
|
'grammar': False
|
||||||
|
}
|
||||||
|
|
||||||
|
# This interface is deprecated. Use simpler code_deparse.
|
||||||
def deparse_code(version, co, out=sys.stdout, showasm=None, showast=False,
|
def deparse_code(version, co, out=sys.stdout, showasm=None, showast=False,
|
||||||
showgrammar=False, code_objects={}, compile_mode='exec',
|
showgrammar=False, code_objects={}, compile_mode='exec',
|
||||||
is_pypy=False, walker=SourceWalker):
|
is_pypy=False, walker=SourceWalker):
|
||||||
|
debug_opts = {
|
||||||
|
'asm': showasm,
|
||||||
|
'ast': showast,
|
||||||
|
'grammar': showgrammar
|
||||||
|
}
|
||||||
|
return code_deparse(co, out, version, debug_opts, code_objects, compile_mode,
|
||||||
|
is_pypy, walker)
|
||||||
|
|
||||||
|
def code_deparse(co, out=sys.stdout, version=None, debug_opts=DEFAULT_DEBUG_OPTS,
|
||||||
|
code_objects={}, compile_mode='exec', is_pypy=False, walker=SourceWalker):
|
||||||
"""
|
"""
|
||||||
ingests and deparses a given code block 'co'. If version is None,
|
ingests and deparses a given code block 'co'. If version is None,
|
||||||
we will use the current Python interpreter version.
|
we will use the current Python interpreter version.
|
||||||
@@ -2647,16 +2665,16 @@ def deparse_code(version, co, out=sys.stdout, showasm=None, showast=False,
|
|||||||
scanner = get_scanner(version, is_pypy=is_pypy)
|
scanner = get_scanner(version, is_pypy=is_pypy)
|
||||||
|
|
||||||
tokens, customize = scanner.ingest(co, code_objects=code_objects,
|
tokens, customize = scanner.ingest(co, code_objects=code_objects,
|
||||||
show_asm=showasm)
|
show_asm=debug_opts['asm'])
|
||||||
|
|
||||||
debug_parser = dict(PARSER_DEFAULT_DEBUG)
|
debug_parser = dict(PARSER_DEFAULT_DEBUG)
|
||||||
if showgrammar:
|
if debug_opts.get('grammar', None):
|
||||||
debug_parser['reduce'] = showgrammar
|
debug_parser['reduce'] = debug_opts['grammar']
|
||||||
debug_parser['errorstack'] = 'full'
|
debug_parser['errorstack'] = 'full'
|
||||||
|
|
||||||
# Build Syntax Tree from disassembly.
|
# Build Syntax Tree from disassembly.
|
||||||
linestarts = dict(scanner.opc.findlinestarts(co))
|
linestarts = dict(scanner.opc.findlinestarts(co))
|
||||||
deparsed = walker(version, out, scanner, showast=showast,
|
deparsed = walker(version, out, scanner, showast=debug_opts['ast'],
|
||||||
debug_parser=debug_parser, compile_mode=compile_mode,
|
debug_parser=debug_parser, compile_mode=compile_mode,
|
||||||
is_pypy=is_pypy, linestarts=linestarts)
|
is_pypy=is_pypy, linestarts=linestarts)
|
||||||
|
|
||||||
@@ -2705,12 +2723,6 @@ def deparse_code(version, co, out=sys.stdout, showasm=None, showast=False,
|
|||||||
raise SourceWalkerError("Deparsing stopped due to parse error")
|
raise SourceWalkerError("Deparsing stopped due to parse error")
|
||||||
return deparsed
|
return deparsed
|
||||||
|
|
||||||
#
|
|
||||||
DEFAULT_DEBUG_OPTS = {
|
|
||||||
'asm': False,
|
|
||||||
'tree': False,
|
|
||||||
'grammar': False
|
|
||||||
}
|
|
||||||
def deparse_code2str(code, out=sys.stdout, version=None,
|
def deparse_code2str(code, out=sys.stdout, version=None,
|
||||||
debug_opts=DEFAULT_DEBUG_OPTS,
|
debug_opts=DEFAULT_DEBUG_OPTS,
|
||||||
code_objects={}, compile_mode='exec',
|
code_objects={}, compile_mode='exec',
|
||||||
|
Reference in New Issue
Block a user