Skip to content

Commit 05de74f

Browse files
committed
Fix error when use unicode_literal in Python 2
1 parent 75ce78d commit 05de74f

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ install:
1414
- pip install wheelhouse/Cython-0.21.2-cp27-none-linux_x86_64.whl
1515
- cython --cplus msgpack/_packer.pyx msgpack/_unpacker.pyx
1616

17-
script: tox
17+
script: tox -e py26-c,py26-pure,py27-c,py27-pure,py32-c,py32-pure,py33-c,py33-pure,py34-c,py34-pure,pypy-pure,pypy3-pure

msgpack/_unpacker.pyx

+7-3
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ cdef class Unpacker(object):
251251

252252
def __init__(self, file_like=None, Py_ssize_t read_size=0, bint use_list=1,
253253
object object_hook=None, object object_pairs_hook=None, object list_hook=None,
254-
str encoding=None, str unicode_errors='strict', int max_buffer_size=0,
254+
encoding=None, unicode_errors='strict', int max_buffer_size=0,
255255
object ext_hook=ExtType,
256256
Py_ssize_t max_str_len=2147483647, # 2**32-1
257257
Py_ssize_t max_bin_len=2147483647,
@@ -289,15 +289,19 @@ cdef class Unpacker(object):
289289
if encoding is not None:
290290
if isinstance(encoding, unicode):
291291
self.encoding = encoding.encode('ascii')
292-
else:
292+
elif isinstance(encoding, bytes):
293293
self.encoding = encoding
294+
else:
295+
raise TypeError("encoding should be bytes or unicode")
294296
cenc = PyBytes_AsString(self.encoding)
295297

296298
if unicode_errors is not None:
297299
if isinstance(unicode_errors, unicode):
298300
self.unicode_errors = unicode_errors.encode('ascii')
299-
else:
301+
elif isinstance(encoding, bytes)
300302
self.unicode_errors = unicode_errors
303+
else:
304+
raise TypeError("unicode_errors should be bytes or unicode")
301305
cerr = PyBytes_AsString(self.unicode_errors)
302306

303307
init_ctx(&self.ctx, object_hook, object_pairs_hook, list_hook,

tox.ini

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = {py26,py27,py32,py33,py34}-{c,pure},{pypy,pypy3}-pure
2+
envlist = {py26,py27,py32,py33,py34}-{c,pure},{pypy,pypy3}-pure,py27-x86,py34-x86
33

44
[variants:pure]
55
setenv=
@@ -11,6 +11,29 @@ deps=
1111

1212
changedir=test
1313
commands=
14-
c: python -c 'from msgpack import _packer, _unpacker'
15-
c: py.test
14+
c,x86: python -c 'from msgpack import _packer, _unpacker'
15+
c,x86: py.test
1616
pure: py.test
17+
18+
[testenv:py27-x86]
19+
basepython=python2.7-x86
20+
deps=
21+
pytest
22+
23+
changedir=test
24+
commands=
25+
python -c 'import sys; print(hex(sys.maxsize))'
26+
python -c 'from msgpack import _packer, _unpacker'
27+
py.test
28+
29+
[testenv:py34-x86]
30+
basepython=python3.4-x86
31+
deps=
32+
pytest
33+
34+
changedir=test
35+
commands=
36+
python -c 'import sys; print(hex(sys.maxsize))'
37+
python -c 'from msgpack import _packer, _unpacker'
38+
py.test
39+

0 commit comments

Comments
 (0)