Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.10/site-packages/msgpack/__init__.py: 65%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# ruff: noqa: F401
2import os
4from .exceptions import * # noqa: F403
5from .ext import ExtType, Timestamp
7version = (1, 1, 0)
8__version__ = "1.1.0"
11if os.environ.get("MSGPACK_PUREPYTHON"):
12 from .fallback import Packer, Unpacker, unpackb
13else:
14 try:
15 from ._cmsgpack import Packer, Unpacker, unpackb
16 except ImportError:
17 from .fallback import Packer, Unpacker, unpackb
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