mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
[3.13] gh-112346: Always set OS byte to 255, simpler gzip.compress function. (GH-120486) (#120563)
gh-112346: Always set OS byte to 255, simpler gzip.compress function. (GH-120486)
This matches the output behavior in 3.10 and earlier; the optimization in 3.11 allowed the zlib library's "os" value to be filled in instead in the circumstance when mtime was 0. this keeps things consistent.
(cherry picked from commit 08d09cf5ba
)
Co-authored-by: Ruben Vorderman <r.h.p.vorderman@lumc.nl>
This commit is contained in:
parent
3a9f438c92
commit
a19bb261a3
4 changed files with 26 additions and 34 deletions
|
@ -714,7 +714,6 @@ class TestGzip(BaseTest):
|
|||
self.assertEqual(f.mtime, mtime)
|
||||
|
||||
def test_compress_correct_level(self):
|
||||
# gzip.compress calls with mtime == 0 take a different code path.
|
||||
for mtime in (0, 42):
|
||||
with self.subTest(mtime=mtime):
|
||||
nocompress = gzip.compress(data1, compresslevel=0, mtime=mtime)
|
||||
|
@ -722,6 +721,17 @@ class TestGzip(BaseTest):
|
|||
self.assertIn(data1, nocompress)
|
||||
self.assertNotIn(data1, yescompress)
|
||||
|
||||
def test_issue112346(self):
|
||||
# The OS byte should be 255, this should not change between Python versions.
|
||||
for mtime in (0, 42):
|
||||
with self.subTest(mtime=mtime):
|
||||
compress = gzip.compress(data1, compresslevel=1, mtime=mtime)
|
||||
self.assertEqual(
|
||||
struct.unpack("<IxB", compress[4:10]),
|
||||
(mtime, 255),
|
||||
"Gzip header does not properly set either mtime or OS byte."
|
||||
)
|
||||
|
||||
def test_decompress(self):
|
||||
for data in (data1, data2):
|
||||
buf = io.BytesIO()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue