]> granicus.if.org Git - python/commitdiff
Issue #20875: Prevent possible gzip "'read' is not defined" NameError.
authorNed Deily <nad@acm.org>
Sun, 9 Mar 2014 21:44:34 +0000 (14:44 -0700)
committerNed Deily <nad@acm.org>
Sun, 9 Mar 2014 21:44:34 +0000 (14:44 -0700)
Patch by Claudiu Popa.

Lib/gzip.py
Lib/test/test_gzip.py
Misc/NEWS

index 2fd03fa747f96d0f705fe71b0ea38f3d8cc38217..4ff98205fee985163ea41b40a4209286c5fb6d33 100644 (file)
@@ -99,7 +99,7 @@ class _PaddedFile:
             self._read -= len(prepend)
             return
         else:
-            self._buffer = self._buffer[read:] + prepend
+            self._buffer = self._buffer[self._read:] + prepend
         self._length = len(self._buffer)
         self._read = 0
 
index c94d54e02e62692201f41412aea5eb4dbc55bde9..034acb02c21ac87b44daf6adbb2f84d93ce34475 100644 (file)
@@ -396,6 +396,13 @@ class TestGzip(BaseTest):
         with gzip.GzipFile(fileobj=io.BytesIO(gzdata)) as f:
             self.assertEqual(f.read(), b'Test')
 
+    def test_prepend_error(self):
+        # See issue #20875
+        with gzip.open(self.filename, "wb") as f:
+            f.write(data1)
+        with gzip.open(self.filename, "rb") as f:
+            f.fileobj.prepend()
+
 class TestOpen(BaseTest):
     def test_binary_modes(self):
         uncompressed = data1 * 50
index d0aec17f75d04d6222d4236bfcde988318f8704d..7baa0f7df529ba15dcbe4f8bc47867138beae530 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #20875: Prevent possible gzip "'read' is not defined" NameError.
+  Patch by Claudiu Popa.
+
 - Issue #20283: RE pattern methods now accept the string keyword parameters
   as documented.  The pattern and source keyword parameters are left as
   deprecated aliases.