@@ -16,6 +16,7 @@ from msgpack.exceptions import (
1616 UnpackValueError,
1717 ExtraData,
1818 )
19+ from msgpack import ExtType
1920
2021
2122cdef extern from " unpack.h" :
@@ -24,7 +25,7 @@ cdef extern from "unpack.h":
2425 PyObject* object_hook
2526 bint has_pairs_hook # call object_hook with k-v pairs
2627 PyObject* list_hook
27- PyObject* ext_type_hook
28+ PyObject* ext_hook
2829 char * encoding
2930 char * unicode_errors
3031
@@ -43,8 +44,8 @@ cdef extern from "unpack.h":
4344 object unpack_data(unpack_context* ctx)
4445
4546cdef inline init_ctx(unpack_context * ctx,
46- object object_hook, object object_pairs_hook, object list_hook,
47- object ext_type_hook ,
47+ object object_hook, object object_pairs_hook,
48+ object list_hook, object ext_hook ,
4849 bint use_list, char * encoding, char * unicode_errors):
4950 unpack_init(ctx)
5051 ctx.user.use_list = use_list
@@ -71,10 +72,10 @@ cdef inline init_ctx(unpack_context *ctx,
7172 raise TypeError (" list_hook must be a callable." )
7273 ctx.user.list_hook = < PyObject* > list_hook
7374
74- if ext_type_hook is not None :
75- if not PyCallable_Check(ext_type_hook ):
76- raise TypeError (" ext_type_hook must be a callable." )
77- ctx.user.ext_type_hook = < PyObject* > ext_type_hook
75+ if ext_hook is not None :
76+ if not PyCallable_Check(ext_hook ):
77+ raise TypeError (" ext_hook must be a callable." )
78+ ctx.user.ext_hook = < PyObject* > ext_hook
7879
7980 ctx.user.encoding = encoding
8081 ctx.user.unicode_errors = unicode_errors
@@ -84,8 +85,7 @@ def default_read_extended_type(typecode, data):
8485
8586def unpackb (object packed , object object_hook = None , object list_hook = None ,
8687 bint use_list = 1 , encoding = None , unicode_errors = " strict" ,
87- object_pairs_hook = None ,
88- ):
88+ object_pairs_hook = None , ext_hook = ExtType):
8989 """
9090 Unpack packed_bytes to object. Returns an unpacked object.
9191
@@ -114,8 +114,8 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
114114 unicode_errors = unicode_errors.encode(' ascii' )
115115 cerr = PyBytes_AsString(unicode_errors)
116116
117- init_ctx(& ctx, object_hook, object_pairs_hook, list_hook, default_read_extended_type ,
118- use_list, cenc, cerr)
117+ init_ctx(& ctx, object_hook, object_pairs_hook, list_hook, ext_hook ,
118+ use_list, cenc, cerr)
119119 ret = unpack_construct(& ctx, buf, buf_len, & off)
120120 if ret == 1 :
121121 obj = unpack_data(& ctx)
@@ -220,7 +220,7 @@ cdef class Unpacker(object):
220220 def __init__ (self , file_like = None , Py_ssize_t read_size = 0 , bint use_list = 1 ,
221221 object object_hook = None , object object_pairs_hook = None , object list_hook = None ,
222222 str encoding = None , str unicode_errors = ' strict' , int max_buffer_size = 0 ,
223- ):
223+ object ext_hook = ExtType ):
224224 cdef char * cenc= NULL , * cerr= NULL
225225
226226 self .file_like = file_like
@@ -257,10 +257,8 @@ cdef class Unpacker(object):
257257 self .unicode_errors = unicode_errors
258258 cerr = PyBytes_AsString(self .unicode_errors)
259259
260- ext_type_hook = self .read_extended_type
261- Py_INCREF(ext_type_hook)
262260 init_ctx(& self .ctx, object_hook, object_pairs_hook, list_hook,
263- ext_type_hook , use_list, cenc, cerr)
261+ ext_hook , use_list, cenc, cerr)
264262
265263 def feed (self , object next_bytes ):
266264 """ Append `next_bytes` to internal buffer."""
@@ -370,24 +368,6 @@ cdef class Unpacker(object):
370368 """
371369 return self ._unpack(unpack_construct, write_bytes)
372370
373- def unpack_one (self , object write_bytes = None ):
374- """
375- unpack one object
376-
377- If write_bytes is not None, it will be called with parts of the raw
378- message as it is unpacked.
379-
380- Raises `UnpackValueError` if there are no more bytes to unpack.
381- Raises ``ExtraData`` if there are still bytes left after the unpacking.
382- """
383- try :
384- result = self .unpack()
385- except OutOfData:
386- raise UnpackValueError(" Data is not enough" )
387- if self .buf_head < self .buf_tail:
388- raise ExtraData(result, self .buf[self .buf_head:])
389- return result
390-
391371 def skip (self , object write_bytes = None ):
392372 """
393373 read and ignore one object, returning None
@@ -415,9 +395,6 @@ cdef class Unpacker(object):
415395 """
416396 return self ._unpack(read_map_header, write_bytes)
417397
418- def read_extended_type (self , typecode , data ):
419- return default_read_extended_type(typecode, data)
420-
421398 def __iter__ (self ):
422399 return self
423400
0 commit comments