Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions Doc/library/gzip.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ The module defines the following items:
since the Unix epoch (00:00:00 UTC, January 1, 1970).
The initial value before reading any headers is ``None``.

When compressing, this attribute is set to the value passed to the constructor.

.. versionchanged:: 3.16
In previous versions, an :exc:`AttributeError` occured for compressing streams.

.. attribute:: name

The path to the gzip file on disk, as a :class:`str` or :class:`bytes`.
Expand Down
2 changes: 2 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ gzip
* :func:`gzip.open` now accepts an optional argument ``mtime``
which is passed on to the constructor of the :class:`~gzip.GzipFile` class.
(Contributed by Marin Misur in :gh:`91372`.)
* The write-only property :attr:`gzip.GzipFile.mtime` now returns the
constructor value for :class:`~gzip.GzipFile` files in write mode.


imaplib
Expand Down
2 changes: 2 additions & 0 deletions Lib/gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ def __init__(self, filename=None, mode=None,
@property
def mtime(self):
"""Last modification time read from stream, or None"""
if self.mode == WRITE:
return self._write_mtime
return self._buffer.raw._last_mtime

def __repr__(self):
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ def test_paddedfile_getattr(self):
def test_mtime(self):
mtime = 123456789
with gzip.GzipFile(self.filename, 'w', mtime = mtime) as fWrite:
self.assertEqual(fWrite.mtime, mtime)
fWrite.write(data1)
with gzip.GzipFile(self.filename) as fRead:
self.assertHasAttr(fRead, 'mtime')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The write-only property :attr:`gzip.GzipFile.mtime` now returns the
constructor value for :class:`~gzip.GzipFile` files in write mode. Formerly,
this caused an :exc:`AttributeError`.
Loading