diff options
author | Georg Brandl <georg@python.org> | 2010-11-26 08:37:46 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-11-26 08:37:46 (GMT) |
commit | aba9796c5e92413f9fb5863da41a789d2bb225b8 (patch) | |
tree | 959a05fb9787f2e20aa3c2a2e9f87ed46b37f473 /Lib/zipfile.py | |
parent | 229fab3a4cecd0d40c79598b4005838ebfff4014 (diff) | |
download | cpython-aba9796c5e92413f9fb5863da41a789d2bb225b8.zip cpython-aba9796c5e92413f9fb5863da41a789d2bb225b8.tar.gz cpython-aba9796c5e92413f9fb5863da41a789d2bb225b8.tar.bz2 |
Merged revisions 85450-85455,85460-85465 via svnmerge from
svn+ssh://svn.python.org/python/branches/py3k
........
r85450 | georg.brandl | 2010-10-14 08:35:53 +0200 (Do, 14 Okt 2010) | 1 line
#7642: update to os.system() docs.
........
r85451 | georg.brandl | 2010-10-14 08:41:42 +0200 (Do, 14 Okt 2010) | 1 line
#3865: add note about benchmarking with profilers, and move licensing stuff to bottom of document.
........
r85452 | georg.brandl | 2010-10-14 08:43:22 +0200 (Do, 14 Okt 2010) | 1 line
#10046: small correction to atexit docs.
........
r85453 | georg.brandl | 2010-10-14 08:46:08 +0200 (Do, 14 Okt 2010) | 1 line
#6825: small correction to split() docs.
........
r85454 | georg.brandl | 2010-10-14 08:48:47 +0200 (Do, 14 Okt 2010) | 1 line
Mention 2to3.
........
r85455 | georg.brandl | 2010-10-14 08:59:45 +0200 (Do, 14 Okt 2010) | 1 line
#1710703: write zipfile structures also in the case of closing a new, but empty, archive.
........
r85460 | georg.brandl | 2010-10-14 09:24:28 +0200 (Do, 14 Okt 2010) | 1 line
#9964: fix running test_import under -O or -OO.
........
r85461 | georg.brandl | 2010-10-14 09:29:08 +0200 (Do, 14 Okt 2010) | 1 line
#9964: fix lib2to3 fixer fix_operator when running under -OO.
........
r85462 | georg.brandl | 2010-10-14 09:32:52 +0200 (Do, 14 Okt 2010) | 1 line
#9964: fix running test_xml_etree under -OO.
........
r85463 | georg.brandl | 2010-10-14 09:34:56 +0200 (Do, 14 Okt 2010) | 1 line
Better check for "any optimize option given".
........
r85464 | georg.brandl | 2010-10-14 09:42:27 +0200 (Do, 14 Okt 2010) | 1 line
#9964: fix running test_compileall under -O and -OO.
........
r85465 | georg.brandl | 2010-10-14 10:08:56 +0200 (Do, 14 Okt 2010) | 1 line
#9964: fix running test_cmd_line_script under -O and -OO.
........
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r-- | Lib/zipfile.py | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py index 3d2d57b..c376ee4 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -158,7 +158,13 @@ def _EndRecData64(fpin, offset, endrec): """ Read the ZIP64 end-of-archive records and use that to update endrec """ - fpin.seek(offset - sizeEndCentDir64Locator, 2) + try: + fpin.seek(offset - sizeEndCentDir64Locator, 2) + except IOError: + # If the seek fails, the file is not large enough to contain a ZIP64 + # end-of-archive record, so just return the end record we were given. + return endrec + data = fpin.read(sizeEndCentDir64Locator) sig, diskno, reloff, disks = struct.unpack(structEndArchive64Locator, data) if sig != stringEndArchive64Locator: @@ -723,14 +729,22 @@ class ZipFile: if key == 'r': self._GetContents() elif key == 'w': - pass + # set the modified flag so central directory gets written + # even if no files are added to the archive + self._didModify = True elif key == 'a': - try: # See if file is a zip file + try: + # See if file is a zip file self._RealGetContents() # seek to start of directory and overwrite self.fp.seek(self.start_dir, 0) - except BadZipfile: # file is not a zip file, just append + except BadZipfile: + # file is not a zip file, just append self.fp.seek(0, 2) + + # set the modified flag so central directory gets written + # even if no files are added to the archive + self._didModify = True else: if not self._filePassed: self.fp.close() @@ -751,7 +765,10 @@ class ZipFile: def _RealGetContents(self): """Read in the table of contents for the ZIP file.""" fp = self.fp - endrec = _EndRecData(fp) + try: + endrec = _EndRecData(fp) + except IOError: + raise BadZipfile("File is not a zip file") if not endrec: raise BadZipfile("File is not a zip file") if self.debug > 1: |