[Python-Dev] Universal newlines, and the gzip module.

Christopher Barker Chris.Barker at noaa.gov
Fri Jan 30 18:43:05 CET 2009


skip at pobox.com wrote:
>     Christopher> 1) It would be nice if the gzip module (and the zip lib
>     Christopher>    module) supported Universal newlines -- you could read a
>     Christopher>    compressed text file with "wrong" newlines, and have
>     Christopher>    them handled properly. However, that may be hard to do,
>     Christopher>    so at least:
> 
>     Christopher> 2) Passing a 'U' flag in to gzip.open shouldn't break it.
> 
> I agree with Brett that 'U' is meaningless on the compressed file itself.

right -- I think the code that deals with the flags is not smart enough 
-- it adds the 'b' flag if it isn't already there, but that's all it 
does. There are only a few flags that make sense for opening a gzip file 
-- it should only use those, and either ignore others or raise an 
exception if there are others that don't make sense.

> You want it applied to the contents of the compressed file though, is that
> right?

That would be great.

>  That makes sense to me.  It probably belongs in a separate argument
> though.

I could go either way on that -- if we simply extracted the 'U' from the 
  passed in mode, we wouldn't have to change the API at all, and it 
wouldn't break any code that wasn't broken already.

As for having 'U' applied to the uncompressed data -- I have no idea how 
much work that would be -- it depends on how it is currently handling 
text files (does that work -- i.e \r\n converted to \n on Windows?), and 
how the Universal newline code is written.


In any case, the 'U' flag should NEVER get passed through to the file 
opening code, and that's easy to fix.

I tried to post this to the bug tracker, but my attempt to create an 
account failed -- do I need to be pre-approved or something?

-Chris








-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov


More information about the Python-Dev mailing list