Lines Matching refs:ZipFile
13 import zipfile
42 self.line_gen = ["Zipfile test line %d. random float: %f" % (i, random())
52 with zipfile.ZipFile(f, "w", compression) as zipfp:
61 with zipfile.ZipFile(f, "r", compression) as zipfp:
117 self.zip_test(f, zipfile.ZIP_STORED)
123 with zipfile.ZipFile(f, "r", compression) as zipfp:
145 self.zip_open_test(f, zipfile.ZIP_STORED)
149 with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
153 with zipfile.ZipFile(TESTFN2, "r") as zipfp:
169 with zipfile.ZipFile(f, "r", compression) as zipfp:
182 self.zip_random_open_test(f, zipfile.ZIP_STORED)
188 with zipfile.ZipFile(f, 'w', zipfile.ZIP_STORED) as zipfp:
192 with zipfile.ZipFile(f, 'r') as zipfp:
203 with zipfile.ZipFile(f, "r") as zipfp:
223 with zipfile.ZipFile(f, "r") as zipfp:
233 with zipfile.ZipFile(f, "r") as zipfp:
243 with zipfile.ZipFile(f, "r") as zipfp:
250 self.zip_readline_read_test(f, zipfile.ZIP_STORED)
254 self.zip_readline_test(f, zipfile.ZIP_STORED)
258 self.zip_readlines_test(f, zipfile.ZIP_STORED)
262 self.zip_iterlines_test(f, zipfile.ZIP_STORED)
267 self.zip_test(f, zipfile.ZIP_DEFLATED)
272 self.zip_open_test(f, zipfile.ZIP_DEFLATED)
277 self.zip_random_open_test(f, zipfile.ZIP_DEFLATED)
283 self.zip_readline_read_test(f, zipfile.ZIP_DEFLATED)
288 self.zip_readline_test(f, zipfile.ZIP_DEFLATED)
293 self.zip_readlines_test(f, zipfile.ZIP_DEFLATED)
298 self.zip_iterlines_test(f, zipfile.ZIP_DEFLATED)
304 with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_DEFLATED) as zipfp:
308 with zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_DEFLATED) as zipfp:
314 with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
317 with zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_STORED) as zipfp:
321 """Test appending to an existing zipfile."""
322 with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
325 with zipfile.ZipFile(TESTFN2, "a", zipfile.ZIP_STORED) as zipfp:
330 """Test appending to an existing file that is not a zipfile."""
333 data = 'I am not a ZipFile!'*10
337 with zipfile.ZipFile(TESTFN2, "a", zipfile.ZIP_STORED) as zipfp:
342 with zipfile.ZipFile(f, "r") as zipfp:
346 with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
350 with zipfile.ZipFile(TESTFN2, "r") as zipfp:
351 self.assertIsInstance(zipfp, zipfile.ZipFile)
354 with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
359 with zipfile.ZipFile(TESTFN2, "r") as zipfp:
360 self.assertIsInstance(zipfp, zipfile.ZipFile)
364 """Check that calling ZipFile.write without arcname specified
366 with zipfile.ZipFile(TESTFN2, "w") as zipfp:
374 with zipfile.ZipFile(TESTFN2, "w") as zipfp:
375 zipfp.write(TESTFN, 'storeme', zipfile.ZIP_STORED)
376 zipfp.write(TESTFN, 'deflateme', zipfile.ZIP_DEFLATED)
379 self.assertEqual(sinfo.compress_type, zipfile.ZIP_STORED)
380 self.assertEqual(dinfo.compress_type, zipfile.ZIP_DEFLATED)
383 """Check that trying to call write() on a readonly ZipFile object
385 with zipfile.ZipFile(TESTFN2, mode="w") as zipfp:
388 with zipfile.ZipFile(TESTFN2, mode="r") as zipfp:
392 with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
396 with zipfile.ZipFile(TESTFN2, "r") as zipfp:
414 with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
418 with zipfile.ZipFile(TESTFN2, "r") as zipfp:
438 with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
442 with zipfile.ZipFile(TESTFN2, "r") as zipfp:
496 with zipfile.ZipFile(TESTFN2, 'w', zipfile.ZIP_STORED) as zipfp:
497 zinfo = zipfile.ZipInfo()
507 with zipfile.ZipFile(TESTFN2, 'r') as zipfp:
514 with zipfile.ZipFile(TESTFN2, 'r') as zipfp:
521 with zipfile.ZipFile(TESTFN2, 'r') as zipfp:
528 with zipfile.ZipFile(TESTFN2, 'r') as zipfp:
536 zipfp = zipfile.ZipFile(TESTFN2, "w")
537 zipfp.writestr("a.txt", "hello world", compress_type=zipfile.ZIP_STORED)
539 zipfp.writestr("b.txt", "hello world", compress_type=zipfile.ZIP_DEFLATED)
542 self.assertEqual(info.compress_type, zipfile.ZIP_STORED)
546 self.assertEqual(info.compress_type, zipfile.ZIP_DEFLATED)
554 with zipfile.ZipFile(f, "r") as zipfp:
560 self.zip_test_writestr_permissions(f, zipfile.ZIP_STORED)
563 """Check that the zipfile is closed after the 'with' block."""
564 with zipfile.ZipFile(TESTFN2, "w") as zipfp:
570 with zipfile.ZipFile(TESTFN2, "r") as zipfp:
575 """Check that the zipfile is closed if an exception is raised in the
577 with zipfile.ZipFile(TESTFN2, "w") as zipfp:
582 with zipfile.ZipFile(TESTFN2, "r") as zipfp2:
583 raise zipfile.BadZipfile()
584 except zipfile.BadZipfile:
590 with zipfile.ZipFile(TESTFN2, "w") as zipfp:
603 self._limit = zipfile.ZIP64_LIMIT
604 zipfile.ZIP64_LIMIT = 5
606 line_gen = ("Test of zipfile line %d." % i
615 with zipfile.ZipFile(f, "w", compression) as zipfp:
616 self.assertRaises(zipfile.LargeZipFile,
620 with zipfile.ZipFile(f, "w", compression) as zipfp:
621 self.assertRaises(zipfile.LargeZipFile,
626 self.large_file_exception_test(f, zipfile.ZIP_STORED)
627 self.large_file_exception_test2(f, zipfile.ZIP_STORED)
631 with zipfile.ZipFile(f, "w", compression, allowZip64=True) as zipfp:
637 with zipfile.ZipFile(f, "r", compression) as zipfp:
693 self.zip_test(f, zipfile.ZIP_STORED)
698 self.zip_test(f, zipfile.ZIP_DEFLATED)
701 with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED,
705 with zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_STORED) as zipfp:
709 zipfile.ZIP64_LIMIT = self._limit
716 with zipfile.PyZipFile(TemporaryFile(), "w") as zipfp:
728 with zipfile.PyZipFile(TemporaryFile(), "w") as zipfp:
744 with zipfile.PyZipFile(TemporaryFile(), "w") as zipfp:
767 zipfp = zipfile.PyZipFile(TemporaryFile(), "w")
779 with zipfile.PyZipFile(TemporaryFile(), "w") as zipfp:
787 zipfile.ZIP_STORED: (
796 zipfile.ZIP_DEFLATED: (
808 with zipfile.ZipFile(TESTFN, "w") as zf:
813 with zipfile.ZipFile(TESTFN, "r") as zf:
825 with zipfile.ZipFile(TESTFN, 'a') as zf:
832 with zipfile.ZipFile(TESTFN, 'r') as zf:
836 # This test checks that the ZipFile constructor closes the file object
838 # traceback holds a reference to the ZipFile object and, indirectly,
846 zipfile.ZipFile(TESTFN)
847 except zipfile.BadZipfile:
855 chk = zipfile.is_zipfile(TESTFN)
859 chk = zipfile.is_zipfile(fp)
864 chk = zipfile.is_zipfile(fp)
867 chk = zipfile.is_zipfile(fp)
874 with zipfile.ZipFile(fp, mode="w") as zipf:
882 self.assertRaises(zipfile.BadZipfile, zipfile.ZipFile, fp)
887 with zipfile.ZipFile(TESTFN, mode="w") as zipf:
889 chk = zipfile.is_zipfile(TESTFN)
893 chk = zipfile.is_zipfile(fp)
900 chk = zipfile.is_zipfile(fp)
903 chk = zipfile.is_zipfile(fp)
908 # ZipFile instance is finalized; this tests for regression on SF tracker
912 # when a ZipFile instance was created for a file that did not
918 self.assertRaises(IOError, zipfile.ZipFile, TESTFN)
923 self.assertRaises(zipfile.BadZipfile, zipfile.ZipFile, TESTFN)
927 self.assertRaises(zipfile.BadZipfile, zipfile.ZipFile, TESTFN)
932 with zipfile.ZipFile(data, mode="w") as zipf:
935 # This is correct; calling .read on a closed ZipFile should raise
943 open(TESTFN, 'w').write('zipfile test data')
947 """Check that bad modes passed to ZipFile constructor are caught."""
948 self.assertRaises(RuntimeError, zipfile.ZipFile, TESTFN, "q")
951 """Check that bad modes passed to ZipFile.open are caught."""
952 with zipfile.ZipFile(TESTFN, mode="w") as zipf:
955 with zipfile.ZipFile(TESTFN, mode="r") as zipf:
963 with zipfile.ZipFile(TESTFN, mode="w") as zipf:
975 with zipfile.ZipFile(TESTFN, mode="w") as zipf:
979 """Check that bad compression methods passed to ZipFile.open are
981 self.assertRaises(RuntimeError, zipfile.ZipFile, TESTFN, "w", -1)
991 with zipfile.ZipFile(io.BytesIO(data), 'r') as zipf:
997 with zipfile.ZipFile(TESTFN, mode="w") as zipf:
1003 self.assertEqual(zipfile.sizeEndCentDir, 22)
1004 self.assertEqual(zipfile.sizeCentralDir, 46)
1005 self.assertEqual(zipfile.sizeEndCentDir64, 56)
1006 self.assertEqual(zipfile.sizeEndCentDir64Locator, 20)
1012 with zipfile.ZipFile(TESTFN, mode="w") as zipf:
1016 with zipfile.ZipFile(TESTFN, mode="r") as zipf:
1021 with zipfile.ZipFile(TESTFN, mode="w") as zipf:
1024 with zipfile.ZipFile(TESTFN, mode="r") as zipf:
1029 with zipfile.ZipFile(TESTFN, mode="w") as zipf:
1033 with zipfile.ZipFile(TESTFN, mode="r") as zipf:
1037 with zipfile.ZipFile(TESTFN, mode="w") as zipf:
1040 with zipfile.ZipFile(TESTFN, mode="r") as zipf:
1044 with zipfile.ZipFile(TESTFN, "a", zipfile.ZIP_STORED) as zipf:
1047 with zipfile.ZipFile(TESTFN, "r") as zipf:
1051 with zipfile.ZipFile(TESTFN, "w", zipfile.ZIP_STORED) as zipf:
1053 with zipfile.ZipFile(TESTFN, "a", zipfile.ZIP_STORED) as zipf:
1056 with zipfile.ZipFile(TESTFN, "r") as zipf:
1063 with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf:
1068 self.check_testzip_with_bad_crc(zipfile.ZIP_STORED)
1072 self.check_testzip_with_bad_crc(zipfile.ZIP_DEFLATED)
1078 # Using ZipFile.read()
1079 with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf:
1080 self.assertRaises(zipfile.BadZipfile, zipf.read, 'afile')
1083 with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf:
1085 self.assertRaises(zipfile.BadZipfile, corrupt_file.read)
1088 with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf:
1091 with self.assertRaises(zipfile.BadZipfile):
1096 self.check_read_with_bad_crc(zipfile.ZIP_STORED)
1100 self.check_read_with_bad_crc(zipfile.ZIP_DEFLATED)
1109 with zipfile.ZipFile(io.BytesIO(), "w", compression) as zipf:
1116 self.check_read_return_size(zipfile.ZIP_STORED)
1120 self.check_read_return_size(zipfile.ZIP_DEFLATED)
1125 with zipfile.ZipFile(TESTFN, mode="w") as zipf:
1128 zipf = zipfile.ZipFile(TESTFN, mode="r")
1129 except zipfile.BadZipfile:
1132 with zipfile.ZipFile(TESTFN, mode="a") as zipf:
1135 zipf = zipfile.ZipFile(TESTFN, mode="r")
1145 self.assertRaises(zipfile.BadZipfile, zipfile.ZipFile, TESTFN, 'r')
1149 zipfile.ZipInfo, 'seventies', (1979, 1, 1, 0, 0, 0))
1179 plain = 'zipfile.py encryption test'
1185 self.zip = zipfile.ZipFile(TESTFN, "r")
1188 self.zip2 = zipfile.ZipFile(TESTFN2, "r")
1232 with zipfile.ZipFile(f, "w", compression) as zipfp:
1240 with zipfile.ZipFile(f, "r", compression) as zipfp:
1248 self.zip_test(f, zipfile.ZIP_STORED)
1253 self.zip_test(f, zipfile.ZIP_DEFLATED)
1259 with zipfile.ZipFile(f, "r", compression) as zipfp:
1286 self.zip_open_test(f, zipfile.ZIP_STORED)
1291 self.zip_open_test(f, zipfile.ZIP_DEFLATED)
1297 with zipfile.ZipFile(f, "r", compression) as zipfp:
1312 self.zip_random_open_test(f, zipfile.ZIP_STORED)
1317 self.zip_random_open_test(f, zipfile.ZIP_DEFLATED)
1324 with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_DEFLATED) as zipfp:
1329 # Verify that (when the ZipFile is in control of creating file objects)
1331 with zipfile.ZipFile(TESTFN2, mode="r") as zipf:
1341 # Verify that (when the ZipFile is in control of creating file objects)
1343 with zipfile.ZipFile(TESTFN2, mode="r") as zipf:
1353 # Verify that (when the ZipFile is in control of creating file objects)
1355 with zipfile.ZipFile(TESTFN2, mode="r") as zipf:
1373 with zipfile.ZipFile(findfile("zipdir.zip")) as zipf:
1386 zipf = zipfile.ZipFile(TESTFN, "w")
1398 self.line_gen = ["Test of zipfile line %d." % i
1409 with zipfile.ZipFile(f, "w", compression) as zipfp:
1417 with zipfile.ZipFile(f, "r") as zipfp:
1427 zipfp = zipfile.ZipFile(f, "r")
1450 with zipfile.ZipFile(f, "r") as zipfp:
1461 with zipfile.ZipFile(f, "r") as zipfp:
1472 with zipfile.ZipFile(f, "r") as zipfp:
1479 self.read_test(f, zipfile.ZIP_STORED)
1484 self.readline_read_test(f, zipfile.ZIP_STORED)
1488 self.readline_test(f, zipfile.ZIP_STORED)
1492 self.readlines_test(f, zipfile.ZIP_STORED)
1496 self.iterlines_test(f, zipfile.ZIP_STORED)
1501 self.read_test(f, zipfile.ZIP_DEFLATED)
1507 self.readline_read_test(f, zipfile.ZIP_DEFLATED)
1512 self.readline_test(f, zipfile.ZIP_DEFLATED)
1517 self.readlines_test(f, zipfile.ZIP_DEFLATED)
1522 self.iterlines_test(f, zipfile.ZIP_DEFLATED)