Skip to content

Commit 523eb77

Browse files
committed
Fix(ImportManager): Fixed unmarshalling byte-code files
Different Python versions change marshalled byte-code format.
1 parent b6499ba commit 523eb77

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Cheetah/ImportManager.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,21 @@ def getmod(self, nm, getsuffixes=get_suffixes,
239239
with open(pyc[0], 'rb') as pyc_file:
240240
stuff = pyc_file.read()
241241
try:
242-
co = loadco(stuff[8:])
242+
# Different Python versions
243+
# change marshalled byte-code format
244+
if PY2:
245+
offsets = [8]
246+
else:
247+
offsets = [16, 12]
248+
for offset in offsets:
249+
try:
250+
co = loadco(stuff[offset:])
251+
except (ValueError, EOFError):
252+
pass
253+
else:
254+
break
255+
else:
256+
raise
243257
__file__ = pyc[0]
244258
break
245259
except (ValueError, EOFError):

docs/news.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ Bug fixes:
1414
- Use ``cache_from_source`` in ``ImportManager`` to find out
1515
``.pyc``/``.pyo`` byte-code files.
1616

17+
- Fixed unmarshalling ``.pyc``/``.pyo`` byte-code files
18+
in ``ImportManager``.
19+
1720
- Fixed ``Template.webInput``: Use ``urllib.parse.parse_qs``
1821
instead of ``cgi.FieldStorage``; Python 3.13 dropped ``cgi``.
1922

0 commit comments

Comments
 (0)