Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apachedex
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Vincent Pelletier
apachedex
Commits
2f4388dd
Commit
2f4388dd
authored
Mar 18, 2019
by
Jérome Perrin
Committed by
Vincent Pelletier
Mar 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wrap lzma.open, so that it supports encoding and errors on py2
parent
10d91ee0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
1 deletion
+14
-1
apachedex/__init__.py
apachedex/__init__.py
+3
-1
apachedex/tests.py
apachedex/tests.py
+11
-0
No files found.
apachedex/__init__.py
View file @
2f4388dd
...
@@ -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 ?
...
...
apachedex/tests.py
View file @
2f4388dd
...
@@ -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"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment