mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-20 12:23:16 +00:00
fallback: refactor
This commit is contained in:
parent
230537cf28
commit
1e38bfa123
1 changed files with 28 additions and 30 deletions
|
@ -60,46 +60,44 @@ TYPE_RAW = 3
|
||||||
|
|
||||||
DEFAULT_RECURSE_LIMIT=511
|
DEFAULT_RECURSE_LIMIT=511
|
||||||
|
|
||||||
def pack(o, stream, default=None, encoding='utf-8', unicode_errors='strict'):
|
def pack(o, stream, **kwargs):
|
||||||
""" Pack object `o` and write it to `stream` """
|
"""
|
||||||
packer = Packer(default=default, encoding=encoding,
|
Pack object `o` and write it to `stream`
|
||||||
unicode_errors=unicode_errors)
|
|
||||||
|
See :class:`Packer` for options.
|
||||||
|
"""
|
||||||
|
packer = Packer(**kwargs)
|
||||||
stream.write(packer.pack(o))
|
stream.write(packer.pack(o))
|
||||||
|
|
||||||
def packb(o, default=None, encoding='utf-8', unicode_errors='struct',
|
def packb(o, **kwargs):
|
||||||
use_single_float=False):
|
"""
|
||||||
""" Pack object `o` and return packed bytes """
|
Pack object `o` and return packed bytes
|
||||||
packer = Packer(default=default,
|
|
||||||
encoding=encoding,
|
|
||||||
unicode_errors=unicode_errors,
|
|
||||||
use_single_float=use_single_float)
|
|
||||||
return packer.pack(o)
|
|
||||||
|
|
||||||
def unpack(stream, object_hook=None, list_hook=None, use_list=True,
|
See :class:`Packer` for options.
|
||||||
encoding=None, unicode_errors='strict',
|
"""
|
||||||
object_pairs_hook=None):
|
return Packer(**kwargs).pack(o)
|
||||||
""" Unpack an object from `stream`.
|
|
||||||
|
|
||||||
Raises `ExtraData` when `stream` has extra bytes. """
|
def unpack(stream, **kwargs):
|
||||||
unpacker = Unpacker(stream, object_hook=object_hook, list_hook=list_hook,
|
"""
|
||||||
use_list=use_list,
|
Unpack an object from `stream`.
|
||||||
encoding=encoding, unicode_errors=unicode_errors,
|
|
||||||
object_pairs_hook=object_pairs_hook)
|
Raises `ExtraData` when `packed` contains extra bytes.
|
||||||
|
See :class:`Unpacker` for options.
|
||||||
|
"""
|
||||||
|
unpacker = Unpacker(stream, **kwargs)
|
||||||
ret = unpacker._fb_unpack()
|
ret = unpacker._fb_unpack()
|
||||||
if unpacker._fb_got_extradata():
|
if unpacker._fb_got_extradata():
|
||||||
raise ExtraData(ret, unpacker._fb_get_extradata())
|
raise ExtraData(ret, unpacker._fb_get_extradata())
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def unpackb(packed, object_hook=None, list_hook=None, use_list=True,
|
def unpackb(packed, **kwargs):
|
||||||
encoding=None, unicode_errors='strict',
|
"""
|
||||||
object_pairs_hook=None):
|
Unpack an object from `packed`.
|
||||||
""" Unpack an object from `packed`.
|
|
||||||
|
|
||||||
Raises `ExtraData` when `packed` contains extra bytes. """
|
Raises `ExtraData` when `packed` contains extra bytes.
|
||||||
unpacker = Unpacker(None, object_hook=object_hook, list_hook=list_hook,
|
See :class:`Unpacker` for options.
|
||||||
use_list=use_list,
|
"""
|
||||||
encoding=encoding, unicode_errors=unicode_errors,
|
unpacker = Unpacker(None, **kwargs)
|
||||||
object_pairs_hook=object_pairs_hook)
|
|
||||||
unpacker.feed(packed)
|
unpacker.feed(packed)
|
||||||
try:
|
try:
|
||||||
ret = unpacker._fb_unpack()
|
ret = unpacker._fb_unpack()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue