[Patches] [ python-Patches-536278 ] force gzip to open files with 'b'

noreply@sourceforge.net noreply@sourceforge.net
Wed, 22 May 2002 16:09:55 -0700


Patches item #536278, was opened at 2002-03-28 09:53
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=536278&group_id=5470

Category: Library (Lib)
Group: Python 2.3
Status: Open
>Resolution: Accepted
Priority: 5
Submitted By: Skip Montanaro (montanaro)
>Assigned to: Skip Montanaro (montanaro)
Summary: force gzip to open files with 'b'

Initial Comment:
It doesn't make sense that the gzip module should
try to open a file in text mode.  The attached
patch forces a 'b' into the file open mode if it
wasn't given.  I also modified the test slightly to
try and tickle this code, but I can't test it very
effectively, because I don't do Windows... :-)


----------------------------------------------------------------------

>Comment By: Neal Norwitz (nnorwitz)
Date: 2002-05-22 19:09

Message:
Logged In: YES 
user_id=33168

Works for me, go ahead and check it in.

----------------------------------------------------------------------

Comment By: Skip Montanaro (montanaro)
Date: 2002-05-21 21:33

Message:
Logged In: YES 
user_id=44345

assigning to Neal for a final opinion.  New patch includes 
test_gzip.py modification.

----------------------------------------------------------------------

Comment By: Skip Montanaro (montanaro)
Date: 2002-04-09 12:30

Message:
Logged In: YES 
user_id=44345

good point.  updated patch.


----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-03-30 23:12

Message:
Logged In: YES 
user_id=31435

I suggest fixing this via changing the test to

if mode and 'b' not in mode:

Then mode=None and mode='' will be left alone (as Neal 
says, the code already does the right thing for those).



----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2002-03-28 10:04

Message:
Logged In: YES 
user_id=33168

There is a problem (sorry, I have an evil mind). :-)

If '' is passed as the mode, before the patch, this would
have been converted to 'rb'.  After the patch, mode will
become 'b' and that will raise an exception:

>>> open('/dev/null', 'b')
IOError: [Errno 22] Invalid argument: b

If you add an (and mode) condition and that should be fine.


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=536278&group_id=5470