Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
pkgutil.ImpLoader Class Reference

List of all members.

Public Member Functions

def __init__
def load_module
def get_data
def is_package
def get_code
def get_source
def get_filename
def iter_zipimport_modules

Public Attributes

 file
 filename
 fullname
 etc
 source

Static Public Attributes

 code = sourceNone

Private Member Functions

def _reopen
def _fix_name
def _get_delegate

Detailed Description

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

Definition at line 221 of file pkgutil.py.


Constructor & Destructor Documentation

def pkgutil.ImpLoader.__init__ (   self,
  fullname,
  file,
  filename,
  etc 
)

Definition at line 226 of file pkgutil.py.

00226 
00227     def __init__(self, fullname, file, filename, etc):
00228         self.file = file
00229         self.filename = filename
00230         self.fullname = fullname
00231         self.etc = etc

Here is the caller graph for this function:


Member Function Documentation

def pkgutil.ImpLoader._fix_name (   self,
  fullname 
) [private]

Definition at line 255 of file pkgutil.py.

00255 
00256     def _fix_name(self, fullname):
00257         if fullname is None:
00258             fullname = self.fullname
00259         elif fullname != self.fullname:
00260             raise ImportError("Loader for module %s cannot handle "
00261                               "module %s" % (self.fullname, fullname))
00262         return fullname

Here is the caller graph for this function:

def pkgutil.ImpLoader._get_delegate (   self) [private]

Definition at line 304 of file pkgutil.py.

00304 
00305     def _get_delegate(self):
00306         return ImpImporter(self.filename).find_module('__init__')

Here is the call graph for this function:

Here is the caller graph for this function:

def pkgutil.ImpLoader._reopen (   self) [private]

Definition at line 247 of file pkgutil.py.

00247 
00248     def _reopen(self):
00249         if self.file and self.file.closed:
00250             mod_type = self.etc[2]
00251             if mod_type==imp.PY_SOURCE:
00252                 self.file = open(self.filename, 'rU')
00253             elif mod_type in (imp.PY_COMPILED, imp.C_EXTENSION):
00254                 self.file = open(self.filename, 'rb')

Here is the caller graph for this function:

def pkgutil.ImpLoader.get_code (   self,
  fullname = None 
)

Definition at line 267 of file pkgutil.py.

00267 
00268     def get_code(self, fullname=None):
00269         fullname = self._fix_name(fullname)
00270         if self.code is None:
00271             mod_type = self.etc[2]
00272             if mod_type==imp.PY_SOURCE:
00273                 source = self.get_source(fullname)
00274                 self.code = compile(source, self.filename, 'exec')
00275             elif mod_type==imp.PY_COMPILED:
00276                 self._reopen()
00277                 try:
00278                     self.code = read_code(self.file)
00279                 finally:
00280                     self.file.close()
00281             elif mod_type==imp.PKG_DIRECTORY:
00282                 self.code = self._get_delegate().get_code()
00283         return self.code

Here is the call graph for this function:

Here is the caller graph for this function:

def pkgutil.ImpLoader.get_data (   self,
  pathname 
)

Definition at line 243 of file pkgutil.py.

00243 
00244     def get_data(self, pathname):
00245         with open(pathname, "rb") as file:
00246             return file.read()

Here is the caller graph for this function:

def pkgutil.ImpLoader.get_filename (   self,
  fullname = None 
)

Definition at line 307 of file pkgutil.py.

00307 
00308     def get_filename(self, fullname=None):
00309         fullname = self._fix_name(fullname)
00310         mod_type = self.etc[2]
00311         if self.etc[2]==imp.PKG_DIRECTORY:
00312             return self._get_delegate().get_filename()
00313         elif self.etc[2] in (imp.PY_SOURCE, imp.PY_COMPILED, imp.C_EXTENSION):
00314             return self.filename
00315         return None
00316 
00317 
try:

Here is the call graph for this function:

Here is the caller graph for this function:

def pkgutil.ImpLoader.get_source (   self,
  fullname = None 
)

Definition at line 284 of file pkgutil.py.

00284 
00285     def get_source(self, fullname=None):
00286         fullname = self._fix_name(fullname)
00287         if self.source is None:
00288             mod_type = self.etc[2]
00289             if mod_type==imp.PY_SOURCE:
00290                 self._reopen()
00291                 try:
00292                     self.source = self.file.read()
00293                 finally:
00294                     self.file.close()
00295             elif mod_type==imp.PY_COMPILED:
00296                 if os.path.exists(self.filename[:-1]):
00297                     f = open(self.filename[:-1], 'rU')
00298                     self.source = f.read()
00299                     f.close()
00300             elif mod_type==imp.PKG_DIRECTORY:
00301                 self.source = self._get_delegate().get_source()
00302         return self.source
00303 

Here is the call graph for this function:

Here is the caller graph for this function:

def pkgutil.ImpLoader.is_package (   self,
  fullname 
)

Definition at line 263 of file pkgutil.py.

00263 
00264     def is_package(self, fullname):
00265         fullname = self._fix_name(fullname)
00266         return self.etc[2]==imp.PKG_DIRECTORY

Here is the call graph for this function:

def pkgutil.ImpLoader.iter_zipimport_modules (   importer,
  prefix = '' 
)

Definition at line 321 of file pkgutil.py.

00321 
00322     def iter_zipimport_modules(importer, prefix=''):
00323         dirlist = sorted(zipimport._zip_directory_cache[importer.archive])
00324         _prefix = importer.prefix
00325         plen = len(_prefix)
00326         yielded = {}
00327         import inspect
00328         for fn in dirlist:
00329             if not fn.startswith(_prefix):
00330                 continue
00331 
00332             fn = fn[plen:].split(os.sep)
00333 
00334             if len(fn)==2 and fn[1].startswith('__init__.py'):
00335                 if fn[0] not in yielded:
00336                     yielded[fn[0]] = 1
00337                     yield fn[0], True
00338 
00339             if len(fn)!=1:
00340                 continue
00341 
00342             modname = inspect.getmodulename(fn[0])
00343             if modname=='__init__':
00344                 continue
00345 
00346             if modname and '.' not in modname and modname not in yielded:
00347                 yielded[modname] = 1
00348                 yield prefix + modname, False

Here is the call graph for this function:

def pkgutil.ImpLoader.load_module (   self,
  fullname 
)

Definition at line 232 of file pkgutil.py.

00232 
00233     def load_module(self, fullname):
00234         self._reopen()
00235         try:
00236             mod = imp.load_module(fullname, self.file, self.filename, self.etc)
00237         finally:
00238             if self.file:
00239                 self.file.close()
00240         # Note: we don't set __loader__ because we want the module to look
00241         # normal; i.e. this is just a wrapper for standard import machinery
00242         return mod

Here is the call graph for this function:


Member Data Documentation

pkgutil.ImpLoader.code = sourceNone [static]

Definition at line 224 of file pkgutil.py.

Definition at line 230 of file pkgutil.py.

Definition at line 227 of file pkgutil.py.

Definition at line 228 of file pkgutil.py.

Definition at line 229 of file pkgutil.py.

Definition at line 291 of file pkgutil.py.


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