Lines Matching refs:tarfile
11 import tarfile
46 self.tar = tarfile.open(self.tarname, mode=self.mode, encoding="iso8859-1")
166 self.tar = tarfile.open(self.tarname, mode=self.mode)
207 # ?rw-r--r-- tarfile/tarfile 7011 2003-01-06 07:19:43 ustar/conttype
208 # ?rw-r--r-- tarfile/tarfile 7011 2003-01-06 07:19:43 ustar/regtype
210 self.assertRegexpMatches(out, (r'-rw-r--r-- tarfile/tarfile\s+7011 '
227 taropen = tarfile.TarFile.gzopen
233 taropen = tarfile.TarFile.bz2open
240 # This test checks if tarfile.open() is able to open an empty tar
243 with tarfile.open(tmpname, self.mode.replace("r", "w")):
246 tar = tarfile.open(tmpname, self.mode)
248 except tarfile.ReadError:
249 self.fail("tarfile.open() failed on empty archive")
257 # This test guarantees that tarfile.open() does not treat an empty
261 self.assertRaises(tarfile.ReadError, tarfile.open, tmpname, self.mode)
262 self.assertRaises(tarfile.ReadError, tarfile.open, tmpname)
269 tarfile.open("xxx", self.mode)
273 # Test TarFile's ignore_zeros option.
288 tarinfo = tarfile.TarInfo("foo")
293 tar = tarfile.open(tmpname, mode="r", ignore_zeros=True)
302 with tarfile.open(tmpname, "w:") as tar:
303 t = tarfile.TarInfo("foo")
310 with tarfile.open(tmpname) as tar:
311 with self.assertRaisesRegexp(tarfile.ReadError, "unexpected end of data"):
315 with tarfile.open(tmpname) as tar:
318 with self.assertRaisesRegexp(tarfile.ReadError, "unexpected end of data"):
321 with self.assertRaisesRegexp(tarfile.ReadError, "unexpected end of data"):
326 taropen = tarfile.TarFile.taropen
330 tar = tarfile.open(fileobj=fobj, mode=self.mode)
338 tar = tarfile.open(fileobj=fobj, mode=self.mode)
346 tar = tarfile.open(fileobj=fobj, mode=self.mode)
363 tar = tarfile.open(self.tarname, mode=self.mode)
384 # Test if the tarfile starts with the second member.
401 self.assertRaises(tarfile.ReadError, tarfile.open, tarname, self.mode)
403 self.assertRaises(tarfile.ReadError, tarfile.open,
411 self.assertTrue(tarinfo.type == tarfile.DIRTYPE,
429 self.assertTrue(tarinfo.uname == "tarfile",
438 with tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") as tar:
457 tar = tarfile.open(tarname, encoding="iso8859-1")
471 # Issue #7341: Close the internal file object in the TarFile
479 tar = object.__new__(tarfile.TarFile)
482 except tarfile.ReadError:
490 # Issue #16601: Restarting iteration over tarfile continued
492 with tarfile.open(self.tarname) as tar:
512 self.assertRaises(tarfile.StreamError, f.read)
515 tar1 = tarfile.open(tarname, encoding="iso8859-1")
527 self.assertRaises(tarfile.StreamError, tar2.extractfile, t2)
544 tar = tarfile.open(name, mode)
545 except tarfile.ReadError:
552 tar = tarfile.open(name, mode, fileobj=open(name, "rb"))
553 except tarfile.ReadError:
566 self.assertRaises(tarfile.ReadError, tarfile.open, tarname, mode="r:gz")
567 self.assertRaises(tarfile.ReadError, tarfile.open, tarname, mode="r|gz")
568 self.assertRaises(tarfile.ReadError, tarfile.open, gzipname, mode="r:")
569 self.assertRaises(tarfile.ReadError, tarfile.open, gzipname, mode="r|")
578 self.assertRaises(tarfile.ReadError, tarfile.open, tarname, mode="r:bz2")
579 self.assertRaises(tarfile.ReadError, tarfile.open, tarname, mode="r|bz2")
580 self.assertRaises(tarfile.ReadError, tarfile.open, bz2name, mode="r:")
581 self.assertRaises(tarfile.ReadError, tarfile.open, bz2name, mode="r|")
597 # Originally, tarfile's stream detection looked for the string
623 kwargs["uname"] = "tarfile"
624 kwargs["gname"] = "tarfile"
682 self.tar = tarfile.open(self.tarname, mode=self.mode, encoding="iso8859-1")
696 self.assertTrue(tarinfo.type != tarfile.DIRTYPE, "read longname as dirtype")
713 self.assertRaises(tarfile.ReadError, tarfile.open, name="foo.tar", fileobj=fobj)
722 tarinfo = tarfile.TarInfo.frombuf(fobj.read(512))
729 longnametype = tarfile.GNUTYPE_LONGNAME
743 longnametype = tarfile.XHDTYPE
746 tar = tarfile.open(tarname, encoding="iso8859-1")
760 self.assertEqual(tarinfo.uname, "tarfile")
761 self.assertEqual(tarinfo.gname, "tarfile")
768 tar = tarfile.open(tarname, encoding="iso8859-1")
788 tar = tarfile.open(fileobj=fobj, mode=self.mode)
789 tar.addfile(tarfile.TarInfo("foo"))
810 tar = tarfile.open(tmpname, self.mode)
812 t = tarfile.TarInfo(name)
817 tar = tarfile.open(tmpname)
826 tar = tarfile.open(tmpname, self.mode)
835 "tarfile is empty")
839 tar = tarfile.open(tmpname, self.mode)
859 tar = tarfile.open(tmpname, self.mode)
876 tar = tarfile.open(tmpname, self.mode)
893 tar = tarfile.open(tmpname, self.mode)
905 tar = tarfile.open(tmpname, self.mode)
929 tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1")
937 tar = tarfile.open(tmpname, "r")
961 tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1")
967 tar = tarfile.open(tmpname, "r")
983 # Create a tarfile with an empty member named path
991 tar = tarfile.open(tmpname, self.mode)
997 tar = tarfile.open(tmpname, "r")
1037 tar = tarfile.open(tmpname, self.mode)
1043 tar = tarfile.open(tmpname, "r")
1052 # Test if extractall works properly when tarfile contains symlinks
1062 tar = tarfile.open(temparchive,'w')
1067 tar = tarfile.open(temparchive,'r')
1081 # Test if extractall works properly when tarfile contains broken
1092 tar = tarfile.open(temparchive,'w')
1098 tar = tarfile.open(temparchive,'r')
1112 # Test if extractall works properly when tarfile contains symlinks
1122 tar = tarfile.open(temparchive,'w')
1127 tar = tarfile.open(temparchive,'r')
1150 tar = tarfile.open(tmpname, self.mode, fileobj=f,
1151 format=tarfile.PAX_FORMAT,
1161 tar = tarfile.open(tmpname, self.mode)
1178 self.assertTrue(data.count("\0") == tarfile.RECORDSIZE,
1191 tar = tarfile.open(tmpname, self.mode)
1200 with tarfile.open(unicode(tmpname, sys.getfilesystemencoding()), self.mode):
1220 if len(name) > tarfile.LENGTH_NAME:
1224 if link is not None and len(link) > tarfile.LENGTH_LINK:
1231 tarinfo = tarfile.TarInfo(name)
1234 tarinfo.type = tarfile.LNKTYPE
1236 tar = tarfile.open(tmpname, "w")
1238 tar.format = tarfile.GNU_FORMAT
1247 tar = tarfile.open(tmpname)
1302 self.tar = tarfile.open(tmpname, "w")
1314 self.assertTrue(tarinfo.type == tarfile.REGTYPE,
1319 self.assertTrue(tarinfo.type == tarfile.LNKTYPE,
1325 self.assertTrue(tarinfo.type == tarfile.REGTYPE,
1333 tarinfo = tarfile.TarInfo(name)
1336 tarinfo.type = tarfile.LNKTYPE
1338 tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT)
1344 tar = tarfile.open(tmpname)
1363 tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT,
1366 tar.addfile(tarfile.TarInfo("test"))
1371 tar = tarfile.open(tmpname, encoding="iso8859-1")
1380 if key in tarfile.PAX_NUMBER_FIELDS:
1382 tarfile.PAX_NUMBER_FIELDS[key](val)
1393 tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT, encoding="iso8859-1")
1395 t = tarfile.TarInfo()
1403 tar = tarfile.open(tmpname, encoding="iso8859-1")
1416 format = tarfile.USTAR_FORMAT
1428 tar = tarfile.open(tmpname, "w", format=self.format, encoding=encoding, errors="strict")
1431 tar.addfile(tarfile.TarInfo(name))
1435 tar = tarfile.open(tmpname, encoding=encoding)
1443 tar = tarfile.open(tmpname, "w", format=self.format, encoding="ascii", errors="strict")
1445 tarinfo = tarfile.TarInfo()
1448 if self.format == tarfile.PAX_FORMAT:
1463 tar = tarfile.open(tarname, "r", encoding="iso8859-1", errors="strict")
1475 t = tarfile.TarInfo("foo")
1480 tar = tarfile.open("foo.tar", mode="w", fileobj=fobj, format=self.format, encoding="iso8859-1")
1487 tar = tarfile.open("foo.tar", fileobj=fobj, encoding="iso8859-1")
1495 format = tarfile.GNU_FORMAT
1500 format = tarfile.PAX_FORMAT
1503 tar = tarfile.open(tmpname, "w", format=self.format)
1504 t = tarfile.TarInfo()
1516 tar = tarfile.open(tmpname, format=self.format, encoding="ascii",
1520 self.assertRaises(UnicodeError, tarfile.open, tmpname,
1528 tar = tarfile.open(tmpname, format=self.format, encoding="iso8859-1",
1542 with tarfile.open(self.tarname, "a", fileobj=fileobj) as tar:
1543 tar.addfile(tarfile.TarInfo("bar"))
1546 with tarfile.open(tarname, encoding="iso8859-1") as src:
1550 with tarfile.open(self.tarname, mode) as tar:
1554 with tarfile.open(self.tarname, fileobj=fileobj) as tar:
1562 tarfile.open(self.tarname, "w:").close()
1589 self.assertRaises(tarfile.ReadError, tarfile.open, tmpname, "a")
1594 self.assertRaises(tarfile.ReadError, tarfile.open, tmpname, "a")
1596 # Append mode is supposed to fail if the tarfile to append to
1601 self.assertRaises(tarfile.ReadError, self._add_testfile)
1610 data = tarfile.TarInfo("foo").tobuf()
1614 data = tarfile.TarInfo("foo").tobuf()
1625 tarinfo = tarfile.TarInfo("0123456789" * 10)
1626 tarinfo.tobuf(tarfile.USTAR_FORMAT)
1629 tarinfo = tarfile.TarInfo("0123456789" * 10 + "0")
1630 self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)
1633 tarinfo = tarfile.TarInfo("123/" * 62 + "longname")
1634 tarinfo.tobuf(tarfile.USTAR_FORMAT)
1637 tarinfo = tarfile.TarInfo("1234567/" * 31 + "longname")
1638 self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)
1641 tarinfo = tarfile.TarInfo("123/" * 126 + "longname")
1642 self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)
1645 tarinfo = tarfile.TarInfo("longlink")
1647 self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)
1650 tarinfo = tarfile.TarInfo("name")
1652 self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)
1655 tarinfo = tarfile.TarInfo("123/" * 126 + "longname")
1656 tarinfo.tobuf(tarfile.GNU_FORMAT)
1658 tarinfo = tarfile.TarInfo("longlink")
1660 tarinfo.tobuf(tarfile.GNU_FORMAT)
1663 tarinfo = tarfile.TarInfo("name")
1665 self.assertRaises(ValueError, tarinfo.tobuf, tarfile.GNU_FORMAT)
1668 tarinfo = tarfile.TarInfo("123/" * 126 + "longname")
1669 tarinfo.tobuf(tarfile.PAX_FORMAT)
1671 tarinfo = tarfile.TarInfo("longlink")
1673 tarinfo.tobuf(tarfile.PAX_FORMAT)
1675 tarinfo = tarfile.TarInfo("name")
1677 tarinfo.tobuf(tarfile.PAX_FORMAT)
1684 self.assertEqual(tarfile.nti("\0"), 0)
1685 self.assertEqual(tarfile.nti(" \0"), 0)
1691 with tarfile.open(tarname) as tar:
1697 # if the TarFile object is already closed.
1698 tar = tarfile.open(tarname)
1707 with tarfile.open(tarname) as tar:
1717 with tarfile.open(tmpname, "w") as tar:
1727 # TarFile.close() if there was no error.
1728 with tarfile.open(tmpname, "w"):
1738 with tarfile.open(fileobj=fobj, mode="w") as tar:
1749 # symbolic or hard links tarfile tries to extract these types of members as
1772 taropen = tarfile.TarFile.gzopen
1788 taropen = tarfile.TarFile.bz2open
1809 raise AssertionError("infinite loop detected in tarfile.open()")
1816 tarfile.TarInfo("foo").tobuf())
1819 tarfile.open(fileobj=MyStringIO(data[:x]), mode=mode)
1820 except tarfile.ReadError: