8000 docs: better unpacker docstring. · peter80/msgpack-python@8e13598 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e13598

Browse files
committed
docs: better unpacker docstring.
1 parent 3ce005c commit 8e13598

File tree

3 files changed

+46
-24
lines changed

3 files changed

+46
-24
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ all: cython
66
doc-serve: all
77
cd docs && make serve
88

9+
doc:
10+
cd docs && make zip
11+
912
cython:
1013
cython msgpack/*.pyx
1114

docs/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,6 @@ doctest:
154154

155155
serve: html
156156
cd _build/html && python3.3 -m http.server
157+
158+
zip: html
159+
cd _build/html && zip -r ../../../msgpack-doc.zip .

msgpack/_unpacker.pyx

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,12 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
8181
bint use_list=1, encoding=None, unicode_errors="strict",
8282
object_pairs_hook=None,
8383
):
84-
"""Unpack packed_bytes to object. Returns an unpacked object.
84+
"""
85+
Unpack packed_bytes to object. Returns an unpacked object.
8586
8687
Raises `ValueError` when `packed` contains extra bytes.
88+
89+
See :class:`Unpacker` for options.
8790
"""
8891
cdef template_context ctx
8992
cdef size_t off = 0
@@ -121,9 +124,12 @@ def unpack(object stream, object object_hook=None, object list_hook=None,
121124
bint use_list=1, encoding=None, unicode_errors="strict",
122125
object_pairs_hook=None,
123126
):
124-
"""Unpack an object from `stream`.
127+
"""
128+
Unpack an object from `stream`.
125129
126130
Raises `ValueError` when `stream` has extra bytes.
131+
132+
See :class:`Unpacker` for options.
127133
"""
128134
return unpackb(stream.read(), use_list=use_list,
129135
object_hook=object_hook, object_pairs_hook=object_pairs_hook, list_hook=list_hook,
@@ -135,48 +141,58 @@ cdef class Unpacker(object):
135141
"""
136142
Streaming unpacker.
137143
138-
`file_like` is a file-like object having `.read(n)` method.
139-
When `Unpacker` initialized with `file_like`, unpacker reads serialized data
140-
from it and `.feed()` method is not usable.
144+
arguments:
145+
146+
:param file_like:
147+
File-like object having `.read(n)` method.
148+
If specified, unpacker reads serialized data from it and :meth:`feed()` is not usable.
141149
142-
`read_size` is used as `file_like.read(read_size)`.
143-
(default: min(1024**2, max_buffer_size))
150+
:param int read_size:
151+
Used as `file_like.read(read_size)`. (default: `min(1024**2, max_buffer_size)`)
144152
145-
If `use_list` is true (default), msgpack list is deserialized to Python list.
146-
Otherwise, it is deserialized to Python tuple.
153+
:param bool use_list:
154+
If true, unpack msgpack array to Python list.
155+
Otherwise, unpack to Python tuple. (default: True)
147156
148-
`object_hook` is same to simplejson. If it is not None, it should be callable
149-
and Unpacker calls it with a dict argument after deserializing a map.
157+
:param callable object_hook:
158+
When specified, it should be callable.
159+
Unpacker calls it with a dict argument after unpacking msgpack map.
160+
(See also simplejson)
150161
151-
`object_pairs_hook` is same to simplejson. If it is not None, it should be callable
152-
and Unpacker calls it with a list of key-value pairs after deserializing a map.
162+
:param callable object_pairs_hook:
163+
When specified, it should be callable.
164+
Unpacker calls it with a list of key-value pairs after unpacking msgpack map.
165+
(See also simplejson)
153166
154-
`encoding` is encoding used for decoding msgpack bytes. If it is None (default),
155-
msgpack bytes is deserialized to Python bytes.
167+
:param str encoding:
168+
Encoding used for decoding msgpack raw.
169+
If it is None (default), msgpack raw is deserialized to Python bytes.
156170
157-
`unicode_errors` is used for decoding bytes.
171+
:param str unicode_errors:
172+
Used for decoding msgpack raw with *encoding*.
173+
(default: `'strict'`)
158174
159-
`max_buffer_size` limits size of data waiting unpacked.
160-
0 means system's INT_MAX (default).
161-
Raises `BufferFull` exception when it is insufficient.
162-
You shoud set this parameter when unpacking data from untrasted source.
175+
:param int max_buffer_size:
176+
Limits size of data waiting unpacked. 0 means system's INT_MAX (default).
177+
Raises `BufferFull` exception when it is insufficient.
178+
You shoud set this parameter when unpacking data from untrasted source.
163179
164180
example of streaming deserialize from file-like object::
165181
166182
unpacker = Unpacker(file_like)
167183
for o in unpacker:
168-
do_something(o)
184+
process(o)
169185
170186
example of streaming deserialize from socket::
171187
172188
unpacker = Unpacker()
173-
while 1:
189+
while True:
174190
buf = sock.recv(1024**2)
175191
if not buf:
176192
break
177193
unpacker.feed(buf)
178194
for o in unpacker:
179-
do_something(o)
195+
process(o)
180196
"""
181197
cdef template_context ctx
182198
cdef char* buf
@@ -197,7 +213,7 @@ cdef class Unpacker(object):
197213

198214
def __init__(self, file_like=None, Py_ssize_t read_size=0, bint use_list=1,
199215
object object_hook=None, object object_pairs_hook=None, object list_hook=None,
200-
encoding=None, unicode_errors='strict', int max_buffer_size=0,
216+
str encoding=None, str unicode_errors='strict', int max_buffer_size=0,
201217
):
202218
cdef char *cenc=NULL, *cerr=NULL
203219

0 commit comments

Comments
 (0)
0