Commit 2f4388dd authored by Jérome Perrin's avatar Jérome Perrin Committed by Vincent Pelletier

wrap lzma.open, so that it supports encoding and errors on py2

parent 10d91ee0
......@@ -83,6 +83,7 @@ def _wrapOpen(func):
gzip_open = gzip.open
if sys.version_info >= (3, 3):
import lzma
lzma_open = lzma.open
bz2_open = bz2.open
_read_mode = 'rt'
else:
......@@ -91,6 +92,7 @@ else:
_read_mode = 'r'
try:
from backports import lzma
lzma_open = _wrapOpen(lzma.open)
except ImportError:
lzma = None
......@@ -99,7 +101,7 @@ FILE_OPENER_LIST = [
(bz2_open, IOError),
]
if lzma is not None:
FILE_OPENER_LIST.append((lzma.open, lzma.LZMAError))
FILE_OPENER_LIST.append((lzma_open, lzma.LZMAError))
# XXX: what encoding ? apache doesn't document one, but requests are supposed
# to be urlencoded, so pure ascii. Are timestamps localised ?
......
......@@ -6,6 +6,7 @@ import gzip
from StringIO import StringIO
import tempfile
import apachedex
from . import lzma
class ApacheDEXTestCase(unittest.TestCase):
......@@ -89,3 +90,13 @@ class TestZlibEncoding(ApacheDEXTestCase, EncodedInputTestMixin):
with gzip.GzipFile(mode="w", fileobj=f) as gzfile:
gzfile.write(self.DEFAULT_LINE)
return f.getvalue()
if lzma is not None:
class TestLzmaEncoding(ApacheDEXTestCase, EncodedInputTestMixin):
def _getInputData(self):
return lzma.compress(self.DEFAULT_LINE)
else:
class TestLzmaEncoding(ApacheDEXTestCase):
def test(self):
self.skipTest("lzma not available")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment