diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-01-26 12:01:27 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-01-26 12:01:27 (GMT) |
commit | a14f7d239f000d889e38d818fb65df79700192ad (patch) | |
tree | 7763aef6ceade68e553aa23b75e3b1d475f57319 /Lib/zipfile.py | |
parent | f15e52402640284b01860b6f56dfa50d7efda67b (diff) | |
download | cpython-a14f7d239f000d889e38d818fb65df79700192ad.zip cpython-a14f7d239f000d889e38d818fb65df79700192ad.tar.gz cpython-a14f7d239f000d889e38d818fb65df79700192ad.tar.bz2 |
Issue #14099: Restored support of writing ZIP files to tellable but
non-seekable streams.
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r-- | Lib/zipfile.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py index d0789b6..845c6a9 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -1504,7 +1504,14 @@ class ZipFile: zinfo.file_size = len(data) # Uncompressed size with self._lock: - self.fp.seek(self.start_dir, 0) + try: + self.fp.seek(self.start_dir) + except (AttributeError, io.UnsupportedOperation): + # Some file-like objects can provide tell() but not seek() + pass + zinfo.header_offset = self.fp.tell() # Start of header data + if compress_type is not None: + zinfo.compress_type = compress_type zinfo.header_offset = self.fp.tell() # Start of header data if compress_type is not None: zinfo.compress_type = compress_type @@ -1550,7 +1557,11 @@ class ZipFile: try: if self.mode in ("w", "a") and self._didModify: # write ending records with self._lock: - self.fp.seek(self.start_dir, 0) + try: + self.fp.seek(self.start_dir) + except (AttributeError, io.UnsupportedOperation): + # Some file-like objects can provide tell() but not seek() + pass self._write_end_record() finally: fp = self.fp @@ -1558,7 +1569,6 @@ class ZipFile: self._fpclose(fp) def _write_end_record(self): - self.fp.seek(self.start_dir, 0) for zinfo in self.filelist: # write central directory dt = zinfo.date_time dosdate = (dt[0] - 1980) << 9 | dt[1] << 5 | dt[2] |