[issue2959] calling GzipFile close() more than once causes exception

Michael Magin report at bugs.python.org
Sun May 25 01:26:16 CEST 2008


New submission from Michael Magin <mmagin at lowerarchy.com>:

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.

----------
components: Library (Lib)
files: gzip.py.patch
keywords: patch
messages: 67313
nosy: mmagin
severity: normal
status: open
title: calling GzipFile close() more than once causes exception
versions: Python 2.4, Python 2.5
Added file: http://bugs.python.org/file10431/gzip.py.patch

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2959>
__________________________________


More information about the Python-bugs-list mailing list