@@ -39,23 +39,29 @@ cdef int DEFAULT_RECURSE_LIMIT=511
3939
4040
4141cdef class Packer(object ):
42- """ MessagePack Packer
42+ """
43+ MessagePack Packer
4344
44- usage:
45+ usage::
4546
4647 packer = Packer()
4748 astream.write(packer.pack(a))
4849 astream.write(packer.pack(b))
4950
5051 Packer's constructor has some keyword arguments:
5152
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.
5965 """
6066 cdef msgpack_packer pk
6167 cdef object _default
@@ -75,6 +81,8 @@ cdef class Packer(object):
7581 self .pk.length = 0
7682
7783 def __init__ (self , default = None , encoding = ' utf-8' , unicode_errors = ' strict' , use_single_float = False , bint autoreset = 1 ):
84+ """
85+ """
7886 self .use_float = use_single_float
7987 self .autoreset = autoreset
8088 if default is not None :
@@ -218,7 +226,7 @@ cdef class Packer(object):
218226 Pack *pairs* as msgpack map type.
219227
220228 *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.)
222230 """
223231 cdef int ret = msgpack_pack_map(& self .pk, len (pairs))
224232 if ret == 0 :
@@ -245,15 +253,21 @@ cdef class Packer(object):
245253 return PyBytes_FromStringAndSize(self .pk.buf, self .pk.length)
246254
247255
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.
249261 """
250- pack an object `o` and write it to stream)."""
251262 packer = Packer(default = default, encoding = encoding, unicode_errors = unicode_errors)
252263 stream.write(packer.pack(o))
253264
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.
255270 """
256- pack o and return packed bytes."""
257271 packer = Packer(default = default, encoding = encoding, unicode_errors = unicode_errors,
258272 use_single_float = use_single_float)
259273 return packer.pack(o)
0 commit comments