@@ -39,23 +39,29 @@ cdef int DEFAULT_RECURSE_LIMIT=511
39
39
40
40
41
41
cdef class Packer(object ):
42
- """ MessagePack Packer
42
+ """
43
+ MessagePack Packer
43
44
44
- usage:
45
+ usage::
45
46
46
47
packer = Packer()
47
48
astream.write(packer.pack(a))
48
49
astream.write(packer.pack(b))
49
50
50
51
Packer's constructor has some keyword arguments:
51
52
52
- * *defaut* - Convert user type to builtin type that Packer supports.
53
- See also simplejson's document.
54
- * *encoding* - Convert unicode to bytes with this encoding. (default: 'utf-8')
55
- * *unicode_erros* - Error handler for encoding unicode. (default: 'strict')
56
- * *use_single_float* - Use single precision float type for float. (default: False)
57
- * *autoreset* - Reset buffer after each pack and return it's content as `bytes`. (default: True).
58
- If set this to false, use `bytes()` to get content and `.reset()` to clear buffer.
53
+ :param callable default:
54
+ Convert user type to builtin type that Packer supports.
55
+ See also simplejson's document.
56
+ :param str encoding:
57
+ Convert unicode to bytes with this encoding. (default: 'utf-8')
58
+ :param str unicode_erros:
59
+ Error handler for encoding unicode. (default: 'strict')
60
+ :param bool use_single_float:
61
+ Use single precision float type for float. (default: False)
62
+ :param bool autoreset:
63
+ Reset buffer after each pack and return it's content as `bytes`. (default: True).
64
+ If set this to false, use `bytes()` to get content and `.reset()` to clear buffer.
59
65
"""
60
66
cdef msgpack_packer pk
61
67
cdef object _default
@@ -75,6 +81,8 @@ cdef class Packer(object):
75
81
self .pk.length = 0
76
82
77
83
def __init__ (self , default = None , encoding = ' utf-8' , unicode_errors = ' strict' , use_single_float = False , bint autoreset = 1 ):
84
+ """
85
+ """
78
86
self .use_float = use_single_float
79
87
self .autoreset = autoreset
80
88
if default is not None :
@@ -218,7 +226,7 @@ cdef class Packer(object):
218
226
Pack *pairs* as msgpack map type.
219
227
220
228
*pairs* should sequence of pair.
221
- (`len(pairs)` and `for k, v in * pairs* :` should be supported.)
229
+ (`len(pairs)` and `for k, v in pairs:` should be supported.)
222
230
"""
223
231
cdef int ret = msgpack_pack_map(& self .pk, len (pairs))
224
232
if ret == 0 :
@@ -245,15 +253,21 @@ cdef class Packer(object):
245
253
return PyBytes_FromStringAndSize(self .pk.buf, self .pk.length)
246
254
247
255
248
- def pack (object o , object stream , default = None , encoding = ' utf-8' , unicode_errors = ' strict' ):
256
+ def pack (object o , object stream , default = None , str encoding = ' utf-8' , str unicode_errors = ' strict' ):
257
+ """
258
+ pack an object `o` and write it to stream)
259
+
260
+ See :class:`Packer` for options.
249
261
"""
250
- pack an object `o` and write it to stream)."""
251
262
packer = Packer(default = default, encoding = encoding, unicode_errors = unicode_errors)
252
263
stream.write(packer.pack(o))
253
264
254
- def packb (object o , default = None , encoding = ' utf-8' , unicode_errors = ' strict' , use_single_float = False ):
265
+ def packb (object o , default = None , encoding = ' utf-8' , str unicode_errors = ' strict' , bint use_single_float = False ):
266
+ """
267
+ pack o and return packed bytes
268
+
269
+ See :class:`Packer` for options.
255
270
"""
256
- pack o and return packed bytes."""
257
271
packer = Packer(default = default, encoding = encoding, unicode_errors = unicode_errors,
258
272
use_single_float = use_single_float)
259
273
return packer.pack(o)
0 commit comments