[Python-Dev] PEP 273 comments

James C. Ahlstrom jim@interet.com
Fri, 16 Nov 2001 09:25:46 -0500


Hi Martin,

Thanks for taking the time to look at my code.

"Martin v. Loewis" wrote:

> Section zlib, "will fail with a message":
> 
> Is this still current? Looking at the implementation, it seems that
> you'll rather get an import error, which sounds much better.

Yes, you are right.  If a module is found in a zip file, and the
zip module is compressed, and zlib is unavailable, then get_zip_string()
fails with PyExc_ValueError (and a message), and the import fails.
 
> Section Booting
> 
> Looking at the implementation, it appears that PyImport_InitZip
> already invokes PyImport_ImportModule. Is there a mechanism that
> prevents ZIP import from being used while it is not ready yet?

At the point that PyImport_ImportModule("os") is called, zip
imports are ready.  Specifically, python22.zip has been added
to sys.path, and zlib has been imported.  The attempted import
of the "os" module can be satisfied from a zip archive or from
a directory.

We are attempting to import the os module to support caching of
directory contents using os.listdir().  This would cause an
infinite loop except for the use of the use_os_listdir flag.
This flag is zero if os.listdir has not yet been imported.
It is 1 if os.listdir is available, and -1 if it is unavailable.

JimA