cpython: 9a99a88301ef (original) (raw)

Mercurial > cpython

changeset 104353:9a99a88301ef 2.7

Issue #26293: Fixed writing ZIP files that starts not from the start of the file. Offsets in ZIP file now are relative to the start of the archive in conforming to the specification. [#26293]

Serhiy Storchaka storchaka@gmail.com
date Fri, 07 Oct 2016 23:12:53 +0300
parents 47d5bf5a846f
children ba76dd106e66
files Lib/test/test_zipfile.py Lib/zipfile.py Misc/NEWS
diffstat 3 files changed, 62 insertions(+), 13 deletions(-)[+] [-] Lib/test/test_zipfile.py 43 Lib/zipfile.py 28 Misc/NEWS 4

line wrap: on

line diff

--- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -344,6 +344,49 @@ class TestsWithSourceFile(unittest.TestC f.seek(len(data)) with zipfile.ZipFile(f, "r") as zipfp: self.assertEqual(zipfp.namelist(), [TESTFN])

+

+

+

+

+

def test_ignores_newline_at_end(self): with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:

--- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -772,6 +772,7 @@ class ZipFile(object): # set the modified flag so central directory gets written # even if no files are added to the archive self._didModify = True

@@ -785,6 +786,7 @@ class ZipFile(object): # set the modified flag so central directory gets written # even if no files are added to the archive self._didModify = True

@@ -815,17 +817,18 @@ class ZipFile(object): offset_cd = endrec[_ECD_OFFSET] # offset of central directory self._comment = endrec[_ECD_COMMENT] # archive comment

if self.debug > 2:

@@ -855,7 +858,7 @@ class ZipFile(object): t>>11, (t>>5)&0x3F, (t&0x1F) * 2 ) x._decodeExtra()

@@ -1198,7 +1201,7 @@ class ZipFile(object): raise RuntimeError('Compressed size larger than uncompressed size') # Seek backwards and write file header (which will now include # correct CRC and file sizes)

@@ -1284,11 +1287,10 @@ class ZipFile(object): file_size = zinfo.file_size compress_size = zinfo.compress_size

extra_data = zinfo.extra if extra: @@ -1332,7 +1334,7 @@ class ZipFile(object): # Write end-of-zip-archive record centDirCount = len(self.filelist) centDirSize = pos2 - pos1

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -49,6 +49,10 @@ Core and Builtins Library ------- +- Issue #26293: Fixed writing ZIP files that starts not from the start of the