This commit is contained in:
rocky
2024-07-21 18:36:12 -04:00
parent 1a3f2b8ab0
commit b0dd7f57c6
2 changed files with 10 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2015-2016, 2818-2022 by Rocky Bernstein # Copyright (c) 2015-2016, 2818-2022, 2024 by Rocky Bernstein
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org> # Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com> # Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
# Copyright (c) 1999 John Aycock # Copyright (c) 1999 John Aycock
@@ -17,10 +17,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
CPython magic- and version- independent disassembly routines CPython magic- and version-independent disassembly routines
There are two reasons we can't use Python's built-in routines There are two reasons we can't use Python's built-in routines
from dis. First, the bytecode we are extracting may be from a different from ``dis``.
First, the bytecode we are extracting may be from a different
version of Python (different magic number) than the version of Python version of Python (different magic number) than the version of Python
that is doing the extraction. that is doing the extraction.
@@ -39,12 +41,12 @@ from uncompyle6.scanner import get_scanner
def disco(version, co, out=None, is_pypy=False): def disco(version, co, out=None, is_pypy=False):
""" """
diassembles and deparses a given code block 'co' diassembles and deparses a given code block ``co``.
""" """
assert iscode(co) assert iscode(co)
# store final output stream for case of error # Store final output stream in case there is an error.
real_out = out or sys.stdout real_out = out or sys.stdout
print("# Python %s" % version_tuple_to_str(version), file=real_out) print("# Python %s" % version_tuple_to_str(version), file=real_out)
if co.co_filename: if co.co_filename:
@@ -99,7 +101,7 @@ def disco_loop(disasm, queue, real_out):
def disassemble_file(filename, outstream=None): def disassemble_file(filename, outstream=None):
""" """
disassemble Python byte-code file (.pyc) Disassemble Python byte-code file (.pyc).
If given a Python source file (".py") file, we'll If given a Python source file (".py") file, we'll
try to find the corresponding compiled object. try to find the corresponding compiled object.
@@ -113,7 +115,6 @@ def disassemble_file(filename, outstream=None):
disco(version, con, outstream) disco(version, con, outstream)
else: else:
disco(version, co, outstream, is_pypy=is_pypy) disco(version, co, outstream, is_pypy=is_pypy)
co = None
def _test(): def _test():

View File

@@ -669,6 +669,8 @@ def get_python_parser(
version = version[:2] version = version[:2]
p = None
# FIXME: there has to be a better way... # FIXME: there has to be a better way...
# We could do this as a table lookup, but that would force us # We could do this as a table lookup, but that would force us
# in import all of the parsers all of the time. Perhaps there is # in import all of the parsers all of the time. Perhaps there is