[Python-Dev] New and Improved Import Hooks
Gordon McMillan
gmcm@hypernet.com
Thu, 5 Dec 2002 08:46:37 -0500
On 5 Dec 2002 at 11:51, M.-A. Lemburg wrote:
> Here's a sketch:
>
> 1. User programs register import hooks based on REs
> which are
> used to match the entries in sys.path, e.g.
> ".*\.zip" for ZIP importers (caching could help in
> improving the mapping performance).
>
> 2. When Python sees an import request, it scans
> sys.path and
> creates hook objects for each entry which it then
> calls to say "go look and check whether you have
> module X" until one of the hooks succeeds.
>
> 3. Python then uses the hook object to complete the
> import
> in much a similar way as e.g. SAX parsers call out
> to event handlers.
Except for where the policy that associates a
"hook object" with an element of sys.path resides,
this is what iu.py does. In your case, you've got it
in the manager. In iu.py, each importer is given
a chance, until one says "yes, I can handle this".
I base this design choice on the observation that
managers, no matter how smart they are to start
with, tend to become very stupid over time <wink>.
-- Gordon
http://www.mcmillan-inc.com/