[Python-Dev] zipimport & import hooks (original) (raw)

Finn Bock bckfnn@worldonline.dk
Fri, 06 Dec 2002 15:22:07 +0100


[Just van Rossum]

This gets nessesarily more complex for packages, as now we also have to cater for path items of this form: "/path/to/my/archive.zip/packagedir". In this case we need to create a "subimporter" of "/path/to/my/archive.zip" if only because we don't want to reread the zip archive's file index.

and

The last patch I posted here inserts zipimporter instances in path, just as it replaces *.zip sys.path entries with zipimporter instances. Allowing objects on sys.path/pkg.path is still the most lo-tech solution, but it seems there's too much opposition for that, so I'll continue to work on an iu.py-inspired solution.

You are getting mighty close to what Jython has hardcoded for its .zip support . If the framework you come up with should be usefull from jython, then it is very important that it also somehow support cleanup. If objects are added to sys.path and path then cleanup is easily handled in the del method of the object. If the object is placed on some kind of shadowpath then some other cleanup means should be available.

From jython I can also note that:

So I would prefer that:

It would also be nice if user code could use the import framework to access resources, data files, gifs etc. That would match java's ClassLoader.getResourceAsStream() method.

regards, finn