mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-22 21:33:17 +00:00
parent
ae8d469482
commit
da902f9c1d
3 changed files with 14 additions and 39 deletions
|
@ -19,13 +19,13 @@ class ExtType(namedtuple('ExtType', 'code data')):
|
||||||
|
|
||||||
import os
|
import os
|
||||||
if os.environ.get('MSGPACK_PUREPYTHON'):
|
if os.environ.get('MSGPACK_PUREPYTHON'):
|
||||||
from msgpack.fallback import Packer, unpack, unpackb, Unpacker
|
from msgpack.fallback import Packer, unpackb, Unpacker
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
from msgpack._packer import Packer
|
from msgpack._packer import Packer
|
||||||
from msgpack._unpacker import unpack, unpackb, Unpacker
|
from msgpack._unpacker import unpackb, Unpacker
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from msgpack.fallback import Packer, unpack, unpackb, Unpacker
|
from msgpack.fallback import Packer, unpackb, Unpacker
|
||||||
|
|
||||||
|
|
||||||
def pack(o, stream, **kwargs):
|
def pack(o, stream, **kwargs):
|
||||||
|
@ -46,6 +46,17 @@ def packb(o, **kwargs):
|
||||||
"""
|
"""
|
||||||
return Packer(**kwargs).pack(o)
|
return Packer(**kwargs).pack(o)
|
||||||
|
|
||||||
|
|
||||||
|
def unpack(stream, **kwargs):
|
||||||
|
"""
|
||||||
|
Unpack an object from `stream`.
|
||||||
|
|
||||||
|
Raises `ExtraData` when `packed` contains extra bytes.
|
||||||
|
See :class:`Unpacker` for options.
|
||||||
|
"""
|
||||||
|
return unpackb(stream.read(), **kwargs)
|
||||||
|
|
||||||
|
|
||||||
# alias for compatibility to simplejson/marshal/pickle.
|
# alias for compatibility to simplejson/marshal/pickle.
|
||||||
load = unpack
|
load = unpack
|
||||||
loads = unpackb
|
loads = unpackb
|
||||||
|
|
|
@ -211,32 +211,6 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
|
||||||
raise UnpackValueError("Unpack failed: error = %d" % (ret,))
|
raise UnpackValueError("Unpack failed: error = %d" % (ret,))
|
||||||
|
|
||||||
|
|
||||||
def unpack(object stream, object object_hook=None, object list_hook=None,
|
|
||||||
bint use_list=1, encoding=None, unicode_errors=None,
|
|
||||||
object_pairs_hook=None, ext_hook=ExtType,
|
|
||||||
Py_ssize_t max_str_len=2147483647, # 2**32-1
|
|
||||||
Py_ssize_t max_bin_len=2147483647,
|
|
||||||
Py_ssize_t max_array_len=2147483647,
|
|
||||||
Py_ssize_t max_map_len=2147483647,
|
|
||||||
Py_ssize_t max_ext_len=2147483647):
|
|
||||||
"""
|
|
||||||
Unpack an object from `stream`.
|
|
||||||
|
|
||||||
Raises `ValueError` when `stream` has extra bytes.
|
|
||||||
|
|
||||||
See :class:`Unpacker` for options.
|
|
||||||
"""
|
|
||||||
return unpackb(stream.read(), use_list=use_list,
|
|
||||||
object_hook=object_hook, object_pairs_hook=object_pairs_hook, list_hook=list_hook,
|
|
||||||
encoding=encoding, unicode_errors=unicode_errors, ext_hook=ext_hook,
|
|
||||||
max_str_len=max_str_len,
|
|
||||||
max_bin_len=max_bin_len,
|
|
||||||
max_array_len=max_array_len,
|
|
||||||
max_map_len=max_map_len,
|
|
||||||
max_ext_len=max_ext_len,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
cdef class Unpacker(object):
|
cdef class Unpacker(object):
|
||||||
"""Streaming unpacker.
|
"""Streaming unpacker.
|
||||||
|
|
||||||
|
|
|
@ -100,16 +100,6 @@ def _get_data_from_buffer(obj):
|
||||||
return view
|
return view
|
||||||
|
|
||||||
|
|
||||||
def unpack(stream, **kwargs):
|
|
||||||
"""
|
|
||||||
Unpack an object from `stream`.
|
|
||||||
|
|
||||||
Raises `ExtraData` when `packed` contains extra bytes.
|
|
||||||
See :class:`Unpacker` for options.
|
|
||||||
"""
|
|
||||||
data = stream.read()
|
|
||||||
return unpackb(data, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
def unpackb(packed, **kwargs):
|
def unpackb(packed, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue