本文整理汇总了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)
示例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)
示例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)
示例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
示例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)
示例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)
示例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)
示例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)
示例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"), "")
示例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)
示例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)
示例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)
示例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)
示例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, "")
示例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, '')