Ñò §ÚêLc @ s} d Z d d k l Z e d d d ƒ[ d d k Z d d k Z d d k Z d d k Z d d d d d d d d g Z d Z d d k l Z l Z l Z d d k l Z l Z l Z e Z e Z d d d „ ƒ YZ d e f d „ ƒ YZ d e f d „ ƒ YZ d e f d „ ƒ YZ d e f d „ ƒ YZ d e f d „ ƒ YZ d e f d „ ƒ YZ d Z d a d d „ Z d „ Z d S( s, 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 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(). iÿÿÿÿ( t warnpy3ks0 the ihooks module has been removed in Python 3.0t stackleveli Nt BasicModuleLoadert Hookst ModuleLoadert FancyModuleLoadert BasicModuleImportert ModuleImportert installt uninstalli ( t C_EXTENSIONt PY_SOURCEt PY_COMPILED( t C_BUILTINt PY_FROZENt PKG_DIRECTORYt _Verbosec B s8 e Z e d „ Z d „ Z d „ Z d „ Z d „ Z RS( c C s | | _ d S( N( t verbose( t selfR ( ( s /usr/lib64/python2.6/ihooks.pyt __init__K s c C s | i S( N( R ( R ( ( s /usr/lib64/python2.6/ihooks.pyt get_verboseN s c C s | | _ d S( N( R ( R R ( ( s /usr/lib64/python2.6/ihooks.pyt set_verboseQ s c G s | i o | i | Œ n d S( N( R t message( R t args( ( s /usr/lib64/python2.6/ihooks.pyt noteV s c G s | o | | GHn | GHd S( N( ( R t formatR ( ( s /usr/lib64/python2.6/ihooks.pyR Z s ( t __name__t __module__t VERBOSER R R R R ( ( ( s /usr/lib64/python2.6/ihooks.pyR I s c B s> e Z d Z d d „ Z d „ Z d „ Z d „ Z d „ Z RS( s; 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. c C sW | d j o d g | i ƒ } n x, | D]$ } | i | | ƒ } | o | Sq+ Wd S( N( t Nonet default_patht find_module_in_dir( R t namet patht dirt stuff( ( s /usr/lib64/python2.6/ihooks.pyt find_moduler s c C s t i S( N( t sysR! ( R ( ( s /usr/lib64/python2.6/ihooks.pyR z s c C sM | d j o | i | ƒ Sy t i | | g ƒ SWn t j o d SXd S( N( R t find_builtin_modulet impR$ t ImportError( R R R" ( ( s /usr/lib64/python2.6/ihooks.pyR } s c C sR t i | ƒ o d d d d t f f St i | ƒ o d d d d t f f Sd S( Nt ( R' t is_builtinR t BUILTIN_MODULEt is_frozent FROZEN_MODULE( R R ( ( s /usr/lib64/python2.6/ihooks.pyR&