[Python-Dev] New and Improved Import Hooks (original) (raw)

M.-A. Lemburg mal@lemburg.com
Thu, 05 Dec 2002 13:39:10 +0100


Martin v. L=F6wis wrote:

"M.-A. Lemburg" <mal@lemburg.com> writes: =20 =20

Well, that's what I tried to solve in the sketch I posted earlier (slightly modified to meet Fredrik's requirements):

1. User programs register import hooks based on suffixes which are used to match the entries in sys.path, e.g. ".zip" for ZIP importers (caching could help in improving the mapping performance; this is where the auxilliary dictionary comes into play). =20 =20 I don't like this idea. How could I then make a HTTP importer, where no suffix is available?

I first had "based on RE matching" in there, but Fredrik pointed out that this would cause bootstrapping problems. The suffix approach is easily implementable in plain C. Its open for discussion, of course. If you have a better idea, please speak up. We could also use a combined prefix/suffix approach so that URLs can be recognized by prefix, while ZIP files are by suffix.

To answer your question: web-imports could use a special suffix to signal their web-import nature (I'm sure you'll want to apply some more security checks on such modules and or packages), e.g. ".py.web".

--=20 Marc-Andre Lemburg CEO eGenix.com Software GmbH


eGenix.com -- Makers of the Python mx Extensions: mxDateTime,mxODBC,... Python Consulting: http://www.egenix.com/ Python Software: http://www.egenix.com/files/python/