# HG changeset patch # User Jeffrey Finkelstein # Date 1284435875 14400 # Branch release27-maint # Node ID fa31782279f11a63457965cc8a6652a1a42c302b # Parent 1c15ad6c9ad519ead35ec746b5788eaf4d64e8f4 fix for issue #9759: adds a check to GzipFile.read() which raises a ValueError if the file being read has already been closed diff -r 1c15ad6c9ad5 -r fa31782279f1 Lib/gzip.py --- a/Lib/gzip.py Tue Sep 14 00:14:36 2010 +0200 +++ b/Lib/gzip.py Mon Sep 13 23:44:35 2010 -0400 @@ -222,6 +222,9 @@ return len(data) def read(self, size=-1): + if self.closed: + raise ValueError('I/O operation on closed file.') + if self.mode != READ: import errno raise IOError(errno.EBADF, "read() on write-only GzipFile object") diff -r 1c15ad6c9ad5 -r fa31782279f1 Lib/test/test_gzip.py --- a/Lib/test/test_gzip.py Tue Sep 14 00:14:36 2010 +0200 +++ b/Lib/test/test_gzip.py Mon Sep 13 23:44:35 2010 -0400 @@ -51,6 +51,10 @@ f = gzip.GzipFile(self.filename, 'r') ; d = f.read() ; f.close() self.assertEqual(d, data1*50) + # Reading after closing the file should raise an error. + with self.assertRaises(ValueError): + f.read() + def test_append(self): self.test_write() # Append to the previous file