Added support for lzma compression (#984)

* Added support for lzma compression.

* Ignore branch.
This commit is contained in:
Omer Katz 2019-01-10 11:00:37 +02:00 committed by Asif Saif Uddin
parent 9dd7e7ae1f
commit 8c88d9276a
4 changed files with 42 additions and 0 deletions

View File

@ -6,6 +6,15 @@ from kombu.utils.encoding import ensure_bytes
import bz2
import zlib
try:
import lzma
except ImportError: # pragma: no cover
# TODO: Drop fallback to backports once we drop Python 2.7 support
try:
from backports import lzma
except ImportError: # pragma: no cover
lzma = None
_aliases = {}
_encoders = {}
_decoders = {}
@ -85,3 +94,9 @@ else:
register(brotli.compress,
brotli.decompress,
'application/x-brotli', aliases=['brotli'])
# TODO: Drop condition once we drop Python 2.7 support
if lzma: # pragma: no cover
register(lzma.compress,
lzma.decompress,
'application/x-lzma', aliases=['lzma', 'xz'])

View File

@ -0,0 +1 @@
backports.lzma;python_version<"3.3"

View File

@ -1 +1,2 @@
-r extras/sqs.txt
-r extras/lzma.txt

View File

@ -18,6 +18,16 @@ class test_compression:
assert 'application/x-brotli' in compression.encoders()
def test_encoders__lzma(self):
pytest.importorskip('lzma')
assert 'application/x-lzma' in compression.encoders()
def test_encoders__backports_lzma(self):
pytest.importorskip('backports.lzma')
assert 'application/x-lzma' in compression.encoders()
def test_compress__decompress__zlib(self):
text = b'The Quick Brown Fox Jumps Over The Lazy Dog'
c, ctype = compression.compress(text, 'zlib')
@ -37,6 +47,21 @@ class test_compression:
text = b'The Brown Quick Fox Over The Lazy Dog Jumps'
c, ctype = compression.compress(text, 'brotli')
def test_compress__decompress__lzma(self):
pytest.importorskip('lzma')
text = b'The Brown Quick Fox Over The Lazy Dog Jumps'
c, ctype = compression.compress(text, 'lzma')
assert text != c
d = compression.decompress(c, ctype)
assert d == text
def test_compress__decompress__backports_lzma(self):
pytest.importorskip('backports.lzma')
text = b'The Brown Quick Fox Over The Lazy Dog Jumps'
c, ctype = compression.compress(text, 'lzma')
assert text != c
d = compression.decompress(c, ctype)
assert d == text