comparison env/lib/python3.9/site-packages/pip/_vendor/msgpack/__init__.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 # coding: utf-8
2 from ._version import version
3 from .exceptions import *
4 from .ext import ExtType, Timestamp
5
6 import os
7 import sys
8
9
10 if os.environ.get("MSGPACK_PUREPYTHON") or sys.version_info[0] == 2:
11 from .fallback import Packer, unpackb, Unpacker
12 else:
13 try:
14 from ._cmsgpack import Packer, unpackb, Unpacker
15 except ImportError:
16 from .fallback import Packer, unpackb, Unpacker
17
18
19 def pack(o, stream, **kwargs):
20 """
21 Pack object `o` and write it to `stream`
22
23 See :class:`Packer` for options.
24 """
25 packer = Packer(**kwargs)
26 stream.write(packer.pack(o))
27
28
29 def packb(o, **kwargs):
30 """
31 Pack object `o` and return packed bytes
32
33 See :class:`Packer` for options.
34 """
35 return Packer(**kwargs).pack(o)
36
37
38 def unpack(stream, **kwargs):
39 """
40 Unpack an object from `stream`.
41
42 Raises `ExtraData` when `stream` contains extra bytes.
43 See :class:`Unpacker` for options.
44 """
45 data = stream.read()
46 return unpackb(data, **kwargs)
47
48
49 # alias for compatibility to simplejson/marshal/pickle.
50 load = unpack
51 loads = unpackb
52
53 dump = pack
54 dumps = packb