bpo-5950: Support reading zips with comments in zipimport (#9548)

* bpo-5950: Support reading zips with comments in zipimport
This commit is contained in:
Zackery Spytz 2018-09-25 13:15:47 -06:00 committed by Barry Warsaw
parent 996859a90d
commit 5a5ce064b3
5 changed files with 1084 additions and 1013 deletions

View file

@ -116,6 +116,9 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
zinfo = ZipInfo(name, time.localtime(mtime))
zinfo.compress_type = self.compression
z.writestr(zinfo, data)
comment = kw.get("comment", None)
if comment is not None:
z.comment = comment
stuff = kw.get("stuff", None)
if stuff is not None:
@ -665,6 +668,18 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
with self.assertRaises(TypeError):
zipimport.zipimporter(memoryview(os.fsencode(filename)))
def testComment(self):
files = {TESTMOD + ".py": (NOW, test_src)}
self.doTest(".py", files, TESTMOD, comment=b"comment")
def testBeginningCruftAndComment(self):
files = {TESTMOD + ".py": (NOW, test_src)}
self.doTest(".py", files, TESTMOD, stuff=b"cruft" * 64, comment=b"hi")
def testLargestPossibleComment(self):
files = {TESTMOD + ".py": (NOW, test_src)}
self.doTest(".py", files, TESTMOD, comment=b"c" * ((1 << 16) - 1))
@support.requires_zlib
class CompressedZipImportTestCase(UncompressedZipImportTestCase):