From 5ae16a2bfbc30aabb6979dee29f59260ff060c86 Mon Sep 17 00:00:00 2001 From: Jeong Yunwon Date: Mon, 23 May 2022 08:27:24 +0900 Subject: [PATCH] update gzip and test_gzip from CPython 3.10.4 --- Lib/gzip.py | 10 +++---- Lib/test/test_gzip.py | 62 ++++++++++++++++++++++++++++--------------- 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/Lib/gzip.py b/Lib/gzip.py index e422773b3..475ec326c 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -62,6 +62,7 @@ def open(filename, mode="rb", compresslevel=_COMPRESS_LEVEL_BEST, raise TypeError("filename must be a str or bytes object, or a file") if "t" in mode: + encoding = io.text_encoding(encoding) return io.TextIOWrapper(binary_file, encoding, errors, newline) else: return binary_file @@ -277,7 +278,7 @@ class GzipFile(_compression.BaseStream): if self.fileobj is None: raise ValueError("write() on closed GzipFile object") - if isinstance(data, bytes): + if isinstance(data, (bytes, bytearray)): length = len(data) else: # accept any data that supports the buffer protocol @@ -516,7 +517,7 @@ class _GzipReader(_compression.DecompressReader): def _read_eof(self): # We've read to the end of the file - # We check the that the computed CRC and size of the + # We check that the computed CRC and size of the # uncompressed data matches the stored values. Note that the size # stored is the true file size mod 2**32. crc32, isize = struct.unpack("