ihooks
index
/usr/lib/python2.2/ihooks.py

Import hook support.
 
Consistent use of this module will make it possible to change the
different mechanisms involved in loading modules independently.
 
While the built-in module imp exports interfaces to the built-in
module searching and loading algorithm, and it is possible to replace
the built-in function __import__ in order to change the semantics of
the import statement, until now it has been difficult to combine the
effect of different __import__ hacks, like loading modules from URLs
by rimport.py, or restricted execution by rexec.py.
 
This module defines three new concepts:
 
1) A "file system hooks" class provides an interface to a filesystem.
 
One hooks class is defined (Hooks), which uses the interface provided
by standard modules os and os.path.  It should be used as the base
class for other hooks classes.
 
2) A "module loader" class provides an interface to to search for a
module in a search path and to load it.  It defines a method which
searches for a module in a single directory; by overriding this method
one can redefine the details of the search.  If the directory is None,
built-in and frozen modules are searched instead.
 
Two module loader class are defined, both implementing the search
strategy used by the built-in __import__ function: ModuleLoader uses
the imp module's find_module interface, while HookableModuleLoader
uses a file system hooks class to interact with the file system.  Both
use the imp module's load_* interfaces to actually load the module.
 
3) A "module importer" class provides an interface to import a
module, as well as interfaces to reload and unload a module.  It also
provides interfaces to install and uninstall itself instead of the
default __import__ and reload (and unload) functions.
 
One module importer class is defined (ModuleImporter), which uses a
module loader instance passed in (by default HookableModuleLoader is
instantiated).
 
The classes defined here should be used as base classes for extended
functionality along those lines.
 
If a module importer class supports dotted names, its import_module()
must return a different value depending on whether it is called on
behalf of a "from ... import ..." statement or not.  (This is caused
by the way the __import__ hook is used by the Python interpreter.)  It
would also do wise to install a different version of reload().

 
Modules
            
__builtin__
imp
os
sys
 
Classes
            
_Verbose
BasicModuleImporter
ModuleImporter
BasicModuleLoader
ModuleLoader
FancyModuleLoader
Hooks
 
class BasicModuleImporter(_Verbose)
      Basic module importer; uses module loader.
 
This provides basic import facilities but no package imports.
 
   Methods defined here:
__init__(self, loader=None, verbose=0)
get_hooks(self)
get_loader(self)
import_module(self, name, globals={}, locals={}, fromlist=[])
install(self)
reload(self, module, path=None)
set_hooks(self, hooks)
set_loader(self, loader)
uninstall(self)
unload(self, module)

Data and non-method functions defined here:
__doc__ = 'Basic module importer; uses module loader.\n\n ...mport facilities but no package imports.\n\n '
__module__ = 'ihooks'

Methods inherited from _Verbose:
get_verbose(self)
message(self, format, *args)
note(self, *args)
set_verbose(self, verbose)
 
class BasicModuleLoader(_Verbose)
      Basic module loader.
 
This provides the same functionality as built-in import.  It
doesn't deal with checking sys.modules -- all it provides is
find_module() and a load_module(), as well as find_module_in_dir()
which searches just one directory, and can be overridden by a
derived class to change the module search algorithm when the basic
dependency on sys.path is unchanged.
 
The interface is a little more convenient than imp's:
find_module(name, [path]) returns None or 'stuff', and
load_module(name, stuff) loads the module.
 
   Methods defined here:
default_path(self)
find_builtin_module(self, name)
find_module(self, name, path=None)
find_module_in_dir(self, name, dir)
load_module(self, name, stuff)

Data and non-method functions defined here:
__doc__ = 'Basic module loader.\n\n This provides the s...ad_module(name, stuff) loads the module.\n\n '
__module__ = 'ihooks'

Methods inherited from _Verbose:
__init__(self, verbose=0)
get_verbose(self)
message(self, format, *args)
note(self, *args)
set_verbose(self, verbose)
 
class FancyModuleLoader(ModuleLoader)
      Fancy module loader -- parses and execs the code itself.
 
  
Method resolution order:
FancyModuleLoader
ModuleLoader
BasicModuleLoader
_Verbose

Methods defined here:
load_module(self, name, stuff)

Data and non-method functions defined here:
__doc__ = 'Fancy module loader -- parses and execs the code itself.'
__module__ = 'ihooks'

Methods inherited from ModuleLoader:
__init__(self, hooks=None, verbose=0)
default_path(self)
find_builtin_module(self, name)
find_module_in_dir(self, name, dir, allow_packages=1)
get_hooks(self)
modules_dict(self)
set_hooks(self, hooks)

Methods inherited from BasicModuleLoader:
find_module(self, name, path=None)

Methods inherited from _Verbose:
get_verbose(self)
message(self, format, *args)
note(self, *args)
set_verbose(self, verbose)
 
class Hooks(_Verbose)
      Hooks into the filesystem and interpreter.
 
By deriving a subclass you can redefine your filesystem interface,
e.g. to merge it with the URL space.
 
This base class behaves just like the native filesystem.
 
   Methods defined here:
add_module(self, name)
default_path(self)
get_frozen_object(self, name)
get_suffixes(self)
# imp interface
init_builtin(self, name)
init_frozen(self, name)
is_builtin(self, name)
is_frozen(self, name)
listdir(self, x)
load_compiled(self, name, filename, file=None)
load_dynamic(self, name, filename, file=None)
load_package(self, name, filename, file=None)
load_source(self, name, filename, file=None)
modules_dict(self)
# sys interface
new_module(self, name)
openfile(self, *x)
path_exists(self, x)
path_isabs(self, x)
path_isdir(self, x)
path_isfile(self, x)
path_islink(self, x)
path_join(self, x, y)
path_split(self, x)

Data and non-method functions defined here:
__doc__ = 'Hooks into the filesystem and interpreter.\n\n ...behaves just like the native filesystem.\n\n '
__module__ = 'ihooks'
listdir_error = <class exceptions.OSError>
OS system call failed.
openfile_error = <class exceptions.IOError>
I/O operation failed.

Methods inherited from _Verbose:
__init__(self, verbose=0)
get_verbose(self)
message(self, format, *args)
note(self, *args)
set_verbose(self, verbose)
 
class ModuleImporter(BasicModuleImporter)
      A module importer that supports packages.
 
  
Method resolution order:
ModuleImporter
BasicModuleImporter
_Verbose

Methods defined here:
determine_parent(self, globals)
ensure_fromlist(self, m, fromlist, recursive=0)
find_head_package(self, parent, name)
import_it(self, partname, fqname, parent, force_load=0)
import_module(self, name, globals=None, locals=None, fromlist=None)
load_tail(self, q, tail)
reload(self, module)

Data and non-method functions defined here:
__doc__ = 'A module importer that supports packages.'
__module__ = 'ihooks'

Methods inherited from BasicModuleImporter:
__init__(self, loader=None, verbose=0)
get_hooks(self)
get_loader(self)
install(self)
set_hooks(self, hooks)
set_loader(self, loader)
uninstall(self)
unload(self, module)

Methods inherited from _Verbose:
get_verbose(self)
message(self, format, *args)
note(self, *args)
set_verbose(self, verbose)
 
class ModuleLoader(BasicModuleLoader)
      Default module loader; uses file system hooks.
 
By defining suitable hooks, you might be able to load modules from
other sources than the file system, e.g. from compressed or
encrypted files, tar files or (if you're brave!) URLs.
 
  
Method resolution order:
ModuleLoader
BasicModuleLoader
_Verbose

Methods defined here:
__init__(self, hooks=None, verbose=0)
default_path(self)
find_builtin_module(self, name)
find_module_in_dir(self, name, dir, allow_packages=1)
get_hooks(self)
load_module(self, name, stuff)
modules_dict(self)
set_hooks(self, hooks)

Data and non-method functions defined here:
__doc__ = "Default module loader; uses file system hooks.\...s, tar files or (if you're brave!) URLs.\n\n "
__module__ = 'ihooks'

Methods inherited from BasicModuleLoader:
find_module(self, name, path=None)

Methods inherited from _Verbose:
get_verbose(self)
message(self, format, *args)
note(self, *args)
set_verbose(self, verbose)
 
class _Verbose
       
   Methods defined here:
__init__(self, verbose=0)
get_verbose(self)
message(self, format, *args)
note(self, *args)
set_verbose(self, verbose)

Data and non-method functions defined here:
__doc__ = None
__module__ = 'ihooks'
 
Functions
            
install(importer=None)
uninstall()
 
Data
             BUILTIN_MODULE = 6
C_BUILTIN = 6
C_EXTENSION = 3
FROZEN_MODULE = 7
PKG_DIRECTORY = 5
PY_COMPILED = 2
PY_FROZEN = 7
PY_SOURCE = 1
VERBOSE = 0
__all__ = ['BasicModuleLoader', 'Hooks', 'ModuleLoader', 'FancyModuleLoader', 'BasicModuleImporter', 'ModuleImporter', 'install', 'uninstall']
__file__ = '/usr/lib/python2.2/ihooks.pyc'
__name__ = 'ihooks'
current_importer = None
default_importer = None