From: Nadeem Vawda Date: Wed, 18 Jan 2012 07:32:25 +0000 (+0200) Subject: Merge: #13781: Fix GzipFile to work with os.fdopen()'d file objects. X-Git-Tag: v3.3.0a1~357 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=50a4d5debb952bb319d8a8141e47a39c3fb03250;p=thirdparty%2FPython%2Fcpython.git Merge: #13781: Fix GzipFile to work with os.fdopen()'d file objects. --- 50a4d5debb952bb319d8a8141e47a39c3fb03250 diff --cc Lib/test/test_gzip.py index 9c7a96eb7a11,5ae7467e669b..d2b487121713 --- a/Lib/test/test_gzip.py +++ b/Lib/test/test_gzip.py @@@ -338,14 -323,14 +338,22 @@@ class TestGzip(unittest.TestCase) self.assertEqual(f.read(100), b'') self.assertEqual(nread, len(uncompressed)) + def test_textio_readlines(self): + # Issue #10791: TextIOWrapper.readlines() fails when wrapping GzipFile. + lines = (data1 * 50).decode("ascii").splitlines(keepends=True) + self.test_write() + with gzip.GzipFile(self.filename, 'r') as f: + with io.TextIOWrapper(f, encoding="ascii") as t: + self.assertEqual(t.readlines(), lines) + + def test_fileobj_from_fdopen(self): + # Issue #13781: Opening a GzipFile for writing fails when using a + # fileobj created with os.fdopen(). + fd = os.open(self.filename, os.O_WRONLY | os.O_CREAT) + with os.fdopen(fd, "wb") as f: + with gzip.GzipFile(fileobj=f, mode="w") as g: + pass + # Testing compress/decompress shortcut functions def test_compress(self):