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

Skip to content

Commit da902f9

Browse files
authored
Move unpack() from each implementation to __init__. (msgpack#286)
Fixes msgpack#285
1 parent ae8d469 commit da902f9

File tree

3 files changed

+14
-39
lines changed

3 files changed

+14
-39
lines changed

msgpack/__init__.py

Lines changed: 14 additions & 3 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, unpack, unpackb, Unpacker
22+
from msgpack.fallback import Packer, unpackb, Unpacker
2323
else:
2424
try:
2525
from msgpack._packer import Packer
26-
from msgpack._unpacker import unpack, unpackb, Unpacker
26+
from msgpack._unpacker import unpackb, Unpacker
2727
except ImportError:
28-
from msgpack.fallback import Packer, unpack, unpackb, Unpacker
28+
from msgpack.fallback import Packer, unpackb, Unpacker
2929

3030

3131
def pack(o, stream, **kwargs):
@@ -46,6 +46,17 @@ 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+
4960
# alias for compatibility to simplejson/marshal/pickle.
5061
load = unpack
5162
loads = unpackb

msgpack/_unpacker.pyx

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -211,32 +211,6 @@ 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-
240214
cdef class Unpacker(object):
241215
"""Streaming unpacker.
242216

msgpack/fallback.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,6 @@ 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-
113103

114104
def unpackb(packed, **kwargs):
115105
"""

0 commit comments

Comments
 (0)
0