Message41948
This patch implements two things:
- a new set of import hooks, modelled after iu.py
- builtin support for imports from Zip archives (a
competing implementation for PEP 273)
The new set of hooks probably need a better document
explaining them (perhaps a PEP). My motivations have
been posted to python-dev.
Here's a brief description.
Three new objects are added to the sys module:
- path_hooks
- path_importer_cache
- meta_path
sys.path_hooks is a list of callable objects that take
a string as their only argument. A hook will be called
with a sys.path or pkg.__path__ item. It should return
an "importer" object (see below), or raise ImportError
or return None if it can't deal with the path item. By
default, sys.path_hooks only contains the zipimporter
type, if the zipimport module is available.
sys.path_importer_cache is a dict that caches the
results of sys.path_hooks to avoid repeated hook lookups.
sys.meta_path is a list of importer objects that are
invoked *before* the builtin import mechanism kicks in.
This allows overriding of builtin module and frozen
module import, but the main feature is that it allows
importer objects *without* a corresponding sys.path
item (just like builtin and frozen modules).
Importer objects must conform to the following protocol:
i.find_module(fullname) -> None or an importer object
i.load_module(fullname) -> the imported module (or
raise ImportError)
The 'fullname' is always the fully qualified module
name, ie. a dotted name for a submodule.
This patch adds one more feature: a sys.path item may
*itself* be an importer object. This is convenient for
experimentation, but using it may break third-party
code that assumes sys.path contains only strings. |
|
Date |
User |
Action |
Args |
2007-08-23 15:18:55 | admin | link | issue652586 messages |
2007-08-23 15:18:55 | admin | create | |
|