Skip to content

Commit 9a388b9

Browse files
bpo-43848: explain optional argument mtime in gzip.py. (GH-25410)
Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent 8dbfdb2 commit 9a388b9

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

Doc/library/gzip.rst

+10-13
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@ The module defines the following items:
100100
compression, and ``9`` is slowest and produces the most compression. ``0``
101101
is no compression. The default is ``9``.
102102

103-
The *mtime* argument is an optional numeric timestamp to be written to
104-
the last modification time field in the stream when compressing. It
105-
should only be provided in compression mode. If omitted or ``None``, the
106-
current time is used. See the :attr:`mtime` attribute for more details.
103+
The optional *mtime* argument is the timestamp requested by gzip. The time
104+
is in Unix format, i.e., seconds since 00:00:00 UTC, January 1, 1970.
105+
If *mtime* is omitted or None, the current time is used. Use *mtime* = 0
106+
to generate a compressed stream that does not depend on creation time.
107+
108+
See below for the :attr:`mtime` attribute that is set when decompressing.
107109

108110
Calling a :class:`GzipFile` object's :meth:`!close` method does not close
109111
*fileobj*, since you might wish to append more material after the compressed
@@ -133,15 +135,10 @@ The module defines the following items:
133135

134136
.. attribute:: mtime
135137

136-
When decompressing, the value of the last modification time field in
137-
the most recently read header may be read from this attribute, as an
138-
integer. The initial value before reading any headers is ``None``.
139-
140-
All :program:`gzip` compressed streams are required to contain this
141-
timestamp field. Some programs, such as :program:`gunzip`\ , make use
142-
of the timestamp. The format is the same as the return value of
143-
:func:`time.time` and the :attr:`~os.stat_result.st_mtime` attribute of
144-
the object returned by :func:`os.stat`.
138+
When decompressing, this attribute is set to the last timestamp in the most
139+
recently read header. It is an integer, holding the number of seconds
140+
since the Unix epoch (00:00:00 UTC, January 1, 1970).
141+
The initial value before reading any headers is ``None``.
145142

146143
.. attribute:: name
147144

Lib/gzip.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,10 @@ def __init__(self, filename=None, mode=None,
178178
and 9 is slowest and produces the most compression. 0 is no compression
179179
at all. The default is 9.
180180
181-
The mtime argument is an optional numeric timestamp to be written
182-
to the last modification time field in the stream when compressing.
183-
If omitted or None, the current time is used.
181+
The optional mtime argument is the timestamp requested by gzip. The time
182+
is in Unix format, i.e., seconds since 00:00:00 UTC, January 1, 1970.
183+
If mtime is omitted or None, the current time is used. Use mtime = 0
184+
to generate a compressed stream that does not depend on creation time.
184185
185186
"""
186187

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
In documentation of :class:`gzip.GzipFile` in module gzip, explain data type
2+
of optional constructor argument *mtime*, and recommend ``mtime = 0`` for
3+
generating deterministic streams.

0 commit comments

Comments
 (0)