[Python-checkins] r69281 - python/branches/py3k/Lib/importlib/_bootstrap.py

brett.cannon python-checkins at python.org
Thu Feb 5 03:52:18 CET 2009


Author: brett.cannon
Date: Thu Feb  5 03:52:18 2009
New Revision: 69281

Log:
Rename importlib._bootstrap.SysPathFinder to PathFinder and expose off of
importlib.machinery. Also make the methods either class or staticmethods.


Modified:
   python/branches/py3k/Lib/importlib/_bootstrap.py

Modified: python/branches/py3k/Lib/importlib/_bootstrap.py
==============================================================================
--- python/branches/py3k/Lib/importlib/_bootstrap.py	(original)
+++ python/branches/py3k/Lib/importlib/_bootstrap.py	Thu Feb  5 03:52:18 2009
@@ -589,33 +589,29 @@
         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 @@
             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 @@
 
         """
         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)


More information about the Python-checkins mailing list