• Home
  • Raw
  • Download

Lines Matching full:zipfile

17 import zipfile
56 cls.line_gen = [bytes("Zipfile test line %d. random float: %f\n" %
69 with zipfile.ZipFile(f, "w", **kwargs) as zipfp:
81 with zipfile.ZipFile(f, "r", compression) as zipfp:
139 with zipfile.ZipFile(f, "r", compression) as zipfp:
166 with zipfile.ZipFile(path, "r", self.compression) as zipfp:
173 with zipfile.ZipFile(f, "r", compression) as zipfp:
192 with zipfile.ZipFile(f, "r") as zipfp, \
211 with zipfile.ZipFile(f, "r") as zipfp, \
231 with zipfile.ZipFile(f, "r") as zipfp, \
256 with zipfile.ZipFile(f, "r") as zipfp:
270 with zipfile.ZipFile(f, "r") as zipfp:
284 with zipfile.ZipFile(f, "r") as zipfp:
296 with zipfile.ZipFile(TESTFN2, "w", self.compression) as zipfp:
300 with zipfile.ZipFile(TESTFN2, "r", self.compression) as zipfp:
306 zipfp = zipfile.ZipFile(TESTFN2, "w")
312 zipfp = zipfile.ZipFile(TESTFN2, "w", compresslevel=1)
333 with zipfile.ZipFile(io.BytesIO(), "w", self.compression) as zipf:
341 with zipfile.ZipFile(fp, mode='w') as zipf:
347 with zipfile.ZipFile(fp) as zipf:
354 with zipfile.ZipFile(fp) as zipf:
362 with zipfile.ZipFile(fp) as zipf:
372 with zipfile.ZipFile(f, 'w', self.compression) as zipfp:
377 with zipfile.ZipFile(f, 'r') as zipfp:
388 if self.compression != zipfile.ZIP_STORED:
395 if self.compression != zipfile.ZIP_STORED:
407 with zipfile.ZipFile(TESTFN2, "w", compresslevel=1) as zipfp:
429 with zipfile.ZipFile(testfile, 'w', self.compression) as zipfp:
442 with zipfile.ZipFile(io.BytesIO(testfile.getvalue())) as zipfp:
446 with zipfile.ZipFile(io.BytesIO(testfile.getvalue())) as zipfp:
459 compression = zipfile.ZIP_STORED
468 with zipfile.ZipFile(f, "r") as zipfp:
477 self.zip_test_writestr_permissions(f, zipfile.ZIP_STORED)
480 with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
483 with zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_STORED) as zipfp:
487 """Test appending to an existing zipfile."""
488 with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
491 with zipfile.ZipFile(TESTFN2, "a", zipfile.ZIP_STORED) as zipfp:
496 """Test appending to an existing file that is not a zipfile."""
499 data = b'I am not a ZipFile!'*10
503 with zipfile.ZipFile(TESTFN2, "a", zipfile.ZIP_STORED) as zipfp:
508 with zipfile.ZipFile(f, "r") as zipfp:
514 with io.BytesIO(zipfiledata) as bio, zipfile.ZipFile(bio) as zipfp:
520 with zipfile.ZipFile(bio, 'w', zipfile.ZIP_STORED) as zipfp:
523 data = b'I am not a ZipFile!'*10
528 with zipfile.ZipFile(TESTFN2) as zipfp:
534 with zipfile.ZipFile(bio, 'w', zipfile.ZIP_STORED) as zipfp:
537 data = b'I am not a ZipFile!'*1000000
542 with zipfile.ZipFile(TESTFN2, 'a') as zipfp:
549 with io.BytesIO(zipfiledata) as bio, zipfile.ZipFile(bio) as zipfp:
555 with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
559 with zipfile.ZipFile(TESTFN2, "r") as zipfp:
560 self.assertIsInstance(zipfp, zipfile.ZipFile)
563 with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
568 with zipfile.ZipFile(TESTFN2, "r") as zipfp:
569 self.assertIsInstance(zipfp, zipfile.ZipFile)
573 """Check that calling ZipFile.write without arcname specified
575 with zipfile.ZipFile(TESTFN2, "w") as zipfp:
582 with zipfile.ZipFile(TESTFN2, mode="w") as zipfp:
585 with zipfile.ZipFile(TESTFN2, mode="r") as zipfp:
595 """Check that trying to call write() on a readonly ZipFile object
597 with zipfile.ZipFile(TESTFN2, mode="w") as zipfp:
600 with zipfile.ZipFile(TESTFN2, mode="r") as zipfp:
603 with zipfile.ZipFile(TESTFN2, mode="r") as zipfp:
610 with zipfile.ZipFile(TESTFN2, "w") as zipfp:
613 with zipfile.ZipFile(TESTFN2, "w", strict_timestamps=False) as zipfp:
642 with zipfile.ZipFile(TESTFN2, "w") as zipfp:
645 with zipfile.ZipFile(TESTFN2, "w", strict_timestamps=False) as zipfp:
654 compression = zipfile.ZIP_DEFLATED
659 with zipfile.ZipFile(TESTFN2, "w") as zipfp:
660 zipfp.write(TESTFN, 'storeme', zipfile.ZIP_STORED)
661 zipfp.write(TESTFN, 'deflateme', zipfile.ZIP_DEFLATED)
664 self.assertEqual(sinfo.compress_type, zipfile.ZIP_STORED)
665 self.assertEqual(dinfo.compress_type, zipfile.ZIP_DEFLATED)
670 compression = zipfile.ZIP_BZIP2
675 compression = zipfile.ZIP_LZMA
684 line_gen = (bytes("Test of zipfile line %d." % i, "ascii")
689 self._limit = zipfile.ZIP64_LIMIT
690 self._filecount_limit = zipfile.ZIP_FILECOUNT_LIMIT
691 zipfile.ZIP64_LIMIT = 1000
692 zipfile.ZIP_FILECOUNT_LIMIT = 9
700 with zipfile.ZipFile(f, "w", compression, allowZip64=True) as zipfp:
706 with zipfile.ZipFile(f, "r", compression) as zipfp:
761 # and that the resulting archive can be read properly by ZipFile
762 zipf = zipfile.ZipFile(TESTFN, "w", self.compression,
771 zipf2 = zipfile.ZipFile(TESTFN, "r", self.compression)
779 zipf = zipfile.ZipFile(TESTFN, "w", self.compression,
786 with self.assertRaises(zipfile.LargeZipFile):
791 zipf = zipfile.ZipFile(TESTFN, "a", self.compression,
795 with self.assertRaises(zipfile.LargeZipFile):
800 zipf = zipfile.ZipFile(TESTFN, "a", self.compression,
810 zipf2 = zipfile.ZipFile(TESTFN, "r", self.compression)
818 zipfile.ZIP64_LIMIT = self._limit
819 zipfile.ZIP_FILECOUNT_LIMIT = self._filecount_limit
826 compression = zipfile.ZIP_STORED
829 with zipfile.ZipFile(f, "w", compression, allowZip64=False) as zipfp:
830 self.assertRaises(zipfile.LargeZipFile,
834 with zipfile.ZipFile(f, "w", compression, allowZip64=False) as zipfp:
835 self.assertRaises(zipfile.LargeZipFile,
840 self.large_file_exception_test(f, zipfile.ZIP_STORED)
841 self.large_file_exception_test2(f, zipfile.ZIP_STORED)
844 with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED,
848 with zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_STORED) as zipfp:
854 with zipfile.ZipFile(TESTFN2, "w", allowZip64=True) as zipfp:
856 with zipfile.ZipFile(TESTFN2, "r", allowZip64=True) as zipfp:
859 with zipfile.ZipFile(TESTFN2, "a", allowZip64=True) as zipfp:
861 with zipfile.ZipFile(TESTFN2, "r", allowZip64=True) as zipfp:
985 with self.assertRaises(zipfile.BadZipFile) as e:
986 zipfile.ZipFile(io.BytesIO(missing_file_size_extra))
996 with self.assertRaises(zipfile.BadZipFile) as e:
997 zipfile.ZipFile(io.BytesIO(missing_compress_size_extra))
1005 with self.assertRaises(zipfile.BadZipFile) as e:
1006 zipfile.ZipFile(io.BytesIO(missing_compress_size_extra))
1019 with self.assertRaises(zipfile.BadZipFile) as e:
1020 zipfile.ZipFile(io.BytesIO(missing_header_offset_extra))
1031 with self.assertRaises(zipfile.BadZipFile) as e:
1032 zipfile.ZipFile(io.BytesIO(missing_header_offset_extra))
1043 with self.assertRaises(zipfile.BadZipFile) as e:
1044 zipfile.ZipFile(io.BytesIO(missing_header_offset_extra))
1054 with self.assertRaises(zipfile.BadZipFile) as e:
1055 zipfile.ZipFile(io.BytesIO(missing_header_offset_extra))
1078 with zipfile.ZipFile(io.BytesIO(self.make_zip64_file(**kwargs))) as zf:
1107 with zipfile.ZipFile(data, mode="w", allowZip64=True) as zf:
1120 self.assertGreaterEqual(vers, zipfile.ZIP64_VERSION) # requires zip64 to extract
1134 z = zipfile.ZipFile(io.BytesIO(zipdata))
1137 …self.assertGreaterEqual(zinfos[0].extract_version, zipfile.ZIP64_VERSION) # requires zip64 to ext…
1143 with zipfile.ZipFile(fp, mode="w", allowZip64=True) as zf:
1145 zi.write(b"_" * (zipfile.ZIP64_LIMIT + 1))
1153 with zipfile.ZipFile(fp, mode="w", allowZip64=False) as zf:
1154 # pretend zipfile.ZipInfo.from_file was used to get the name and filesize
1155 info = zipfile.ZipInfo("text.txt")
1156 info.file_size = zipfile.ZIP64_LIMIT + 1
1159 self.assertRaises(zipfile.LargeZipFile, make_zip, io.BytesIO())
1160 self.assertRaises(zipfile.LargeZipFile, make_zip, Unseekable(io.BytesIO()))
1178 file_size = zipfile.ZIP64_LIMIT + 1
1181 with zipfile.ZipFile(fp, mode="w", allowZip64=True) as zf:
1182 # pretend zipfile.ZipInfo.from_file was used to get the name and filesize
1183 info = zipfile.ZipInfo("text.txt")
1198 self.assertGreaterEqual(vers, zipfile.ZIP64_VERSION) # requires zip64 to extract
1221 self.assertGreaterEqual(vers, zipfile.ZIP64_VERSION) # requires zip64 to extract
1242 compression = zipfile.ZIP_DEFLATED
1247 compression = zipfile.ZIP_BZIP2
1252 compression = zipfile.ZIP_LZMA
1262 with zipfile.ZipFile(TESTFN2, "w", self.compression) as zipf:
1273 with zipfile.ZipFile(TESTFN2, "w", self.compression) as zipf:
1284 with zipfile.ZipFile(io.BytesIO(), 'w', self.compression) as zip:
1290 compression = zipfile.ZIP_STORED
1294 compression = zipfile.ZIP_DEFLATED
1298 compression = zipfile.ZIP_BZIP2
1302 compression = zipfile.ZIP_LZMA
1325 with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp:
1342 with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp:
1358 with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp:
1372 with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp:
1405 zipfile.PyZipFile(t, "w", optimize=optlevel) as zipfp:
1424 with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp:
1444 with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp:
1456 with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp:
1468 with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp:
1490 with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp:
1501 with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
1508 with zipfile.ZipFile(TESTFN2, "r") as zipfp:
1526 with zipfile.ZipFile(TESTFN2, "r") as zipfp:
1554 with zipfile.ZipFile(TESTFN2, "r") as zipfp:
1566 with zipfile.ZipFile(TESTFN2, "r") as zipfp:
1592 san = zipfile.ZipFile._sanitize_windows_name
1649 with zipfile.ZipFile(TESTFN2, 'w', zipfile.ZIP_STORED) as zipfp:
1650 zinfo = zipfile.ZipInfo()
1660 with zipfile.ZipFile(TESTFN2, 'r') as zipfp:
1668 with zipfile.ZipFile(TESTFN2, 'r') as zipfp:
1675 with zipfile.ZipFile(TESTFN2, 'r') as zipfp:
1682 with zipfile.ZipFile(TESTFN2, 'r') as zipfp:
1693 with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
1699 with zipfile.ZipFile(TESTFN2, "r") as zipfp:
1712 with zipfile.ZipFile(TESTFN2, 'w') as orig_zip:
1714 zinfo = zipfile.ZipInfo(data)
1715 … zinfo.flag_bits |= zipfile._MASK_USE_DATA_DESCRIPTOR # Include an extended local header.
1719 """Check that the zipfile is closed after the 'with' block."""
1720 with zipfile.ZipFile(TESTFN2, "w") as zipfp:
1726 with zipfile.ZipFile(TESTFN2, "r") as zipfp:
1731 """Check that the zipfile is closed if an exception is raised in the
1733 with zipfile.ZipFile(TESTFN2, "w") as zipfp:
1738 with zipfile.ZipFile(TESTFN2, "r") as zipfp2:
1739 raise zipfile.BadZipFile()
1740 except zipfile.BadZipFile:
1751 self.assertRaises(NotImplementedError, zipfile.ZipFile,
1758 with zipfile.ZipFile(fname) as zipfp:
1763 with zipfile.ZipFile(TESTFN, "w") as zf:
1768 with zipfile.ZipFile(TESTFN, "r") as zf:
1773 with zipfile.ZipFile(TESTFN2, 'w') as zipfp:
1778 """Test exclusive creating a new zipfile."""
1782 with zipfile.ZipFile(TESTFN2, "x", zipfile.ZIP_STORED) as zipfp:
1785 zipfile.ZipFile(TESTFN2, "x", zipfile.ZIP_STORED)
1786 with zipfile.ZipFile(TESTFN2, "r") as zipfp:
1798 with zipfile.ZipFile(TESTFN, 'a') as zf:
1805 with zipfile.ZipFile(TESTFN, 'r') as zf:
1809 # This test checks that the ZipFile constructor closes the file object
1811 # traceback holds a reference to the ZipFile object and, indirectly,
1819 zf = zipfile.ZipFile(TESTFN)
1820 except zipfile.BadZipFile:
1828 self.assertFalse(zipfile.is_zipfile(TESTFN))
1830 self.assertFalse(zipfile.is_zipfile(pathlib.Path(TESTFN)))
1833 self.assertFalse(zipfile.is_zipfile(fp))
1837 self.assertFalse(zipfile.is_zipfile(fp))
1839 self.assertFalse(zipfile.is_zipfile(fp))
1845 with zipfile.ZipFile(fp, mode="w") as zipf:
1853 self.assertRaises(zipfile.BadZipFile, zipfile.ZipFile, fp)
1858 with zipfile.ZipFile(TESTFN, mode="w") as zipf:
1861 self.assertTrue(zipfile.is_zipfile(TESTFN))
1864 self.assertTrue(zipfile.is_zipfile(fp))
1870 self.assertTrue(zipfile.is_zipfile(fp))
1872 self.assertTrue(zipfile.is_zipfile(fp))
1876 # ZipFile instance is finalized; this tests for regression on SF tracker
1880 # when a ZipFile instance was created for a file that did not
1886 self.assertRaises(OSError, zipfile.ZipFile, TESTFN)
1891 self.assertRaises(zipfile.BadZipFile, zipfile.ZipFile, TESTFN)
1895 self.assertRaises(zipfile.BadZipFile, zipfile.ZipFile, TESTFN)
1906 self.assertRaises(zipfile.BadZipFile, zipfile.ZipFile, f)
1911 with zipfile.ZipFile(data, mode="w") as zipf:
1914 # This is correct; calling .read on a closed ZipFile should raise
1923 f.write('zipfile test data')
1927 """Check that bad modes passed to ZipFile constructor are caught."""
1928 self.assertRaises(ValueError, zipfile.ZipFile, TESTFN, "q")
1931 """Check that bad modes passed to ZipFile.open are caught."""
1932 with zipfile.ZipFile(TESTFN, mode="w") as zipf:
1935 with zipfile.ZipFile(TESTFN, mode="r") as zipf:
1946 with zipfile.ZipFile(TESTFN, mode="w") as zipf:
1958 with zipfile.ZipFile(TESTFN, mode="w") as zipf:
1962 """Check that bad compression methods passed to ZipFile.open are
1964 self.assertRaises(NotImplementedError, zipfile.ZipFile, TESTFN, "w", -1)
1974 with zipfile.ZipFile(io.BytesIO(data), 'r') as zipf:
1980 with zipfile.ZipFile(TESTFN, mode="w") as zipf:
1986 self.assertEqual(zipfile.sizeEndCentDir, 22)
1987 self.assertEqual(zipfile.sizeCentralDir, 46)
1988 self.assertEqual(zipfile.sizeEndCentDir64, 56)
1989 self.assertEqual(zipfile.sizeEndCentDir64Locator, 20)
1995 with zipfile.ZipFile(TESTFN, mode="w") as zipf:
1999 with zipfile.ZipFile(TESTFN, mode="r") as zipfr:
2004 with zipfile.ZipFile(TESTFN, mode="w") as zipf:
2007 with zipfile.ZipFile(TESTFN, mode="r") as zipfr:
2013 with zipfile.ZipFile(TESTFN, mode="w") as zipf:
2017 with zipfile.ZipFile(TESTFN, mode="r") as zipfr:
2021 with zipfile.ZipFile(TESTFN, mode="w") as zipf:
2025 with zipfile.ZipFile(TESTFN, mode="r") as zipfr:
2029 with zipfile.ZipFile(TESTFN,mode="w") as zipf:
2032 with zipfile.ZipFile(TESTFN,mode="a") as zipf:
2034 with zipfile.ZipFile(TESTFN,mode="r") as zipf:
2039 with zipfile.ZipFile(TESTFN,mode="w") as zipf:
2043 with zipfile.ZipFile(TESTFN,mode="a") as zipf:
2046 with zipfile.ZipFile(TESTFN,mode="r") as zipf:
2050 with zipfile.ZipFile(TESTFN, "w", zipfile.ZIP_STORED) as zipf:
2056 with zipfile.ZipFile(TESTFN, "a", zipfile.ZIP_STORED) as zipf:
2059 with zipfile.ZipFile(TESTFN, "r") as zipf:
2063 with zipfile.ZipFile(TESTFN, "w", zipfile.ZIP_STORED) as zipf:
2065 with zipfile.ZipFile(TESTFN, "a", zipfile.ZIP_STORED) as zipf:
2068 with zipfile.ZipFile(TESTFN, "r") as zipf:
2074 zipf = zipfile.ZipFile(TESTFN, mode="w")
2077 zipf = zipfile.ZipFile(TESTFN, mode="r")
2078 except zipfile.BadZipFile:
2081 zipf = zipfile.ZipFile(TESTFN, mode="a")
2084 zipf = zipfile.ZipFile(TESTFN, mode="r")
2094 self.assertRaises(zipfile.BadZipFile, zipfile.ZipFile, TESTFN, 'r')
2098 zipfile.ZipInfo, 'seventies', (1979, 1, 1, 0, 0, 0))
2102 zi = zipfile.ZipInfo(filename="empty")
2107 zi = zipfile.ZipInfo()
2111 self.assertEqual(zi.compress_type, zipfile.ZIP_STORED)
2115 self.assertEqual(zi.create_version, zipfile.DEFAULT_VERSION)
2116 self.assertEqual(zi.extract_version, zipfile.DEFAULT_VERSION)
2138 with zipfile.ZipFile(io.BytesIO(zipdata), 'r') as zipf:
2147 with zipfile.ZipFile(TESTFN2, 'w', zipfile.ZIP_STORED) as zipf:
2165 with zipfile.ZipFile(TESTFN2, 'r') as zipf:
2176 with zipfile.ZipFile(TESTFN, "w") as zipf:
2178 with zipfile.ZipFile(TESTFN, "r") as zipf:
2193 with zipfile.ZipFile(data, mode="w") as zipf:
2195 with zipfile.ZipFile(data, mode="r") as zipf:
2213 with zipfile.ZipFile(zip_file, 'w', compression=zipfile.ZIP_BZIP2) as zf:
2215 with mock.patch('zipfile.bz2', None):
2216 with zipfile.ZipFile(zip_file) as zf:
2229 with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf:
2237 # Using ZipFile.read()
2238 with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf:
2239 self.assertRaises(zipfile.BadZipFile, zipf.read, 'afile')
2242 with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf:
2244 self.assertRaises(zipfile.BadZipFile, corrupt_file.read)
2247 with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf:
2250 with self.assertRaises(zipfile.BadZipFile):
2256 compression = zipfile.ZIP_STORED
2269 compression = zipfile.ZIP_DEFLATED
2282 compression = zipfile.ZIP_BZIP2
2298 compression = zipfile.ZIP_LZMA
2334 plain = b'zipfile.py encryption test'
2340 self.zip = zipfile.ZipFile(TESTFN, "r")
2343 self.zip2 = zipfile.ZipFile(TESTFN2, "r")
2445 with zipfile.ZipFile(f, "w", compression) as zipfp:
2453 with zipfile.ZipFile(f, "r", compression) as zipfp:
2467 with zipfile.ZipFile(f, "r", compression) as zipfp:
2500 with zipfile.ZipFile(f, "r", compression) as zipfp:
2520 compression = zipfile.ZIP_STORED
2525 compression = zipfile.ZIP_DEFLATED
2530 compression = zipfile.ZIP_BZIP2
2535 compression = zipfile.ZIP_LZMA
2572 with zipfile.ZipFile(wrapper(bf), 'w', zipfile.ZIP_STORED) as zipfp:
2576 with zipfile.ZipFile(f, mode='r') as zipf:
2588 with zipfile.ZipFile(wrapper(bf), 'w', zipfile.ZIP_STORED) as zipfp:
2597 with zipfile.ZipFile(f, mode='r') as zipf:
2609 with zipfile.ZipFile(wrapper(bf), 'w', zipfile.ZIP_STORED) as zipf:
2615 with zipfile.ZipFile(f) as zipf:
2629 with zipfile.ZipFile(f, "w", zipfile.ZIP_DEFLATED) as zipfp:
2634 # Verify that (when the ZipFile is in control of creating file objects)
2638 with zipfile.ZipFile(f, mode="r") as zipf:
2648 # Verify that (when the ZipFile is in control of creating file objects)
2652 with zipfile.ZipFile(f, mode="r") as zipf:
2662 # Verify that (when the ZipFile is in control of creating file objects)
2666 with zipfile.ZipFile(f, mode="r") as zipf:
2680 with zipfile.ZipFile(f, 'r') as zipf:
2692 with zipfile.ZipFile(f, 'w', zipfile.ZIP_DEFLATED) as zipf:
2698 with zipfile.ZipFile(f, 'r') as zipf:
2706 with zipfile.ZipFile(f, "w", zipfile.ZIP_DEFLATED) as zipf:
2711 with zipfile.ZipFile(f, 'r') as zipf:
2722 with zipfile.ZipFile(TESTFN2, mode="r") as zipf:
2730 with zipfile.ZipFile(TESTFN2, 'w', zipfile.ZIP_DEFLATED) as zipf:
2732 with zipfile.ZipFile(TESTFN2, 'a', zipfile.ZIP_DEFLATED) as zipf:
2739 with zipfile.ZipFile(TESTFN2) as zipf:
2751 with zipfile.ZipFile(findfile("zipdir.zip")) as zipf:
2766 with zipfile.ZipFile(TESTFN, "w") as zipf:
2775 with zipfile.ZipFile(TESTFN, "r") as zipf:
2790 with zipfile.ZipFile(TESTFN, "w") as zipf:
2795 with zipfile.ZipFile(TESTFN, "r") as zipf:
2806 with zipfile.ZipFile(TESTFN, "w") as zf:
2822 old_zinfo = zipfile.ZipInfo("directory4/")
2838 with zipfile.ZipFile(TESTFN, "w") as zf:
2839 zf.writestr(zipfile.ZipInfo('directory/'), '')
2866 zi = zipfile.ZipInfo.from_file(__file__)
2872 zi = zipfile.ZipInfo.from_file(pathlib.Path(__file__))
2878 zi = zipfile.ZipInfo.from_file(os.fsencode(__file__), 'test')
2885 zi = zipfile.ZipInfo.from_file(f.fileno(), 'test')
2892 zi = zipfile.ZipInfo.from_file(dirpath, 'stdlib_tests')
2895 self.assertEqual(zi.compress_type, zipfile.ZIP_STORED)
2902 rc, out, err = script_helper.assert_python_ok('-m', 'zipfile', *args,
2907 return script_helper.assert_python_failure('-m', 'zipfile', *args)
2931 with zipfile.ZipFile(zip_name, 'r') as tf:
2954 with zipfile.ZipFile(TESTFN2) as zf:
2967 with zipfile.ZipFile(zip_name) as zf:
2988 self.assertTrue(zipfile.is_zipfile(name),
2990 # Ensure we can operate on these via ZipFile.
2991 with zipfile.ZipFile(name) as zipfp:
3045 for name in zipfile.CompleteDirs._implied_dirs(zf.namelist()):
3076 zf = zipfile.ZipFile(data, "w")
3122 root = zipfile.Path(alpharep)
3138 root = zipfile.Path(alpharep)
3143 root = zipfile.Path(alpharep)
3150 root = zipfile.Path(alpharep)
3158 root = zipfile.Path(alpharep)
3169 zf = zipfile.ZipFile(in_memory_file, "w")
3172 root = zipfile.Path(zf)
3184 zf = zipfile.ZipFile(in_memory_file, "w")
3187 root = zipfile.Path(zf)
3210 import io, zipfile
3211 with zipfile.ZipFile(io.BytesIO(), "w") as zf:
3214 root = zipfile.Path(zf)
3228 If the zipfile is open for write, it should be possible to
3231 zf = zipfile.Path(zipfile.ZipFile(io.BytesIO(), mode='w'))
3241 zf = zipfile.Path(add_dirs(build_alpharep_fixture()))
3247 root = zipfile.Path(alpharep)
3257 zf = zipfile.Path(add_dirs(build_alpharep_fixture()))
3263 root = zipfile.Path(alpharep)
3271 root = zipfile.Path(alpharep)
3279 root = zipfile.Path(alpharep)
3285 root = zipfile.Path(alpharep)
3297 source="zipfile.Path(alpharep) / 'a'",
3307 zipfile.Path should be constructable from a path-like object
3311 zipfile.Path(pathlike)
3315 root = zipfile.Path(alpharep)
3320 root = zipfile.Path(alpharep)
3326 root = zipfile.Path(alpharep)
3332 root = zipfile.Path(alpharep)
3338 If the underlying zipfile is changed, the Path object should
3341 root = zipfile.Path(alpharep)
3353 """Create a read-only zipfile with a huge number of entries entries."""
3355 zf = zipfile.ZipFile(strm, "w")
3363 Ensure joinpath on items in zipfile is linear time.
3365 root = zipfile.Path(self.huge_zipfile())
3375 zipfile.CompleteDirs._implied_dirs(data)
3380 with zipfile.ZipFile(alpharep) as file:
3382 zipfile.Path(file, 'a.txt').read_text(encoding="utf-8")
3386 class Subclass(zipfile.Path):
3394 root = zipfile.Path(alpharep)
3400 The name of the root should be the name of the zipfile
3402 root = zipfile.Path(alpharep)
3408 The suffix of the root should be the suffix of the zipfile.
3412 root = zipfile.Path(alpharep)
3427 The suffix of the root should be the suffix of the zipfile.
3431 root = zipfile.Path(alpharep)
3451 root = zipfile.Path(alpharep)
3465 root = zipfile.Path(alpharep)
3474 or parent of an unnamed zipfile.
3477 root = zipfile.Path(alpharep)
3490 cls = type('PathChild', (zipfile.Path,), {})
3501 zf = zipfile.ZipFile(source_path)
3502 # wrap the zipfile for its side effect
3503 zipfile.Path(zf)
3525 with zipfile.ZipFile(TESTFN, mode="w") as tf:
3527 tf.writestr(temp, content, zipfile.ZIP_STORED)
3556 with zipfile.ZipFile(TESTFN, "r", metadata_encoding='shift_jis') as zipfp:
3563 with zipfile.ZipFile(TESTFN, "r") as zipfp:
3570 with zipfile.ZipFile(TESTFN, "r", metadata_encoding='koi8-u') as zipfp:
3577 zipfile.ZipFile(TESTFN, "r", metadata_encoding='ascii')
3579 zipfile.ZipFile(TESTFN, "r", metadata_encoding='utf-8')
3588 with zipfile.ZipFile(TESTFN, "a") as zipfp:
3592 with zipfile.ZipFile(TESTFN, "r") as zipfp:
3595 with zipfile.ZipFile(TESTFN, "r", metadata_encoding='shift_jis') as zipfp:
3602 with self.assertRaises(zipfile.BadZipFile):
3608 ZF = zipfile.ZipFile
3619 self.assertRaises(SystemExit, zipfile.main, args)
3624 zipfile.main(["--metadata-encoding=shift_jis", "-t", TESTFN])
3628 zipfile.main(["--metadata-encoding=shift_jis", "-l", TESTFN])
3646 zipfile.main(["--metadata-encoding=shift_jis", "-e", TESTFN, TESTFN2])
3665 self.assertEqual(b'', zipfile._strip_extra(a, (self.ZIP64_EXTRA,)))
3666 self.assertEqual(b, zipfile._strip_extra(b, (self.ZIP64_EXTRA,)))
3668 b+b"z", zipfile._strip_extra(b+b"z", (self.ZIP64_EXTRA,)))
3670 self.assertEqual(b+c, zipfile._strip_extra(a+b+c, (self.ZIP64_EXTRA,)))
3671 self.assertEqual(b+c, zipfile._strip_extra(b+a+c, (self.ZIP64_EXTRA,)))
3672 self.assertEqual(b+c, zipfile._strip_extra(b+c+a, (self.ZIP64_EXTRA,)))
3680 self.assertEqual(b"", zipfile._strip_extra(a, (self.ZIP64_EXTRA,)))
3681 self.assertEqual(b, zipfile._strip_extra(b, (self.ZIP64_EXTRA,)))
3683 b+b"z", zipfile._strip_extra(b+b"z", (self.ZIP64_EXTRA,)))
3685 self.assertEqual(b+c, zipfile._strip_extra(a+b+c, (self.ZIP64_EXTRA,)))
3686 self.assertEqual(b+c, zipfile._strip_extra(b+a+c, (self.ZIP64_EXTRA,)))
3687 self.assertEqual(b+c, zipfile._strip_extra(b+c+a, (self.ZIP64_EXTRA,)))
3694 self.assertEqual(b"", zipfile._strip_extra(a+a, (self.ZIP64_EXTRA,)))
3695 self.assertEqual(b"", zipfile._strip_extra(a+a+a, (self.ZIP64_EXTRA,)))
3697 b"z", zipfile._strip_extra(a+a+b"z", (self.ZIP64_EXTRA,)))
3699 b+b"z", zipfile._strip_extra(a+a+b+b"z", (self.ZIP64_EXTRA,)))
3701 self.assertEqual(b, zipfile._strip_extra(a+a+b, (self.ZIP64_EXTRA,)))
3702 self.assertEqual(b, zipfile._strip_extra(a+b+a, (self.ZIP64_EXTRA,)))
3703 self.assertEqual(b, zipfile._strip_extra(b+a+a, (self.ZIP64_EXTRA,)))
3706 self.assertEqual(b"", zipfile._strip_extra(b"", (self.ZIP64_EXTRA,)))
3707 self.assertEqual(b"z", zipfile._strip_extra(b"z", (self.ZIP64_EXTRA,)))
3709 b"zz", zipfile._strip_extra(b"zz", (self.ZIP64_EXTRA,)))
3711 b"zzz", zipfile._strip_extra(b"zzz", (self.ZIP64_EXTRA,)))