summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2009-02-05 02:52:18 (GMT)
committerBrett Cannon <bcannon@gmail.com>2009-02-05 02:52:18 (GMT)
commitf7e5a8c72483fbfd3cd8b8fe531500e0828c62ec (patch)
tree87f77fd5cd03d1641ccf4aec543cd60a08f81b91 /Lib/importlib
parentbe2f57c39a2d63e55f03c28289379e67ceb1a766 (diff)
downloadcpython-f7e5a8c72483fbfd3cd8b8fe531500e0828c62ec.zip
cpython-f7e5a8c72483fbfd3cd8b8fe531500e0828c62ec.tar.gz
cpython-f7e5a8c72483fbfd3cd8b8fe531500e0828c62ec.tar.bz2
Rename importlib._bootstrap.SysPathFinder to PathFinder and expose off of
importlib.machinery. Also make the methods either class or staticmethods.
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/_bootstrap.py34
1 files changed, 16 insertions, 18 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index d59fa85..849dabb 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -589,33 +589,29 @@ class PyFileImporter(FileImporter):
super(PyFileImporter, self).__init__(path_entry)
-class SysPathFinder:
+class PathFinder:
"""Meta path finder for sys.(path|path_hooks|path_importer_cache)."""
- def _default_hook(self, path):
- """Use the default hook on 'path'.
-
- If the path will not work for the default hook then raise ImportError.
-
- """
- # TODO(brett.cannon) Implement
- raise ImportError
+ _default_hook = staticmethod(chaining_fs_path_hook(ExtensionFileImporter,
+ PyFileImporter))
# The list of implicit hooks cannot be a class attribute because of
# bootstrapping issues for accessing imp.
- def _implicit_hooks(self, path):
+ @classmethod
+ def _implicit_hooks(cls):
"""Return a list of the implicit path hooks."""
return [self._default_hook, imp.NullImporter]
- def _path_hooks(self, path):
+ @classmethod
+ def _path_hooks(cls, path):
"""Search sys.path_hooks for a finder for 'path'.
Guaranteed to return a finder for the path as NullImporter is the
default importer for any path that does not have an explicit finder.
"""
- for hook in sys.path_hooks + self._implicit_hooks():
+ for hook in sys.path_hooks + cls._implicit_hooks():
try:
return hook(path)
except ImportError:
@@ -625,7 +621,8 @@ class SysPathFinder:
raise SystemError("no hook could find an importer for "
"{0}".format(path))
- def _path_importer_cache(self, path):
+ @classmethod
+ def _path_importer_cache(cls, path):
"""Get the finder for the path from sys.path_importer_cache.
If the path is not in the cache, find the appropriate finder and cache
@@ -638,24 +635,25 @@ class SysPathFinder:
"""
try:
- finder = sys.path_importer_cache(path);
+ finder = sys.path_importer_cache[path]
except KeyError:
- finder = self._path_hooks(path)
+ finder = cls._path_hooks(path)
sys.path_importer_cache[path] = finder
else:
if finder is None:
# Raises ImportError on failure.
- finder = self._default_hook(path)
+ finder = cls._default_hook(path)
sys.path_importer_cache[path] = finder
return finder
- def find_module(self, fullname, path=None):
+ @classmethod
+ def find_module(cls, fullname, path=None):
"""Find the module on sys.path or 'path'."""
if not path:
path = sys.path
for entry in path:
try:
- finder = self._path_importer_cache(entry)
+ finder = cls._path_importer_cache(entry)
except ImportError:
continue
loader = finder.find_module(fullname)