mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Merged revisions 64688 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r64688 | martin.v.loewis | 2008-07-03 14:51:14 +0200 (Do, 03 Jul 2008) | 9 lines Patch #1622: Correct interpretation of various ZIP header fields. Also fixes - Issue #1526: Allow more than 64k files to be added to Zip64 file. - Issue #1746: Correct handling of zipfile archive comments (previously archives with comments over 4k were flagged as invalid). Allow writing Zip files with archives by setting the 'comment' attribute of a ZipFile. ........
This commit is contained in:
parent
451a356f11
commit
b09b844a5c
5 changed files with 314 additions and 106 deletions
|
@ -699,6 +699,55 @@ class OtherTests(unittest.TestCase):
|
|||
zipf.writestr("foo.txt\x00qqq", b"O, for a Muse of Fire!")
|
||||
self.assertEqual(zipf.namelist(), ['foo.txt'])
|
||||
|
||||
def test_StructSizes(self):
|
||||
# check that ZIP internal structure sizes are calculated correctly
|
||||
self.assertEqual(zipfile.sizeEndCentDir, 22)
|
||||
self.assertEqual(zipfile.sizeCentralDir, 46)
|
||||
self.assertEqual(zipfile.sizeEndCentDir64, 56)
|
||||
self.assertEqual(zipfile.sizeEndCentDir64Locator, 20)
|
||||
|
||||
def testComments(self):
|
||||
# This test checks that comments on the archive are handled properly
|
||||
|
||||
# check default comment is empty
|
||||
zipf = zipfile.ZipFile(TESTFN, mode="w")
|
||||
self.assertEqual(zipf.comment, b'')
|
||||
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
|
||||
zipf.close()
|
||||
zipfr = zipfile.ZipFile(TESTFN, mode="r")
|
||||
self.assertEqual(zipfr.comment, b'')
|
||||
zipfr.close()
|
||||
|
||||
# check a simple short comment
|
||||
comment = b'Bravely taking to his feet, he beat a very brave retreat.'
|
||||
zipf = zipfile.ZipFile(TESTFN, mode="w")
|
||||
zipf.comment = comment
|
||||
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
|
||||
zipf.close()
|
||||
zipfr = zipfile.ZipFile(TESTFN, mode="r")
|
||||
self.assertEqual(zipfr.comment, comment)
|
||||
zipfr.close()
|
||||
|
||||
# check a comment of max length
|
||||
comment2 = ''.join(['%d' % (i**3 % 10) for i in range((1 << 16)-1)])
|
||||
comment2 = comment2.encode("ascii")
|
||||
zipf = zipfile.ZipFile(TESTFN, mode="w")
|
||||
zipf.comment = comment2
|
||||
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
|
||||
zipf.close()
|
||||
zipfr = zipfile.ZipFile(TESTFN, mode="r")
|
||||
self.assertEqual(zipfr.comment, comment2)
|
||||
zipfr.close()
|
||||
|
||||
# check a comment that is too long is truncated
|
||||
zipf = zipfile.ZipFile(TESTFN, mode="w")
|
||||
zipf.comment = comment2 + b'oops'
|
||||
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
|
||||
zipf.close()
|
||||
zipfr = zipfile.ZipFile(TESTFN, mode="r")
|
||||
self.assertEqual(zipfr.comment, comment2)
|
||||
zipfr.close()
|
||||
|
||||
def tearDown(self):
|
||||
support.unlink(TESTFN)
|
||||
support.unlink(TESTFN2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue