You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Show magic number in output
Fix bugs due to removal of token.format()
This commit is contained in:
@@ -12,7 +12,7 @@ from xdis.load import load_module
|
|||||||
def uncompyle(
|
def uncompyle(
|
||||||
version, co, out=None, showasm=False, showast=False,
|
version, co, out=None, showasm=False, showast=False,
|
||||||
timestamp=None, showgrammar=False, code_objects={},
|
timestamp=None, showgrammar=False, code_objects={},
|
||||||
is_pypy=False):
|
is_pypy=False, magic_int=None):
|
||||||
"""
|
"""
|
||||||
disassembles and deparses a given code block 'co'
|
disassembles and deparses a given code block 'co'
|
||||||
"""
|
"""
|
||||||
@@ -22,8 +22,10 @@ def uncompyle(
|
|||||||
real_out = out or sys.stdout
|
real_out = out or sys.stdout
|
||||||
co_pypy_str = 'PyPy ' if is_pypy else ''
|
co_pypy_str = 'PyPy ' if is_pypy else ''
|
||||||
run_pypy_str = 'PyPy ' if IS_PYPY else ''
|
run_pypy_str = 'PyPy ' if IS_PYPY else ''
|
||||||
print('# %sPython bytecode %s (disassembled from %sPython %s)\n' %
|
print('# %sPython bytecode %s%s disassembled from %sPython %s' %
|
||||||
(co_pypy_str, version, run_pypy_str, PYTHON_VERSION),
|
(co_pypy_str, version,
|
||||||
|
" (%d)" % magic_int if magic_int else "",
|
||||||
|
run_pypy_str, PYTHON_VERSION),
|
||||||
file=real_out)
|
file=real_out)
|
||||||
if co.co_filename:
|
if co.co_filename:
|
||||||
print('# Embedded file name: %s' % co.co_filename,
|
print('# Embedded file name: %s' % co.co_filename,
|
||||||
@@ -60,11 +62,11 @@ def uncompyle_file(filename, outstream=None, showasm=False, showast=False,
|
|||||||
for con in co:
|
for con in co:
|
||||||
uncompyle(version, con, outstream, showasm, showast,
|
uncompyle(version, con, outstream, showasm, showast,
|
||||||
timestamp, showgrammar, code_objects=code_objects,
|
timestamp, showgrammar, code_objects=code_objects,
|
||||||
is_pypy=is_pypy)
|
is_pypy=is_pypy, magic_int=magic_int)
|
||||||
else:
|
else:
|
||||||
uncompyle(version, co, outstream, showasm, showast,
|
uncompyle(version, co, outstream, showasm, showast,
|
||||||
timestamp, showgrammar, code_objects=code_objects,
|
timestamp, showgrammar, code_objects=code_objects,
|
||||||
is_pypy=is_pypy)
|
is_pypy=is_pypy, magic_int=magic_int)
|
||||||
co = None
|
co = None
|
||||||
|
|
||||||
# FIXME: combine into an options parameter
|
# FIXME: combine into an options parameter
|
||||||
|
@@ -14,7 +14,7 @@ def maybe_show_asm(showasm, tokens):
|
|||||||
if showasm:
|
if showasm:
|
||||||
stream = showasm if hasattr(showasm, 'write') else sys.stdout
|
stream = showasm if hasattr(showasm, 'write') else sys.stdout
|
||||||
for t in tokens:
|
for t in tokens:
|
||||||
stream.write(t)
|
stream.write(str(t))
|
||||||
stream.write('\n')
|
stream.write('\n')
|
||||||
|
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ def maybe_show_ast(showast, ast):
|
|||||||
"""
|
"""
|
||||||
if showast:
|
if showast:
|
||||||
stream = showast if hasattr(showast, 'write') else sys.stdout
|
stream = showast if hasattr(showast, 'write') else sys.stdout
|
||||||
stream.write(repr(ast))
|
stream.write(str(ast))
|
||||||
stream.write('\n')
|
stream.write('\n')
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user