This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: force gzip to open files with 'b'
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: skip.montanaro Nosy List: nnorwitz, skip.montanaro, tim.peters
Priority: normal Keywords: patch

Created on 2002-03-28 14:53 by skip.montanaro, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
gzip.diff skip.montanaro, 2002-04-09 16:30
gzip.diff skip.montanaro, 2002-05-22 01:33
Messages (7)
msg39394 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2002-03-28 14:53
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... :-)
msg39395 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2002-03-28 15:04
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.
msg39396 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2002-03-31 04:12
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).

msg39397 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2002-04-09 16:30
Logged In: YES 
user_id=44345

good point.  updated patch.
msg39398 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2002-05-22 01:33
Logged In: YES 
user_id=44345

assigning to Neal for a final opinion.  New patch includes 
test_gzip.py modification.
msg39399 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2002-05-22 23:09
Logged In: YES 
user_id=33168

Works for me, go ahead and check it in.
msg39400 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2002-05-23 01:50
Logged In: YES 
user_id=44345

gzip.py 1.33, test/test_gzip.py 1.9
History
Date User Action Args
2022-04-10 16:05:10adminsetgithub: 36347
2002-03-28 14:53:32skip.montanarocreate