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.
This commit is contained in:
Ruben Vorderman 2024-06-15 20:46:39 +02:00 committed by GitHub
parent 31d1d72d7e
commit 08d09cf5ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 26 additions and 34 deletions

View file

@ -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()