8000 Update docstring · shadchin/msgpack-python@44bc2bd · GitHub
[go: up one dir, main page]

Skip to content

Commit 44bc2bd

Browse files
committed
Update docstring
1 parent 8fb709f commit 44bc2bd

File tree

3 files changed

+63
-50
lines changed

3 files changed

+63
-50
lines changed

msgpack/_packer.pyx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ cdef class Packer(object):
6363
"""
6464
MessagePack Packer
6565
66-
usage::
66+
Usage::
6767
6868
packer = Packer()
6969
astream.write(packer.pack(a))
@@ -94,6 +94,12 @@ cdef class Packer(object):
9494
This is useful when trying to implement accurate serialization
9595
for python types.
9696
97+
:param bool datetime:
98+
If set to true, datetime with tzinfo is packed into Timestamp type.
99+
Note that the tzinfo is stripped in the timestamp.
100+
You can get UTC datetime with `timestamp=3` option of the Unpacker.
101+
(Python 2 is not supported).
102+
97103
:param str unicode_errors:
98104
The error handler for encoding unicode. (default: 'strict')
99105
DO NOT USE THIS!! This option is kept for very specific usage.

msgpack/_unpacker.pyx

Lines changed: 32 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -212,65 +212,49 @@ def unpackb(object packed, *, object object_hook=None, object list_hook=None,
212212

213213

214214
cdef class Unpacker(object):
215-
"""Streaming unpacker.
216-
217-
Arguments:
218-
219-
:param file_like:
220-
File-like object having `.read(n)` method.
221-
If specified, unpacker reads serialized data from it and :meth:`feed()` is not usable.
222-
223-
:param int read_size:
224-
Used as `file_like.read(read_size)`. (default: `min(1024**2, max_buffer_size)`)
225-
226-
:param bool use_list:
227-
If true, unpack msgpack array to Python list.
228-
Otherwise, unpack to Python tuple. (default: True)
229-
230-
:param bool raw:
231-
If true, unpack msgpack raw to Python bytes.
232-
Otherwise, unpack to Python str by decoding with UTF-8 encoding (default).
215+
"""
216+
MessagePack Packer
233217
234-
:param bool strict_map_key:
235-
If true (default), only str or bytes are accepted for map (dict) keys.
218+
Usage::
236219
237-
:param callable object_hook:
238-
When specified, it should be callable.
239-
Unpacker calls it with a dict argument after unpacking msgpack map.
240-
(See also simplejson)
220+
packer = Packer()
221+
astream.write(packer.pack(a))
222+
astream.write(packer.pack(b))
241223
242-
:param callable object_pairs_hook:
243-
When specified, it should be callable.
244-
Unpacker calls it with a list of key-value pairs after unpacking msgpack map.
245-
(See also simplejson)
224+
Packer's constructor has some keyword arguments:
246225
247-
:param int max_buffer_size:
248-
Limits size of data waiting unpacked. 0 means system's INT_MAX.
249-
The default value is 100*1024*1024 (100MiB).
250-
Raises `BufferFull` exception when it is insufficient.
251-
You should set this parameter when unpacking data from untrusted source.
226+
:param callable default:
227+
Convert user type to builtin type that Packer supports.
228+
See also simplejson's document.
252229
253-
:param int max_str_len:
254-
Deprecated, use *max_buffer_size* instead.
255-
Limits max length of str. (default: max_buffer_size)
230+
:param bool use_single_float:
231+
Use single precision float type for float. (default: False)
256232
257-
:param int max_bin_len:
258-
Deprecated, use *max_buffer_size* instead.
259-
Limits max length of bin. (default: max_buffer_size)
233+
:param bool autoreset:
234+
Reset buffer after each pack and return its content as `bytes`. (default: True).
235+
If set this to false, use `bytes()` to get content and `.reset()` to clear buffer.
260236
261-
:param int max_array_len:
262-
Limits max length of array. (default: max_buffer_size)
237+
:param bool use_bin_type:
238+
Use bin type introduced in msgpack spec 2.0 for bytes.
239+
It also enables str8 type for unicode. (default: True)
263240
264-
:param int max_map_len:
265-
Limits max length of map. (default: max_buffer_size//2)
241+
:param bool strict_types:
242+
If set to true, types will be checked to be exact. Derived classes
243+
from serializable types will not be serialized and will be
244+
treated as unsupported type and forwarded to default.
245+
Additionally tuples will not be serialized as lists.
246+
This is useful when trying to implement accurate serialization
247+
for python types.
266248
267-
:param int max_ext_len:
268-
Deprecated, use *max_buffer_size* instead.
269-
Limits max size of ext type. (default: max_buffer_size)
249+
:param bool datetime:
250+
If set to true, datetime with tzinfo is packed into Timestamp type.
251+
Note that the tzinfo is stripped in the timestamp.
252+
You can get UTC datetime with `timestamp=3` option of the Unpacker.
253+
(Python 2 is not supported).
270254
271255
:param str unicode_errors:
272-
Error handler used for decoding str type. (default: `'strict'`)
273-
256+
The error handler for encoding unicode. (default: 'strict')
257+
DO NOT USE THIS!! This option is kept for very specific usage.
274258
275259
Example of streaming deserialize from file-like object::
276260

msgpack/fallback.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ class Packer(object):
744744
"""
745745
MessagePack Packer
746746
747-
Usage:
747+
Usage::
748748
749749
packer = Packer()
750750
astream.write(packer.pack(a))
@@ -784,6 +784,29 @@ class Packer(object):
784784
:param str unicode_errors:
785785
The error handler for encoding unicode. (default: 'strict')
786786
DO NOT USE THIS!! This option is kept for very specific usage.
787+
788+
Example of streaming deserialize from file-like object::
789+
790+
unpacker = Unpacker(file_like)
791+
for o in unpacker:
792+
process(o)
793+
794+
Example of streaming deserialize from socket::
795+
796+
unpacker = Unpacker()
797+
while True:
798+
buf = sock.recv(1024**2)
799+
if not buf:
800+
break
801+
unpacker.feed(buf)
802+
for o in unpacker:
803+
process(o)
804+
805+
Raises ``ExtraData`` when *packed* contains extra bytes.
806+
Raises ``OutOfData`` when *packed* is incomplete.
807+
Raises ``FormatError`` when *packed* is not valid msgpack.
808+
Raises ``StackError`` when *packed* contains too nested.
809+
Other exceptions can be raised during unpacking.
787810
"""
788811

789812
def __init__(

0 commit comments

Comments
 (0)
0