本文整理汇总了Python中tarfile.StreamError方法的典型用法代码示例。如果您正苦于以下问题:Python tarfile.StreamError方法的具体用法?Python tarfile.StreamError怎么用?Python tarfile.StreamError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tarfile
的用法示例。
在下文中一共展示了tarfile.StreamError方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_compare_members
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import StreamError [as 别名]
def test_compare_members(self):
tar1 = tarfile.open(tarname, encoding="iso8859-1")
try:
tar2 = self.tar
while True:
t1 = tar1.next()
t2 = tar2.next()
if t1 is None:
break
self.assertTrue(t2 is not None, "stream.next() failed.")
if t2.islnk() or t2.issym():
self.assertRaises(tarfile.StreamError, tar2.extractfile, t2)
continue
v1 = tar1.extractfile(t1)
v2 = tar2.extractfile(t2)
if v1 is None:
continue
self.assertTrue(v2 is not None, "stream.extractfile() failed")
self.assertTrue(v1.read() == v2.read(), "stream extraction failed")
finally:
tar1.close()
示例2: test_compare_members
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import StreamError [as 别名]
def test_compare_members(self):
tar1 = tarfile.open(tarname, encoding="iso8859-1")
tar2 = self.tar
while True:
t1 = tar1.next()
t2 = tar2.next()
if t1 is None:
break
self.assertTrue(t2 is not None, "stream.next() failed.")
if t2.islnk() or t2.issym():
self.assertRaises(tarfile.StreamError, tar2.extractfile, t2)
continue
v1 = tar1.extractfile(t1)
v2 = tar2.extractfile(t2)
if v1 is None:
continue
self.assertTrue(v2 is not None, "stream.extractfile() failed")
self.assertTrue(v1.read() == v2.read(), "stream extraction failed")
tar1.close()
示例3: test_stream
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import StreamError [as 别名]
def test_stream(self):
"""Compare the normal tar and the stream tar.
"""
stream = self.tar
tar = tarfile.open(tarname(), 'r')
while 1:
t1 = tar.next()
t2 = stream.next()
if t1 is None:
break
self.assert_(t2 is not None, "stream.next() failed.")
if t2.islnk() or t2.issym():
self.assertRaises(tarfile.StreamError, stream.extractfile, t2)
continue
v1 = tar.extractfile(t1)
v2 = stream.extractfile(t2)
if v1 is None:
continue
self.assert_(v2 is not None, "stream.extractfile() failed")
self.assert_(v1.read() == v2.read(), "stream extraction failed")
tar.close()
stream.close()
示例4: test_provoke_stream_error
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import StreamError [as 别名]
def test_provoke_stream_error(self):
tarinfos = self.tar.getmembers()
f = self.tar.extractfile(tarinfos[0]) # read the first member
self.assertRaises(tarfile.StreamError, f.read)
示例5: test_read_through
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import StreamError [as 别名]
def test_read_through(self):
# Issue #11224: A poorly designed _FileInFile.read() method
# caused seeking errors with stream tar files.
for tarinfo in self.tar:
if not tarinfo.isreg():
continue
with self.tar.extractfile(tarinfo) as fobj:
while True:
try:
buf = fobj.read(512)
except tarfile.StreamError:
self.fail("simple read-through using "
"TarFile.extractfile() failed")
if not buf:
break
示例6: test_provoke_stream_error
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import StreamError [as 别名]
def test_provoke_stream_error(self):
tarinfos = self.tar.getmembers()
with self.tar.extractfile(tarinfos[0]) as f: # read the first member
self.assertRaises(tarfile.StreamError, f.read)
示例7: test_compare_members
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import StreamError [as 别名]
def test_compare_members(self):
tar1 = tarfile.open(tarname, encoding="iso8859-1")
try:
tar2 = self.tar
while True:
t1 = tar1.next()
t2 = tar2.next()
if t1 is None:
break
self.assertIsNotNone(t2, "stream.next() failed.")
if t2.islnk() or t2.issym():
with self.assertRaises(tarfile.StreamError):
tar2.extractfile(t2)
continue
v1 = tar1.extractfile(t1)
v2 = tar2.extractfile(t2)
if v1 is None:
continue
self.assertIsNotNone(v2, "stream.extractfile() failed")
self.assertEqual(v1.read(), v2.read(),
"stream extraction failed")
finally:
tar1.close()
示例8: test
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import StreamError [as 别名]
def test(self):
"""Test member extraction, and for StreamError when
seeking backwards.
"""
ReadTest.test(self)
tarinfo = self.tar.getmembers()[0]
f = self.tar.extractfile(tarinfo)
self.assertRaises(tarfile.StreamError, f.read)