@@ -81,9 +81,12 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
81
81
bint use_list = 1 , encoding = None , unicode_errors = " strict" ,
82
82
object_pairs_hook = None ,
83
83
):
84
- """ Unpack packed_bytes to object. Returns an unpacked object.
84
+ """
85
+ Unpack packed_bytes to object. Returns an unpacked object.
85
86
86
87
Raises `ValueError` when `packed` contains extra bytes.
88
+
89
+ See :class:`Unpacker` for options.
87
90
"""
88
91
cdef template_context ctx
89
92
cdef size_t off = 0
@@ -121,9 +124,12 @@ def unpack(object stream, object object_hook=None, object list_hook=None,
121
124
bint use_list = 1 , encoding = None , unicode_errors = " strict" ,
122
125
object_pairs_hook = None ,
123
126
):
124
- """ Unpack an object from `stream`.
127
+ """
128
+ Unpack an object from `stream`.
125
129
126
130
Raises `ValueError` when `stream` has extra bytes.
131
+
132
+ See :class:`Unpacker` for options.
127
133
"""
128
134
return unpackb(stream.read(), use_list = use_list,
129
135
object_hook = object_hook, object_pairs_hook = object_pairs_hook, list_hook = list_hook,
@@ -135,48 +141,58 @@ cdef class Unpacker(object):
135
141
"""
136
142
Streaming unpacker.
137
143
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.
141
149
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)` )
144
152
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)
147
156
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)
150
161
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)
153
166
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.
156
170
157
- `unicode_errors` is used for decoding bytes.
171
+ :param str unicode_errors:
172
+ Used for decoding msgpack raw with *encoding*.
173
+ (default: `'strict'`)
158
174
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.
163
179
164
180
example of streaming deserialize from file-like object::
165
181
166
182
unpacker = Unpacker(file_like)
167
183
for o in unpacker:
168
- do_something (o)
184
+ process (o)
169
185
170
186
example of streaming deserialize from socket::
171
187
172
188
unpacker = Unpacker()
173
- while 1 :
189
+ while True :
174
190
buf = sock.recv(1024**2)
175
191
if not buf:
176
192
break
177
193
unpacker.feed(buf)
178
194
for o in unpacker:
179
- do_something (o)
195
+ process (o)
180
196
"""
181
197
cdef template_context ctx
182
198
cdef char * buf
@@ -197,7 +213,7 @@ cdef class Unpacker(object):
197
213
198
214
def __init__ (self , file_like = None , Py_ssize_t read_size = 0 , bint use_list = 1 ,
199
215
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 ,
201
217
):
202
218
cdef char * cenc= NULL , * cerr= NULL
203
219
0 commit comments