Skip to content

Commit 3c2b602

Browse files
committed
Rewind in the third-party decompressor test; wrap two long lines
1 parent 77c81d7 commit 3c2b602

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

Lib/test/test_zipfile/test_core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4970,8 +4970,12 @@ def test_read_through_third_party_decompressor(self):
49704970
self.assertEqual(zf.read("member"), data)
49714971
with zf.open("member") as f:
49724972
self.assertEqual(f.read(100), data[:100])
4973+
self.assertEqual(f.read1(100), data[100:200])
49734974
f.seek(-100, os.SEEK_END)
49744975
self.assertEqual(f.read(), data[-100:])
4976+
# Rewinding past the read buffer re-creates the decompressor.
4977+
f.seek(0)
4978+
self.assertEqual(f.read(), data)
49754979

49764980

49774981
class AbstractBadCrcTests:

Lib/zipfile/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,8 @@ def read1(self, n):
12041204

12051205
def _set_decompressor(self):
12061206
self._decompressor = _get_decompressor(self._compress_type)
1207-
self._decompress_bounded = _decompressor_bounds_output(self._decompressor)
1207+
self._decompress_bounded = _decompressor_bounds_output(
1208+
self._decompressor)
12081209

12091210
def _read1(self, n):
12101211
# Read up to n compressed bytes with at most one read() system call,
@@ -1245,7 +1246,8 @@ def _read1(self, n):
12451246
data = self._decompressor.decompress(data, max(n, self.MIN_READ_SIZE))
12461247
self._eof = (self._decompressor.eof or
12471248
self._compress_left <= 0 and
1248-
_decompressor_needs_input(self._decompressor, default=True))
1249+
_decompressor_needs_input(self._decompressor,
1250+
default=True))
12491251
else:
12501252
data = self._decompressor.decompress(data)
12511253
self._eof = self._decompressor.eof or self._compress_left <= 0
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
:mod:`zipfile` again reads members through a third-party decompressor
2-
installed by replacing ``_get_decompressor()``, unbounded as before the
3-
bounded-decompression fix, instead of raising :exc:`AttributeError`. The
4-
bound still applies to the standard library's bzip2, LZMA and Zstandard
5-
decompressors.
2+
installed by replacing the private ``_get_decompressor()``, unbounded as
3+
before the bounded-decompression fix, instead of raising
4+
:exc:`AttributeError`. The bound still applies to the standard library's
5+
bzip2, LZMA and Zstandard decompressors.

0 commit comments

Comments
 (0)