當前位置: 首頁>>代碼示例>>Python>>正文


Python tarfile.StreamError方法代碼示例

本文整理匯總了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() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:test_tarfile.py

示例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() 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:25,代碼來源:test_tarfile.py

示例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() 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:27,代碼來源:test_tarfile.py

示例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) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,代碼來源:test_tarfile.py

示例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 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:17,代碼來源:test_tarfile.py

示例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) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:6,代碼來源:test_tarfile.py

示例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() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:28,代碼來源:test_tarfile.py

示例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) 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:10,代碼來源:test_tarfile.py


注:本文中的tarfile.StreamError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。