Skip to content

Commit 6237282

Browse files
committed
Track chaning xdis api
1 parent 94ca614 commit 6237282

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ description = "Python cross-version byte-code library and disassembler"
1212
dependencies = [
1313
"click",
1414
"spark-parser >= 1.8.9, < 1.9.2",
15-
"xdis >= 6.1.0, < 6.3",
15+
"xdis >= 6.2",
1616
]
1717
readme = "README.rst"
1818

uncompyle6/code_fns.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
from collections import deque
3636

3737
from xdis import check_object_path, iscode, load_module
38-
from xdis.version_info import version_tuple_to_str
38+
from xdis.version_info import PythonImplementation, version_tuple_to_str
39+
3940
from uncompyle6.scanner import get_scanner
4041

4142

@@ -70,8 +71,7 @@ def disco_loop(disasm, queue, real_out):
7071
)
7172
else:
7273
print(
73-
"\n# %s of %s"
74-
% (co.co_name, co.co_filename),
74+
"\n# %s of %s" % (co.co_name, co.co_filename),
7575
file=real_out,
7676
)
7777
tokens, customize = disasm(co)
@@ -107,14 +107,26 @@ def disassemble_file(filename, outstream=None):
107107
try to find the corresponding compiled object.
108108
"""
109109
filename = check_object_path(filename)
110-
(version, timestamp, magic_int, co, is_pypy, source_size, sip_hash) = load_module(
111-
filename
112-
)
113-
if type(co) == list:
110+
(
111+
version,
112+
timestamp,
113+
magic_int,
114+
co,
115+
python_implementation,
116+
source_size,
117+
sip_hash,
118+
_,
119+
) = load_module(filename)
120+
if isinstance(co, list):
114121
for con in co:
115122
disco(version, con, outstream)
116123
else:
117-
disco(version, co, outstream, is_pypy=is_pypy)
124+
disco(
125+
version,
126+
co,
127+
outstream,
128+
is_pypy=python_implementation == PythonImplementation.PyPy,
129+
)
118130

119131

120132
def _test():

uncompyle6/main.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@
2525

2626
from xdis import iscode
2727
from xdis.load import load_module
28-
from xdis.version_info import IS_PYPY, PYTHON_VERSION_TRIPLE, version_tuple_to_str
28+
from xdis.version_info import (
29+
IS_PYPY,
30+
PYTHON_VERSION_TRIPLE,
31+
PythonImplementation,
32+
version_tuple_to_str,
33+
)
2934

3035
from uncompyle6.code_fns import check_object_path
3136
from uncompyle6.parser import ParserError
@@ -113,7 +118,7 @@ def write(s):
113118
write(f"# -*- coding: {source_encoding} -*-")
114119
write(
115120
"# uncompyle6 version %s\n"
116-
"# %sPython bytecode version base %s%s\n# Decompiled from: %sPython %s"
121+
"# %sPython bytecode version base %s%s\n# Decompiled from: %sPython %s"
117122
% (
118123
__version__,
119124
co_pypy_str,
@@ -216,9 +221,16 @@ def decompile_file(
216221

217222
filename = check_object_path(filename)
218223
code_objects = {}
219-
version, timestamp, magic_int, co, is_pypy, source_size, _ = load_module(
220-
filename, code_objects
221-
)
224+
(
225+
version,
226+
timestamp,
227+
magic_int,
228+
co,
229+
python_implementation,
230+
source_size,
231+
_,
232+
_,
233+
) = load_module(filename, code_objects)
222234

223235
if isinstance(co, list):
224236
deparsed = []
@@ -234,7 +246,7 @@ def decompile_file(
234246
showgrammar,
235247
source_encoding,
236248
code_objects=code_objects,
237-
is_pypy=is_pypy,
249+
is_pypy=python_implementation == PythonImplementation.PyPy,
238250
magic_int=magic_int,
239251
mapstream=mapstream,
240252
start_offset=start_offset,
@@ -254,7 +266,7 @@ def decompile_file(
254266
source_encoding,
255267
code_objects=code_objects,
256268
source_size=source_size,
257-
is_pypy=is_pypy,
269+
is_pypy=python_implementation == PythonImplementation.PyPy,
258270
magic_int=magic_int,
259271
mapstream=mapstream,
260272
do_fragments=do_fragments,

0 commit comments

Comments
 (0)