我们从Python开源项目中,提取了以下22个代码示例,用于说明如何使用tarfile.StreamError()。
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.assertEqual(v1.read(), v2.read(), "stream extraction failed") finally: tar1.close()
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()
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()
def test_compressed_stream(self): with AndroidBackup(io.BytesIO(TEST_DATA_NONENC)) as ab: self.assertEqual(ab.version, 3) self.assertEqual(ab.encryption, EncryptionType.NONE) self.assertEqual(ab.compression, CompressionType.ZLIB) names = list(map(lambda f: f.name, ab.get_files())) self.assertListEqual(names, TEST_MEMBERS_NAMES) tar = ab.read_data() with self.assertRaisesRegex(tarfile.StreamError, 'seeking backwards is not allowed'): tar.extractfile( 'apps/eu.bluec0re.android-backup/r/settings.cfg').read()
def test_encrypted_stream(self): with AndroidBackup(io.BytesIO(TEST_DATA_ENC_TEST), password='test') as ab: self.assertEqual(ab.version, 3) self.assertEqual(ab.encryption, EncryptionType.AES256) self.assertEqual(ab.compression, CompressionType.ZLIB) names = list(map(lambda f: f.name, ab.get_files())) self.assertListEqual(names, TEST_MEMBERS_NAMES) tar = ab.read_data() with self.assertRaisesRegex(tarfile.StreamError, 'seeking backwards is not allowed'): tar.extractfile( 'apps/eu.bluec0re.android-backup/r/settings.cfg').read()
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 fobj = self.tar.extractfile(tarinfo) while True: try: buf = fobj.read(512) except tarfile.StreamError: self.fail("simple read-through using TarFile.extractfile() failed") if not buf: break fobj.close()
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)
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
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)
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()