mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
Issue #5148: Ignore 'U' in mode given to gzip.open() and gzip.GzipFile().
This commit is contained in:
parent
c30848344c
commit
dd72b3f6b7
3 changed files with 13 additions and 0 deletions
|
@ -81,6 +81,10 @@ class GzipFile(io.BufferedIOBase):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Make sure we don't inadvertently enable universal newlines on the
|
||||||
|
# underlying file object - in read mode, this causes data corruption.
|
||||||
|
if mode:
|
||||||
|
mode = mode.replace('U', '')
|
||||||
# guarantee the file is opened in binary mode on platforms
|
# guarantee the file is opened in binary mode on platforms
|
||||||
# that care about that sort of thing
|
# that care about that sort of thing
|
||||||
if mode and 'b' not in mode:
|
if mode and 'b' not in mode:
|
||||||
|
|
|
@ -53,6 +53,13 @@ class TestGzip(unittest.TestCase):
|
||||||
d = f.read()
|
d = f.read()
|
||||||
self.assertEqual(d, data1*50)
|
self.assertEqual(d, data1*50)
|
||||||
|
|
||||||
|
def test_read_universal_newlines(self):
|
||||||
|
# Issue #5148: Reading breaks when mode contains 'U'.
|
||||||
|
self.test_write()
|
||||||
|
with gzip.GzipFile(self.filename, 'rU') as f:
|
||||||
|
d = f.read()
|
||||||
|
self.assertEqual(d, data1*50)
|
||||||
|
|
||||||
def test_io_on_closed_object(self):
|
def test_io_on_closed_object(self):
|
||||||
# Test that I/O operations on closed GzipFile objects raise a
|
# Test that I/O operations on closed GzipFile objects raise a
|
||||||
# ValueError, just like the corresponding functions on file objects.
|
# ValueError, just like the corresponding functions on file objects.
|
||||||
|
|
|
@ -122,6 +122,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #5148: Ignore 'U' in mode given to gzip.open() and gzip.GzipFile().
|
||||||
|
|
||||||
- Issue #16220: wsgiref now always calls close() on an iterable response.
|
- Issue #16220: wsgiref now always calls close() on an iterable response.
|
||||||
Patch by Brent Tubbs.
|
Patch by Brent Tubbs.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue