]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merge: #13781: Fix GzipFile to work with os.fdopen()'d file objects.
authorNadeem Vawda <nadeem.vawda@gmail.com>
Wed, 18 Jan 2012 07:32:25 +0000 (09:32 +0200)
committerNadeem Vawda <nadeem.vawda@gmail.com>
Wed, 18 Jan 2012 07:32:25 +0000 (09:32 +0200)
1  2 
Lib/gzip.py
Lib/test/test_gzip.py
Misc/NEWS

diff --cc Lib/gzip.py
Simple merge
index 9c7a96eb7a11026297d8db860edbb56c2746091c,5ae7467e669b6ed0aafb07d32505771ce4fe1b58..d2b48712171312316883dc2560dff8c1d91ac153
@@@ -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):
diff --cc Misc/NEWS
Simple merge