Skip to content

Commit

Permalink
Fix(ImportManager): Fixed unmarshalling byte-code files
Browse files Browse the repository at this point in the history
Different Python versions change marshalled byte-code format.
  • Loading branch information
phdru committed Nov 16, 2024
1 parent b6499ba commit 523eb77
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Cheetah/ImportManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,21 @@ def getmod(self, nm, getsuffixes=get_suffixes,
with open(pyc[0], 'rb') as pyc_file:
stuff = pyc_file.read()
try:
co = loadco(stuff[8:])
# Different Python versions
# change marshalled byte-code format
if PY2:
offsets = [8]
else:
offsets = [16, 12]
for offset in offsets:
try:
co = loadco(stuff[offset:])
except (ValueError, EOFError):
pass
else:
break
else:
raise
__file__ = pyc[0]
break
except (ValueError, EOFError):
Expand Down
3 changes: 3 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Bug fixes:
- Use ``cache_from_source`` in ``ImportManager`` to find out
``.pyc``/``.pyo`` byte-code files.

- Fixed unmarshalling ``.pyc``/``.pyo`` byte-code files
in ``ImportManager``.

- Fixed ``Template.webInput``: Use ``urllib.parse.parse_qs``
instead of ``cgi.FieldStorage``; Python 3.13 dropped ``cgi``.

Expand Down

0 comments on commit 523eb77

Please sign in to comment.