cpython: ac0ec1f31b0a (original) (raw)

Mercurial > cpython

changeset 76269:ac0ec1f31b0a 2.7

#14399: zipfile now correctly handles comments added to empty zipfiles. Patch by Serhiy Storchaka. [#14399]

R David Murray rdmurray@bitdance.com
date Thu, 12 Apr 2012 18:42:47 -0400
parents cc2e3c6d2669
children dd15e1cddefb
files Lib/test/test_zipfile.py Lib/zipfile.py Misc/ACKS Misc/NEWS
diffstat 4 files changed, 42 insertions(+), 12 deletions(-)[+] [-] Lib/test/test_zipfile.py 16 Lib/zipfile.py 33 Misc/ACKS 1 Misc/NEWS 4

line wrap: on

line diff

--- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -908,6 +908,22 @@ class OtherTests(unittest.TestCase): with zipfile.ZipFile(TESTFN, mode="r") as zipf: self.assertEqual(zipf.comment, comment2)

+

+ def check_testzip_with_bad_crc(self, compression): """Tests that files with bad CRCs return their name from testzip.""" zipdata = self.zips_with_bad_crc[compression]

--- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -651,7 +651,7 @@ class ZipExtFile(io.BufferedIOBase): -class ZipFile: +class ZipFile(object): """ Class with methods to open, read, write, close, list zip files. z = ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=False) @@ -690,7 +690,7 @@ class ZipFile: self.compression = compression # Method of compression self.mode = key = mode.replace('b', '')[0] self.pwd = None

# Check if we were passed a file-like object if isinstance(file, basestring): @@ -765,7 +765,7 @@ class ZipFile: print endrec size_cd = endrec[_ECD_SIZE] # bytes in central directory offset_cd = endrec[_ECD_OFFSET] # offset of central directory

# "concat" is zero, unless zip was concatenated to another file concat = endrec[_ECD_LOCATION] - size_cd - offset_cd @@ -864,6 +864,22 @@ class ZipFile: """Set default password for encrypted files.""" self.pwd = pwd

+

+ def read(self, name, pwd=None): """Return file bytes (as a string) for name.""" return self.open(name, "r", pwd).read() @@ -1243,18 +1259,11 @@ class ZipFile: centDirSize = min(centDirSize, 0xFFFFFFFF) centDirOffset = min(centDirOffset, 0xFFFFFFFF)

- endrec = struct.pack(structEndArchive, stringEndArchive, 0, 0, centDirCount, centDirCount,

if not self._filePassed:

--- a/Misc/ACKS +++ b/Misc/ACKS @@ -814,6 +814,7 @@ Richard Stoakley Peter Stoehr Casper Stoel Michael Stone +Serhiy Storchaka Ken Stox Patrick Strawderman Dan Stromberg

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -44,6 +44,10 @@ Core and Builtins Library ------- +- Issue #14399: zipfile now correctly adds a comment even when the zipfile