]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43848: explain optional argument mtime in gzip.py. (GH-25410)
authorJoachim Wuttke <j.wuttke@fz-juelich.de>
Thu, 28 Mar 2024 13:43:07 +0000 (14:43 +0100)
committerGitHub <noreply@github.com>
Thu, 28 Mar 2024 13:43:07 +0000 (13:43 +0000)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Doc/library/gzip.rst
Lib/gzip.py
Misc/NEWS.d/next/Library/2024-03-28-13-54-20.gh-issue-88014.zJz31I.rst [new file with mode: 0644]

index 79be215a766045484b06f6cf1eb0c0c6b54cced2..044be8c1c1bf418c05b3abcf0e9fff9ad06fcf39 100644 (file)
@@ -100,10 +100,12 @@ The module defines the following items:
    compression, and ``9`` is slowest and produces the most compression. ``0``
    is no compression. The default is ``9``.
 
-   The *mtime* argument is an optional numeric timestamp to be written to
-   the last modification time field in the stream when compressing.  It
-   should only be provided in compression mode.  If omitted or ``None``, the
-   current time is used.  See the :attr:`mtime` attribute for more details.
+   The optional *mtime* argument is the timestamp requested by gzip. The time
+   is in Unix format, i.e., seconds since 00:00:00 UTC, January 1, 1970.
+   If *mtime* is omitted or None, the current time is used. Use *mtime* = 0
+   to generate a compressed stream that does not depend on creation time.
+
+   See below for the :attr:`mtime` attribute that is set when decompressing.
 
    Calling a :class:`GzipFile` object's :meth:`!close` method does not close
    *fileobj*, since you might wish to append more material after the compressed
@@ -133,15 +135,10 @@ The module defines the following items:
 
    .. attribute:: mtime
 
-      When decompressing, the value of the last modification time field in
-      the most recently read header may be read from this attribute, as an
-      integer.  The initial value before reading any headers is ``None``.
-
-      All :program:`gzip` compressed streams are required to contain this
-      timestamp field.  Some programs, such as :program:`gunzip`\ , make use
-      of the timestamp.  The format is the same as the return value of
-      :func:`time.time` and the :attr:`~os.stat_result.st_mtime` attribute of
-      the object returned by :func:`os.stat`.
+      When decompressing, this attribute is set to the last timestamp in the most
+      recently read header.  It is an integer, holding the number of seconds
+      since the Unix epoch (00:00:00 UTC, January 1, 1970).
+      The initial value before reading any headers is ``None``.
 
    .. attribute:: name
 
index fda93e0261e02858a740a133086a2c4cee0f41bc..1d6faaa82c6a681eab25653c9190af98314aa5c6 100644 (file)
@@ -178,9 +178,10 @@ class GzipFile(_compression.BaseStream):
         and 9 is slowest and produces the most compression. 0 is no compression
         at all. The default is 9.
 
-        The mtime argument is an optional numeric timestamp to be written
-        to the last modification time field in the stream when compressing.
-        If omitted or None, the current time is used.
+        The optional mtime argument is the timestamp requested by gzip. The time
+        is in Unix format, i.e., seconds since 00:00:00 UTC, January 1, 1970.
+        If mtime is omitted or None, the current time is used. Use mtime = 0
+        to generate a compressed stream that does not depend on creation time.
 
         """
 
diff --git a/Misc/NEWS.d/next/Library/2024-03-28-13-54-20.gh-issue-88014.zJz31I.rst b/Misc/NEWS.d/next/Library/2024-03-28-13-54-20.gh-issue-88014.zJz31I.rst
new file mode 100644 (file)
index 0000000..f8bb784
--- /dev/null
@@ -0,0 +1,3 @@
+In documentation of :class:`gzip.GzipFile` in module gzip, explain data type
+of optional constructor argument *mtime*, and recommend ``mtime = 0`` for
+generating deterministic streams.