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): ...@@ -83,6 +83,7 @@ def _wrapOpen(func):
gzip_open = gzip.open gzip_open = gzip.open
if sys.version_info >= (3, 3): if sys.version_info >= (3, 3):
import lzma import lzma
lzma_open = lzma.open
bz2_open = bz2.open bz2_open = bz2.open
_read_mode = 'rt' _read_mode = 'rt'
else: else:
...@@ -91,6 +92,7 @@ else: ...@@ -91,6 +92,7 @@ else:
_read_mode = 'r' _read_mode = 'r'
try: try:
from backports import lzma from backports import lzma
lzma_open = _wrapOpen(lzma.open)
except ImportError: except ImportError:
lzma = None lzma = None
...@@ -99,7 +101,7 @@ FILE_OPENER_LIST = [ ...@@ -99,7 +101,7 @@ FILE_OPENER_LIST = [
(bz2_open, IOError), (bz2_open, IOError),
] ]
if lzma is not None: 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 # XXX: what encoding ? apache doesn't document one, but requests are supposed
# to be urlencoded, so pure ascii. Are timestamps localised ? # to be urlencoded, so pure ascii. Are timestamps localised ?
......
...@@ -6,6 +6,7 @@ import gzip ...@@ -6,6 +6,7 @@ import gzip
from StringIO import StringIO from StringIO import StringIO
import tempfile import tempfile
import apachedex import apachedex
from . import lzma
class ApacheDEXTestCase(unittest.TestCase): class ApacheDEXTestCase(unittest.TestCase):
...@@ -89,3 +90,13 @@ class TestZlibEncoding(ApacheDEXTestCase, EncodedInputTestMixin): ...@@ -89,3 +90,13 @@ class TestZlibEncoding(ApacheDEXTestCase, EncodedInputTestMixin):
with gzip.GzipFile(mode="w", fileobj=f) as gzfile: with gzip.GzipFile(mode="w", fileobj=f) as gzfile:
gzfile.write(self.DEFAULT_LINE) gzfile.write(self.DEFAULT_LINE)
return f.getvalue() 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