Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6120739

Browse files
committed
Issue #20875: Prevent possible gzip "'read' is not defined" NameError.
Patch by Claudiu Popa.
1 parent 5e572fd commit 6120739

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

Lib/gzip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def prepend(self, prepend=b'', readprevious=False):
9999
self._read -= len(prepend)
100100
return
101101
else:
102-
self._buffer = self._buffer[read:] + prepend
102+
self._buffer = self._buffer[self._read:] + prepend
103103
self._length = len(self._buffer)
104104
self._read = 0
105105

Lib/test/test_gzip.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,13 @@ def test_read_with_extra(self):
396396
with gzip.GzipFile(fileobj=io.BytesIO(gzdata)) as f:
397397
self.assertEqual(f.read(), b'Test')
398398

399+
def test_prepend_error(self):
400+
# See issue #20875
401+
with gzip.open(self.filename, "wb") as f:
402+
f.write(data1)
403+
with gzip.open(self.filename, "rb") as f:
404+
f.fileobj.prepend()
405+
399406
class TestOpen(BaseTest):
400407
def test_binary_modes(self):
401408
uncompressed = data1 * 50

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Core and Builtins
1313
Library
1414
-------
1515

16+
- Issue #20875: Prevent possible gzip "'read' is not defined" NameError.
17+
Patch by Claudiu Popa.
18+
1619
- Issue #20283: RE pattern methods now accept the string keyword parameters
1720
as documented. The pattern and source keyword parameters are left as
1821
deprecated aliases.

0 commit comments

Comments
 (0)