當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。