Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/msgpack/__init__.py: 74%
23 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-02 06:19 +0000
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-02 06:19 +0000
1from .exceptions import *
2from .ext import ExtType, Timestamp
4import os
7version = (1, 0, 8)
8__version__ = "1.0.8"
11if os.environ.get("MSGPACK_PUREPYTHON"):
12 from .fallback import Packer, unpackb, Unpacker
13else:
14 try:
15 from ._cmsgpack import Packer, unpackb, Unpacker
16 except ImportError:
17 from .fallback import Packer, unpackb, Unpacker
20def pack(o, stream, **kwargs):
21 """
22 Pack object `o` and write it to `stream`
24 See :class:`Packer` for options.
25 """
26 packer = Packer(**kwargs)
27 stream.write(packer.pack(o))
30def packb(o, **kwargs):
31 """
32 Pack object `o` and return packed bytes
34 See :class:`Packer` for options.
35 """
36 return Packer(**kwargs).pack(o)
39def unpack(stream, **kwargs):
40 """
41 Unpack an object from `stream`.
43 Raises `ExtraData` when `stream` contains extra bytes.
44 See :class:`Unpacker` for options.
45 """
46 data = stream.read()
47 return unpackb(data, **kwargs)
50# alias for compatibility to simplejson/marshal/pickle.
51load = unpack
52loads = unpackb
54dump = pack
55dumps = packb