summaryrefslogtreecommitdiffstats
path: root/Lib/pkgutil.py
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2014-01-04 22:09:53 (GMT)
committerEric Snow <ericsnowcurrently@gmail.com>2014-01-04 22:09:53 (GMT)
commit37148b27ac742bc61087a8413863d70d43476bf4 (patch)
tree1d475f45c86875345f77065c1410d82168c0da8b /Lib/pkgutil.py
parent335e14dd1adb302bc0e5b99534ccfca43c7a4d6c (diff)
downloadcpython-37148b27ac742bc61087a8413863d70d43476bf4.zip
cpython-37148b27ac742bc61087a8413863d70d43476bf4.tar.gz
cpython-37148b27ac742bc61087a8413863d70d43476bf4.tar.bz2
Issue #19708: Update pkgutil to use the new importer APIs.
Diffstat (limited to 'Lib/pkgutil.py')
-rw-r--r--Lib/pkgutil.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py
index 4682d22..405a03d 100644
--- a/Lib/pkgutil.py
+++ b/Lib/pkgutil.py
@@ -16,6 +16,21 @@ __all__ = [
'ImpImporter', 'ImpLoader', 'read_code', 'extend_path',
]
+
+def _get_spec(finder, name):
+ """Return the finder-specific module spec."""
+ # Works with legacy finders.
+ try:
+ find_spec = finder.find_spec
+ except AttributeError:
+ loader = finder.find_module(name)
+ if loader is None:
+ return None
+ return importlib.util.spec_from_loader(name, loader)
+ else:
+ return find_spec(name)
+
+
def read_code(stream):
# This helper is needed in order for the PEP 302 emulation to
# correctly handle compiled files
@@ -326,9 +341,10 @@ class ImpLoader:
self.source = self._get_delegate().get_source()
return self.source
-
def _get_delegate(self):
- return ImpImporter(self.filename).find_module('__init__')
+ finder = ImpImporter(self.filename)
+ spec = _get_spec(finder, '__init__')
+ return spec.loader
def get_filename(self, fullname=None):
fullname = self._fix_name(fullname)