]> granicus.if.org Git - python/commitdiff
force gzip module to open files using 'b'inary mode.
authorSkip Montanaro <skip@pobox.com>
Thu, 23 May 2002 01:43:05 +0000 (01:43 +0000)
committerSkip Montanaro <skip@pobox.com>
Thu, 23 May 2002 01:43:05 +0000 (01:43 +0000)
closes patch #536278.

Lib/gzip.py
Lib/test/test_gzip.py

index b2bbeda3e88b4ffef91ad8323291af020eb9ce20..9e198c75d500d26a5f0f2cfbba4010325b55db20 100644 (file)
@@ -35,6 +35,10 @@ class GzipFile:
 
     def __init__(self, filename=None, mode=None,
                  compresslevel=9, fileobj=None):
+        # guarantee the file is opened in binary mode on platforms
+        # that care about that sort of thing
+        if mode and 'b' not in mode:
+            mode += 'b'
         if fileobj is None:
             fileobj = self.myfileobj = __builtin__.open(filename, mode or 'rb')
         if filename is None:
index a5660a9ec26b9ce636ca8ad5cc1f93900e8854ed..d42dee66678943b7236903f9e2161704904123e9 100644 (file)
@@ -18,7 +18,7 @@ data2 = """/* zlibmodule.c -- gzip-compatible data compression */
 
 f = gzip.GzipFile(filename, 'wb') ; f.write(data1 * 50) ; f.close()
 
-f = gzip.GzipFile(filename, 'rb') ; d = f.read() ; f.close()
+f = gzip.GzipFile(filename, 'r') ; d = f.read() ; f.close()
 verify(d == data1*50)
 
 # Append to the previous file
@@ -75,4 +75,8 @@ for pos in range(0, 256, 16):
     f.write('GZ\n')
 f.close()
 
+f = gzip.GzipFile(filename, 'r')
+verify(f.myfileobj.mode == 'rb')
+f.close()
+
 os.unlink(filename)