Lines Matching refs:tarfile
11 import tarfile
45 self.tar = tarfile.open(self.tarname, mode=self.mode, encoding="iso8859-1")
162 # This test checks if tarfile.open() is able to open an empty tar
165 tarfile.open(tmpname, self.mode.replace("r", "w")).close()
167 tar = tarfile.open(tmpname, self.mode)
169 except tarfile.ReadError:
170 self.fail("tarfile.open() failed on empty archive")
175 # This test guarantees that tarfile.open() does not treat an empty
178 self.assertRaises(tarfile.ReadError, tarfile.open, tmpname, self.mode)
179 self.assertRaises(tarfile.ReadError, tarfile.open, tmpname)
182 # Test TarFile's ignore_zeros option.
195 fobj.write(tarfile.TarInfo("foo").tobuf())
198 tar = tarfile.open(tmpname, mode="r", ignore_zeros=True)
208 tar = tarfile.open(fileobj=fobj, mode=self.mode)
215 tar = tarfile.open(fileobj=fobj, mode=self.mode)
222 tar = tarfile.open(fileobj=fobj, mode=self.mode)
228 tar = tarfile.open(self.tarname, mode=self.mode)
246 # Test if the tarfile starts with the second member.
261 self.assertRaises(tarfile.ReadError, tarfile.open, tarname, self.mode)
263 self.assertRaises(tarfile.ReadError, tarfile.open, fileobj=fobj, mode=self.mode)
270 self.assertTrue(tarinfo.type == tarfile.DIRTYPE,
288 self.assertTrue(tarinfo.uname == "tarfile",
297 tar = tarfile.open(tarname, errorlevel=1, encoding="iso8859-1")
321 tar = tarfile.open(tarname, encoding="iso8859-1")
333 # Issue #7341: Close the internal file object in the TarFile
340 tar = object.__new__(tarfile.TarFile)
343 except tarfile.ReadError:
365 self.assertRaises(tarfile.StreamError, f.read)
368 tar1 = tarfile.open(tarname, encoding="iso8859-1")
379 self.assertRaises(tarfile.StreamError, tar2.extractfile, t2)
396 tarfile.open(name, mode)
397 except tarfile.ReadError:
402 tarfile.open(name, mode, fileobj=open(name, "rb"))
403 except tarfile.ReadError:
414 self.assertRaises(tarfile.ReadError, tarfile.open, tarname, mode="r:gz")
415 self.assertRaises(tarfile.ReadError, tarfile.open, tarname, mode="r|gz")
416 self.assertRaises(tarfile.ReadError, tarfile.open, gzipname, mode="r:")
417 self.assertRaises(tarfile.ReadError, tarfile.open, gzipname, mode="r|")
426 self.assertRaises(tarfile.ReadError, tarfile.open, tarname, mode="r:bz2")
427 self.assertRaises(tarfile.ReadError, tarfile.open, tarname, mode="r|bz2")
428 self.assertRaises(tarfile.ReadError, tarfile.open, bz2name, mode="r:")
429 self.assertRaises(tarfile.ReadError, tarfile.open, bz2name, mode="r|")
456 kwargs["uname"] = "tarfile"
457 kwargs["gname"] = "tarfile"
515 self.tar = tarfile.open(self.tarname, mode=self.mode, encoding="iso8859-1")
529 self.assertTrue(tarinfo.type != tarfile.DIRTYPE, "read longname as dirtype")
546 self.assertRaises(tarfile.ReadError, tarfile.open, name="foo.tar", fileobj=fobj)
555 tarinfo = tarfile.TarInfo.frombuf(fobj.read(512))
562 longnametype = tarfile.GNUTYPE_LONGNAME
576 longnametype = tarfile.XHDTYPE
579 tar = tarfile.open(tarname, encoding="iso8859-1")
592 self.assertEqual(tarinfo.uname, "tarfile")
593 self.assertEqual(tarinfo.gname, "tarfile")
598 tar = tarfile.open(tarname, encoding="iso8859-1")
615 tar = tarfile.open(fileobj=fobj, mode=self.mode)
616 tar.addfile(tarfile.TarInfo("foo"))
631 tar = tarfile.open(tmpname, self.mode)
632 t = tarfile.TarInfo(name)
636 tar = tarfile.open(tmpname)
643 tar = tarfile.open(tmpname, self.mode)
651 "tarfile is empty")
655 tar = tarfile.open(tmpname, self.mode)
675 tar = tarfile.open(tmpname, self.mode)
690 tar = tarfile.open(tmpname, self.mode)
704 tar = tarfile.open(tmpname, self.mode)
714 tar = tarfile.open(tmpname, self.mode)
736 tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1")
742 tar = tarfile.open(tmpname, "r")
763 tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1")
767 tar = tarfile.open(tmpname, "r")
781 # Create a tarfile with an empty member named path
789 tar = tarfile.open(tmpname, self.mode)
793 tar = tarfile.open(tmpname, "r")
835 tar = tarfile.open(tmpname, self.mode)
839 tar = tarfile.open(tmpname, "r")
848 # Test if extractall works properly when tarfile contains symlinks
858 tar = tarfile.open(temparchive,'w')
863 tar = tarfile.open(temparchive,'r')
877 # Test if extractall works properly when tarfile
888 tar = tarfile.open(temparchive,'w')
894 tar = tarfile.open(temparchive,'r')
908 # Test if extractall works properly when tarfile contains symlinks
918 tar = tarfile.open(temparchive,'w')
923 tar = tarfile.open(temparchive,'r')
941 tar = tarfile.open(tmpname, self.mode)
959 self.assertTrue(data.count("\0") == tarfile.RECORDSIZE,
973 tar = tarfile.open(tmpname, self.mode)
995 if len(name) > tarfile.LENGTH_NAME:
999 if link is not None and len(link) > tarfile.LENGTH_LINK:
1006 tarinfo = tarfile.TarInfo(name)
1009 tarinfo.type = tarfile.LNKTYPE
1011 tar = tarfile.open(tmpname, "w")
1012 tar.format = tarfile.GNU_FORMAT
1021 tar = tarfile.open(tmpname)
1074 self.tar = tarfile.open(tmpname, "w")
1086 self.assertTrue(tarinfo.type == tarfile.REGTYPE,
1091 self.assertTrue(tarinfo.type == tarfile.LNKTYPE,
1097 self.assertTrue(tarinfo.type == tarfile.REGTYPE,
1105 tarinfo = tarfile.TarInfo(name)
1108 tarinfo.type = tarfile.LNKTYPE
1110 tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT)
1114 tar = tarfile.open(tmpname)
1130 tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT,
1132 tar.addfile(tarfile.TarInfo("test"))
1136 tar = tarfile.open(tmpname, encoding="iso8859-1")
1144 if key in tarfile.PAX_NUMBER_FIELDS:
1146 tarfile.PAX_NUMBER_FIELDS[key](val)
1155 tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT, encoding="iso8859-1")
1156 t = tarfile.TarInfo()
1163 tar = tarfile.open(tmpname, encoding="iso8859-1")
1173 format = tarfile.USTAR_FORMAT
1185 tar = tarfile.open(tmpname, "w", format=self.format, encoding=encoding, errors="strict")
1187 tar.addfile(tarfile.TarInfo(name))
1190 tar = tarfile.open(tmpname, encoding=encoding)
1196 tar = tarfile.open(tmpname, "w", format=self.format, encoding="ascii", errors="strict")
1197 tarinfo = tarfile.TarInfo()
1200 if self.format == tarfile.PAX_FORMAT:
1213 tar = tarfile.open(tarname, "r", encoding="iso8859-1", errors="strict")
1223 t = tarfile.TarInfo("foo")
1228 tar = tarfile.open("foo.tar", mode="w", fileobj=fobj, format=self.format, encoding="iso8859-1")
1233 tar = tarfile.open("foo.tar", fileobj=fobj, encoding="iso8859-1")
1241 format = tarfile.GNU_FORMAT
1246 format = tarfile.PAX_FORMAT
1249 tar = tarfile.open(tmpname, "w", format=self.format)
1250 t = tarfile.TarInfo()
1262 tar = tarfile.open(tmpname, format=self.format, encoding="ascii",
1266 self.assertRaises(UnicodeError, tarfile.open, tmpname,
1274 tar = tarfile.open(tmpname, format=self.format, encoding="iso8859-1",
1288 tar = tarfile.open(self.tarname, "a", fileobj=fileobj)
1289 tar.addfile(tarfile.TarInfo("bar"))
1293 src = tarfile.open(tarname, encoding="iso8859-1")
1297 tar = tarfile.open(self.tarname, mode)
1302 tar = tarfile.open(self.tarname, fileobj=fileobj)
1310 tarfile.open(self.tarname, "w:").close()
1337 self.assertRaises(tarfile.ReadError, tarfile.open, tmpname, "a")
1343 self.assertRaises(tarfile.ReadError, tarfile.open, tmpname, "a")
1345 # Append mode is supposed to fail if the tarfile to append to
1349 self.assertRaises(tarfile
1358 data = tarfile.TarInfo("foo").tobuf()
1362 data = tarfile.TarInfo("foo").tobuf()
1373 tarinfo = tarfile.TarInfo("0123456789" * 10)
1374 tarinfo.tobuf(tarfile.USTAR_FORMAT)
1377 tarinfo = tarfile.TarInfo("0123456789" * 10 + "0")
1378 self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)
1381 tarinfo = tarfile.TarInfo("123/" * 62 + "longname")
1382 tarinfo.tobuf(tarfile.USTAR_FORMAT)
1385 tarinfo = tarfile.TarInfo("1234567/" * 31 + "longname")
1386 self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)
1389 tarinfo = tarfile.TarInfo("123/" * 126 + "longname")
1390 self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)
1393 tarinfo = tarfile.TarInfo("longlink")
1395 self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)
1398 tarinfo = tarfile.TarInfo("name")
1400 self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)
1403 tarinfo = tarfile.TarInfo("123/" * 126 + "longname")
1404 tarinfo.tobuf(tarfile.GNU_FORMAT)
1406 tarinfo = tarfile.TarInfo("longlink")
1408 tarinfo.tobuf(tarfile.GNU_FORMAT)
1411 tarinfo = tarfile.TarInfo("name")
1413 self.assertRaises(ValueError, tarinfo.tobuf, tarfile.GNU_FORMAT)
1416 tarinfo = tarfile.TarInfo("123/" * 126 + "longname")
1417 tarinfo.tobuf(tarfile.PAX_FORMAT)
1419 tarinfo = tarfile.TarInfo("longlink")
1421 tarinfo.tobuf(tarfile.PAX_FORMAT)
1423 tarinfo = tarfile.TarInfo("name")
1425 tarinfo.tobuf(tarfile.PAX_FORMAT)
1431 with tarfile.open(tarname) as tar:
1437 # if the TarFile object is already closed.
1438 tar = tarfile.open(tarname)
1447 with tarfile.open(tarname) as tar:
1457 with tarfile.open(tmpname, "w") as tar:
1467 # TarFile.close() if there was no error.
1468 with tarfile.open(tmpname, "w"):
1478 with tarfile.open(fileobj=fobj, mode="w") as tar:
1490 # symbolic or hard links tarfile tries to extract these types of members as
1548 raise AssertionError("infinite loop detected in tarfile.open()")
1555 data = bz2.compress(tarfile.TarInfo("foo").tobuf())
1558 tarfile.open(fileobj=MyStringIO(data[:x]), mode=mode)
1559 except tarfile.ReadError: