bpo-34035: Fix several AttributeError in zipfile seek() methods. (GH-8527)
authorMickaël Schoentgen <contact@tiger-222.fr>
Sun, 29 Jul 2018 18:26:52 +0000 (20:26 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 29 Jul 2018 18:26:52 +0000 (21:26 +0300)
Lib/test/test_zipfile.py
Lib/zipfile.py
Misc/ACKS
Misc/NEWS.d/next/Library/2018-07-28-15-00-31.bpo-34035.75nW0H.rst [new file with mode: 0644]

index 61c3e349a69ef4f827c8653e091b597c054e6b07..ac9a4ff6fef002921c3e737e4b29f4001867a793 100644 (file)
@@ -1646,6 +1646,8 @@ class OtherTests(unittest.TestCase):
                 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:
@@ -1661,6 +1663,8 @@ class OtherTests(unittest.TestCase):
                 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)
index b90b60f72e2bcd984141063e3697cefaf7fa5394..2757ce91cf485c9a2ed0a641d8124faa729d8e33 100644 (file)
@@ -701,11 +701,11 @@ class _SharedFile:
 
     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
 
@@ -1021,14 +1021,13 @@ class ZipExtFile(io.BufferedIOBase):
             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
 
index 2cf5e10dd141db43c78c01a91434b83e7424af46..0b0bb3a763db3d57ebbb020238b4f07408394c59 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1435,6 +1435,7 @@ Michael Schneider
 Peter Schneider-Kamp
 Arvin Schnell
 Nofar Schnider
+Mickaël Schoentgen
 Ed Schouten
 Scott Schram
 Robin Schreiber
diff --git a/Misc/NEWS.d/next/Library/2018-07-28-15-00-31.bpo-34035.75nW0H.rst b/Misc/NEWS.d/next/Library/2018-07-28-15-00-31.bpo-34035.75nW0H.rst
new file mode 100644 (file)
index 0000000..b66d281
--- /dev/null
@@ -0,0 +1 @@
+Fix several AttributeError in zipfile seek() methods. Patch by Mickaël Schoentgen.