summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/abc.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-07-02 18:35:34 (GMT)
committerBrett Cannon <brett@python.org>2012-07-02 18:35:34 (GMT)
commit1e331560eea62c78ec189f2b72b59864ee315ddc (patch)
tree1d87381377f9e8d61439dacc74d56d516344df1c /Lib/importlib/abc.py
parentd57caf36bd4f261b5d1e7ba758001fe5b6416daf (diff)
downloadcpython-1e331560eea62c78ec189f2b72b59864ee315ddc.zip
cpython-1e331560eea62c78ec189f2b72b59864ee315ddc.tar.gz
cpython-1e331560eea62c78ec189f2b72b59864ee315ddc.tar.bz2
Closes #15030: Make importlib.abc.PyPycLoader respect the new .pyc
file size header field. Thanks to Marc Abramowitz and Ronan Lamy for helping out with various parts of the patch.
Diffstat (limited to 'Lib/importlib/abc.py')
-rw-r--r--Lib/importlib/abc.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py
index c171da3..8d65907 100644
--- a/Lib/importlib/abc.py
+++ b/Lib/importlib/abc.py
@@ -282,7 +282,12 @@ class PyPycLoader(PyLoader):
if len(raw_timestamp) < 4:
raise EOFError("bad timestamp in {}".format(fullname))
pyc_timestamp = _bootstrap._r_long(raw_timestamp)
- bytecode = data[8:]
+ raw_source_size = data[8:12]
+ if len(raw_source_size) != 4:
+ raise EOFError("bad file size in {}".format(fullname))
+ # Source size is unused as the ABC does not provide a way to
+ # get the size of the source ahead of reading it.
+ bytecode = data[12:]
# Verify that the magic number is valid.
if imp.get_magic() != magic:
raise ImportError(
@@ -318,6 +323,7 @@ class PyPycLoader(PyLoader):
if not sys.dont_write_bytecode:
data = bytearray(imp.get_magic())
data.extend(_bootstrap._w_long(source_timestamp))
+ data.extend(_bootstrap._w_long(len(source) & 0xFFFFFFFF))
data.extend(marshal.dumps(code_object))
self.write_bytecode(fullname, data)
return code_object