Home | History | Annotate | Download | only in test

Lines Matching refs:TarFile

10 import tarfile
49 taropen = tarfile.TarFile.taropen
60 taropen = tarfile.TarFile.gzopen
67 taropen = tarfile.TarFile.bz2open
74 taropen = tarfile.TarFile.xzopen
82 self.tar = tarfile.open(self.tarname, mode=self.mode,
229 self.tar = tarfile.open(self.tarname, mode=self.mode)
276 # ?rw-r--r-- tarfile/tarfile 7011 2003-01-06 07:19:43 ustar/conttype
277 # ?rw-r--r-- tarfile/tarfile 7011 2003-01-06 07:19:43 ustar/regtype
279 self.assertRegex(out, (br'\?rw-r--r-- tarfile/tarfile\s+7011 '
321 # This test checks if tarfile.open() is able to open an empty tar
324 with tarfile.open(tmpname, self.mode.replace("r", "w")):
327 tar = tarfile.open(tmpname, self.mode)
329 except tarfile.ReadError:
330 self.fail("tarfile.open() failed on empty archive")
340 tarfile.open("xxx", self.mode)
344 # This test guarantees that tarfile.open() does not treat an empty
348 self.assertRaises(tarfile.ReadError, tarfile.open, tmpname, self.mode)
349 self.assertRaises(tarfile.ReadError, tarfile.open, tmpname)
352 # Test TarFile's ignore_zeros option.
360 tarinfo = tarfile.TarInfo("foo")
365 tar = tarfile.open(tmpname, mode="r", ignore_zeros=True)
375 with tarfile.open(tmpname, "w:") as tar:
376 t = tarfile.TarInfo("foo")
383 with tarfile.open(tmpname) as tar:
384 with self.assertRaisesRegex(tarfile.ReadError, "unexpected end of data"):
388 with tarfile.open(tmpname) as tar:
391 with self.assertRaisesRegex(tarfile.ReadError, "unexpected end of data"):
394 with self.assertRaisesRegex(tarfile.ReadError, "unexpected end of data"):
405 with tarfile.open(fileobj=fobj, mode=self.mode) as tar:
414 tar = tarfile.open(fileobj=fobj, mode=self.mode)
422 with tarfile.open(fileobj=fobj, mode=self.mode) as tar:
426 # Issue 21044: tarfile.open() should handle fileobj with an integer
431 with tarfile.open(fileobj=fobj, mode=self.mode) as tar:
439 with tarfile.open(fileobj=fobj, mode=self.mode) as tar:
456 tar = tarfile.open(self.tarname, mode=self.mode)
471 # Test if the tarfile starts with the second member.
484 self.assertRaises(tarfile.ReadError, tarfile.open, tarname, self.mode)
486 self.assertRaises(tarfile.ReadError, tarfile.open,
494 self.assertEqual(tarinfo.type, tarfile.DIRTYPE,
512 self.assertEqual(tarinfo.uname, "tarfile",
524 with tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") as tar:
543 tar = tarfile.open(tarname, encoding="iso8859-1")
575 with tarfile.open(tarname, encoding="iso8859-1") as tar:
586 # Issue #7341: Close the internal file object in the TarFile
594 tar = object.__new__(tarfile.TarFile)
597 except tarfile.ReadError:
605 # Issue #16601: Restarting iteration over tarfile continued
607 with tarfile.open(self.tarname) as tar:
641 except tarfile.StreamError:
643 "TarFile.extractfile() failed")
659 self.assertRaises(tarfile.StreamError, f.read)
662 tar1 = tarfile.open(tarname, encoding="iso8859-1")
674 with self.assertRaises(tarfile.StreamError):
701 tar = tarfile.open(name, mode)
702 except tarfile.ReadError as e:
710 tar = tarfile.open(name, mode, fileobj=f)
711 except tarfile.ReadError as e:
718 with self.assertRaises(tarfile.ReadError):
719 tarfile.open(tarname, mode="r:" + self.suffix)
720 with self.assertRaises(tarfile.ReadError):
721 tarfile.open(tarname, mode="r|" + self.suffix)
722 with self.assertRaises(tarfile.ReadError):
723 tarfile.open(self.tarname, mode="r:")
724 with self.assertRaises(tarfile.ReadError):
725 tarfile.open(self.tarname, mode="r|")
743 # Originally, tarfile's stream detection looked for the string
773 kwargs["uname"] = "tarfile"
774 kwargs["gname"] = "tarfile"
850 self.tar = tarfile.open(self.tarname, mode=self.mode,
866 self.assertNotEqual(tarinfo.type, tarfile.DIRTYPE,
884 with self.assertRaises(tarfile.ReadError):
885 tarfile.open(name="foo.tar", fileobj=fobj)
894 tarinfo = tarfile.TarInfo.frombuf(fobj.read(512),
902 longnametype = tarfile.GNUTYPE_LONGNAME
904 # Since 3.2 tarfile is supposed to accurately restore sparse members and
956 longnametype = tarfile.XHDTYPE
959 tar = tarfile.open(tarname, encoding="iso8859-1")
974 self.assertEqual(tarinfo.uname, "tarfile")
975 self.assertEqual(tarinfo.gname, "tarfile")
983 tar = tarfile.open(tarname, encoding="iso8859-1")
1003 tar = tarfile.open(fileobj=fobj, mode=self.mode)
1004 tar.addfile(tarfile.TarInfo("foo"))
1016 # tarfile insists on aligning archives to a 20 * 512 byte recordsize.
1019 with tarfile.open(tmpname, self.mode) as tar:
1020 t = tarfile.TarInfo("foo")
1021 t.size = tarfile.RECORDSIZE - tarfile.BLOCKSIZE
1025 self.assertEqual(len(fobj.read()), tarfile.RECORDSIZE * 2)
1038 tar = tarfile.open(tmpname, self.mode)
1040 t = tarfile.TarInfo(name)
1045 tar = tarfile.open(tmpname)
1054 tar = tarfile.open(tmpname, self.mode)
1063 "tarfile is empty")
1067 tar = tarfile.open(tmpname, self.mode)
1086 tar = tarfile.open(tmpname, self.mode)
1104 tar = tarfile.open(tmpname, self.mode)
1121 tar = tarfile.open(tmpname, self.mode)
1133 tar = tarfile.open(tmpname, self.mode)
1158 tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1")
1166 tar = tarfile.open(tmpname, "r")
1190 tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1")
1200 tar = tarfile.open(tmpname, "r")
1216 # Create a tarfile with an empty member named path
1224 tar = tarfile.open(tmpname, self.mode)
1230 tar = tarfile.open(tmpname, "r")
1246 # Test if extractall works properly when tarfile contains symlinks
1256 tar = tarfile.open(temparchive,'w')
1261 tar = tarfile.open(temparchive,'r')
1300 tar = tarfile.open(tmpname, self.mode)
1306 tar = tarfile.open(tmpname, "r")
1325 tar = tarfile.open(tmpname, self.mode, fileobj=f,
1326 format=tarfile.PAX_FORMAT,
1347 tar = tarfile.open(tmpname, self.mode)
1358 self.assertEqual(data.count(b"\0"), tarfile.RECORDSIZE,
1371 tar = tarfile.open(tmpname, self.mode)
1400 if len(name) > tarfile.LENGTH_NAME:
1404 if link is not None and len(link) > tarfile.LENGTH_LINK:
1411 tarinfo = tarfile.TarInfo(name)
1414 tarinfo.type = tarfile.LNKTYPE
1416 tar = tarfile.open(tmpname, "w")
1418 tar.format = tarfile.GNU_FORMAT
1427 tar = tarfile.open(tmpname)
1489 with tarfile.open(tmpname, self.mode) as tobj:
1498 with tarfile.open(tmpname, self.mode) as tobj:
1502 tobj = tarfile.open(tmpname, self.mode)
1565 self.tar = tarfile.open(tmpname, "w")
1577 self.assertEqual(tarinfo.type, tarfile.REGTYPE,
1582 self.assertEqual(tarinfo.type, tarfile.LNKTYPE,
1588 self.assertEqual(tarinfo.type, tarfile.REGTYPE,
1596 tarinfo = tarfile.TarInfo(name)
1599 tarinfo.type = tarfile.LNKTYPE
1601 tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT)
1607 tar = tarfile.open(tmpname)
1626 tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT,
1629 tar.addfile(tarfile.TarInfo("test"))
1634 tar = tarfile.open(tmpname, encoding="iso8859-1")
1642 if key in tarfile.PAX_NUMBER_FIELDS:
1644 tarfile.PAX_NUMBER_FIELDS[key](val)
1655 tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT,
1658 t = tarfile.TarInfo()
1666 tar = tarfile.open(tmpname, encoding="iso8859-1")
1688 tar = tarfile.open(tmpname, "w", format=self.format,
1692 tar.addfile(tarfile.TarInfo(name))
1696 tar = tarfile.open(tmpname, encoding=encoding)
1703 tar = tarfile.open(tmpname, "w", format=self.format,
1706 tarinfo = tarfile.TarInfo()
1718 tar = tarfile.open(tarname, "r",
1730 t = tarfile.TarInfo("foo")
1734 tar = tarfile.open(tmpname, mode="w", format=self.format,
1741 tar = tarfile.open(tmpname, encoding="iso8859-1")
1747 if self.format != tarfile.PAX_FORMAT:
1749 tar = tarfile.open(tmpname, encoding="ascii")
1759 format = tarfile.USTAR_FORMAT
1796 with tarfile.open(tmpname, "w", format=self.format, encoding="utf-8") as tar:
1797 t = tarfile.TarInfo(name)
1804 with tarfile.open(tmpname, "r", encoding="utf-8") as tar:
1821 with tarfile.open(tmpname, "w", format=self.format, encoding="utf-8") as tar:
1822 t = tarfile.TarInfo("foo")
1830 with tarfile.open(tmpname, "r", encoding="utf-8") as tar:
1838 format = tarfile.GNU_FORMAT
1846 with tarfile.open(tarname, encoding=encoding,
1856 format = tarfile.PAX_FORMAT
1866 with tarfile.open(tarname, encoding=encoding,
1883 with tarfile.open(tarname, encoding="iso8859-1") as src:
1887 with tarfile.open(self.tarname, mode) as tar:
1892 self.assertRaises(tarfile.ReadError, tarfile.open, tmpname, "a")
1898 with tarfile.open(self.tarname, "a", fileobj=fileobj) as tar:
1899 tar.addfile(tarfile.TarInfo("bar"))
1902 with tarfile.open(self.tarname, fileobj=fileobj) as tar:
1910 tarfile.open(self.tarname, "w:").close()
1934 # Append mode is supposed to fail if the tarfile to append to
1939 self.assertRaises(tarfile.ReadError, self._add_testfile)
1948 data = tarfile.TarInfo("foo").tobuf()
1952 data = tarfile.TarInfo("foo").tobuf()
1972 tarinfo = tarfile.TarInfo("0123456789" * 10)
1973 tarinfo.tobuf(tarfile.USTAR_FORMAT)
1976 tarinfo = tarfile.TarInfo("0123456789" * 10 + "0")
1977 self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)
1980 tarinfo = tarfile.TarInfo("123/" * 62 + "longname")
1981 tarinfo.tobuf(tarfile.USTAR_FORMAT)
1984 tarinfo = tarfile.TarInfo("1234567/" * 31 + "longname")
1985 self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)
1988 tarinfo = tarfile.TarInfo("123/" * 126 + "longname")
1989 self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)
1992 tarinfo = tarfile.TarInfo("longlink")
1994 self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)
1997 tarinfo = tarfile.TarInfo("name")
1999 self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)
2002 tarinfo = tarfile.TarInfo("123/" * 126 + "longname")
2003 tarinfo.tobuf(tarfile.GNU_FORMAT)
2005 tarinfo = tarfile.TarInfo("longlink")
2007 tarinfo.tobuf(tarfile.GNU_FORMAT)
2010 tarinfo = tarfile.TarInfo("name")
2012 self.assertRaises(ValueError, tarinfo.tobuf, tarfile.GNU_FORMAT)
2015 tarinfo = tarfile.TarInfo("123/" * 126 + "longname")
2016 tarinfo.tobuf(tarfile.PAX_FORMAT)
2018 tarinfo = tarfile.TarInfo("longlink")
2020 tarinfo.tobuf(tarfile.PAX_FORMAT)
2022 tarinfo = tarfile.TarInfo("name")
2024 tarinfo.tobuf(tarfile.PAX_FORMAT)
2030 self.assertEqual(tarfile.stn("foo", 8, "ascii", "strict"),
2032 self.assertEqual(tarfile.stn("foobar", 3, "ascii", "strict"),
2034 self.assertEqual(tarfile.nts(b"foo\0\0\0\0\0", "ascii", "strict"),
2036 self.assertEqual(tarfile.nts(b"foo\0bar\0", "ascii", "strict"),
2042 self.assertEqual(tarfile.nti(b"0000001\x00"), 1)
2043 self.assertEqual(tarfile.nti(b"7777777\x00"), 0o7777777)
2044 self.assertEqual(tarfile.nti(b"\x80\x00\x00\x00\x00\x20\x00\x00"),
2046 self.assertEqual(tarfile.nti(b"\x80\x00\x00\x00\xff\xff\xff\xff"),
2048 self.assertEqual(tarfile.nti(b"\xff\xff\xff\xff\xff\xff\xff\xff"),
2050 self.assertEqual(tarfile.nti(b"\xff\xff\xff\xff\xff\xff\xff\x9c"),
2052 self.assertEqual(tarfile.nti(b"\xff\x00\x00\x00\x00\x00\x00\x00"),
2056 self.assertEqual(tarfile.nti(b"\0"), 0)
2057 self.assertEqual(tarfile.nti(b" \0"), 0)
2060 self.assertEqual(tarfile.itn(1), b"0000001\x00")
2061 self.assertEqual(tarfile.itn(0o7777777), b"7777777\x00")
2062 self.assertEqual(tarfile.itn(0o10000000),
2064 self.assertEqual(tarfile.itn(0xffffffff),
2066 self.assertEqual(tarfile.itn(-1),
2068 self.assertEqual(tarfile.itn(-100),
2070 self.assertEqual(tarfile.itn(-0x100000000000000),
2075 tarfile.itn(-1, 8, tarfile.USTAR_FORMAT)
2077 tarfile.itn(0o10000000, 8, tarfile.USTAR_FORMAT)
2079 tarfile.itn(-0x10000000001, 6, tarfile.GNU_FORMAT)
2081 tarfile.itn(0x10000000000, 6, tarfile.GNU_FORMAT)
2099 support.check__all__(self, tarfile, blacklist=blacklist)
2105 rc, out, err = script_helper.assert_python_ok('-m', 'tarfile', *args,
2110 return script_helper.assert_python_failure('-m', 'tarfile', *args)
2117 with tarfile.open(tar_name, 'w') as tf:
2156 with tarfile.open(tar_name, 'r') as tf:
2167 with tarfile.open(tar_name, 'r') as tf:
2190 with tarfile.open(tmpname) as tar:
2203 with tarfile.open(tmpname) as tar:
2213 with tarfile.open(dotlessname) as tar:
2224 with tarfile.open(tar_name) as tar:
2285 with tarfile.open(tarname) as tar:
2291 # if the TarFile object is already closed.
2292 tar = tarfile.open(tarname)
2301 with tarfile.open(tarname) as tar:
2311 with tarfile.open(tmpname, "w") as tar:
2321 # TarFile.close() if there was no error.
2322 with tarfile.open(tmpname, "w"):
2332 with tarfile.open(fileobj=fobj, mode="w") as tar:
2344 # symbolic or hard links tarfile tries to extract these types of members
2384 "tarfile.open()")
2391 data = bz2.compress(tarfile.TarInfo("foo").tobuf())
2394 tarfile.open(fileobj=MyBytesIO(data[:x]), mode=mode)
2395 except tarfile.ReadError:
2433 items = [(filename_1, 99, 98, tarfile.REGTYPE, fobj),
2434 (dirname_1, 77, 76, tarfile.DIRTYPE, None),
2435 (filename_2, 88, 87, tarfile.REGTYPE, fobj),
2437 with tarfile.open(tmpname, 'w') as tarfl:
2439 t = tarfile.TarInfo(name)
2457 # the names we want stored in the tarfile
2462 # create the tarfile with the contents we're after
2467 # open the tarfile for reading. yield it and the names of the items
2469 with tarfile.open(tar_filename) as tarfl: