当前位置: 首页>>代码示例>>Python>>正文


Python BZ2Decompressor.decompress方法代码示例

本文整理汇总了Python中bz2.BZ2Decompressor.decompress方法的典型用法代码示例。如果您正苦于以下问题:Python BZ2Decompressor.decompress方法的具体用法?Python BZ2Decompressor.decompress怎么用?Python BZ2Decompressor.decompress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bz2.BZ2Decompressor的用法示例。


在下文中一共展示了BZ2Decompressor.decompress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_decompressor_inputbuf_1

# 需要导入模块: from bz2 import BZ2Decompressor [as 别名]
# 或者: from bz2.BZ2Decompressor import decompress [as 别名]
def test_decompressor_inputbuf_1(self):
        # Test reusing input buffer after moving existing
        # contents to beginning
        bzd = BZ2Decompressor()
        out = []

        # Create input buffer and fill it
        self.assertEqual(bzd.decompress(self.DATA[:100],
                                        max_length=0), b'')

        # Retrieve some results, freeing capacity at beginning
        # of input buffer
        out.append(bzd.decompress(b'', 2))

        # Add more data that fits into input buffer after
        # moving existing data to beginning
        out.append(bzd.decompress(self.DATA[100:105], 15))

        # Decompress rest of data
        out.append(bzd.decompress(self.DATA[105:]))
        self.assertEqual(b''.join(out), self.TEXT) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_bz2.py

示例2: test_binary_modes

# 需要导入模块: from bz2 import BZ2Decompressor [as 别名]
# 或者: from bz2.BZ2Decompressor import decompress [as 别名]
def test_binary_modes(self):
        for mode in ("wb", "xb"):
            if mode == "xb":
                unlink(self.filename)
            with self.open(self.filename, mode) as f:
                f.write(self.TEXT)
            with open(self.filename, "rb") as f:
                file_data = self.decompress(f.read())
                self.assertEqual(file_data, self.TEXT)
            with self.open(self.filename, "rb") as f:
                self.assertEqual(f.read(), self.TEXT)
            with self.open(self.filename, "ab") as f:
                f.write(self.TEXT)
            with open(self.filename, "rb") as f:
                file_data = self.decompress(f.read())
                self.assertEqual(file_data, self.TEXT * 2) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:test_bz2.py

示例3: test_text_modes

# 需要导入模块: from bz2 import BZ2Decompressor [as 别名]
# 或者: from bz2.BZ2Decompressor import decompress [as 别名]
def test_text_modes(self):
        text = self.TEXT.decode("ascii")
        text_native_eol = text.replace("\n", os.linesep)
        for mode in ("wt", "xt"):
            if mode == "xt":
                unlink(self.filename)
            with self.open(self.filename, mode) as f:
                f.write(text)
            with open(self.filename, "rb") as f:
                file_data = self.decompress(f.read()).decode("ascii")
                self.assertEqual(file_data, text_native_eol)
            with self.open(self.filename, "rt") as f:
                self.assertEqual(f.read(), text)
            with self.open(self.filename, "at") as f:
                f.write(text)
            with open(self.filename, "rb") as f:
                file_data = self.decompress(f.read()).decode("ascii")
                self.assertEqual(file_data, text_native_eol * 2) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:test_bz2.py

示例4: decompress

# 需要导入模块: from bz2 import BZ2Decompressor [as 别名]
# 或者: from bz2.BZ2Decompressor import decompress [as 别名]
def decompress(self, data):
            pop = subprocess.Popen("bunzip2", shell=True,
                                   stdin=subprocess.PIPE,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.STDOUT)
            pop.stdin.write(data)
            pop.stdin.close()
            ret = pop.stdout.read()
            pop.stdout.close()
            if pop.wait() != 0:
                ret = bz2.decompress(data)
            return ret 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:test_bz2.py

示例5: testWrite

# 需要导入模块: from bz2 import BZ2Decompressor [as 别名]
# 或者: from bz2.BZ2Decompressor import decompress [as 别名]
def testWrite(self):
        # "Test BZ2File.write()"
        with BZ2File(self.filename, "w") as bz2f:
            self.assertRaises(TypeError, bz2f.write)
            bz2f.write(self.TEXT)
        with open(self.filename, 'rb') as f:
            self.assertEqual(self.decompress(f.read()), self.TEXT) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_bz2.py

示例6: testWriteChunks10

# 需要导入模块: from bz2 import BZ2Decompressor [as 别名]
# 或者: from bz2.BZ2Decompressor import decompress [as 别名]
def testWriteChunks10(self):
        # "Test BZ2File.write() with chunks of 10 bytes"
        with BZ2File(self.filename, "w") as bz2f:
            n = 0
            while 1:
                str = self.TEXT[n*10:(n+1)*10]
                if not str:
                    break
                bz2f.write(str)
                n += 1
        with open(self.filename, 'rb') as f:
            self.assertEqual(self.decompress(f.read()), self.TEXT) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:test_bz2.py

示例7: testWriteLines

# 需要导入模块: from bz2 import BZ2Decompressor [as 别名]
# 或者: from bz2.BZ2Decompressor import decompress [as 别名]
def testWriteLines(self):
        # "Test BZ2File.writelines()"
        with BZ2File(self.filename, "w") as bz2f:
            self.assertRaises(TypeError, bz2f.writelines)
            sio = StringIO(self.TEXT)
            bz2f.writelines(sio.readlines())
        # patch #1535500
        self.assertRaises(ValueError, bz2f.writelines, ["a"])
        with open(self.filename, 'rb') as f:
            self.assertEqual(self.decompress(f.read()), self.TEXT) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_bz2.py

示例8: testCompressChunks10

# 需要导入模块: from bz2 import BZ2Decompressor [as 别名]
# 或者: from bz2.BZ2Decompressor import decompress [as 别名]
def testCompressChunks10(self):
        # "Test BZ2Compressor.compress()/flush() with chunks of 10 bytes"
        bz2c = BZ2Compressor()
        n = 0
        data = ''
        while 1:
            str = self.TEXT[n*10:(n+1)*10]
            if not str:
                break
            data += bz2c.compress(str)
            n += 1
        data += bz2c.flush()
        self.assertEqual(self.decompress(data), self.TEXT) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_bz2.py

示例9: testBigmem

# 需要导入模块: from bz2 import BZ2Decompressor [as 别名]
# 或者: from bz2.BZ2Decompressor import decompress [as 别名]
def testBigmem(self, size):
        text = "a" * size
        bz2c = bz2.BZ2Compressor()
        data = bz2c.compress(text) + bz2c.flush()
        del text
        text = self.decompress(data)
        self.assertEqual(len(text), size)
        self.assertEqual(text.strip("a"), "") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_bz2.py

示例10: testDecompress

# 需要导入模块: from bz2 import BZ2Decompressor [as 别名]
# 或者: from bz2.BZ2Decompressor import decompress [as 别名]
def testDecompress(self):
        # "Test BZ2Decompressor.decompress()"
        bz2d = BZ2Decompressor()
        self.assertRaises(TypeError, bz2d.decompress)
        text = bz2d.decompress(self.DATA)
        self.assertEqual(text, self.TEXT) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_bz2.py

示例11: testDecompressChunks10

# 需要导入模块: from bz2 import BZ2Decompressor [as 别名]
# 或者: from bz2.BZ2Decompressor import decompress [as 别名]
def testDecompressChunks10(self):
        # "Test BZ2Decompressor.decompress() with chunks of 10 bytes"
        bz2d = BZ2Decompressor()
        text = ''
        n = 0
        while 1:
            str = self.DATA[n*10:(n+1)*10]
            if not str:
                break
            text += bz2d.decompress(str)
            n += 1
        self.assertEqual(text, self.TEXT) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:test_bz2.py

示例12: testDecompressUnusedData

# 需要导入模块: from bz2 import BZ2Decompressor [as 别名]
# 或者: from bz2.BZ2Decompressor import decompress [as 别名]
def testDecompressUnusedData(self):
        # "Test BZ2Decompressor.decompress() with unused data"
        bz2d = BZ2Decompressor()
        unused_data = "this is unused data"
        text = bz2d.decompress(self.DATA+unused_data)
        self.assertEqual(text, self.TEXT)
        self.assertEqual(bz2d.unused_data, unused_data) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_bz2.py

示例13: testCompress

# 需要导入模块: from bz2 import BZ2Decompressor [as 别名]
# 或者: from bz2.BZ2Decompressor import decompress [as 别名]
def testCompress(self):
        # "Test compress() function"
        data = bz2.compress(self.TEXT)
        self.assertEqual(self.decompress(data), self.TEXT) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_bz2.py

示例14: testDecompressEmpty

# 需要导入模块: from bz2 import BZ2Decompressor [as 别名]
# 或者: from bz2.BZ2Decompressor import decompress [as 别名]
def testDecompressEmpty(self):
        # "Test decompress() function with empty string"
        text = bz2.decompress("")
        self.assertEqual(text, "") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_bz2.py

示例15: testDecompressToEmptyString

# 需要导入模块: from bz2 import BZ2Decompressor [as 别名]
# 或者: from bz2.BZ2Decompressor import decompress [as 别名]
def testDecompressToEmptyString(self):
        # "Test decompress() of minimal bz2 data to empty string"
        text = bz2.decompress(self.EMPTY_DATA)
        self.assertEqual(text, '') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_bz2.py


注:本文中的bz2.BZ2Decompressor.decompress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。