11# coding: utf-8
22# cython: embedsignature=True
33
4+ import warnings
5+
46from cpython cimport *
57cdef extern from " Python.h" :
68 ctypedef char * const_char_ptr " const char*"
79 ctypedef char * const_void_ptr " const void*"
810 ctypedef struct PyObject
911 cdef int PyObject_AsReadBuffer(object o, const_void_ptr* buff, Py_ssize_t* buf_len) except - 1
12+ char * __FILE__
13+ int __LINE__
1014
1115from libc.stdlib cimport *
1216from libc.string cimport *
@@ -195,7 +199,7 @@ def packb(object o, default=None, encoding='utf-8', unicode_errors='strict', use
195199
196200cdef extern from " unpack.h" :
197201 ctypedef struct msgpack_user:
198- int use_list
202+ bint use_list
199203 PyObject* object_hook
200204 PyObject* list_hook
201205 char * encoding
@@ -215,7 +219,7 @@ cdef extern from "unpack.h":
215219
216220
217221def unpackb (object packed , object object_hook = None , object list_hook = None ,
218- bint use_list = 0 , encoding = None , unicode_errors = " strict" ,
222+ use_list = None , encoding = None , unicode_errors = " strict" ,
219223 ):
220224 """ Unpack packed_bytes to object. Returns an unpacked object.
221225
@@ -227,6 +231,7 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
227231
228232 cdef char * buf
229233 cdef Py_ssize_t buf_len
234+
230235 PyObject_AsReadBuffer(packed, < const_void_ptr* > & buf, & buf_len)
231236
232237 if encoding is None :
@@ -245,7 +250,11 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
245250 err = PyBytes_AsString(berrors)
246251
247252 template_init(& ctx)
248- ctx.user.use_list = use_list
253+ if use_list is None :
254+ warnings.warn(" Set use_list explicitly." , category = DeprecationWarning , stacklevel = 1 )
255+ ctx.user.use_list = 0
256+ else :
257+ ctx.user.use_list = use_list
249258 ctx.user.object_hook = ctx.user.list_hook = NULL
250259 ctx.user.encoding = < const_char_ptr> enc
251260 ctx.user.unicode_errors = < const_char_ptr> err
@@ -268,12 +277,15 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
268277
269278
270279def unpack (object stream , object object_hook = None , object list_hook = None ,
271- bint use_list = 0 , encoding = None , unicode_errors = " strict" ,
280+ use_list = None , encoding = None , unicode_errors = " strict" ,
272281 ):
273282 """ Unpack an object from `stream`.
274283
275284 Raises `ValueError` when `stream` has extra bytes.
276285 """
286+ if use_list is None :
287+ warnings.warn(" Set use_list explicitly." , category = DeprecationWarning , stacklevel = 1 )
288+ use_list = 0
277289 return unpackb(stream.read(), use_list = use_list,
278290 object_hook = object_hook, list_hook = list_hook,
279291 encoding = encoding, unicode_errors = unicode_errors,
@@ -292,7 +304,7 @@ cdef class Unpacker(object):
292304 (default: min(1024**2, max_buffer_size))
293305
294306 If `use_list` is true, msgpack list is deserialized to Python list.
295- Otherwise, it is deserialized to Python tuple. (default: False)
307+ Otherwise, it is deserialized to Python tuple.
296308
297309 `object_hook` is same to simplejson. If it is not None, it should be callable
298310 and Unpacker calls it when deserializing key-value.
@@ -330,7 +342,6 @@ cdef class Unpacker(object):
330342 cdef object file_like
331343 cdef object file_like_read
332344 cdef Py_ssize_t read_size
333- cdef bint use_list
334345 cdef object object_hook
335346 cdef object _bencoding
336347 cdef object _berrors
@@ -345,12 +356,15 @@ cdef class Unpacker(object):
345356 free(self .buf)
346357 self .buf = NULL
347358
348- def __init__ (self , file_like = None , Py_ssize_t read_size = 0 , bint use_list = 0 ,
359+ def __init__ (self , file_like = None , Py_ssize_t read_size = 0 , use_list = None ,
349360 object object_hook = None , object list_hook = None ,
350361 encoding = None , unicode_errors = ' strict' , int max_buffer_size = 0 ,
351362 object object_pairs_hook = None ,
352363 ):
353- self .use_list = use_list
364+ if use_list is None :
365+ warnings.warn(" Set use_list explicitly." , category = DeprecationWarning , stacklevel = 1 )
366+ use_list = 0
367+
354368 self .file_like = file_like
355369 if file_like:
356370 self .file_like_read = file_like.read
0 commit comments