Skip to content

Commit 3889463

Browse files
author
rocky
committed
Detect RustPython magic
1 parent 9db5641 commit 3889463

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

xdis/disasm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ def disassemble_file(
334334
source_size,
335335
sip_hash,
336336
) = load_module(pyc_filename)
337+
except (ImportError, NotImplementedError):
338+
raise
337339
except Exception:
338340
# Hack alert: we're using pyc_filename set as a proxy for whether the filename exists.
339341
# check_object_path() will succeed if the file exists.

xdis/load.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ def load_module_from_file_object(
329329
pass
330330
else:
331331
co = None
332+
except NotImplementedError:
333+
raise
332334
except Exception:
333335
kind, msg = sys.exc_info()[0:2]
334336
import traceback

xdis/magics.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
PYPY3_MAGICS = (48, 64, 112, 160, 192, 240, 244, 256, 336, 384)
4343
GRAAL3_MAGICS = (21150, 21280)
44+
RUSTPYTHON_MAGICS = (12641,)
4445

4546

4647
def add_magic_from_int(magic_int, version):
@@ -457,6 +458,8 @@ def __by_version(magic_versions: Dict[bytes, str]) -> dict:
457458
add_magic_from_int(336, "3.9pypy") # PyPy 3.9.15, PyPy 3.9.17
458459
add_magic_from_int(384, "3.10pypy") # PyPy 3.10.12
459460

461+
add_magic_from_int(12641, "3.13.0rust") # RustPython 3.13.0
462+
460463
# NOTE: This is JVM bytecode not Python bytecode
461464
add_magic_from_int(21150, "3.8.5Graal")
462465

xdis/unmarshal.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
from xdis.codetype import to_portable
3535
from xdis.cross_types import LongTypeForPython3, UnicodeForPython3
36-
from xdis.magics import GRAAL3_MAGICS, PYPY3_MAGICS, magic_int2tuple
36+
from xdis.magics import GRAAL3_MAGICS, PYPY3_MAGICS, RUSTPYTHON_MAGICS, magic_int2tuple
3737
from xdis.version_info import PYTHON3, PYTHON_VERSION_TRIPLE
3838

3939
if PYTHON3:
@@ -141,6 +141,8 @@ def __init__(self, fp, magic_int, bytes_for_s, code_objects={}):
141141
142142
In Python 3, a ``bytes`` type is used for strings.
143143
"""
144+
if magic_int in RUSTPYTHON_MAGICS:
145+
raise NotImplementedError("RustPython not supported yet")
144146
self.fp = fp
145147
self.magic_int = magic_int
146148
self.code_objects = code_objects
@@ -162,8 +164,8 @@ def __init__(self, fp, magic_int, bytes_for_s, code_objects={}):
162164
self.internStrings = []
163165
self.internObjects = []
164166
self.version_tuple = tuple()
165-
self.is_graal = False
166-
self.is_pypy = False
167+
self.is_graal = magic_int in GRAAL3_MAGICS
168+
self.is_pypy = magic_int in PYPY3_MAGICS
167169

168170
def load(self):
169171
"""

0 commit comments

Comments
 (0)