]> granicus.if.org Git - python/commitdiff
#2959: allow multiple close() calls for GzipFile.
authorGeorg Brandl <georg@python.org>
Sun, 25 May 2008 08:07:37 +0000 (08:07 +0000)
committerGeorg Brandl <georg@python.org>
Sun, 25 May 2008 08:07:37 +0000 (08:07 +0000)
Lib/gzip.py
Lib/test/test_gzip.py
Misc/NEWS

index eeef3f8b908ef228eaa2328d68805371180c0cc8..7a3f813de62bc67c8ae84aa0ee1791492ea051c6 100644 (file)
@@ -306,6 +306,8 @@ class GzipFile:
             raise IOError, "Incorrect length of data produced"
 
     def close(self):
+        if self.fileobj is None:
+            return
         if self.mode == WRITE:
             self.fileobj.write(self.compress.flush())
             write32u(self.fileobj, self.crc)
index a1a267e9914aec1ee06ef04c78e63a18b4105850..105882abbc42bee1c781cc58673c0369a65fa50e 100644 (file)
@@ -24,14 +24,14 @@ data2 = """/* zlibmodule.c -- gzip-compatible data compression */
 class TestGzip(unittest.TestCase):
     filename = test_support.TESTFN
 
-    def setUp (self):
+    def setUp(self):
         test_support.unlink(self.filename)
 
-    def tearDown (self):
+    def tearDown(self):
         test_support.unlink(self.filename)
 
 
-    def test_write (self):
+    def test_write(self):
         f = gzip.GzipFile(self.filename, 'wb') ; f.write(data1 * 50)
 
         # Try flush and fileno.
@@ -41,6 +41,9 @@ class TestGzip(unittest.TestCase):
             os.fsync(f.fileno())
         f.close()
 
+        # Test multiple close() calls.
+        f.close()
+
     def test_read(self):
         self.test_write()
         # Try reading.
index 6b4016472fb5aa751a15fabe397ff7992e6bc33f..732cfa79428cde584f64766d1108c0de03a6c63d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -59,6 +59,10 @@ Extension Modules
 Library
 -------
 
+- Issue #2959: For consistency with other file-like objects, gzip's
+  GzipFile.close() can now be called multiple times without raising
+  an exception.
+
 - Issue #1390: Raise ValueError in toxml when an invalid comment would
   otherwise be produced.