[Python-Dev] Add a -z interpreter flag to execute a zip file

Guido van Rossum guido at python.org
Tue Jul 24 19:28:46 CEST 2007


On 7/24/07, David Gowers <00ai99 at gmail.com> wrote:
> On 7/24/07, Guido van Rossum <guido at python.org> wrote:
> > On 7/12/07, Daniel Stutzbach <daniel at stutzbachenterprises.com> wrote:
> > > On 7/11/07, Andy C <andychup at gmail.com> wrote:
> > > > The good thing about this is that it's extremely simple -- basically
> > > > 20 lines of C code to add a -z flag that calls a 3-line Python
> > > > function in the runpy module.
> > >
> > > Instead of requiring a -z flag, why not have the interpreter peak at
> > > the file to see if it starts with one of the ZIP magic numbers?
> > >
> > > That way it Just Works.
> >
> > I guess you wouldn't recognize a zip file if it hits you in the face.
> > Literally. :-)
> >
> > Zip files don't start with a magic number.
>
> ZIP files *do* start with a magic number; either PK\03\04 (non-empty
> archive) or PK\05\06 (empty archive). This is rather easy to notice,
> as I did in the bad old days of DOS, and i recently doubly verified it
> ('zip'+'khexedit', and
> http://en.wikipedia.org/wiki/ZIP_%28file_format%29; I tried the
> infozip website too, but it seems to be down.)

You can believe that, but it's not the whole story. You can *prepend*
arbitrary data and the zip tools can still read the archive.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list