本文整理汇总了Python中lzma.LZMACompressor方法的典型用法代码示例。如果您正苦于以下问题:Python lzma.LZMACompressor方法的具体用法?Python lzma.LZMACompressor怎么用?Python lzma.LZMACompressor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lzma
的用法示例。
在下文中一共展示了lzma.LZMACompressor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: urlstate
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import LZMACompressor [as 别名]
def urlstate(self, encryption_key):
"""
Will return a url safe representation of the state.
:type encryption_key: Key used for encryption.
:rtype: str
:return: Url representation av of the state.
"""
lzma = LZMACompressor()
urlstate_data = json.dumps(self.data)
urlstate_data = lzma.compress(urlstate_data.encode("UTF-8"))
urlstate_data += lzma.flush()
urlstate_data = _AESCipher(encryption_key).encrypt(urlstate_data)
lzma = LZMACompressor()
urlstate_data = lzma.compress(urlstate_data)
urlstate_data += lzma.flush()
urlstate_data = base64.urlsafe_b64encode(urlstate_data)
return urlstate_data.decode("utf-8")
示例2: test_simple_bad_args
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import LZMACompressor [as 别名]
def test_simple_bad_args(self):
self.assertRaises(TypeError, LZMACompressor, [])
self.assertRaises(TypeError, LZMACompressor, format=3.45)
self.assertRaises(TypeError, LZMACompressor, check="")
self.assertRaises(TypeError, LZMACompressor, preset="asdf")
self.assertRaises(TypeError, LZMACompressor, filters=3)
# Can't specify FORMAT_AUTO when compressing.
self.assertRaises(ValueError, LZMACompressor, format=lzma.FORMAT_AUTO)
# Can't specify a preset and a custom filter chain at the same time.
with self.assertRaises(ValueError):
LZMACompressor(preset=7, filters=[{"id": lzma.FILTER_LZMA2}])
self.assertRaises(TypeError, LZMADecompressor, ())
self.assertRaises(TypeError, LZMADecompressor, memlimit=b"qw")
with self.assertRaises(TypeError):
LZMADecompressor(lzma.FORMAT_RAW, filters="zzz")
# Cannot specify a memory limit with FILTER_RAW.
with self.assertRaises(ValueError):
LZMADecompressor(lzma.FORMAT_RAW, memlimit=0x1000000)
# Can only specify a custom filter chain with FILTER_RAW.
self.assertRaises(ValueError, LZMADecompressor, filters=FILTERS_RAW_1)
with self.assertRaises(ValueError):
LZMADecompressor(format=lzma.FORMAT_XZ, filters=FILTERS_RAW_1)
with self.assertRaises(ValueError):
LZMADecompressor(format=lzma.FORMAT_ALONE, filters=FILTERS_RAW_1)
lzc = LZMACompressor()
self.assertRaises(TypeError, lzc.compress)
self.assertRaises(TypeError, lzc.compress, b"foo", b"bar")
self.assertRaises(TypeError, lzc.flush, b"blah")
empty = lzc.flush()
self.assertRaises(ValueError, lzc.compress, b"quux")
self.assertRaises(ValueError, lzc.flush)
lzd = LZMADecompressor()
self.assertRaises(TypeError, lzd.decompress)
self.assertRaises(TypeError, lzd.decompress, b"foo", b"bar")
lzd.decompress(empty)
self.assertRaises(EOFError, lzd.decompress, b"quux")
示例3: test_bad_filter_spec
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import LZMACompressor [as 别名]
def test_bad_filter_spec(self):
self.assertRaises(TypeError, LZMACompressor, filters=[b"wobsite"])
self.assertRaises(ValueError, LZMACompressor, filters=[{"xyzzy": 3}])
self.assertRaises(ValueError, LZMACompressor, filters=[{"id": 98765}])
with self.assertRaises(ValueError):
LZMACompressor(filters=[{"id": lzma.FILTER_LZMA2, "foo": 0}])
with self.assertRaises(ValueError):
LZMACompressor(filters=[{"id": lzma.FILTER_DELTA, "foo": 0}])
with self.assertRaises(ValueError):
LZMACompressor(filters=[{"id": lzma.FILTER_X86, "foo": 0}])
示例4: test_decompressor_bad_input
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import LZMACompressor [as 别名]
def test_decompressor_bad_input(self):
lzd = LZMADecompressor()
self.assertRaises(LZMAError, lzd.decompress, COMPRESSED_RAW_1)
lzd = LZMADecompressor(lzma.FORMAT_XZ)
self.assertRaises(LZMAError, lzd.decompress, COMPRESSED_ALONE)
lzd = LZMADecompressor(lzma.FORMAT_ALONE)
self.assertRaises(LZMAError, lzd.decompress, COMPRESSED_XZ)
lzd = LZMADecompressor(lzma.FORMAT_RAW, filters=FILTERS_RAW_1)
self.assertRaises(LZMAError, lzd.decompress, COMPRESSED_XZ)
# Test that LZMACompressor->LZMADecompressor preserves the input data.
示例5: test_roundtrip_xz
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import LZMACompressor [as 别名]
def test_roundtrip_xz(self):
lzc = LZMACompressor()
cdata = lzc.compress(INPUT) + lzc.flush()
lzd = LZMADecompressor()
self._test_decompressor(lzd, cdata, lzma.CHECK_CRC64)
示例6: test_roundtrip_alone
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import LZMACompressor [as 别名]
def test_roundtrip_alone(self):
lzc = LZMACompressor(lzma.FORMAT_ALONE)
cdata = lzc.compress(INPUT) + lzc.flush()
lzd = LZMADecompressor()
self._test_decompressor(lzd, cdata, lzma.CHECK_NONE)
示例7: test_roundtrip_chunks
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import LZMACompressor [as 别名]
def test_roundtrip_chunks(self):
lzc = LZMACompressor()
cdata = []
for i in range(0, len(INPUT), 10):
cdata.append(lzc.compress(INPUT[i:i+10]))
cdata.append(lzc.flush())
cdata = b"".join(cdata)
lzd = LZMADecompressor()
self._test_decompressor(lzd, cdata, lzma.CHECK_CRC64)
# LZMADecompressor intentionally does not handle concatenated streams.
示例8: test_compressor_bigmem
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import LZMACompressor [as 别名]
def test_compressor_bigmem(self, size):
lzc = LZMACompressor()
cdata = lzc.compress(b"x" * size) + lzc.flush()
ddata = lzma.decompress(cdata)
try:
self.assertEqual(len(ddata), size)
self.assertEqual(len(ddata.strip(b"x")), 0)
finally:
ddata = None
示例9: test_pickle
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import LZMACompressor [as 别名]
def test_pickle(self):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
with self.assertRaises(TypeError):
pickle.dumps(LZMACompressor(), proto)
with self.assertRaises(TypeError):
pickle.dumps(LZMADecompressor(), proto)
示例10: test_decompressor_bug_28275
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import LZMACompressor [as 别名]
def test_decompressor_bug_28275(self):
# Test coverage for Issue 28275
lzd = LZMADecompressor()
self.assertRaises(LZMAError, lzd.decompress, COMPRESSED_RAW_1)
# Previously, a second call could crash due to internal inconsistency
self.assertRaises(LZMAError, lzd.decompress, COMPRESSED_RAW_1)
# Test that LZMACompressor->LZMADecompressor preserves the input data.
示例11: test_roundtrip_raw_empty
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import LZMACompressor [as 别名]
def test_roundtrip_raw_empty(self):
lzc = LZMACompressor(lzma.FORMAT_RAW, filters=FILTERS_RAW_4)
cdata = lzc.compress(INPUT)
cdata += lzc.compress(b'')
cdata += lzc.compress(b'')
cdata += lzc.compress(b'')
cdata += lzc.flush()
lzd = LZMADecompressor(lzma.FORMAT_RAW, filters=FILTERS_RAW_4)
self._test_decompressor(lzd, cdata, lzma.CHECK_NONE)
示例12: test_roundtrip_chunks
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import LZMACompressor [as 别名]
def test_roundtrip_chunks(self):
lzc = LZMACompressor()
cdata = []
for i in range(0, len(INPUT), 10):
cdata.append(lzc.compress(INPUT[i:i+10]))
cdata.append(lzc.flush())
cdata = b"".join(cdata)
lzd = LZMADecompressor()
self._test_decompressor(lzd, cdata, lzma.CHECK_CRC64)
示例13: test_roundtrip_empty_chunks
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import LZMACompressor [as 别名]
def test_roundtrip_empty_chunks(self):
lzc = LZMACompressor()
cdata = []
for i in range(0, len(INPUT), 10):
cdata.append(lzc.compress(INPUT[i:i+10]))
cdata.append(lzc.compress(b''))
cdata.append(lzc.compress(b''))
cdata.append(lzc.compress(b''))
cdata.append(lzc.flush())
cdata = b"".join(cdata)
lzd = LZMADecompressor()
self._test_decompressor(lzd, cdata, lzma.CHECK_CRC64)
# LZMADecompressor intentionally does not handle concatenated streams.
示例14: _set_native_compressors_coders
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import LZMACompressor [as 别名]
def _set_native_compressors_coders(self, filters):
self.cchain.add_filter(lzma.LZMACompressor(format=lzma.FORMAT_RAW, filters=filters))
for filter in filters:
self.coders.insert(0, SupportedMethods.get_coder(filter))
示例15: test_lzmadecompressor_lzmabcj
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import LZMACompressor [as 别名]
def test_lzmadecompressor_lzmabcj():
indata = b'This file is located in the root.'
compressor = lzma.LZMACompressor(format=lzma.FORMAT_RAW,
filters=[{'id': lzma.FILTER_X86}, {'id': lzma.FILTER_LZMA1}])
compressed = compressor.compress(indata)
compressed += compressor.flush()
decompressor = lzma.LZMADecompressor(format=lzma.FORMAT_RAW,
filters=[{'id': lzma.FILTER_X86}, {'id': lzma.FILTER_LZMA1}])
outdata = decompressor.decompress(data=compressed)
assert outdata == indata