Cheetah.ImportManager module

Provides an emulator/replacement for Python’s standard import system.

@@TR: Be warned that Import Hooks are in the deepest, darkest corner of Python’s jungle. If you need to start hacking with this, be prepared to get lost for a while. Also note, this module predates the newstyle import hooks in Python 2.3

This is a hacked/documented version of Gordon McMillan’s I have:

  • made it a little less terse
  • added docstrings and explanatations
  • standardized the variable naming scheme
  • reorganized the code layout to enhance readability
class Cheetah.ImportManager.BuiltinImportDirector

Bases: Cheetah.ImportManager.ImportDirector

Directs imports of builtin modules

getmod(nm, isbuiltin=<built-in function is_builtin>)
class Cheetah.ImportManager.DirOwner(path)

Bases: Cheetah.ImportManager.Owner

getmod(nm, getsuffixes=<function get_suffixes>, loadco=<built-in function loads>, newmod=<function new_module>)
class Cheetah.ImportManager.FrozenImportDirector

Bases: Cheetah.ImportManager.ImportDirector

Directs imports of frozen modules

getmod(nm, isFrozen=<built-in function is_frozen>, loadMod=<function load_module>)
class Cheetah.ImportManager.ImportDirector(path)

Bases: Cheetah.ImportManager.Owner

ImportDirectors live on the metapath There’s one for builtins, one for frozen modules, and one for sys.path Windows gets one for modules gotten from the Registry Mac would have them for PY_RESOURCE modules etc. A generalization of Owner - their concept of ‘turf’ is broader

class Cheetah.ImportManager.ImportManager

Bases: object

doimport(nm, parentnm, fqname)
importHook(name, globals=None, locals=None, fromlist=None, level=-1)

NOTE: Currently importHook will accept the keyword-argument “level” but it will NOT use it (currently). Details about the “level” keyword argument can be found here:

class Cheetah.ImportManager.Owner(path)

Bases: object

An Owner does imports from a particular piece of turf That is, there’s an Owner for each thing on sys.path There are owners for directories and .pyz files. There could be owners for zip files, or even URLs. A shadowpath (a dictionary mapping the names in sys.path to their owners) is used so that sys.path (or a package’s __path__) is still a bunch of strings,

class Cheetah.ImportManager.PathImportDirector(pathlist=None, importers=None, ownertypes=None)

Bases: Cheetah.ImportManager.ImportDirector

Directs imports of modules stored on the filesystem.

class Cheetah.ImportManager.RegistryImportDirector

Bases: Cheetah.ImportManager.ImportDirector

Directs imports of modules stored in the Windows Registry


Local replacement for os.path.isdir().