summaryrefslogtreecommitdiffstats
path: root/Lib/modulefinder.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/modulefinder.py')
-rw-r--r--Lib/modulefinder.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/Lib/modulefinder.py b/Lib/modulefinder.py
index 264b0f0..cc5b8cc 100644
--- a/Lib/modulefinder.py
+++ b/Lib/modulefinder.py
@@ -1,13 +1,17 @@
"""Find modules used by a script, using introspection."""
import dis
-import imp
+import importlib._bootstrap
import importlib.machinery
import marshal
import os
import sys
import types
import struct
+import warnings
+with warnings.catch_warnings():
+ warnings.simplefilter('ignore', PendingDeprecationWarning)
+ import imp
# XXX Clean up once str8's cstor matches bytes.
LOAD_CONST = bytes([dis.opname.index('LOAD_CONST')])
@@ -229,7 +233,7 @@ class ModuleFinder:
for dir in m.__path__:
try:
names = os.listdir(dir)
- except os.error:
+ except OSError:
self.msg(2, "can't list directory", dir)
continue
for name in names:
@@ -284,11 +288,12 @@ class ModuleFinder:
if type == imp.PY_SOURCE:
co = compile(fp.read()+'\n', pathname, 'exec')
elif type == imp.PY_COMPILED:
- if fp.read(4) != imp.get_magic():
- self.msgout(2, "raise ImportError: Bad magic number", pathname)
- raise ImportError("Bad magic number in %s" % pathname)
- fp.read(8) # Skip mtime and size.
- co = marshal.load(fp)
+ try:
+ marshal_data = importlib._bootstrap._validate_bytecode_header(fp.read())
+ except ImportError as exc:
+ self.msgout(2, "raise ImportError: " + str(exc), pathname)
+ raise
+ co = marshal.loads(marshal_data)
else:
co = None
m = self.add_module(fqname)