Skip to content

Commit 3f8c691

Browse files
BoboTiGserhiy-storchaka
authored andcommitted
bpo-34035: Fix several AttributeError in zipfile seek() methods. (GH-8527)
1 parent d2e902e commit 3f8c691

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

Lib/test/test_zipfile.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,8 @@ def test_seek_tell(self):
16461646
self.assertEqual(fp.read(5), txt[bloc:bloc+5])
16471647
fp.seek(0, os.SEEK_END)
16481648
self.assertEqual(fp.tell(), len(txt))
1649+
fp.seek(0, os.SEEK_SET)
1650+
self.assertEqual(fp.tell(), 0)
16491651
# Check seek on memory file
16501652
data = io.BytesIO()
16511653
with zipfile.ZipFile(data, mode="w") as zipf:
@@ -1661,6 +1663,8 @@ def test_seek_tell(self):
16611663
self.assertEqual(fp.read(5), txt[bloc:bloc+5])
16621664
fp.seek(0, os.SEEK_END)
16631665
self.assertEqual(fp.tell(), len(txt))
1666+
fp.seek(0, os.SEEK_SET)
1667+
self.assertEqual(fp.tell(), 0)
16641668

16651669
def tearDown(self):
16661670
unlink(TESTFN)

Lib/zipfile.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -701,11 +701,11 @@ def __init__(self, file, pos, close, lock, writing):
701701

702702
def seek(self, offset, whence=0):
703703
with self._lock:
704-
if self.writing():
704+
if self._writing():
705705
raise ValueError("Can't reposition in the ZIP file while "
706706
"there is an open writing handle on it. "
707707
"Close the writing handle before trying to read.")
708-
self._file.seek(self._pos)
708+
self._file.seek(offset, whence)
709709
self._pos = self._file.tell()
710710
return self._pos
711711

@@ -1021,14 +1021,13 @@ def seek(self, offset, whence=0):
10211021
read_offset = 0
10221022
elif read_offset < 0:
10231023
# Position is before the current position. Reset the ZipExtFile
1024-
10251024
self._fileobj.seek(self._orig_compress_start)
10261025
self._running_crc = self._orig_start_crc
10271026
self._compress_left = self._orig_compress_size
10281027
self._left = self._orig_file_size
10291028
self._readbuffer = b''
10301029
self._offset = 0
1031-
self._decompressor = zipfile._get_decompressor(self._compress_type)
1030+
self._decompressor = _get_decompressor(self._compress_type)
10321031
self._eof = False
10331032
read_offset = new_pos
10341033

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,7 @@ Michael Schneider
14351435
Peter Schneider-Kamp
14361436
Arvin Schnell
14371437
Nofar Schnider
1438+
Mickaël Schoentgen
14381439
Ed Schouten
14391440
Scott Schram
14401441
Robin Schreiber
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix several AttributeError in zipfile seek() methods. Patch by Mickaël Schoentgen.

0 commit comments

Comments
 (0)