Update docstring

This commit is contained in:
Inada Naoki 2020-12-04 17:23:09 +09:00
parent 8fb709f2e0
commit 44bc2bd439
3 changed files with 63 additions and 50 deletions

View file

@ -63,7 +63,7 @@ cdef class Packer(object):
""" """
MessagePack Packer MessagePack Packer
usage:: Usage::
packer = Packer() packer = Packer()
astream.write(packer.pack(a)) astream.write(packer.pack(a))
@ -94,6 +94,12 @@ cdef class Packer(object):
This is useful when trying to implement accurate serialization This is useful when trying to implement accurate serialization
for python types. for python types.
:param bool datetime:
If set to true, datetime with tzinfo is packed into Timestamp type.
Note that the tzinfo is stripped in the timestamp.
You can get UTC datetime with `timestamp=3` option of the Unpacker.
(Python 2 is not supported).
:param str unicode_errors: :param str unicode_errors:
The error handler for encoding unicode. (default: 'strict') The error handler for encoding unicode. (default: 'strict')
DO NOT USE THIS!! This option is kept for very specific usage. DO NOT USE THIS!! This option is kept for very specific usage.

View file

@ -212,65 +212,49 @@ def unpackb(object packed, *, object object_hook=None, object list_hook=None,
cdef class Unpacker(object): cdef class Unpacker(object):
"""Streaming unpacker. """
MessagePack Packer
Arguments: Usage::
:param file_like: packer = Packer()
File-like object having `.read(n)` method. astream.write(packer.pack(a))
If specified, unpacker reads serialized data from it and :meth:`feed()` is not usable. astream.write(packer.pack(b))
:param int read_size: Packer's constructor has some keyword arguments:
Used as `file_like.read(read_size)`. (default: `min(1024**2, max_buffer_size)`)
:param bool use_list: :param callable default:
If true, unpack msgpack array to Python list. Convert user type to builtin type that Packer supports.
Otherwise, unpack to Python tuple. (default: True) See also simplejson's document.
:param bool raw: :param bool use_single_float:
If true, unpack msgpack raw to Python bytes. Use single precision float type for float. (default: False)
Otherwise, unpack to Python str by decoding with UTF-8 encoding (default).
:param bool strict_map_key: :param bool autoreset:
If true (default), only str or bytes are accepted for map (dict) keys. Reset buffer after each pack and return its content as `bytes`. (default: True).
If set this to false, use `bytes()` to get content and `.reset()` to clear buffer.
:param callable object_hook: :param bool use_bin_type:
When specified, it should be callable. Use bin type introduced in msgpack spec 2.0 for bytes.
Unpacker calls it with a dict argument after unpacking msgpack map. It also enables str8 type for unicode. (default: True)
(See also simplejson)
:param callable object_pairs_hook: :param bool strict_types:
When specified, it should be callable. If set to true, types will be checked to be exact. Derived classes
Unpacker calls it with a list of key-value pairs after unpacking msgpack map. from serializable types will not be serialized and will be
(See also simplejson) treated as unsupported type and forwarded to default.
Additionally tuples will not be serialized as lists.
This is useful when trying to implement accurate serialization
for python types.
:param int max_buffer_size: :param bool datetime:
Limits size of data waiting unpacked. 0 means system's INT_MAX. If set to true, datetime with tzinfo is packed into Timestamp type.
The default value is 100*1024*1024 (100MiB). Note that the tzinfo is stripped in the timestamp.
Raises `BufferFull` exception when it is insufficient. You can get UTC datetime with `timestamp=3` option of the Unpacker.
You should set this parameter when unpacking data from untrusted source. (Python 2 is not supported).
:param int max_str_len:
Deprecated, use *max_buffer_size* instead.
Limits max length of str. (default: max_buffer_size)
:param int max_bin_len:
Deprecated, use *max_buffer_size* instead.
Limits max length of bin. (default: max_buffer_size)
:param int max_array_len:
Limits max length of array. (default: max_buffer_size)
:param int max_map_len:
Limits max length of map. (default: max_buffer_size//2)
:param int max_ext_len:
Deprecated, use *max_buffer_size* instead.
Limits max size of ext type. (default: max_buffer_size)
:param str unicode_errors: :param str unicode_errors:
Error handler used for decoding str type. (default: `'strict'`) The error handler for encoding unicode. (default: 'strict')
DO NOT USE THIS!! This option is kept for very specific usage.
Example of streaming deserialize from file-like object:: Example of streaming deserialize from file-like object::

View file

@ -744,7 +744,7 @@ class Packer(object):
""" """
MessagePack Packer MessagePack Packer
Usage: Usage::
packer = Packer() packer = Packer()
astream.write(packer.pack(a)) astream.write(packer.pack(a))
@ -784,6 +784,29 @@ class Packer(object):
:param str unicode_errors: :param str unicode_errors:
The error handler for encoding unicode. (default: 'strict') The error handler for encoding unicode. (default: 'strict')
DO NOT USE THIS!! This option is kept for very specific usage. DO NOT USE THIS!! This option is kept for very specific usage.
Example of streaming deserialize from file-like object::
unpacker = Unpacker(file_like)
for o in unpacker:
process(o)
Example of streaming deserialize from socket::
unpacker = Unpacker()
while True:
buf = sock.recv(1024**2)
if not buf:
break
unpacker.feed(buf)
for o in unpacker:
process(o)
Raises ``ExtraData`` when *packed* contains extra bytes.
Raises ``OutOfData`` when *packed* is incomplete.
Raises ``FormatError`` when *packed* is not valid msgpack.
Raises ``StackError`` when *packed* contains too nested.
Other exceptions can be raised during unpacking.
""" """
def __init__( def __init__(