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

1from .exceptions import * 

2from .ext import ExtType, Timestamp 

3 

4import os 

5 

6 

7version = (1, 0, 8) 

8__version__ = "1.0.8" 

9 

10 

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 

18 

19 

20def pack(o, stream, **kwargs): 

21 """ 

22 Pack object `o` and write it to `stream` 

23 

24 See :class:`Packer` for options. 

25 """ 

26 packer = Packer(**kwargs) 

27 stream.write(packer.pack(o)) 

28 

29 

30def packb(o, **kwargs): 

31 """ 

32 Pack object `o` and return packed bytes 

33 

34 See :class:`Packer` for options. 

35 """ 

36 return Packer(**kwargs).pack(o) 

37 

38 

39def unpack(stream, **kwargs): 

40 """ 

41 Unpack an object from `stream`. 

42 

43 Raises `ExtraData` when `stream` contains extra bytes. 

44 See :class:`Unpacker` for options. 

45 """ 

46 data = stream.read() 

47 return unpackb(data, **kwargs) 

48 

49 

50# alias for compatibility to simplejson/marshal/pickle. 

51load = unpack 

52loads = unpackb 

53 

54dump = pack 

55dumps = packb