Added optional support for brotli compression (#983)

* Added optional support for brotli compression.

* Ignore import error for coverage purposes.
This commit is contained in:
Omer Katz 2019-01-09 19:05:02 +02:00 committed by GitHub
parent fa0cb19d27
commit 93a05f7261
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 0 deletions

View File

@ -76,3 +76,12 @@ register(zlib.compress,
register(bz2.compress,
bz2.decompress,
'application/x-bz2', aliases=['bzip2', 'bzip'])
try:
import brotli
except ImportError: # pragma: no cover
pass
else:
register(brotli.compress,
brotli.decompress,
'application/x-brotli', aliases=['brotli'])

View File

@ -0,0 +1,2 @@
brotlipy>=0.7.0;python_implementation=="PyPy"
brotli>=1.0.0;python_implementation=="CPython"

View File

@ -9,4 +9,5 @@ msgpack-python>0.2.0
-r extras/consul.txt
-r extras/librabbitmq.txt
-r extras/zookeeper.txt
-r extras/brotli.txt
sqlalchemy

View File

@ -1,5 +1,7 @@
from __future__ import absolute_import, unicode_literals
import pytest
from kombu import compression
@ -11,6 +13,11 @@ class test_compression:
def test_encoders__bz2(self):
assert 'application/x-bz2' in compression.encoders()
def test_encoders__brotli(self):
pytest.importorskip('brotli')
assert 'application/x-brotli' 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')
@ -24,3 +31,12 @@ class test_compression:
assert text != c
d = compression.decompress(c, ctype)
assert d == text
def test_compress__decompress__brotli(self):
pytest.importorskip('brotli')
text = b'The Brown Quick Fox Over The Lazy Dog Jumps'
c, ctype = compression.compress(text, 'brotli')
assert text != c
d = compression.decompress(c, ctype)
assert d == text