Skip to content

Commit 2985f4d

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

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

.travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ language: python
77
python:
88
- 2.7
99

10+
env:
11+
- TOXENV=py26-c,py27-c
12+
- TOXENV=py32-c,py33-c,py34-c
13+
- TOXENV=py26-pure,py27-pure
14+
- TOXENV=py32-pure,py33-pure,py34-pure
15+
- TOXENV=pypy-pure,pypy3-pure
16+
1017
install:
1118
- pip install wheel tox
1219
- ls -la wheelhouse

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(unicode_errors, 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)