Skip to content

Commit

Permalink
Drop support for the lzma backport.
Browse files Browse the repository at this point in the history
  • Loading branch information
thedrow authored and auvipy committed Mar 16, 2021
1 parent c7068ef commit 1e20625
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
20 changes: 7 additions & 13 deletions kombu/compression.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
"""Compression utilities."""

from kombu.utils.encoding import ensure_bytes

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
from kombu.utils.encoding import ensure_bytes

_aliases = {}
_encoders = {}
Expand Down Expand Up @@ -82,7 +73,7 @@ def decompress(body, content_type):

try:
import bz2
except ImportError:
except ImportError: # pragma: no cover
pass # No bz2 support
else:
register(bz2.compress,
Expand All @@ -98,8 +89,11 @@ def decompress(body, content_type):
brotli.decompress,
'application/x-brotli', aliases=['brotli'])

# TODO: Drop condition once we drop Python 2.7 support
if lzma: # pragma: no cover
try:
import lzma
except ImportError: # pragma: no cover
pass # no lzma support
else:
register(lzma.compress,
lzma.decompress,
'application/x-lzma', aliases=['lzma', 'xz'])
Expand Down
28 changes: 13 additions & 15 deletions t/unit/test_compression.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

import sys

import pytest
from case import mock

from kombu import compression
Expand All @@ -26,11 +25,6 @@ def test_encoders__lzma(self):

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_encoders__zstd(self):
pytest.importorskip('zstandard')

Expand All @@ -55,18 +49,12 @@ def test_compress__decompress__brotli(self):

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')
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')
Expand All @@ -92,3 +80,13 @@ def test_no_bz2(self):
finally:
if c is not None:
sys.modules['kombu.compression'] = c

@mock.mask_modules('lzma')
def test_no_lzma(self):
c = sys.modules.pop('kombu.compression')
try:
import kombu.compression
assert not hasattr(kombu.compression, 'lzma')
finally:
if c is not None:
sys.modules['kombu.compression'] = c

0 comments on commit 1e20625

Please sign in to comment.