This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: calling GzipFile close() more than once causes exception
Type: Stage:
Components: Library (Lib) Versions: Python 2.4, Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, mmagin
Priority: normal Keywords: patch

Created on 2008-05-24 23:26 by mmagin, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
gzip.py.patch mmagin, 2008-05-24 23:26 patch to allow multiple calls to close.
Messages (2)
msg67313 - (view) Author: Michael Magin (mmagin) Date: 2008-05-24 23:25
Built-in file objects allow repeated calls to .close(), even the
documentation states, "Calling close() more than once is allowed."
(http://docs.python.org/lib/bltin-file-objects.html)

GzipFile does not obey this aspect of the file interface:
>>> import gzip
>>> f = gzip.GzipFile('testfile1.gz', 'ab')
>>> f.close()
>>> f.close()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File
"/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/gzip.py",
line 315, in close
    self.fileobj.write(self.compress.flush())
AttributeError: 'NoneType' object has no attribute 'write'

The gzip documentation does not document this (mis-)behavior.

(Trivial) patch against 2.4.3 gzip.py attached.
msg67329 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-05-25 08:07
Thanks, fixed in r63614.
History
Date User Action Args
2022-04-11 14:56:34adminsetgithub: 47208
2008-05-25 08:07:50georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg67329
nosy: + georg.brandl
2008-05-24 23:26:11mmagincreate