summaryrefslogtreecommitdiffstats
path: root/Lib/gzip.py
diff options
context:
space:
mode:
authorguoci <zguoci@gmail.com>2018-11-07 09:50:23 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2018-11-07 09:50:23 (GMT)
commit0e7497cb469b003a45a4abe4105b81ef6d0c4002 (patch)
tree6c14770bf03a79d5e2ce008432309cfbddab858e /Lib/gzip.py
parentd2b11af91560eaaeb499f702f4b0f244ec756280 (diff)
downloadcpython-0e7497cb469b003a45a4abe4105b81ef6d0c4002.zip
cpython-0e7497cb469b003a45a4abe4105b81ef6d0c4002.tar.gz
cpython-0e7497cb469b003a45a4abe4105b81ef6d0c4002.tar.bz2
bpo-34898: Add mtime parameter to gzip.compress(). (GH-9704)
Without setting mtime, time.time() will be used as the timestamp which will end up in the compressed data and each invocation of the compress() function will vary over time.
Diffstat (limited to 'Lib/gzip.py')
-rw-r--r--Lib/gzip.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py
index 151ff14..948fec2 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -520,12 +520,12 @@ class _GzipReader(_compression.DecompressReader):
super()._rewind()
self._new_member = True
-def compress(data, compresslevel=_COMPRESS_LEVEL_BEST):
+def compress(data, compresslevel=_COMPRESS_LEVEL_BEST, *, mtime=None):
"""Compress data in one shot and return the compressed string.
Optional argument is the compression level, in range of 0-9.
"""
buf = io.BytesIO()
- with GzipFile(fileobj=buf, mode='wb', compresslevel=compresslevel) as f:
+ with GzipFile(fileobj=buf, mode='wb', compresslevel=compresslevel, mtime=mtime) as f:
f.write(data)
return buf.getvalue()