Skip to content

Commit 6f465cc

Browse files
committed
resolve issues in review
1 parent 88749c8 commit 6f465cc

6 files changed

Lines changed: 14 additions & 5 deletions

File tree

Doc/library/gzip.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ The module defines the following items:
157157
Accepts a :term:`path-like object`.
158158

159159

160-
.. function:: compress(data, compresslevel=9, mtime=None)
160+
.. function:: compress(data, compresslevel=9, *, mtime=None)
161161

162162
Compress the *data*, returning a :class:`bytes` object containing
163163
the compressed data. *compresslevel* and *mtime* have the same meaning as in
164164
the :class:`GzipFile` constructor above.
165165

166166
.. versionadded:: 3.2
167167
.. versionchanged:: 3.8
168-
Added *mtime* argument
168+
Added the *mtime* parameter for reproducible output.
169169

170170
.. function:: decompress(data)
171171

Doc/whatsnew/3.8.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ asyncio
128128
On Windows, the default event loop is now :class:`~asyncio.ProactorEventLoop`.
129129

130130

131+
gzip
132+
----
133+
134+
Added the *mtime* parameter to :func:`gzip.compress` for reproducible output.
135+
(Contributed by Guo Ci Teo in :issue:`34898`.)
136+
137+
131138
idlelib and IDLE
132139
----------------
133140

Lib/gzip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def _rewind(self):
520520
super()._rewind()
521521
self._new_member = True
522522

523-
def compress(data, compresslevel=_COMPRESS_LEVEL_BEST, mtime=None):
523+
def compress(data, compresslevel=_COMPRESS_LEVEL_BEST, *, mtime=None):
524524
"""Compress data in one shot and return the compressed string.
525525
Optional argument is the compression level, in range of 0-9.
526526
"""

Lib/test/test_gzip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,9 @@ def test_compress(self):
502502
def test_compress_mtime(self):
503503
mtime = 123456789
504504
for data in [data1, data2]:
505-
for args in [(1, mtime), (6, mtime), (9, mtime)]:
505+
for args in [(), (1,), (6,), (9,)]:
506506
with self.subTest(data=data, args=args):
507-
datac = gzip.compress(data, *args)
507+
datac = gzip.compress(data, *args, mtime=mtime)
508508
self.assertEqual(type(datac), bytes)
509509
with gzip.GzipFile(fileobj=io.BytesIO(datac), mode="rb") as f:
510510
f.read(1) # to set mtime attribute

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,7 @@ Monty Taylor
16151615
Anatoly Techtonik
16161616
Martin Teichmann
16171617
Gustavo Temple
1618+
Guo Ci Teo
16181619
Mikhail Terekhov
16191620
Victor Terrón
16201621
Pablo Galindo
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
Add `mtime` argument to `gzip.compress` for reproducible output.
2+
Patch by Guo Ci Teo.

0 commit comments

Comments
 (0)