Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Lib/test/test_zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,8 @@ def test_seek_tell(self):
self.assertEqual(fp.read(5), txt[bloc:bloc+5])
fp.seek(0, os.SEEK_END)
self.assertEqual(fp.tell(), len(txt))
fp.seek(0, os.SEEK_SET)
self.assertEqual(fp.tell(), 0)
# Check seek on memory file
data = io.BytesIO()
with zipfile.ZipFile(data, mode="w") as zipf:
Expand All @@ -1661,6 +1663,8 @@ def test_seek_tell(self):
self.assertEqual(fp.read(5), txt[bloc:bloc+5])
fp.seek(0, os.SEEK_END)
self.assertEqual(fp.tell(), len(txt))
fp.seek(0, os.SEEK_SET)
self.assertEqual(fp.tell(), 0)

def tearDown(self):
unlink(TESTFN)
Expand Down
7 changes: 3 additions & 4 deletions Lib/zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,11 +701,11 @@ def __init__(self, file, pos, close, lock, writing):

def seek(self, offset, whence=0):
with self._lock:
if self.writing():
if self._writing():
raise ValueError("Can't reposition in the ZIP file while "
"there is an open writing handle on it. "
"Close the writing handle before trying to read.")
self._file.seek(self._pos)
self._file.seek(offset, whence)
self._pos = self._file.tell()
return self._pos

Expand Down Expand Up @@ -1021,14 +1021,13 @@ def seek(self, offset, whence=0):
read_offset = 0
elif read_offset < 0:
# Position is before the current position. Reset the ZipExtFile

self._fileobj.seek(self._orig_compress_start)
self._running_crc = self._orig_start_crc
self._compress_left = self._orig_compress_size
self._left = self._orig_file_size
self._readbuffer = b''
self._offset = 0
self._decompressor = zipfile._get_decompressor(self._compress_type)
self._decompressor = _get_decompressor(self._compress_type)
self._eof = False
read_offset = new_pos

Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,7 @@ Michael Schneider
Peter Schneider-Kamp
Arvin Schnell
Nofar Schnider
Mickaël Schoentgen
Ed Schouten
Scott Schram
Robin Schreiber
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix several AttributeError in zipfile seek() methods. Patch by Mickaël Schoentgen.