mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-20 04:13:16 +00:00

The following steps have been taken: 1. Black was updated to latest version. The code has been formatted with the new version. 2. The pyupgrade utility is installed. This helped to remove all the code that was needed to support Python < 3.7. Fix #541. Co-authored-by: Inada Naoki <songofacandy@gmail.com>
56 lines
1.1 KiB
Python
56 lines
1.1 KiB
Python
from .exceptions import *
|
|
from .ext import ExtType, Timestamp
|
|
|
|
import os
|
|
import sys
|
|
|
|
|
|
version = (1, 0, 5)
|
|
__version__ = "1.0.5"
|
|
|
|
|
|
if os.environ.get("MSGPACK_PUREPYTHON"):
|
|
from .fallback import Packer, unpackb, Unpacker
|
|
else:
|
|
try:
|
|
from ._cmsgpack import Packer, unpackb, Unpacker
|
|
except ImportError:
|
|
from .fallback import Packer, unpackb, Unpacker
|
|
|
|
|
|
def pack(o, stream, **kwargs):
|
|
"""
|
|
Pack object `o` and write it to `stream`
|
|
|
|
See :class:`Packer` for options.
|
|
"""
|
|
packer = Packer(**kwargs)
|
|
stream.write(packer.pack(o))
|
|
|
|
|
|
def packb(o, **kwargs):
|
|
"""
|
|
Pack object `o` and return packed bytes
|
|
|
|
See :class:`Packer` for options.
|
|
"""
|
|
return Packer(**kwargs).pack(o)
|
|
|
|
|
|
def unpack(stream, **kwargs):
|
|
"""
|
|
Unpack an object from `stream`.
|
|
|
|
Raises `ExtraData` when `stream` contains extra bytes.
|
|
See :class:`Unpacker` for options.
|
|
"""
|
|
data = stream.read()
|
|
return unpackb(data, **kwargs)
|
|
|
|
|
|
# alias for compatibility to simplejson/marshal/pickle.
|
|
load = unpack
|
|
loads = unpackb
|
|
|
|
dump = pack
|
|
dumps = packb
|