Skip to content

Commit 90be5b9

Browse files
authored
Merge branch 'main' into gh-149816-61
2 parents 9e50d98 + cf5c8c5 commit 90be5b9

6 files changed

Lines changed: 132 additions & 61 deletions

File tree

Doc/library/gzip.rst

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Note that additional file formats which can be decompressed by the
2828
The module defines the following items:
2929

3030

31-
.. function:: open(filename, mode='rb', compresslevel=6, encoding=None, errors=None, newline=None)
31+
.. function:: open(filename, mode='rb', compresslevel=6, encoding=None, errors=None, newline=None, *, mtime=None)
3232

3333
Open a gzip-compressed file in binary or text mode, returning a :term:`file
3434
object`.
@@ -43,9 +43,12 @@ The module defines the following items:
4343
The *compresslevel* argument is an integer from 0 to 9, as for the
4444
:class:`GzipFile` constructor.
4545

46+
The keyword-only argument *mtime* represents a Unix timestamp.
47+
4648
For binary mode, this function is equivalent to the :class:`GzipFile`
47-
constructor: ``GzipFile(filename, mode, compresslevel)``. In this case, the
48-
*encoding*, *errors* and *newline* arguments must not be provided.
49+
constructor: ``GzipFile(filename, mode, compresslevel, mtime=mtime)``.
50+
In this case, the *encoding*, *errors* and *newline* arguments must not
51+
be provided.
4952

5053
For text mode, a :class:`GzipFile` object is created, and wrapped in an
5154
:class:`io.TextIOWrapper` instance with the specified encoding, error
@@ -66,6 +69,10 @@ The module defines the following items:
6669
It is the default level used by most compression tools and a better
6770
tradeoff between speed and performance.
6871

72+
.. versionchanged:: next
73+
Added keyword-only argument *mtime* which is passed to the class
74+
constructor of :class:`~gzip.GzipFile`.
75+
6976
.. exception:: BadGzipFile
7077

7178
An exception raised for invalid gzip files. It inherits from :exc:`OSError`.

Doc/tools/templates/indexcontent.html

Lines changed: 97 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -14,70 +14,112 @@
1414
<meta property="og:image:width" content="200">
1515
<meta property="og:image:height" content="200">
1616
<meta name="theme-color" content="#3776ab">
17+
<style>
18+
.contentstable {
19+
display: grid;
20+
gap: 0 2em;
21+
grid-template-columns: 1fr 1fr;
22+
margin: 0 auto;
23+
max-width: 90%;
24+
}
25+
.contentstable ul {
26+
list-style: none;
27+
margin: 0;
28+
padding: 0;
29+
}
30+
.contentstable a {
31+
text-decoration: none;
32+
}
33+
.contentstable a:hover {
34+
text-decoration: underline;
35+
}
36+
.contentstable li.biglink {
37+
line-height: 150%;
38+
margin-bottom: 1em;
39+
}
40+
@media (max-width: 600px) {
41+
.contentstable {
42+
grid-template-columns: 1fr;
43+
}
44+
}
45+
</style>
1746
{%- endblock -%}
1847
{% block body %}
1948
<h1>{{ docstitle|e }}</h1>
2049
<p>
2150
{% trans %}Welcome! This is the official documentation for Python {{ release }}.{% endtrans %}
2251
</p>
2352
<p><strong>{% trans %}Documentation sections:{% endtrans %}</strong></p>
24-
<table class="contentstable" align="center"><tr>
25-
<td width="50%">
26-
<p class="biglink"><a class="biglink" href="{{ pathto("whatsnew/" + version) }}">{% trans %}What's new in Python {{ version }}?{% endtrans %}</a><br>
27-
<span class="linkdescr"> {% trans whatsnew_index=pathto("whatsnew/index") %}Or <a href="{{ whatsnew_index }}">all "What's new" documents since Python 2.0</a>{% endtrans %}</span></p>
28-
<p class="biglink"><a class="biglink" href="{{ pathto("tutorial/index") }}">{% trans %}Tutorial{% endtrans %}</a><br>
29-
<span class="linkdescr">{% trans %}Start here: a tour of Python's syntax and features{% endtrans %}</span></p>
30-
<p class="biglink"><a class="biglink" href="{{ pathto("library/index") }}">{% trans %}Library reference{% endtrans %}</a><br>
31-
<span class="linkdescr">{% trans %}Standard library and builtins{% endtrans %}</span></p>
32-
<p class="biglink"><a class="biglink" href="{{ pathto("reference/index") }}">{% trans %}Language reference{% endtrans %}</a><br>
33-
<span class="linkdescr">{% trans %}Syntax and language elements{% endtrans %}</span></p>
34-
<p class="biglink"><a class="biglink" href="{{ pathto("using/index") }}">{% trans %}Python setup and usage{% endtrans %}</a><br>
35-
<span class="linkdescr">{% trans %}How to install, configure, and use Python{% endtrans %}</span></p>
36-
<p class="biglink"><a class="biglink" href="{{ pathto("howto/index") }}">{% trans %}Python HOWTOs{% endtrans %}</a><br>
37-
<span class="linkdescr">{% trans %}In-depth topic manuals{% endtrans %}</span></p>
38-
</td><td width="50%">
39-
<p class="biglink"><a class="biglink" href="{{ pathto("installing/index") }}">{% trans %}Installing Python modules{% endtrans %}</a><br>
40-
<span class="linkdescr">{% trans %}Third-party modules and PyPI.org{% endtrans %}</span></p>
41-
<p class="biglink"><a class="biglink" href="{{ pathto("distributing/index") }}">{% trans %}Distributing Python modules{% endtrans %}</a><br>
42-
<span class="linkdescr">{% trans %}Publishing modules for use by other people{% endtrans %}</span></p>
43-
<p class="biglink"><a class="biglink" href="{{ pathto("extending/index") }}">{% trans %}Extending and embedding{% endtrans %}</a><br>
44-
<span class="linkdescr">{% trans %}For C/C++ programmers{% endtrans %}</span></p>
45-
<p class="biglink"><a class="biglink" href="{{ pathto("c-api/index") }}">{% trans %}Python's C API{% endtrans %}</a><br>
46-
<span class="linkdescr">{% trans %}C API reference{% endtrans %}</span></p>
47-
<p class="biglink"><a class="biglink" href="{{ pathto("faq/index") }}">{% trans %}FAQs{% endtrans %}</a><br>
48-
<span class="linkdescr">{% trans %}Frequently asked questions (with answers!){% endtrans %}</span></p>
49-
<p class="biglink"><a class="biglink" href="{{ pathto("deprecations/index") }}">{% trans %}Deprecations{% endtrans %}</a><br>
50-
<span class="linkdescr">{% trans %}Deprecated functionality{% endtrans %}</span></p>
51-
</td></tr>
52-
</table>
53+
<div class="contentstable">
54+
<ul>
55+
<li class="biglink"><a class="biglink" href="{{ pathto("whatsnew/" + version) }}">{% trans %}What's new in Python {{ version }}?{% endtrans %}</a><br>
56+
<span class="linkdescr"> {% trans whatsnew_index=pathto("whatsnew/index") %}Or <a href="{{ whatsnew_index }}">all "What's new" documents since Python 2.0</a>{% endtrans %}</span></li>
57+
<li class="biglink"><a class="biglink" href="{{ pathto("tutorial/index") }}">{% trans %}Tutorial{% endtrans %}</a><br>
58+
<span class="linkdescr">{% trans %}Start here: a tour of Python's syntax and features{% endtrans %}</span></li>
59+
<li class="biglink"><a class="biglink" href="{{ pathto("library/index") }}">{% trans %}Library reference{% endtrans %}</a><br>
60+
<span class="linkdescr">{% trans %}Standard library and builtins{% endtrans %}</span></li>
61+
<li class="biglink"><a class="biglink" href="{{ pathto("reference/index") }}">{% trans %}Language reference{% endtrans %}</a><br>
62+
<span class="linkdescr">{% trans %}Syntax and language elements{% endtrans %}</span></li>
63+
<li class="biglink"><a class="biglink" href="{{ pathto("using/index") }}">{% trans %}Python setup and usage{% endtrans %}</a><br>
64+
<span class="linkdescr">{% trans %}How to install, configure, and use Python{% endtrans %}</span></li>
65+
<li class="biglink"><a class="biglink" href="{{ pathto("howto/index") }}">{% trans %}Python HOWTOs{% endtrans %}</a><br>
66+
<span class="linkdescr">{% trans %}In-depth topic manuals{% endtrans %}</span></li>
67+
</ul>
68+
<ul>
69+
<li class="biglink"><a class="biglink" href="{{ pathto("installing/index") }}">{% trans %}Installing Python modules{% endtrans %}</a><br>
70+
<span class="linkdescr">{% trans %}Third-party modules and PyPI.org{% endtrans %}</span></li>
71+
<li class="biglink"><a class="biglink" href="{{ pathto("extending/index") }}">{% trans %}Extending and embedding{% endtrans %}</a><br>
72+
<span class="linkdescr">{% trans %}For C/C++ programmers{% endtrans %}</span></li>
73+
<li class="biglink"><a class="biglink" href="{{ pathto("c-api/index") }}">{% trans %}Python's C API{% endtrans %}</a><br>
74+
<span class="linkdescr">{% trans %}C API reference{% endtrans %}</span></li>
75+
<li class="biglink"><a class="biglink" href="{{ pathto("faq/index") }}">{% trans %}FAQs{% endtrans %}</a><br>
76+
<span class="linkdescr">{% trans %}Frequently asked questions (with answers!){% endtrans %}</span></li>
77+
<li class="biglink"><a class="biglink" href="{{ pathto("deprecations/index") }}">{% trans %}Deprecations{% endtrans %}</a><br>
78+
<span class="linkdescr">{% trans %}Deprecated functionality{% endtrans %}</span></li>
79+
</ul>
80+
</div>
81+
82+
<p><strong>{% trans %}Other resources:{% endtrans %}</strong></p>
83+
<div class="contentstable">
84+
<ul>
85+
<li class="biglink"><a class="biglink" href="https://packaging.python.org">{% trans %}Python Packaging User Guide{% endtrans %}</a><br>
86+
<span class="linkdescr">{% trans %}Resources relating to Python packaging{% endtrans %}</span></li>
87+
</ul>
88+
<ul>
89+
<li class="biglink"><a class="biglink" href="https://typing.python.org">{% trans %}Static Typing with Python{% endtrans %}</a><br>
90+
<span class="linkdescr">{% trans %}Information and guides about Python type safety{% endtrans %}</span></li>
91+
</ul>
92+
</div>
5393

5494
<p><strong>{% trans %}Indices, glossary, and search:{% endtrans %}</strong></p>
55-
<table class="contentstable" align="center"><tr>
56-
<td width="50%">
57-
<p class="biglink"><a class="biglink" href="{{ pathto("py-modindex") }}">{% trans %}Global module index{% endtrans %}</a><br>
58-
<span class="linkdescr">{% trans %}All modules and libraries{% endtrans %}</span></p>
59-
<p class="biglink"><a class="biglink" href="{{ pathto("genindex") }}">{% trans %}General index{% endtrans %}</a><br>
60-
<span class="linkdescr">{% trans %}All functions, classes, and terms{% endtrans %}</span></p>
61-
<p class="biglink"><a class="biglink" href="{{ pathto("glossary") }}">{% trans %}Glossary{% endtrans %}</a><br>
62-
<span class="linkdescr">{% trans %}Terms explained{% endtrans %}</span></p>
63-
</td><td width="50%">
64-
<p class="biglink"><a class="biglink" href="{{ pathto("search") }}">{% trans %}Search page{% endtrans %}</a><br>
65-
<span class="linkdescr">{% trans %}Search this documentation{% endtrans %}</span></p>
66-
<p class="biglink"><a class="biglink" href="{{ pathto("contents") }}">{% trans %}Complete table of contents{% endtrans %}</a><br>
67-
<span class="linkdescr">{% trans %}Lists all sections and subsections{% endtrans %}</span></p>
68-
</td></tr>
69-
</table>
95+
<div class="contentstable">
96+
<ul>
97+
<li class="biglink"><a class="biglink" href="{{ pathto("py-modindex") }}">{% trans %}Global module index{% endtrans %}</a><br>
98+
<span class="linkdescr">{% trans %}All modules and libraries{% endtrans %}</span></li>
99+
<li class="biglink"><a class="biglink" href="{{ pathto("genindex") }}">{% trans %}General index{% endtrans %}</a><br>
100+
<span class="linkdescr">{% trans %}All functions, classes, and terms{% endtrans %}</span></li>
101+
<li class="biglink"><a class="biglink" href="{{ pathto("glossary") }}">{% trans %}Glossary{% endtrans %}</a><br>
102+
<span class="linkdescr">{% trans %}Terms explained{% endtrans %}</span></li>
103+
</ul>
104+
<ul>
105+
<li class="biglink"><a class="biglink" href="{{ pathto("search") }}">{% trans %}Search page{% endtrans %}</a><br>
106+
<span class="linkdescr">{% trans %}Search this documentation{% endtrans %}</span></li>
107+
<li class="biglink"><a class="biglink" href="{{ pathto("contents") }}">{% trans %}Complete table of contents{% endtrans %}</a><br>
108+
<span class="linkdescr">{% trans %}All sections and subsections{% endtrans %}</span></li>
109+
</ul>
110+
</div>
70111

71112
<p><strong>{% trans %}Project information:{% endtrans %}</strong></p>
72-
<table class="contentstable" align="center"><tr>
73-
<td width="50%">
74-
<p class="biglink"><a class="biglink" href="{{ pathto("bugs") }}">{% trans %}Reporting issues{% endtrans %}</a></p>
75-
<p class="biglink"><a class="biglink" href="https://devguide.python.org/documentation/help-documenting/">{% trans %}Contributing to docs{% endtrans %}</a></p>
76-
<p class="biglink"><a class="biglink" href="{{ pathto("download") }}">{% trans %}Download the documentation{% endtrans %}</a></p>
77-
</td><td width="50%">
78-
<p class="biglink"><a class="biglink" href="{{ pathto("license") }}">{% trans %}History and license of Python{% endtrans %}</a></p>
79-
<p class="biglink"><a class="biglink" href="{{ pathto("copyright") }}">{% trans %}Copyright{% endtrans %}</a></p>
80-
<p class="biglink"><a class="biglink" href="{{ pathto("about") }}">{% trans %}About the documentation{% endtrans %}</a></p>
81-
</td></tr>
82-
</table>
113+
<div class="contentstable">
114+
<ul>
115+
<li class="biglink"><a class="biglink" href="{{ pathto("bugs") }}">{% trans %}Reporting issues{% endtrans %}</a></li>
116+
<li class="biglink"><a class="biglink" href="https://devguide.python.org/documentation/help-documenting/">{% trans %}Contributing to docs{% endtrans %}</a></li>
117+
<li class="biglink"><a class="biglink" href="{{ pathto("download") }}">{% trans %}Download the documentation{% endtrans %}</a></li>
118+
</ul>
119+
<ul>
120+
<li class="biglink"><a class="biglink" href="{{ pathto("license") }}">{% trans %}History and license of Python{% endtrans %}</a></li>
121+
<li class="biglink"><a class="biglink" href="{{ pathto("copyright") }}">{% trans %}Copyright{% endtrans %}</a></li>
122+
<li class="biglink"><a class="biglink" href="{{ pathto("about") }}">{% trans %}About the documentation{% endtrans %}</a></li>
123+
</ul>
124+
</div>
83125
{% endblock %}

Doc/whatsnew/3.16.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ New modules
8686
Improved modules
8787
================
8888

89+
90+
gzip
91+
----
92+
93+
* :func:`gzip.open` now accepts an optional argument ``mtime``
94+
which is passed on to the constructor of the :class:`~gzip.GzipFile` class.
95+
(Contributed by Marin Misur in :gh:`91372`.)
96+
8997
os
9098
--
9199

Lib/gzip.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232

3333
def open(filename, mode="rb", compresslevel=_COMPRESS_LEVEL_TRADEOFF,
34-
encoding=None, errors=None, newline=None):
34+
encoding=None, errors=None, newline=None, *, mtime=None):
3535
"""Open a gzip-compressed file in binary or text mode.
3636
3737
The filename argument can be an actual filename (a str or bytes object), or
@@ -63,9 +63,10 @@ def open(filename, mode="rb", compresslevel=_COMPRESS_LEVEL_TRADEOFF,
6363

6464
gz_mode = mode.replace("t", "")
6565
if isinstance(filename, (str, bytes, os.PathLike)):
66-
binary_file = GzipFile(filename, gz_mode, compresslevel)
66+
binary_file = GzipFile(filename, gz_mode, compresslevel, mtime=mtime)
6767
elif hasattr(filename, "read") or hasattr(filename, "write"):
68-
binary_file = GzipFile(None, gz_mode, compresslevel, filename)
68+
binary_file = GzipFile(None, gz_mode, compresslevel, filename,
69+
mtime=mtime)
6970
else:
7071
raise TypeError("filename must be a str or bytes object, or a file")
7172

Lib/test/test_gzip.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,17 @@ def test_mtime(self):
351351
self.assertEqual(dataRead, data1)
352352
self.assertEqual(fRead.mtime, mtime)
353353

354+
def test_mtime_with_open(self):
355+
mtime = 123456789
356+
with gzip.open(self.filename, "wb", mtime=mtime) as fWrite:
357+
fWrite.write(data1)
358+
with gzip.open(self.filename, "rb") as fRead:
359+
self.assertTrue(hasattr(fRead, 'mtime'))
360+
self.assertIsNone(fRead.mtime)
361+
dataRead = fRead.read()
362+
self.assertEqual(dataRead, data1)
363+
self.assertEqual(fRead.mtime, mtime)
364+
354365
def test_mtime_out_of_range(self):
355366
for mtime in (-1, 2**32):
356367
with gzip.GzipFile(self.filename, 'w', mtime=mtime) as fWrite:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Added *mtime* option to :func:`gzip.open`, which will be passed
2+
to the constructor of :class:`~gzip.GzipFile`.

0 commit comments

Comments
 (0)