当前位置: 首页>>代码示例>>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;未经允许,请勿转载。