Lines Matching defs:tar
45 tarname = support.findfile("testtar.tar")
46 gzipname = os.path.join(TEMPDIR, "testtar.tar.gz")
47 bz2name = os.path.join(TEMPDIR, "testtar.tar.bz2")
48 xzname = os.path.join(TEMPDIR, "testtar.tar.xz")
49 tmpname = os.path.join(TEMPDIR, "tmp.tar")
97 self.tar = tarfile.open(self.tarname, mode=self.mode,
101 self.tar.close()
107 tarinfo = self.tar.getmember("ustar/regtype")
108 with self.tar.extractfile(tarinfo) as fobj:
116 self.tar.extract("ustar/regtype", TEMPDIR, filter='data')
117 tarinfo = self.tar.getmember("ustar/regtype")
121 with self.tar.extractfile(tarinfo) as fobj:
134 self.tar.extract("ustar/regtype", TEMPDIR, filter='data')
135 tarinfo = self.tar.getmember("ustar/regtype")
138 with self.tar.extractfile(tarinfo) as fobj2:
144 self.tar.extract("ustar/regtype", TEMPDIR,
149 tarinfo = self.tar.getmember("ustar/regtype")
150 with self.tar.extractfile(tarinfo) as fobj:
193 with self.tar.extractfile("ustar/regtype") as fobj:
208 with self.tar.extractfile(lnktype) as a, \
209 self.tar.extractfile(regtype) as b:
242 with tarfile.open(tmpname, 'w') as tar:
243 tar.format = tarfile.USTAR_FORMAT
246 tar.add(name, filter=filter)
249 with tarfile.open(tmpname) as tar:
251 tar.getmember(name),
252 tar.getmember(name + '/')
269 self.tar = tarfile.open(self.tarname, mode=self.mode)
274 self.tar.list(verbose=False)
287 s = b.decode(self.tar.encoding, 'surrogateescape')
311 self.tar.list(verbose=True)
334 def members(tar):
335 for tarinfo in tar.getmembers():
339 self.tar.list(verbose=False, members=members(self.tar))
405 # This test checks if tarfile.open() is able to open an empty tar
406 # archive successfully. Note that an empty tar archive is not the
411 tar = tarfile.open(tmpname, self.mode)
412 tar.getnames()
416 self.assertListEqual(tar.getmembers(), [])
418 tar.close()
429 # file as an empty tar archive.
449 tar = tarfile.open(tmpname, mode="r", ignore_zeros=True)
451 self.assertListEqual(tar.getnames(), ["foo"],
455 tar.close()
459 with tarfile.open(tmpname, "w:") as tar:
462 tar.addfile(t, io.BytesIO(b"a" * 1024))
467 with tarfile.open(tmpname) as tar:
469 for t in tar:
472 with tarfile.open(tmpname) as tar:
473 t = tar.next()
476 tar.extract(t, TEMPDIR, filter='data')
479 tar.extractfile(t).read()
485 with tarfile.open(support.findfile('recursion.tar')) as tar:
496 with tarfile.open(fileobj=fobj, mode=self.mode) as tar:
497 self.assertIsInstance(tar.name, str)
498 self.assertEqual(tar.name, os.path.abspath(fobj.name))
505 tar = tarfile.open(fileobj=fobj, mode=self.mode)
506 self.assertIsNone(tar.name)
513 with tarfile.open(fileobj=fobj, mode=self.mode) as tar:
514 self.assertIsNone(tar.name)
522 with tarfile.open(fileobj=fobj, mode=self.mode) as tar:
523 self.assertIsNone(tar.name)
530 with tarfile.open(fileobj=fobj, mode=self.mode) as tar:
531 self.assertIsInstance(tar.name, bytes)
532 self.assertEqual(tar.name, os.path.abspath(fobj.name))
536 with tarfile.open(tarname, mode=self.mode) as tar:
537 self.assertIsInstance(tar.name, str)
538 self.assertEqual(tar.name, os.path.abspath(os.fspath(tarname)))
539 with self.taropen(tarname) as tar:
540 self.assertIsInstance(tar.name, str)
541 self.assertEqual(tar.name, os.path.abspath(os.fspath(tarname)))
542 with tarfile.TarFile.open(tarname, mode=self.mode) as tar:
543 self.assertIsInstance(tar.name, str)
544 self.assertEqual(tar.name, os.path.abspath(os.fspath(tarname)))
546 with tarfile.TarFile(tarname, mode='r') as tar:
547 self.assertIsInstance(tar.name, str)
548 self.assertEqual(tar.name, os.path.abspath(os.fspath(tarname)))
554 tar = self.taropen(tmpname, 'q')
556 tar = self.taropen(tmpname, 'rw')
558 tar = self.taropen(tmpname, '')
563 tar = tarfile.open(self.tarname, mode=self.mode)
565 tar.next()
566 t = tar.next()
569 with tar.extractfile(t) as f:
572 tar.close()
579 with tar.open(self.tarname, mode="r:", fileobj=fobj) as tar:
580 t = tar.next()
584 tar.getmembers()
585 self.assertEqual(tar.extractfile(t).read(), data,
599 tarinfo = self.tar.getmember("misc/dirtype-old-v7")
608 self.tar.getmember("misc/regtype-xstar")
613 for tarinfo in self.tar:
622 self.assertEqual(self.tar.getmembers()[-1].name, "misc/eof",
630 with tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") as tar:
631 tar.extract("ustar/regtype", TEMPDIR, filter='data')
634 tar.extract("ustar/lnktype", TEMPDIR, filter='data')
640 tar.extract("ustar/symtype", TEMPDIR, filter='data')
650 tar = tarfile.open(tarname, encoding="iso8859-1")
654 directories = [t for t in tar if t.isdir()]
655 tar.extractall(DIR, directories, filter='fully_trusted')
669 errmsg = "tar mtime {0} != file time {1} of path {2!a}".format(
675 tar.close()
684 with tarfile.open(tarname, encoding="iso8859-1") as tar:
685 tarinfo = tar.getmember(dirtype)
686 tar.extract(tarinfo, path=DIR, filter='fully_trusted')
697 tarfile.open(tarname, encoding="iso8859-1") as tar:
698 directories = [t for t in tar if t.isdir()]
699 tar.extractall(DIR, directories, filter='fully_trusted')
708 tarfile.open(tarname, encoding="iso8859-1") as tar:
709 tarinfo = tar.getmember(dirtype)
710 tar.extract(tarinfo, path=DIR, filter='fully_trusted')
723 tar = object.__new__(tarfile.TarFile)
725 tar.__init__(empty)
727 self.assertTrue(tar.fileobj.closed)
736 with tarfile.open(self.tarname) as tar:
737 for m1, m2 in zip(tar, tar):
784 # caused seeking errors with stream tar files.
785 for tarinfo in self.tar:
788 with self.tar.extractfile(tarinfo) as fobj:
799 tarinfo = self.tar.next() # get "regtype" (can't use getmember)
800 with self.tar.extractfile(tarinfo) as fobj:
808 tarinfos = self.tar.getmembers()
809 with self.tar.extractfile(tarinfos[0]) as f: # read the first member
815 tar2 = self.tar
852 tar = tarfile.open(name, mode)
856 tar.close()
861 tar = tarfile.open(name, mode, fileobj=f)
865 tar.close()
915 with self.tar.extractfile(tarinfo) as f:
923 # V7 tar can't handle alphabetic owners.
931 tarinfo = self.tar.getmember("ustar/regtype")
935 tarinfo = self.tar.getmember("ustar/conttype")
939 tarinfo = self.tar.getmember("ustar/dirtype")
943 tarinfo = self.tar.getmember("ustar/dirtype-with-size")
947 tarinfo = self.tar.getmember("ustar/lnktype")
951 tarinfo = self.tar.getmember("ustar/symtype")
955 tarinfo = self.tar.getmember("ustar/blktype")
959 tarinfo = self.tar.getmember("ustar/chrtype")
963 tarinfo = self.tar.getmember("ustar/fifotype")
967 tarinfo = self.tar.getmember("ustar/sparse")
971 tarinfo = self.tar.getmember("gnu/sparse")
975 tarinfo = self.tar.getmember("gnu/sparse-0.0")
979 tarinfo = self.tar.getmember("gnu/sparse-0.1")
983 tarinfo = self.tar.getmember("gnu/sparse-1.0")
987 tarinfo = self.tar.getmember("ustar/umlauts-"
993 self.assertIn(name, self.tar.getnames())
996 tarinfo = self.tar.getmember("misc/regtype-old-v7")
1000 self.tar.close()
1001 self.tar = tarfile.open(self.tarname, mode=self.mode,
1003 tarinfo = self.tar.getmember("pax/umlauts-"
1014 tarinfo = self.tar.getmember(longname)
1024 tarinfo = self.tar.getmember(longlink)
1031 tarinfo = self.tar.getmember(longname)
1033 self.tar.fileobj.seek(offset)
1034 fobj = io.BytesIO(self.tar.fileobj.read(3 * 512))
1036 tarfile.open(name="foo.tar", fileobj=fobj)
1042 offset = self.tar.getmember(longname).offset
1053 with tarfile.open(tmpname, 'w') as tar:
1054 tar.format = self.format
1057 tar.add(longdir)
1060 with tarfile.open(tmpname) as tar:
1061 self.assertIsNotNone(tar.getmember(longdir))
1062 self.assertIsNotNone(tar.getmember(longdir.removesuffix('/')))
1078 self.tar.extract(name, TEMPDIR, filter='data')
1131 tar = tarfile.open(tarname, encoding="iso8859-1")
1133 tarinfo = tar.getmember("pax/regtype1")
1139 tarinfo = tar.getmember("pax/regtype2")
1145 tarinfo = tar.getmember("pax/regtype3")
1151 tar.close()
1155 tar = tarfile.open(tarname, encoding="iso8859-1")
1157 tarinfo = tar.getmember("pax/regtype4")
1166 tar.close()
1187 tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT,
1194 tar.addfile(t)
1196 tar.close()
1207 with self.assertRaisesRegex(tarfile.ReadError, r"method tar: ReadError\('invalid header'\)"):
1217 with tarfile.open(fileobj=fobj, mode=self.mode) as tar:
1218 tar.addfile(tarfile.TarInfo("foo"))
1222 del tar
1232 with tarfile.open(tmpname, self.mode) as tar:
1235 tar.addfile(t, io.BytesIO(b"a" * t.size))
1246 # The name field in a tar header stores strings of at most 100 chars.
1251 tar = tarfile.open(tmpname, self.mode)
1254 tar.addfile(t)
1256 tar.close()
1258 tar = tarfile.open(tmpname)
1260 self.assertEqual(tar.getnames()[0], name,
1263 tar.close()
1267 tar = tarfile.open(tmpname, self.mode)
1272 tar.add(path)
1274 tar.close()
1280 tar = tarfile.open(tmpname, self.mode)
1285 tarinfo = tar.gettarinfo(path)
1290 tarinfo = tar.gettarinfo(path)
1293 tar.close()
1299 tar = tarfile.open(tmpname, self.mode)
1301 tarinfo = tar.gettarinfo(path)
1304 tar.close()
1316 tar = tarfile.open(tmpname, self.mode)
1320 tar.add(path)
1322 for m in tar.getmembers():
1326 tar.close()
1333 with tarfile.open(tmpname, self.mode) as tar:
1337 tarinfo = tar.gettarinfo(path)
1338 tarinfo2 = tar.gettarinfo(os.fspath(path))
1355 tar = tarfile.open(tmpname, self.mode)
1358 tar.gettarinfo(target)
1359 tarinfo = tar.gettarinfo(link)
1362 tar.close()
1372 tar = tarfile.open(tmpname, self.mode)
1374 tarinfo = tar.gettarinfo(path)
1377 tar.close()
1384 tar = tarfile.open(tmpname, self.mode)
1386 self.assertEqual(tar.name, dstname,
1388 tar.add(dstname)
1389 self.assertEqual(tar.getnames(), [],
1393 tar.add(dstname)
1394 self.assertEqual(tar.getnames(), [],
1397 tar.close()
1414 tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1")
1416 tar.add(tempdir, arcname="empty_dir", filter=filter)
1418 tar.close()
1422 tar.add(tempdir, "empty_dir", True, None, filter)
1424 tar = tarfile.open(tmpname, "r")
1426 for tarinfo in tar:
1429 self.assertEqual(len(tar.getmembers()), 3)
1431 tar.close()
1448 tar = tarfile.open(tmpname, self.mode)
1450 tar.add(foo, arcname=path)
1452 tar.close()
1454 tar = tarfile.open(tmpname, "r")
1456 t = tar.next()
1458 tar.close()
1472 temparchive = os.path.join(TEMPDIR, "testsymlinks.tar")
1480 with tarfile.open(temparchive, 'w') as tar:
1481 tar.add(source_file, arcname="source")
1482 tar.add(target_file, arcname="symlink")
1484 with tarfile.open(temparchive, errorlevel=2) as tar:
1487 tar.extractall(path=tempdir,
1522 tar = tarfile.open(tmpname, self.mode)
1524 tar.add(".")
1526 tar.close()
1528 tar = tarfile.open(tmpname, "r")
1530 for t in tar:
1534 tar.close()
1547 tar = tarfile.open(tmpname, self.mode, fileobj=f,
1572 tar = tarfile.open(tmpname, self.mode)
1573 tar.close()
1600 tar = tarfile.open(tmpname, self.mode)
1601 tar.close()
1611 Ensure the source directory is not included in the tar header
1635 # Initial tar header
1654 tar = tarfile.open(tmpname, "w")
1656 tar.format = tarfile.GNU_FORMAT
1657 tar.addfile(tarinfo)
1660 v2 = tar.offset
1663 tar.close()
1665 tar = tarfile.open(tmpname)
1667 member = tar.next()
1675 tar.close()
1717 tar = tarfile.open(tmpname, self.mode)
1723 tar.addfile(input_blk)
1724 tar.addfile(input_reg)
1726 tar.close()
1729 tar = tarfile.open(tmpname, "r")
1731 output_blk = tar.getmember("my_block_device")
1732 output_reg = tar.getmember("my_regular_file")
1734 tar.close()
1746 # <https://www.gnu.org/software/tar/manual/html_node/Standard.html>
1895 self.tar = tarfile.open(tmpname, "w")
1896 self.tar.add(self.foo)
1899 self.tar.close()
1906 tarinfo = self.tar.gettarinfo(self.foo)
1911 tarinfo = self.tar.gettarinfo(self.bar)
1916 self.tar.dereference = True
1917 tarinfo = self.tar.gettarinfo(self.bar)
1931 tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT)
1933 tar.addfile(tarinfo)
1935 tar.close()
1937 tar = tarfile.open(tmpname)
1940 l = tar.getmembers()[0].linkname
1943 n = tar.getmembers()[0].name
1946 tar.close()
1956 tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT,
1959 tar.addfile(tarfile.TarInfo("test"))
1961 tar.close()
1964 tar = tarfile.open(tmpname, encoding="iso8859-1")
1966 self.assertEqual(tar.pax_headers, pax_headers)
1967 self.assertEqual(tar.getmembers()[0].pax_headers, pax_headers)
1969 for key, val in tar.pax_headers.items():
1978 tar.close()
1985 tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT,
1992 tar.addfile(t)
1994 tar.close()
1996 tar = tarfile.open(tmpname, encoding="iso8859-1")
1998 t = tar.getmembers()[0]
2003 tar.close()
2073 tar = tarfile.open(tmpname, "w", format=self.format,
2077 tar.addfile(tarfile.TarInfo(name))
2079 tar.close()
2081 tar = tarfile.open(tmpname, encoding=encoding)
2083 self.assertEqual(tar.getmembers()[0].name, name)
2085 tar.close()
2088 tar = tarfile.open(tmpname, "w", format=self.format,
2094 self.assertRaises(UnicodeError, tar.addfile, tarinfo)
2098 self.assertRaises(UnicodeError, tar.addfile, tarinfo)
2100 tar.close()
2103 tar = tarfile.open(tarname, "r",
2106 for t in tar:
2112 tar.close()
2119 tar = tarfile.open(tmpname, mode="w", format=self.format,
2122 tar.addfile(t)
2124 tar.close()
2126 tar = tarfile.open(tmpname, encoding="iso8859-1")
2128 t = tar.getmember("foo")
2133 tar.close()
2134 tar = tarfile.open(tmpname, encoding="ascii")
2135 t = tar.getmember("foo")
2139 tar.close()
2181 with tarfile.open(tmpname, "w", format=self.format, encoding="utf-8") as tar:
2184 tar.addfile(t)
2186 self.assertRaises(exc, tar.addfile, t)
2189 with tarfile.open(tmpname, "r", encoding="utf-8") as tar:
2190 for t in tar:
2206 with tarfile.open(tmpname, "w", format=self.format, encoding="utf-8") as tar:
2210 tar.addfile(t)
2212 self.assertRaises(exc, tar.addfile, t)
2215 with tarfile.open(tmpname, "r", encoding="utf-8") as tar:
2216 for t in tar:
2226 # Test for issue #8633. GNU tar <= 1.23 creates raw binary fields
2232 errors="surrogateescape") as tar:
2234 t = tar.getmember(name)
2236 self.fail("unable to read bad GNU tar pax header")
2252 errors="surrogateescape") as tar:
2254 t = tar.getmember(name)
2272 with tarfile.open(self.tarname, mode) as tar:
2273 tar.addfile(t, f)
2283 with tarfile.open(self.tarname, "a", fileobj=fileobj) as tar:
2284 tar.addfile(tarfile.TarInfo("bar"))
2287 with tarfile.open(self.tarname, fileobj=fileobj) as tar:
2288 self.assertEqual(tar.getnames(), names)
2425 # Issue 13158: Test if GNU tar specific base-256 number fields
2498 fname = os.path.join(os.path.dirname(__file__), 'testtar.tar.xz')
2559 self.assertIn(b'is a tar archive.\n', out)
2564 self.assertIn(b' is not a tar archive.', err)
2606 self.assertIn(b' is not a tar archive.', err)
2618 with tarfile.open(tmpname) as tar:
2619 tar.getmembers()
2632 with tarfile.open(tmpname) as tar:
2633 tar.getmembers()
2642 with tarfile.open(dotlessname) as tar:
2643 tar.getmembers()
2653 with tarfile.open(tar_name) as tar:
2654 tar.getmembers()
2668 with filetype.taropen(tar_name) as tar:
2669 tar.getmembers()
2726 self.assertIn(b' is not a tar archive.', err)
2734 with tarfile.open(tarname) as tar:
2735 self.assertFalse(tar.closed, "closed inside runtime context")
2736 self.assertTrue(tar.closed, "context manager failed")
2741 tar = tarfile.open(tarname)
2742 tar.close()
2744 with tar:
2750 with tarfile.open(tarname) as tar:
2754 self.assertTrue(tar.closed, "context manager failed")
2760 with tarfile.open(tmpname, "w") as tar:
2766 self.assertTrue(tar.closed, "context manager failed")
2781 with tarfile.open(fileobj=fobj, mode="w") as tar:
2786 self.assertTrue(tar.closed, "context manager failed")
2796 self.tar.extract(name, TEMPDIR, filter='fully_trusted')
2880 # create a tar file with a file, a directory, and a file within that
2896 # return the full pathname to the tar file
2992 member = self.tar.getmember('ustar/regtype')
2996 self.assertEqual(self.tar.getmember('ustar/regtype').name,
3000 member = self.tar.getmember('pax/regtype1')
3005 self.tar.getmember('pax/regtype1').pax_headers['gname'], 'bar')
3008 member = self.tar.getmember('pax/regtype1')
3013 self.tar.getmember('pax/regtype1').pax_headers['gname'], 'not-bar')
3016 member = self.tar.getmember('ustar/regtype')
3025 member = self.tar.getmember('ustar/regtype')
3041 tar = tarfile.open(tarname, mode='r', encoding="iso8859-1")
3043 tar.errorlevel = 0
3044 tar.extractall(cls.control_dir, filter=cls.extraction_filter)
3045 tar.close()
3063 self.tar.errorlevel = 0
3064 for member in self.tar.getmembers():
3068 self.tar.extractall(DIR, filter='fully_trusted')
3132 extraction_filter = 'tar'
3145 tar = tarfile.open(fileobj=bio, mode='w', format=tarformat)
3146 tarinfo = tar.gettarinfo(tarname)
3148 tar.addfile(tarinfo)
3163 tar.addfile(replaced)
3174 tarfile.open(tarname, encoding="iso8859-1") as tar):
3177 tar.list()
3178 for member in tar.getmembers():
3183 tar.list()
3261 """Helper to create a tar file with specific contents
3268 with t.open() as tar:
3269 ... # `tar` is now a TarFile with 'filename' in it!
3335 def check_context(self, tar, filter):
3336 """Extracts `tar` to `self.destdir` and allows checking the result
3347 tar.extractall(self.destdir, filter=filter)
3358 tar.close()
3404 for filter in 'fully_trusted', 'tar', 'data':
3417 for filter in 'tar', 'data':
3420 # We strip leading slashes, as e.g. GNU tar does
3456 with self.check_context(arc.open(), 'tar'):
3472 with self.check_context(arc.open(), 'tar'):
3495 with self.check_context(arc.open(), 'tar'):
3527 with self.check_context(arc.open(), 'tar'):
3556 # Note that e.g. GNU `tar` rejects '..' components,
3568 for filter in 'tar', 'data':
3588 for filter in 'tar', 'data':
3635 with self.check_context(arc.open(), 'tar'):
3658 for filter in 'fully_trusted', 'tar':
3679 tar = tarfile.tar_filter(tarinfo, '')
3680 self.assertEqual(tar.type, special_type)
3688 with tarfile.TarFile.open(tarname) as tar:
3689 for tarinfo in tar.getmembers():
3694 # The 'tar' filter returns TarInfo objects with the same name/type.
3697 with tarfile.TarFile.open(tarname) as tar:
3698 for tarinfo in tar.getmembers():
3706 with tarfile.TarFile.open(tarname) as tar:
3707 for tarinfo in tar.getmembers():
3724 tar = tarfile.TarFile(tarname, 'r')
3730 tar.extraction_filter = strict_filter
3731 with self.check_context(tar, None):
3740 tar = tarfile.TarFile(tarname, 'r')
3743 with self.check_context(tar, None):
3754 tar = TarSubclass(tarname, 'r')
3755 with self.check_context(tar, None):
3759 tar = tarfile.TarFile(tarname, 'r')
3760 tar.extraction_filter = 'data'
3761 with self.check_context(tar, None):
3903 with c.open(c.tarname, "wb") as tar:
3904 tar.write(data)