mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
#14399: zipfile now correctly handles comments added to empty zipfiles.
Patch by Serhiy Storchaka. This also moves the TypeError that results from trying to use a unicode comment from the 'close' step to the point at which the comment is added to the zipfile.
This commit is contained in:
parent
d46d69c279
commit
51804e9725
4 changed files with 50 additions and 11 deletions
|
@ -972,6 +972,28 @@ class OtherTests(unittest.TestCase):
|
|||
with zipfile.ZipFile(TESTFN, mode="r") as zipfr:
|
||||
self.assertEqual(zipfr.comment, comment2)
|
||||
|
||||
def test_unicode_comment(self):
|
||||
with zipfile.ZipFile(TESTFN, "w", zipfile.ZIP_STORED) as zipf:
|
||||
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
|
||||
with self.assertRaises(TypeError):
|
||||
zipf.comment = "this is an error"
|
||||
|
||||
def test_change_comment_in_empty_archive(self):
|
||||
with zipfile.ZipFile(TESTFN, "a", zipfile.ZIP_STORED) as zipf:
|
||||
self.assertFalse(zipf.filelist)
|
||||
zipf.comment = b"this is a comment"
|
||||
with zipfile.ZipFile(TESTFN, "r") as zipf:
|
||||
self.assertEqual(zipf.comment, b"this is a comment")
|
||||
|
||||
def test_change_comment_in_nonempty_archive(self):
|
||||
with zipfile.ZipFile(TESTFN, "w", zipfile.ZIP_STORED) as zipf:
|
||||
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
|
||||
with zipfile.ZipFile(TESTFN, "a", zipfile.ZIP_STORED) as zipf:
|
||||
self.assertTrue(zipf.filelist)
|
||||
zipf.comment = b"this is a comment"
|
||||
with zipfile.ZipFile(TESTFN, "r") as zipf:
|
||||
self.assertEqual(zipf.comment, b"this is a comment")
|
||||
|
||||
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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue