[Python-checkins] r52290 - sandbox/trunk/import_in_py/importer.py
brett at python.org
Thu Oct 12 19:35:26 CEST 2006
On 10/12/06, Jim Jewett <jimjjewett at gmail.com> wrote:
> On 10/11/06, brett.cannon <python-checkins at python.org> wrote:
> > New Revision: 52290
> > Modified:
> > sandbox/trunk/import_in_py/importer.py
> > Log:
> > Add a note of what changes would be needed for zipimport to be easily
> > implemented in Python along with reuse of the source and bytecode
> > +XXX zipimport use-case:
> > + * New path_hooks function.
> > + + If sys.path entry is an existing zip file, return an importer
> for it.
> > + + Initialize the path_hooks function with handlers that are to
> be considered
> > + for use.
> > + * New importer.
> > + + Open zipfile and check if it has a path to the desired
> > + * New loader.
> > + + Return a new file-like object for the zipfile for the
> contained file.
> > + - Implement read().
> > + * Should it implement # of bytes to return, or just a
> complete read?
> > + - Have a 'name' attribute.
> I'm not quite sure I understand your intent. I thought the algorithm
> was basically
> for location in sys.meta_path:
> loader = location.find_module(fullname, path, level)
> if loader:
> return loader.load_module(fullname)
> raise ImportError("Could not find %s" % fullname)
> where a typical storage would try delegating to each format_handler
> (such as source, bytecode, PTL) in turn.
Nope, I am not using a meta_path importer for directory entries on sys.path.
sys.path_hooks holds factory functions that return importers that get cached
for handling specific entries on sys.path. You are right about the
delegating, but this is not done on meta_path.
Then the only thing special about a ZipImporter is that it would use a
> zipfile for (raw data) storage instead of a generic filesystem
Right. I had to completely rethink how I am going to handle this stuff.
But your XXX comment makes it look like zipimport is a special kind of
> file, rather than a special kind of directory.
That's because right now the py/pyc handlers only accept a file path. But I
am going to change this (hopefully) today.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-checkins