mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Fix GzipFile's handling of filenames given as bytes objects.
This commit is contained in:
parent
f29ec4b0c8
commit
103e8113e4
3 changed files with 20 additions and 4 deletions
|
@ -331,6 +331,20 @@ class TestGzip(unittest.TestCase):
|
|||
with gzip.GzipFile(fileobj=f, mode="w") as g:
|
||||
pass
|
||||
|
||||
def test_bytes_filename(self):
|
||||
str_filename = self.filename
|
||||
try:
|
||||
bytes_filename = str_filename.encode("ascii")
|
||||
except UnicodeEncodeError:
|
||||
self.skipTest("Temporary file name needs to be ASCII")
|
||||
with gzip.GzipFile(bytes_filename, "wb") as f:
|
||||
f.write(data1 * 50)
|
||||
with gzip.GzipFile(bytes_filename, "rb") as f:
|
||||
self.assertEqual(f.read(), data1 * 50)
|
||||
# Sanity check that we are actually operating on the right file.
|
||||
with gzip.GzipFile(str_filename, "rb") as f:
|
||||
self.assertEqual(f.read(), data1 * 50)
|
||||
|
||||
# Testing compress/decompress shortcut functions
|
||||
|
||||
def test_compress(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue