mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
#2959: allow multiple close() calls for GzipFile.
This commit is contained in:
parent
ecd0ad3c57
commit
e08e3d0686
3 changed files with 12 additions and 3 deletions
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue