Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions
importlib._bootstrap.PathFinder Class Reference
Inheritance diagram for importlib._bootstrap.PathFinder:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def find_module

Private Member Functions

def _path_hooks
def _path_importer_cache

Detailed Description

Meta path finder for sys.(path|path_hooks|path_importer_cache).

Definition at line 577 of file _bootstrap.py.


Member Function Documentation

def importlib._bootstrap.PathFinder._path_hooks (   cls,
  path,
  hooks = None 
) [private]
Search sequence of hooks for a finder for 'path'.

If 'hooks' is false then use sys.path_hooks.

Definition at line 582 of file _bootstrap.py.

00582 
00583     def _path_hooks(cls, path, hooks=None):
00584         """Search sequence of hooks for a finder for 'path'.
00585 
00586         If 'hooks' is false then use sys.path_hooks.
00587 
00588         """
00589         if not hooks:
00590             hooks = sys.path_hooks
00591         for hook in hooks:
00592             try:
00593                 return hook(path)
00594             except ImportError:
00595                 continue
00596         else:
00597             raise ImportError("no path hook found for {0}".format(path))

def importlib._bootstrap.PathFinder._path_importer_cache (   cls,
  path,
  default = None 
) [private]
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
it. If None is cached, get the default finder and cache that
(if applicable).

Because of NullImporter, some finder should be returned. The only
explicit fail case is if None is cached but the path cannot be used for
the default hook, for which ImportError is raised.

Definition at line 599 of file _bootstrap.py.

00599 
00600     def _path_importer_cache(cls, path, default=None):
00601         """Get the finder for the path from sys.path_importer_cache.
00602 
00603         If the path is not in the cache, find the appropriate finder and cache
00604         it. If None is cached, get the default finder and cache that
00605         (if applicable).
00606 
00607         Because of NullImporter, some finder should be returned. The only
00608         explicit fail case is if None is cached but the path cannot be used for
00609         the default hook, for which ImportError is raised.
00610 
00611         """
00612         try:
00613             finder = sys.path_importer_cache[path]
00614         except KeyError:
00615             finder = cls._path_hooks(path)
00616             sys.path_importer_cache[path] = finder
00617         else:
00618             if finder is None and default:
00619                 # Raises ImportError on failure.
00620                 finder = default(path)
00621                 sys.path_importer_cache[path] = finder
00622         return finder

def importlib._bootstrap.PathFinder.find_module (   cls,
  fullname,
  path = None 
)
Find the module on sys.path or 'path' based on sys.path_hooks and
sys.path_importer_cache.

Definition at line 624 of file _bootstrap.py.

00624 
00625     def find_module(cls, fullname, path=None):
00626         """Find the module on sys.path or 'path' based on sys.path_hooks and
00627         sys.path_importer_cache."""
00628         if not path:
00629             path = sys.path
00630         for entry in path:
00631             try:
00632                 finder = cls._path_importer_cache(entry)
00633             except ImportError:
00634                 continue
00635             if finder:
00636                 loader = finder.find_module(fullname)
00637                 if loader:
00638                     return loader
00639         else:
00640             return None
00641 

Here is the caller graph for this function:


The documentation for this class was generated from the following file: