[PythonCAD] FW: PythonCad in win32

Art Haas ahaas at airmail.net
Fri Mar 26 16:25:02 EST 2004


On Fri, Mar 26, 2004 at 11:15:04AM -0800, Somerlot, Chris wrote:
> Art, I've looked more into this more and have some questions about how
> compression is implemented. 
> 
> Firstly, the endline characters are easy to fix; Python 2.3 comes with
> universal newline supoort. But this isn't solving the problem of reading and
> writing files on windows.
> 

These would be nice to use, and there are some other Python 2.3 features
that I'd like to use (like types.BooleanType), but I'm trying to
maintain Python 2.2 compatibity. I don't know how much longer that will
be worth doing, but for now I'm striving to do this.

> If I redirect the doc.writexml in imageio.py to a standard ascii xml file
> instead of the compression object, I get good data, and can read it back in
> fine.
> 
> The problem seems to be at line 174 in fileio.py, with 
> 
> 	file.write(self, self.__compobj.compress(data))
> 
> Good data is going in, but bad bad data is coming out. My question has to do
> with the following section of fileio:
>             self.__compobj = zlib.compressobj(6,
>                                               zlib.DEFLATED,
>                                               -zlib.MAX_WBITS,
>                                               zlib.DEF_MEM_LEVEL,
>                                               0)
>             file.write(self, '\037\213\010')
>             file.write(self, chr(8)) # flags FNAME - no FHCRC for gzip
> compat.
>             file.write(self, struct.pack("<L", long(time.time())))
>             file.write(self, '\000\377') # extra flags and unknown OS flag
> 
> What do the constants do on init of __compobj do? What about the flags? I
> can not seem to find any documentation on this stuff other than the value of
> the constants. Do you have a link to some documentation?

This stuff comes from the 'gzip.py' file that ships with Python. When I
wrote this stuff initially, I could not get things to work so that
the gzip binary could test the resulting file. When I found how the
'gzip.py' code was doing things, I took what they did as found that
I could use gzip on the compressed file that was just written. I
remember looking at the gzip code to try and figure out the differences,
and the 'FHCRC' thing mattered ...

[ ... searches computer ... ]

Look for 'rfc1952' for info on the gzip format. I'll mail it to you
if you want it rather than sending it to the list and adding to the
size of this message.

Art

-- 
Man once surrendering his reason, has no remaining guard against absurdities
the most monstrous, and like a ship without rudder, is the sport of every wind.

-Thomas Jefferson to James Smith, 1822



More information about the PythonCAD mailing list