Commit 3f8c6913 authored by Mickaël Schoentgen's avatar Mickaël Schoentgen Committed by Serhiy Storchaka

bpo-34035: Fix several AttributeError in zipfile seek() methods. (GH-8527)

parent d2e902e4
...@@ -1646,6 +1646,8 @@ class OtherTests(unittest.TestCase): ...@@ -1646,6 +1646,8 @@ class OtherTests(unittest.TestCase):
self.assertEqual(fp.read(5), txt[bloc:bloc+5]) self.assertEqual(fp.read(5), txt[bloc:bloc+5])
fp.seek(0, os.SEEK_END) fp.seek(0, os.SEEK_END)
self.assertEqual(fp.tell(), len(txt)) self.assertEqual(fp.tell(), len(txt))
fp.seek(0, os.SEEK_SET)
self.assertEqual(fp.tell(), 0)
# Check seek on memory file # Check seek on memory file
data = io.BytesIO() data = io.BytesIO()
with zipfile.ZipFile(data, mode="w") as zipf: with zipfile.ZipFile(data, mode="w") as zipf:
...@@ -1661,6 +1663,8 @@ class OtherTests(unittest.TestCase): ...@@ -1661,6 +1663,8 @@ class OtherTests(unittest.TestCase):
self.assertEqual(fp.read(5), txt[bloc:bloc+5]) self.assertEqual(fp.read(5), txt[bloc:bloc+5])
fp.seek(0, os.SEEK_END) fp.seek(0, os.SEEK_END)
self.assertEqual(fp.tell(), len(txt)) self.assertEqual(fp.tell(), len(txt))
fp.seek(0, os.SEEK_SET)
self.assertEqual(fp.tell(), 0)
def tearDown(self): def tearDown(self):
unlink(TESTFN) unlink(TESTFN)
......
...@@ -701,11 +701,11 @@ class _SharedFile: ...@@ -701,11 +701,11 @@ class _SharedFile:
def seek(self, offset, whence=0): def seek(self, offset, whence=0):
with self._lock: with self._lock:
if self.writing(): if self._writing():
raise ValueError("Can't reposition in the ZIP file while " raise ValueError("Can't reposition in the ZIP file while "
"there is an open writing handle on it. " "there is an open writing handle on it. "
"Close the writing handle before trying to read.") "Close the writing handle before trying to read.")
self._file.seek(self._pos) self._file.seek(offset, whence)
self._pos = self._file.tell() self._pos = self._file.tell()
return self._pos return self._pos
...@@ -1021,14 +1021,13 @@ class ZipExtFile(io.BufferedIOBase): ...@@ -1021,14 +1021,13 @@ class ZipExtFile(io.BufferedIOBase):
read_offset = 0 read_offset = 0
elif read_offset < 0: elif read_offset < 0:
# Position is before the current position. Reset the ZipExtFile # Position is before the current position. Reset the ZipExtFile
self._fileobj.seek(self._orig_compress_start) self._fileobj.seek(self._orig_compress_start)
self._running_crc = self._orig_start_crc self._running_crc = self._orig_start_crc
self._compress_left = self._orig_compress_size self._compress_left = self._orig_compress_size
self._left = self._orig_file_size self._left = self._orig_file_size
self._readbuffer = b'' self._readbuffer = b''
self._offset = 0 self._offset = 0
self._decompressor = zipfile._get_decompressor(self._compress_type) self._decompressor = _get_decompressor(self._compress_type)
self._eof = False self._eof = False
read_offset = new_pos read_offset = new_pos
......
...@@ -1435,6 +1435,7 @@ Michael Schneider ...@@ -1435,6 +1435,7 @@ Michael Schneider
Peter Schneider-Kamp Peter Schneider-Kamp
Arvin Schnell Arvin Schnell
Nofar Schnider Nofar Schnider
Mickaël Schoentgen
Ed Schouten Ed Schouten
Scott Schram Scott Schram
Robin Schreiber Robin Schreiber
......
Fix several AttributeError in zipfile seek() methods. Patch by Mickaël Schoentgen.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment