Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
pkgutil.ImpImporter Class Reference

List of all members.

Public Member Functions

def __init__
def find_module
def iter_modules

Public Attributes

 path

Detailed Description

PEP 302 Importer that wraps Python's "classic" import algorithm

ImpImporter(dirname) produces a PEP 302 importer that searches that
directory.  ImpImporter(None) produces a PEP 302 importer that searches
the current sys.path, plus any modules that are frozen or built-in.

Note that ImpImporter does not currently support being used by placement
on sys.meta_path.

Definition at line 159 of file pkgutil.py.


Constructor & Destructor Documentation

def pkgutil.ImpImporter.__init__ (   self,
  path = None 
)

Definition at line 170 of file pkgutil.py.

00170 
00171     def __init__(self, path=None):
00172         self.path = path

Here is the caller graph for this function:


Member Function Documentation

def pkgutil.ImpImporter.find_module (   self,
  fullname,
  path = None 
)

Definition at line 173 of file pkgutil.py.

00173 
00174     def find_module(self, fullname, path=None):
00175         # Note: we ignore 'path' argument since it is only used via meta_path
00176         subname = fullname.split(".")[-1]
00177         if subname != fullname and self.path is None:
00178             return None
00179         if self.path is None:
00180             path = None
00181         else:
00182             path = [os.path.realpath(self.path)]
00183         try:
00184             file, filename, etc = imp.find_module(subname, path)
00185         except ImportError:
00186             return None
00187         return ImpLoader(fullname, file, filename, etc)

def pkgutil.ImpImporter.iter_modules (   self,
  prefix = '' 
)

Definition at line 188 of file pkgutil.py.

00188 
00189     def iter_modules(self, prefix=''):
00190         if self.path is None or not os.path.isdir(self.path):
00191             return
00192 
00193         yielded = {}
00194         import inspect
00195 
00196         filenames = os.listdir(self.path)
00197         filenames.sort()  # handle packages before same-named modules
00198 
00199         for fn in filenames:
00200             modname = inspect.getmodulename(fn)
00201             if modname=='__init__' or modname in yielded:
00202                 continue
00203 
00204             path = os.path.join(self.path, fn)
00205             ispkg = False
00206 
00207             if not modname and os.path.isdir(path) and '.' not in fn:
00208                 modname = fn
00209                 for fn in os.listdir(path):
00210                     subname = inspect.getmodulename(fn)
00211                     if subname=='__init__':
00212                         ispkg = True
00213                         break
00214                 else:
00215                     continue    # not a package
00216 
00217             if modname and '.' not in modname:
00218                 yielded[modname] = 1
00219                 yield prefix + modname, ispkg
00220 

Here is the call graph for this function:


Member Data Documentation

Definition at line 171 of file pkgutil.py.


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