diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2013-11-22 16:05:39 (GMT) |
---|---|---|
committer | Eric Snow <ericsnowcurrently@gmail.com> | 2013-11-22 16:05:39 (GMT) |
commit | b523f8433a8982e10eb41a3e2b37ee0e6d6a6e00 (patch) | |
tree | b38661db4903b7edc4042e7562b32720dd3687bf /Lib/pkgutil.py | |
parent | 9e6097ebe7bb99a4a22b949ef4b1563b21ad7166 (diff) | |
download | cpython-b523f8433a8982e10eb41a3e2b37ee0e6d6a6e00.zip cpython-b523f8433a8982e10eb41a3e2b37ee0e6d6a6e00.tar.gz cpython-b523f8433a8982e10eb41a3e2b37ee0e6d6a6e00.tar.bz2 |
Implement PEP 451 (ModuleSpec).
Diffstat (limited to 'Lib/pkgutil.py')
-rw-r--r-- | Lib/pkgutil.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py index fb9e56e..4682d22 100644 --- a/Lib/pkgutil.py +++ b/Lib/pkgutil.py @@ -430,6 +430,7 @@ def iter_importers(fullname=""): for item in path: yield get_importer(item) + def get_loader(module_or_name): """Get a PEP 302 "loader" object for module_or_name @@ -570,6 +571,7 @@ def extend_path(path, name): return path + def get_data(package, resource): """Get a resource from a package. @@ -592,10 +594,15 @@ def get_data(package, resource): which does not support get_data(), then None is returned. """ - loader = get_loader(package) + spec = importlib.find_spec(package) + if spec is None: + return None + loader = spec.loader if loader is None or not hasattr(loader, 'get_data'): return None - mod = sys.modules.get(package) or loader.load_module(package) + # XXX needs test + mod = (sys.modules.get(package) or + importlib._bootstrap._SpecMethods(spec).load()) if mod is None or not hasattr(mod, '__file__'): return None |