Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Lib/gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,17 @@ def __init__(self, filename=None, mode=None,

self.fileobj = fileobj

if self.mode == WRITE:
self._write_gzip_header(compresslevel)

try:
if self.mode == WRITE:
self._write_gzip_header(compresslevel)
except BaseException:
# Avoid a ResourceWarning if the write fails, eg read-only file or KI
try:
if self.myfileobj is not None:
self.myfileobj.close()
finally:
self.fileobj = None
raise
@property
def mtime(self):
"""Last modification time read from stream, or None"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix :exc:`ResourceWarning` when constructing a :class:`gzip.GzipFile` in write mode with a broken file object
Loading