mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Merged revisions 78242 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r78242 | brett.cannon | 2010-02-19 11:01:06 -0500 (Fri, 19 Feb 2010) | 5 lines Importlib was not matching import's handling of .pyc files where it had less then 8 bytes total in the file. Fixes issues 7361 & 7875. ........
This commit is contained in:
parent
9603428755
commit
39440b14cd
3 changed files with 111 additions and 29 deletions
|
@ -407,19 +407,24 @@ class PyPycLoader(PyLoader):
|
|||
bytecode_path = self.bytecode_path(fullname)
|
||||
if bytecode_path:
|
||||
data = self.get_data(bytecode_path)
|
||||
magic = data[:4]
|
||||
pyc_timestamp = marshal._r_long(data[4:8])
|
||||
bytecode = data[8:]
|
||||
try:
|
||||
magic = data[:4]
|
||||
if len(magic) < 4:
|
||||
raise ImportError("bad magic number in {}".format(fullname))
|
||||
raw_timestamp = data[4:8]
|
||||
if len(raw_timestamp) < 4:
|
||||
raise EOFError("bad timestamp in {}".format(fullname))
|
||||
pyc_timestamp = marshal._r_long(raw_timestamp)
|
||||
bytecode = data[8:]
|
||||
# Verify that the magic number is valid.
|
||||
if imp.get_magic() != magic:
|
||||
raise ImportError("bad magic number")
|
||||
raise ImportError("bad magic number in {}".format(fullname))
|
||||
# Verify that the bytecode is not stale (only matters when
|
||||
# there is source to fall back on.
|
||||
if source_timestamp:
|
||||
if pyc_timestamp < source_timestamp:
|
||||
raise ImportError("bytecode is stale")
|
||||
except ImportError:
|
||||
except (ImportError, EOFError):
|
||||
# If source is available give it a shot.
|
||||
if source_timestamp is not None:
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue