Package pyamf :: Package util :: Module imports :: Class ModuleFinder
[hide private]
[frames] | no frames]

Class ModuleFinder

source code


This is a special module finder object that executes a collection of callables when a specific module has been imported. An instance of this is placed in sys.meta_path, which is consulted before sys.modules - allowing us to provide this functionality.


See Also: when_imported

Since: 0.5

Instance Methods [hide private]
 
__init__(self)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
find_module(self, name, path=None)
Called when an import is made.
source code
 
load_module(self, name)
If we get this far, then there are hooks waiting to be called on import of this module.
source code
 
when_imported(self, name, *hooks) source code
 
_run_hooks(self, name, module)
Run all hooks for a module.
source code
 
__getstate__(self) source code
 
__setstate__(self, state) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables [hide private]
  loaded_modules
list of modules that this finder has seen.
  post_load_hooks
dict of full module path -> callable to be executed when the module is imported.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

find_module(self, name, path=None)

source code 

Called when an import is made. If there are hooks waiting for this module to be imported then we stop the normal import process and manually load the module.

Parameters:
  • name - The name of the module being imported. @param path The root path of the module (if a package). We ignore this.
Returns:
If we want to hook this module, we return a loader interface (which is this instance again). If not we return None to allow the standard import process to continue.

load_module(self, name)

source code 

If we get this far, then there are hooks waiting to be called on import of this module. We manually load the module and then run the hooks.

Parameters:
  • name - The name of the module to import.

when_imported(self, name, *hooks)

source code 

See Also: when_imported


Instance Variable Details [hide private]

loaded_modules

list of modules that this finder has seen. Used to stop recursive imports in load_module