diff --git a/uncompyle6/__init__.py b/uncompyle6/__init__.py index a029bd7d..f4d69849 100644 --- a/uncompyle6/__init__.py +++ b/uncompyle6/__init__.py @@ -55,7 +55,10 @@ from uncompyle6.main import decompile_file uncompyle_file = decompile_file # 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 + +# This is deprecated: +deparse_code = uncompyle6.semantics.pysource.deparse_code diff --git a/uncompyle6/semantics/fragments.py b/uncompyle6/semantics/fragments.py index f5b93301..011c5fd9 100644 --- a/uncompyle6/semantics/fragments.py +++ b/uncompyle6/semantics/fragments.py @@ -1,4 +1,17 @@ # 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 . """ Creates Python source code from an uncompyle6 parse tree, diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 9ad055ff..d7fc20d8 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -2630,9 +2630,27 @@ class SourceWalker(GenericASTTraversal, object): 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, showgrammar=False, code_objects={}, compile_mode='exec', 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, 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) tokens, customize = scanner.ingest(co, code_objects=code_objects, - show_asm=showasm) + show_asm=debug_opts['asm']) debug_parser = dict(PARSER_DEFAULT_DEBUG) - if showgrammar: - debug_parser['reduce'] = showgrammar + if debug_opts.get('grammar', None): + debug_parser['reduce'] = debug_opts['grammar'] debug_parser['errorstack'] = 'full' # Build Syntax Tree from disassembly. 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, 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") return deparsed -# -DEFAULT_DEBUG_OPTS = { - 'asm': False, - 'tree': False, - 'grammar': False -} def deparse_code2str(code, out=sys.stdout, version=None, debug_opts=DEFAULT_DEBUG_OPTS, code_objects={}, compile_mode='exec',