summaryrefslogtreecommitdiffstats
path: root/Lib/modulefinder.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/modulefinder.py')
-rw-r--r--Lib/modulefinder.py22
1 files changed, 10 insertions, 12 deletions
diff --git a/Lib/modulefinder.py b/Lib/modulefinder.py
index f033ba9..f90a432 100644
--- a/Lib/modulefinder.py
+++ b/Lib/modulefinder.py
@@ -1,16 +1,14 @@
"""Find modules used by a script, using introspection."""
-from __future__ import generators
import dis
import imp
+import importlib.machinery
import marshal
import os
import sys
import types
import struct
-READ_MODE = "rU"
-
# XXX Clean up once str8's cstor matches bytes.
LOAD_CONST = bytes([dis.opname.index('LOAD_CONST')])
IMPORT_NAME = bytes([dis.opname.index('IMPORT_NAME')])
@@ -29,9 +27,7 @@ packagePathMap = {}
# A Public interface
def AddPackagePath(packagename, path):
- paths = packagePathMap.get(packagename, [])
- paths.append(path)
- packagePathMap[packagename] = paths
+ packagePathMap.setdefault(packagename, []).append(path)
replacePackageMap = {}
@@ -106,14 +102,14 @@ class ModuleFinder:
def run_script(self, pathname):
self.msg(2, "run_script", pathname)
- with open(pathname, READ_MODE) as fp:
+ with open(pathname) as fp:
stuff = ("", "r", imp.PY_SOURCE)
self.load_module('__main__', fp, pathname, stuff)
def load_file(self, pathname):
dir, name = os.path.split(pathname)
name, ext = os.path.splitext(name)
- with open(pathname, READ_MODE) as fp:
+ with open(pathname) as fp:
stuff = (ext, "r", imp.PY_SOURCE)
self.load_module(name, fp, pathname, stuff)
@@ -227,8 +223,9 @@ class ModuleFinder:
# But we must also collect Python extension modules - although
# we cannot separate normal dlls from Python extensions.
suffixes = []
- for triple in imp.get_suffixes():
- suffixes.append(triple[0])
+ suffixes += importlib.machinery.EXTENSION_SUFFIXES[:]
+ suffixes += importlib.machinery.SOURCE_SUFFIXES[:]
+ suffixes += importlib.machinery.BYTECODE_SUFFIXES[:]
for dir in m.__path__:
try:
names = os.listdir(dir)
@@ -270,7 +267,8 @@ class ModuleFinder:
try:
m = self.load_module(fqname, fp, pathname, stuff)
finally:
- if fp: fp.close()
+ if fp:
+ fp.close()
if parent:
setattr(parent, partname, m)
self.msgout(3, "import_module ->", m)
@@ -662,4 +660,4 @@ if __name__ == '__main__':
try:
mf = test()
except KeyboardInterrupt:
- print("\n[interrupt]")
+ print("\n[interrupted]")