8000 Revert "Move unpack() from each implementation to __init__. (#286)" · guoyu07/msgpack-python@9455fcc · GitHub
[go: up one dir, main page]

Skip to content

Commit 9455fcc

Browse files
authored
Revert "Move unpack() from each implementation to __init__. (msgpack#286)"
This reverts commit da902f9.
1 parent 9bf3810 commit 9455fcc

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

msgpack/__init__.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ def __new__(cls, code, data):
1919

2020
import os
2121
if os.environ.get('MSGPACK_PUREPYTHON'):
22-
from msgpack.fallback import Packer, unpackb, Unpacker
22+
from msgpack.fallback import Packer, unpack, unpackb, Unpacker
2323
else:
2424
try:
2525
from msgpack._packer import Packer
26-
from msgpack._unpacker import unpackb, Unpacker
26+
from msgpack._unpacker import unpack, unpackb, Unpacker
2727
except ImportError:
28-
from msgpack.fallback import Packer, unpackb, Unpacker
28+
from msgpack.fallback import Packer, unpack, unpackb, Unpacker
2929

3030

3131
def pack(o, stream, **kwargs):
@@ -46,17 +46,6 @@ def packb(o, **kwargs):
4646
"""
4747
return Packer(**kwargs).pack(o)
4848

49-
50-
def unpack(stream, **kwargs):
51-
"""
52-
Unpack an object from `stream`.
53-
54-
Raises `ExtraData` when `packed` contains extra bytes.
55-
See :class:`Unpacker` for options.
56-
"""
57-
return unpackb(stream.read(), **kwargs)
58-
59-
6049
# alias for compatibility to simplejson/marshal/pickle.
6150
load = unpack
6251
loads = unpackb

msgpack/_unpacker.pyx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,32 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
211211
raise UnpackValueError("Unpack failed: error = %d" % (ret,))
212212

213213

214+
def unpack(object stream, object object_hook=None, object list_hook=None,
215+
bint use_list=1, encoding=None, unicode_errors=None,
216+
object_pairs_hook=None, ext_hook=ExtType,
217+
Py_ssize_t max_str_len=2147483647, # 2**32-1
218+
Py_ssize_t max_bin_len=2147483647,
219+
Py_ssize_t max_array_len=2147483647,
220+
Py_ssize_t max_map_len=2147483647,
221+
Py_ssize_t max_ext_len=2147483647):
222+
"""
223+
Unpack an object from `stream`.
224+
225+
Raises `ValueError` when `stream` has extra bytes.
226+
227+
See :class:`Unpacker` for options.
228+
"""
229+
return unpackb(stream.read(), use_list=use_list,
230+
object_hook=object_hook, object_pairs_hook=object_pairs_hook, list_hook=list_hook,
231+
encoding=encoding, unicode_errors=unicode_errors, ext_hook=ext_hook,
232+
max_str_len=max_str_len,
233+
max_bin_len=max_bin_len,
234+
max_array_len=max_array_len,
235+
max_map_len=max_map_len,
236+
max_ext_len=max_ext_len,
237+
)
238+
239+
214240
cdef class Unpacker(object):
215241
"""Streaming unpacker.
216242

msgpack/fallback.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ def _get_data_from_buffer(obj):
100100
return view
101101

102102

103+
def unpack(stream, **kwargs):
104+
"""
105+
Unpack an object from `stream`.
106+
107+
Raises `ExtraData` when `packed` contains extra bytes.
108+
See :class:`Unpacker` for options.
109+
"""
110+
data = stream.read()
111+
return unpackb(data, **kwargs)
112+
103113

104114
def unpackb(packed, **kwargs):
105115
"""

0 commit comments

Comments
 (0)
0