Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__init__.py 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # coding: utf-8
  2. from pip._vendor.msgpack._version import version
  3. from pip._vendor.msgpack.exceptions import *
  4. from collections import namedtuple
  5. class ExtType(namedtuple('ExtType', 'code data')):
  6. """ExtType represents ext type in msgpack."""
  7. def __new__(cls, code, data):
  8. if not isinstance(code, int):
  9. raise TypeError("code must be int")
  10. if not isinstance(data, bytes):
  11. raise TypeError("data must be bytes")
  12. if not 0 <= code <= 127:
  13. raise ValueError("code must be 0~127")
  14. return super(ExtType, cls).__new__(cls, code, data)
  15. import os
  16. if os.environ.get('MSGPACK_PUREPYTHON'):
  17. from pip._vendor.msgpack.fallback import Packer, unpackb, Unpacker
  18. else:
  19. try:
  20. from pip._vendor.msgpack._packer import Packer
  21. from pip._vendor.msgpack._unpacker import unpackb, Unpacker
  22. except ImportError:
  23. from pip._vendor.msgpack.fallback import Packer, unpackb, Unpacker
  24. def pack(o, stream, **kwargs):
  25. """
  26. Pack object `o` and write it to `stream`
  27. See :class:`Packer` for options.
  28. """
  29. packer = Packer(**kwargs)
  30. stream.write(packer.pack(o))
  31. def packb(o, **kwargs):
  32. """
  33. Pack object `o` and return packed bytes
  34. See :class:`Packer` for options.
  35. """
  36. return Packer(**kwargs).pack(o)
  37. def unpack(stream, **kwargs):
  38. """
  39. Unpack an object from `stream`.
  40. Raises `ExtraData` when `stream` contains extra bytes.
  41. See :class:`Unpacker` for options.
  42. """
  43. data = stream.read()
  44. return unpackb(data, **kwargs)
  45. # alias for compatibility to simplejson/marshal/pickle.
  46. load = unpack
  47. loads = unpackb
  48. dump = pack
  49. dumps = packb