summaryrefslogtreecommitdiff
path: root/msgpack/_unpacker.pyx
diff options
context:
space:
mode:
authorINADA Naoki <songofacandy@gmail.com>2015-01-25 02:24:53 +0900
committerINADA Naoki <songofacandy@gmail.com>2015-01-25 02:35:57 +0900
commit2985f4d8651982b07e2cfa7037e7a8c3530a127b (patch)
tree8069223d23b98bfac8af3563e3204e8306fec1b0 /msgpack/_unpacker.pyx
parent75ce78dd1512460712f2600ffd927bedeeb02fbc (diff)
downloadmsgpack-python-2985f4d8651982b07e2cfa7037e7a8c3530a127b.tar.gz
Fix error when use unicode_literal in Python 2
Diffstat (limited to 'msgpack/_unpacker.pyx')
-rw-r--r--msgpack/_unpacker.pyx10
1 files changed, 7 insertions, 3 deletions
diff --git a/msgpack/_unpacker.pyx b/msgpack/_unpacker.pyx
index a9770d4..f5e7d95 100644
--- a/msgpack/_unpacker.pyx
+++ b/msgpack/_unpacker.pyx
@@ -251,7 +251,7 @@ cdef class Unpacker(object):
def __init__(self, file_like=None, Py_ssize_t read_size=0, bint use_list=1,
object object_hook=None, object object_pairs_hook=None, object list_hook=None,
- str encoding=None, str unicode_errors='strict', int max_buffer_size=0,
+ encoding=None, unicode_errors='strict', int max_buffer_size=0,
object ext_hook=ExtType,
Py_ssize_t max_str_len=2147483647, # 2**32-1
Py_ssize_t max_bin_len=2147483647,
@@ -289,15 +289,19 @@ cdef class Unpacker(object):
if encoding is not None:
if isinstance(encoding, unicode):
self.encoding = encoding.encode('ascii')
- else:
+ elif isinstance(encoding, bytes):
self.encoding = encoding
+ else:
+ raise TypeError("encoding should be bytes or unicode")
cenc = PyBytes_AsString(self.encoding)
if unicode_errors is not None:
if isinstance(unicode_errors, unicode):
self.unicode_errors = unicode_errors.encode('ascii')
- else:
+ elif isinstance(unicode_errors, bytes):
self.unicode_errors = unicode_errors
+ else:
+ raise TypeError("unicode_errors should be bytes or unicode")
cerr = PyBytes_AsString(self.unicode_errors)
init_ctx(&self.ctx, object_hook, object_pairs_hook, list_hook,