8000 fallback: refactor · simonsfoundation/msgpack-python@1e38bfa · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e38bfa

Browse files
committed
fallback: refactor
1 parent 230537c commit 1e38bfa

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

msgpack/fallback.py

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -60,46 +60,44 @@ def getvalue(self):
6060

6161
DEFAULT_RECURSE_LIMIT=511
6262

63-
def pack(o, stream, default=None, encoding='utf-8', unicode_errors='strict'):
64-
""" Pack object `o` and write it to `stream` """
65-
packer = Packer(default=default, encoding=encoding,
66-
unicode_errors=unicode_errors)
63+
def pack(o, stream, **kwargs):
64+
"""
65+
Pack object `o` and write it to `stream`
66+
67+
See :class:`Packer` for options.
68+
"""
69+
packer = Packer(**kwargs)
6770
stream.write(packer.pack(o))
6871

69-
def packb(o, default=None, encoding='utf-8', unicode_errors='struct',
70-
use_single_float=False):
71-
""" Pack object `o` and return packed bytes """
72-
packer = Packer(default=default,
73-
encoding=encoding,
74-
unicode_errors=unicode_errors,
75-
use_single_float=use_single_float)
76-
return packer.pack(o)
77-
78-
def unpack(stream, object_hook=None, list_hook=None, use_list=True,
79-
encoding=None, unicode_errors='strict',
80-
object_pairs_hook=None):
81-
""" Unpack an object from `stream`.
82-
83-
Raises `ExtraData` when `stream` has extra bytes. """
84-
unpacker = Unpacker(stream, object_hook=object_hook, list_hook=list_hook,
85-
use_list=use_list,
86-
8000 encoding=encoding, unicode_errors=unicode_errors,
87-
object_pairs_hook=object_pairs_hook)
72+
def packb(o, **kwargs):
73+
"""
74+
Pack object `o` and return packed bytes
75+
76+
See :class:`Packer` for options.
77+
"""
78+
return Packer(**kwargs).pack(o)
79+
80+
def unpack(stream, **kwargs):
81+
"""
82+
Unpack an object from `stream`.
83+
84+
Raises `ExtraData` when `packed` contains extra bytes.
85+
See :class:`Unpacker` for options.
86+
"""
87+
unpacker = Unpacker(stream, **kwargs)
8888
ret = unpacker._fb_unpack()
8989
if unpacker._fb_got_extradata():
9090
raise ExtraData(ret, unpacker._fb_get_extradata())
9191
return ret
9292

93-
def unpackb(packed, object_hook=None, list_hook=None, use_list=True,
94-
encoding=None, unicode_errors='strict',
95-
object_pairs_hook=None):
96-
""" Unpack an object from `packed`.
93+
def unpackb(packed, **kwargs):
94+
"""
95+
Unpack an object from `packed`.
9796
98-
Raises `ExtraData` when `packed` contains extra bytes. """
99-
unpacker = Unpacker(None, object_hook=object_hook, list_hook=list_hook,
100-
use_list=use_list,
101-
encoding=encoding, unicode_errors=unicode_errors,
102-
object_pairs_hook=object_pairs_hook)
97+
Raises `ExtraData` when `packed` contains extra bytes.
98+
See :class:`Unpacker` for options.
99+
"""
100+
unpacker = Unpacker(None, **kwargs)
103101
unpacker.feed(packed)
104102
try:
105103
ret = unpacker._fb_unpack()

0 commit comments

Comments
 (0)
0