Skip to content

Commit 92f618f

Browse files
author
rocky
committed
Handle unsupported magics better.
1 parent 1321433 commit 92f618f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

xdis/load.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828
import xdis.unmarshal
2929
from xdis.dropbox.decrypt25 import fix_dropbox_pyc
3030
from xdis.magics import (
31+
GRAAL3_MAGICS,
32+
JYTHON_MAGICS,
3133
PYPY3_MAGICS,
3234
PYTHON_MAGIC_INT,
35+
RUSTPYTHON_MAGICS,
3336
int2magic,
3437
magic2int,
3538
magic_int2tuple,
@@ -230,7 +233,7 @@ def load_module_from_file_object(
230233
else:
231234
raise ImportError(f"Bad magic number: '{magic}'")
232235

233-
if magic_int in (2657, 65226, 22138):
236+
if magic_int in [2657, 22138] + list(GRAAL3_MAGICS) + list(RUSTPYTHON_MAGICS) + list(JYTHON_MAGICS):
234237
version = magicint2version.get(magic_int, "")
235238
raise ImportError(f"Magic int {magic_int} ({version}) is not supported.")
236239

xdis/magics.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@
4040

4141
from xdis.version_info import IS_GRAAL, IS_PYPY, IS_RUST, version_tuple_to_str
4242

43-
PYPY3_MAGICS = (48, 64, 112, 160, 192, 240, 244, 256, 336, 384, 416)
4443
GRAAL3_MAGICS = (21150, 21280, 21290)
44+
JYTHON_MAGICS = (1011, 65526)
45+
PYPY3_MAGICS = (48, 64, 112, 160, 192, 240, 244, 256, 336, 384, 416)
4546
RUSTPYTHON_MAGICS = (
4647
12641, # RustPython 3.12
4748
12897, # RustPython 3.12

0 commit comments

Comments
 (0)