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

Miss Islington (bot) webhook-mailer at python.org
Sun Jul 29 15:57:24 EDT 2018


https://github.com/python/cpython/commit/ad4f64d58c020016bd438de0e863a0d31d0f0dac
commit: ad4f64d58c020016bd438de0e863a0d31d0f0dac
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-07-29T12:57:21-07:00
summary:

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

(cherry picked from commit 3f8c6913b82ed9c05e57175bcbfeacde46c598e3)

Co-authored-by: Mickaël Schoentgen <contact at tiger-222.fr>

files:
A Misc/NEWS.d/next/Library/2018-07-28-15-00-31.bpo-34035.75nW0H.rst
M Lib/test/test_zipfile.py
M Lib/zipfile.py
M Misc/ACKS

diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index 61c3e349a69e..ac9a4ff6fef0 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -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:
@@ -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)
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index b90b60f72e2b..2757ce91cf48 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -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
 
@@ -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
 
diff --git a/Misc/ACKS b/Misc/ACKS
index c564c048f11f..bcf5604b6e21 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1429,6 +1429,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
index 000000000000..b66d2812179c
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-07-28-15-00-31.bpo-34035.75nW0H.rst
@@ -0,0 +1 @@
+Fix several AttributeError in zipfile seek() methods. Patch by Mickaël Schoentgen.



More information about the Python-checkins mailing list