Lines Matching refs:zipfile
17 import zipfile
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."""
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:
528 with zipfile.ZipFile(TESTFN2) as zipfp:
534 with zipfile.ZipFile(bio, 'w', zipfile.ZIP_STORED) as zipfp:
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)
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:
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:
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 extract
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:
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))
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:
1923 f.write('zipfile test data')
1928 self.assertRaises(ValueError, zipfile.ZipFile, TESTFN, "q")
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:
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:
2234 with zipfile.ZipFile(io.BytesIO(data), 'r') as zipf:
2245 with self.assertRaisesRegex(zipfile.BadZipFile, 'File name.*differ'):
2265 with zipfile.ZipFile(io.BytesIO(data), 'r') as zipf:
2275 with self.assertRaisesRegex(zipfile.BadZipFile, 'Overlapped entries'):
2289 with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf:
2298 with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf:
2299 self.assertRaises(zipfile.BadZipFile, zipf.read, 'afile')
2302 with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf:
2304 self.assertRaises(zipfile.BadZipFile, corrupt_file.read)
2307 with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf:
2310 with self.assertRaises(zipfile.BadZipFile):
2316 compression = zipfile.ZIP_STORED
2329 compression = zipfile.ZIP_DEFLATED
2342 compression = zipfile.ZIP_BZIP2
2358 compression = zipfile.ZIP_LZMA
2394 plain = b'zipfile.py encryption test'
2400 self.zip = zipfile.ZipFile(TESTFN, "r")
2403 self.zip2 = zipfile.ZipFile(TESTFN2, "r")
2505 with zipfile.ZipFile(f, "w", compression) as zipfp:
2513 with zipfile.ZipFile(f, "r", compression) as zipfp:
2527 with zipfile.ZipFile(f, "r", compression) as zipfp:
2560 with zipfile.ZipFile(f, "r", compression) as zipfp:
2580 compression = zipfile.ZIP_STORED
2585 compression = zipfile.ZIP_DEFLATED
2590 compression = zipfile.ZIP_BZIP2
2595 compression = zipfile.ZIP_LZMA
2632 with zipfile.ZipFile(wrapper(bf), 'w', zipfile.ZIP_STORED) as zipfp:
2636 with zipfile.ZipFile(f, mode='r') as zipf:
2648 with zipfile.ZipFile(wrapper(bf), 'w', zipfile.ZIP_STORED) as zipfp:
2657 with zipfile.ZipFile(f, mode='r') as zipf:
2669 with zipfile.ZipFile(wrapper(bf), 'w', zipfile.ZIP_STORED) as zipf:
2675 with zipfile.ZipFile(f) as zipf:
2689 with zipfile.ZipFile(f, "w", zipfile.ZIP_DEFLATED) as zipfp:
2698 with zipfile.ZipFile(f, mode="r") as zipf:
2712 with zipfile.ZipFile(f, mode="r") as zipf:
2726 with zipfile.ZipFile(f, mode="r") as zipf:
2740 with zipfile.ZipFile(f, 'r') as zipf:
2752 with zipfile.ZipFile(f, 'w', zipfile.ZIP_DEFLATED) as zipf:
2758 with zipfile.ZipFile(f, 'r') as zipf:
2766 with zipfile.ZipFile(f, "w", zipfile.ZIP_DEFLATED) as zipf:
2771 with zipfile.ZipFile(f, 'r') as zipf:
2782 with zipfile.ZipFile(TESTFN2, mode="r") as zipf:
2790 with zipfile.ZipFile(TESTFN2, 'w', zipfile.ZIP_DEFLATED) as zipf:
2792 with zipfile.ZipFile(TESTFN2, 'a', zipfile.ZIP_DEFLATED) as zipf:
2799 with zipfile.ZipFile(TESTFN2) as zipf:
2811 with zipfile.ZipFile(findfile("zipdir.zip")) as zipf:
2826 with zipfile.ZipFile(TESTFN, "w") as zipf:
2835 with zipfile.ZipFile(TESTFN, "r") as zipf:
2850 with zipfile.ZipFile(TESTFN, "w") as zipf:
2855 with zipfile.ZipFile(TESTFN, "r") as zipf:
2866 with zipfile.ZipFile(TESTFN, "w") as zf:
2882 old_zinfo = zipfile.ZipInfo("directory4/")
2898 with zipfile.ZipFile(TESTFN, "w") as zf:
2899 zf.writestr(zipfile.ZipInfo('directory/'), '')
2926 zi = zipfile.ZipInfo.from_file(__file__)
2932 zi = zipfile.ZipInfo.from_file(pathlib.Path(__file__))
2938 zi = zipfile.ZipInfo.from_file(os.fsencode(__file__), 'test')
2945 zi = zipfile.ZipInfo.from_file(f.fileno(), 'test')
2952 zi = zipfile.ZipInfo.from_file(dirpath, 'stdlib_tests')
2955 self.assertEqual(zi.compress_type, zipfile.ZIP_STORED)
2962 rc, out, err = script_helper.assert_python_ok('-m', 'zipfile', *args,
2967 return script_helper.assert_python_failure('-m', 'zipfile', *args)
2991 with zipfile.ZipFile(zip_name, 'r') as tf:
3014 with zipfile.ZipFile(TESTFN2) as zf:
3027 with zipfile.ZipFile(zip_name) as zf:
3048 self.assertTrue(zipfile.is_zipfile(name),
3051 with zipfile.ZipFile(name) as zipfp:
3105 for name in zipfile.CompleteDirs._implied_dirs(zf.namelist()):
3136 zf = zipfile.ZipFile(data, "w")
3182 root = zipfile.Path(alpharep)
3198 root = zipfile.Path(alpharep)
3203 root = zipfile.Path(alpharep)
3210 root = zipfile.Path(alpharep)
3218 root = zipfile.Path(alpharep)
3229 zf = zipfile.ZipFile(in_memory_file, "w")
3232 root = zipfile.Path(zf)
3244 zf = zipfile.ZipFile(in_memory_file, "w")
3247 root = zipfile.Path(zf)
3270 import io, zipfile
3271 with zipfile.ZipFile(io.BytesIO(), "w") as zf:
3274 root = zipfile.Path(zf)
3288 If the zipfile is open for write, it should be possible to
3291 zf = zipfile.Path(zipfile.ZipFile(io.BytesIO(), mode='w'))
3301 zf = zipfile.Path(add_dirs(build_alpharep_fixture()))
3307 root = zipfile.Path(alpharep)
3317 zf = zipfile.Path(add_dirs(build_alpharep_fixture()))
3323 root = zipfile.Path(alpharep)
3331 root = zipfile.Path(alpharep)
3339 root = zipfile.Path(alpharep)
3345 root = zipfile.Path(alpharep)
3357 source="zipfile.Path(alpharep) / 'a'",
3367 zipfile.Path should be constructable from a path-like object
3371 zipfile.Path(pathlike)
3375 root = zipfile.Path(alpharep)
3380 root = zipfile.Path(alpharep)
3386 root = zipfile.Path(alpharep)
3392 root = zipfile.Path(alpharep)
3398 If the underlying zipfile is changed, the Path object should
3401 root = zipfile.Path(alpharep)
3413 """Create a read-only zipfile with a huge number of entries entries."""
3415 zf = zipfile.ZipFile(strm, "w")
3423 Ensure joinpath on items in zipfile is linear time.
3425 root = zipfile.Path(self.huge_zipfile())
3435 zipfile.CompleteDirs._implied_dirs(data)
3440 with zipfile.ZipFile(alpharep) as file:
3442 zipfile.Path(file, 'a.txt').read_text(encoding="utf-8")
3446 class Subclass(zipfile.Path):
3454 root = zipfile.Path(alpharep)
3460 The name of the root should be the name of the zipfile
3462 root = zipfile.Path(alpharep)
3468 The suffix of the root should be the suffix of the zipfile.
3472 root = zipfile.Path(alpharep)
3487 The suffix of the root should be the suffix of the zipfile.
3491 root = zipfile.Path(alpharep)
3511 root = zipfile.Path(alpharep)
3525 root = zipfile.Path(alpharep)
3534 or parent of an unnamed zipfile.
3537 root = zipfile.Path(alpharep)
3550 cls = type('PathChild', (zipfile.Path,), {})
3561 zf = zipfile.ZipFile(source_path)
3562 # wrap the zipfile for its side effect
3563 zipfile.Path(zf)
3571 zf = zipfile.ZipFile(data, "w")
3576 root = zipfile.Path(zf)
3602 with zipfile.ZipFile(TESTFN, mode="w") as tf:
3604 tf.writestr(temp, content, zipfile.ZIP_STORED)
3633 with zipfile.ZipFile(TESTFN, "r", metadata_encoding='shift_jis') as zipfp:
3640 with zipfile.ZipFile(TESTFN, "r") as zipfp:
3647 with zipfile.ZipFile(TESTFN, "r", metadata_encoding='koi8-u') as zipfp:
3654 zipfile.ZipFile(TESTFN, "r", metadata_encoding='ascii')
3656 zipfile.ZipFile(TESTFN, "r", metadata_encoding='utf-8')
3665 with zipfile.ZipFile(TESTFN, "a") as zipfp:
3669 with zipfile.ZipFile(TESTFN, "r") as zipfp:
3672 with zipfile.ZipFile(TESTFN, "r", metadata_encoding='shift_jis') as zipfp:
3679 with self.assertRaises(zipfile.BadZipFile):
3685 ZF = zipfile.ZipFile
3696 self.assertRaises(SystemExit, zipfile.main, args)
3701 zipfile.main(["--metadata-encoding=shift_jis", "-t", TESTFN])
3705 zipfile.main(["--metadata-encoding=shift_jis", "-l", TESTFN])
3723 zipfile.main(["--metadata-encoding=shift_jis", "-e", TESTFN, TESTFN2])
3742 self.assertEqual(b'', zipfile._strip_extra(a, (self.ZIP64_EXTRA,)))
3743 self.assertEqual(b, zipfile._strip_extra(b, (self.ZIP64_EXTRA,)))
3745 b+b"z", zipfile._strip_extra(b+b"z", (self.ZIP64_EXTRA,)))
3747 self.assertEqual(b+c, zipfile._strip_extra(a+b+c, (self.ZIP64_EXTRA,)))
3748 self.assertEqual(b+c, zipfile._strip_extra(b+a+c, (self.ZIP64_EXTRA,)))
3749 self.assertEqual(b+c, zipfile._strip_extra(b+c+a, (self.ZIP64_EXTRA,)))
3757 self.assertEqual(b"", zipfile._strip_extra(a, (self.ZIP64_EXTRA,)))
3758 self.assertEqual(b, zipfile._strip_extra(b, (self.ZIP64_EXTRA,)))
3760 b+b"z", zipfile._strip_extra(b+b"z", (self.ZIP64_EXTRA,)))
3762 self.assertEqual(b+c, zipfile._strip_extra(a+b+c, (self.ZIP64_EXTRA,)))
3763 self.assertEqual(b+c, zipfile._strip_extra(b+a+c, (self.ZIP64_EXTRA,)))
3764 self.assertEqual(b+c, zipfile._strip_extra(b+c+a, (self.ZIP64_EXTRA,)))
3771 self.assertEqual(b"", zipfile._strip_extra(a+a, (self.ZIP64_EXTRA,)))
3772 self.assertEqual(b"", zipfile._strip_extra(a+a+a, (self.ZIP64_EXTRA,)))
3774 b"z", zipfile._strip_extra(a+a+b"z", (self.ZIP64_EXTRA,)))
3776 b+b"z", zipfile._strip_extra(a+a+b+b"z", (self.ZIP64_EXTRA,)))
3778 self.assertEqual(b, zipfile._strip_extra(a+a+b, (self.ZIP64_EXTRA,)))
3779 self.assertEqual(b, zipfile._strip_extra(a+b+a, (self.ZIP64_EXTRA,)))
3780 self.assertEqual(b, zipfile._strip_extra(b+a+a, (self.ZIP64_EXTRA,)))
3783 self.assertEqual(b"", zipfile._strip_extra(b"", (self.ZIP64_EXTRA,)))
3784 self.assertEqual(b"z", zipfile._strip_extra(b"z", (self.ZIP64_EXTRA,)))
3786 b"zz", zipfile._strip_extra(b"zz", (self.ZIP64_EXTRA,)))
3788 b"zzz", zipfile._strip_extra(b"zzz", (self.ZIP64_EXTRA,)))