MCPcopy Create free account
hub / github.com/Bitmessage/PyBitmessage / _unpackb2

Function _unpackb2

src/fallback/umsgpack/umsgpack.py:864–906  ·  view source on GitHub ↗

Deserialize MessagePack bytes into a Python object. Args: s: a 'str' or 'bytearray' containing serialized MessagePack bytes Kwargs: ext_handlers (dict): dictionary of Ext handlers, mapping integer Ext type to a callable that unpacks an inst

(s, **options)

Source from the content-addressed store, hash-verified

862
863# For Python 2, expects a str object
864def _unpackb2(s, **options):
865 """
866 Deserialize MessagePack bytes into a Python object.
867
868 Args:
869 s: a 'str' or 'bytearray' containing serialized MessagePack bytes
870
871 Kwargs:
872 ext_handlers (dict): dictionary of Ext handlers, mapping integer Ext
873 type to a callable that unpacks an instance of
874 Ext into an object
875 use_ordered_dict (bool): unpack maps into OrderedDict, instead of
876 unordered dict (default False)
877 allow_invalid_utf8 (bool): unpack invalid strings into instances of
878 InvalidString, for access to the bytes
879 (default False)
880
881 Returns:
882 A Python object.
883
884 Raises:
885 TypeError:
886 Packed data type is neither 'str' nor 'bytearray'.
887 InsufficientDataException(UnpackException):
888 Insufficient data to unpack the serialized object.
889 InvalidStringException(UnpackException):
890 Invalid UTF-8 string encountered during unpacking.
891 ReservedCodeException(UnpackException):
892 Reserved code encountered during unpacking.
893 UnhashableKeyException(UnpackException):
894 Unhashable key encountered during map unpacking.
895 The serialized map cannot be deserialized into a Python dictionary.
896 DuplicateKeyException(UnpackException):
897 Duplicate key encountered during map unpacking.
898
899 Example:
900 >>> umsgpack.unpackb(b'\x82\xa7compact\xc3\xa6schema\x00')
901 {u'compact': True, u'schema': 0}
902 >>>
903 """
904 if not isinstance(s, (str, bytearray)):
905 raise TypeError("packed data must be type 'str' or 'bytearray'")
906 return _unpack(io.BytesIO(s), options)
907
908
909# For Python 3, expects a bytes object

Callers

nothing calls this directly

Calls 1

_unpackFunction · 0.85

Tested by

no test coverage detected