diff options
| author | INADA Naoki <methane@users.noreply.github.com> | 2018-02-22 00:55:32 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-22 00:55:32 +0900 |
| commit | da902f9c1d996fb461f1efef6487ef40d32d365a (patch) | |
| tree | 746e7ce2f15941c1e0251c10bd95e1f0774dab4b /msgpack/__init__.py | |
| parent | ae8d4694829d5b58d613c588c30e29dd29860c4f (diff) | |
| download | msgpack-python-da902f9c1d996fb461f1efef6487ef40d32d365a.tar.gz | |
Move unpack() from each implementation to __init__. (#286)
Fixes #285
Diffstat (limited to 'msgpack/__init__.py')
| -rw-r--r-- | msgpack/__init__.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/msgpack/__init__.py b/msgpack/__init__.py index 6c5ae53..70de97f 100644 --- a/msgpack/__init__.py +++ b/msgpack/__init__.py @@ -19,13 +19,13 @@ class ExtType(namedtuple('ExtType', 'code data')): import os if os.environ.get('MSGPACK_PUREPYTHON'): - from msgpack.fallback import Packer, unpack, unpackb, Unpacker + from msgpack.fallback import Packer, unpackb, Unpacker else: try: from msgpack._packer import Packer - from msgpack._unpacker import unpack, unpackb, Unpacker + from msgpack._unpacker import unpackb, Unpacker except ImportError: - from msgpack.fallback import Packer, unpack, unpackb, Unpacker + from msgpack.fallback import Packer, unpackb, Unpacker def pack(o, stream, **kwargs): @@ -46,6 +46,17 @@ def packb(o, **kwargs): """ 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. load = unpack loads = unpackb |
