Kaydet (Commit) b09b844a authored tarafından Martin v. Löwis's avatar Martin v. Löwis

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.
........
üst 451a356f
......@@ -269,7 +269,7 @@ ZipFile Objects
member of the given :class:`ZipInfo` instance. By default, the
:class:`ZipInfo` constructor sets this member to :const:`ZIP_STORED`.
The following data attribute is also available:
The following data attributes are also available:
.. attribute:: ZipFile.debug
......@@ -278,6 +278,12 @@ The following data attribute is also available:
output) to ``3`` (the most output). Debugging information is written to
``sys.stdout``.
.. attribute:: ZipFile.comment
The comment text associated with the ZIP file. If assigning a comment to a
:class:`ZipFile` instance created with mode 'a' or 'w', this should be a
string no longer than 65535 bytes. Comments longer than this will be
truncated in the written archive when :meth:`ZipFile.close` is called.
.. _pyzipfile-objects:
......
......@@ -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)
......
......@@ -2,6 +2,7 @@
# The support.requires call is the only reason for keeping this separate
# from test_zipfile
from test import support
# XXX(nnorwitz): disable this test by looking for extra largfile resource
# which doesn't exist. This test takes over 30 minutes to run in general
# and requires more disk space than most of the buildbots.
......@@ -92,8 +93,31 @@ class TestsWithSourceFile(unittest.TestCase):
if os.path.exists(fname):
os.remove(fname)
class OtherTests(unittest.TestCase):
def testMoreThan64kFiles(self):
# This test checks that more than 64k files can be added to an archive,
# and that the resulting archive can be read properly by ZipFile
zipf = zipfile.ZipFile(TESTFN, mode="w")
zipf.debug = 100
numfiles = (1 << 16) * 3/2
for i in xrange(numfiles):
zipf.writestr("foo%08d" % i, "%d" % (i**3 % 57))
self.assertEqual(len(zipf.namelist()), numfiles)
zipf.close()
zipf2 = zipfile.ZipFile(TESTFN, mode="r")
self.assertEqual(len(zipf2.namelist()), numfiles)
for i in xrange(numfiles):
self.assertEqual(zipf2.read("foo%08d" % i), "%d" % (i**3 % 57))
zipf.close()
def tearDown(self):
test_support.unlink(TESTFN)
test_support.unlink(TESTFN2)
def test_main():
run_unittest(TestsWithSourceFile)
run_unittest(TestsWithSourceFile, OtherTests)
if __name__ == "__main__":
test_main()
This diff is collapsed.
......@@ -17,8 +17,21 @@ Core and Builtins
Library
-------
<<<<<<< .working
- Issue #2683: Fix inconsistency in subprocess.Popen.communicate(): the
argument now must be a bytes object in any case.
=======
- Issue #1622: Correct interpretation of various ZIP header fields.
- 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.
- Issue #449227: Now with the rlcompleter module, callable objects are added
"(" when completed.
>>>>>>> .merge-right.r64688
- Issue #3145: help("modules whatever") failed when trying to load the source
code of every single module of the standard library, including invalid files
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment