Issue 9759: GzipFile object should raise ValueError on .read() after .close() (original) (raw)

Created on 2010-09-03 17:36 by ack, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue9759.patch jfinkels,2010-09-14 03:34 Patch which changes behavior of GzipFile.read()
issue9759.patch jfinkels,2010-09-14 03:46 2.7 branch patch
issue9759.patch jfinkels,2010-09-15 17:34 Patch which changes behavior of GzipFile.read(), .write(), and .flush()
Messages (7)
msg115473 - (view) Author: Alain Kalker (ack) Date: 2010-09-03 17:36
>>> f = open("test2.gz") >>> d = f.read() >>> f.close() >>> e = f.read() Traceback (most recent call last): File "", line 1, in ValueError: I/O operation on closed file import gzip >>> f = gzip.open("test2.gz") >>> d = f.read() >>> f.close() >>> e = f.read() >>> e '' To remain consistent with other file(-like) objects, I think 'GzipFile's should also raise a ValueError in cases like this.
msg116138 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-09-12 00:15
Should this be fixed in 3.1 and 2.7 too?
msg116362 - (view) Author: Jeffrey Finkelstein (jfinkels) * Date: 2010-09-14 03:34
Here is a patch for the py3k branch which adds a check for whether the GzipFile is closed on each call to GzipFile.read(). If the file is closed already, the method raises a ValueError if it is (with the message text copied from the corresponding fileobject's error message). I added an assertion to the test_read() method in Lib/test/test_gzip.py. The changes will be exactly the same for the 2.7 branch.
msg116363 - (view) Author: Jeffrey Finkelstein (jfinkels) * Date: 2010-09-14 03:46
Here's the 2.7 branch patch.
msg116437 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-15 08:27
You should make sure that all operations (except close() itself) raise ValueError. Currently: >>> f = gzip.open("test.gz", "rb") >>> f.close() >>> f.read() b'' >>> f.seek(0) 0 Also, you don't have to post a patch for 2.7. We'll do the porting ourselves. Thanks for contributing!
msg116470 - (view) Author: Jeffrey Finkelstein (jfinkels) * Date: 2010-09-15 17:34
Here's the updated patch, which checks whether the file is closed on each call to read(), write(), and flush(), along with a test.
msg118083 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-10-06 21:33
Patch committed in r85291 (3.x), and backported to 3.1 (r85293) and 2.7 (r85292). Thank you!
History
Date User Action Args
2022-04-11 14:57:06 admin set github: 53968
2010-10-06 21:33:04 pitrou set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2010-09-15 17:34:58 jfinkels set files: + issue9759.patchmessages: +
2010-09-15 08:27:08 pitrou set messages: + stage: needs patch -> patch review
2010-09-14 03:46:18 jfinkels set files: + issue9759.patchmessages: +
2010-09-14 03:34:15 jfinkels set files: + issue9759.patchnosy: + jfinkelsmessages: + keywords: + patch
2010-09-12 14:59:28 pitrou set versions: + Python 3.1, Python 2.7
2010-09-12 00:15:42 eric.araujo set nosy: + eric.araujomessages: +
2010-09-07 10:16:53 r.david.murray set keywords: + easynosy: + pitrouversions: + Python 3.2
2010-09-03 19:45:26 amaury.forgeotdarc set stage: needs patch
2010-09-03 17:36:30 ack create