Deserialize MessagePack bytes into a Python object. Args: s: a 'bytes' or 'bytearray' containing serialized MessagePack bytes Kwargs: ext_handlers (dict): dictionary of Ext handlers, mapping integer Ext type to a callable that unpacks an in
(s, **options)
| 908 | |
| 909 | # For Python 3, expects a bytes object |
| 910 | def _unpackb3(s, **options): |
| 911 | """ |
| 912 | Deserialize MessagePack bytes into a Python object. |
| 913 | |
| 914 | Args: |
| 915 | s: a 'bytes' or 'bytearray' containing serialized MessagePack bytes |
| 916 | |
| 917 | Kwargs: |
| 918 | ext_handlers (dict): dictionary of Ext handlers, mapping integer Ext |
| 919 | type to a callable that unpacks an instance of |
| 920 | Ext into an object |
| 921 | use_ordered_dict (bool): unpack maps into OrderedDict, instead of |
| 922 | unordered dict (default False) |
| 923 | allow_invalid_utf8 (bool): unpack invalid strings into instances of |
| 924 | InvalidString, for access to the bytes |
| 925 | (default False) |
| 926 | |
| 927 | Returns: |
| 928 | A Python object. |
| 929 | |
| 930 | Raises: |
| 931 | TypeError: |
| 932 | Packed data type is neither 'bytes' nor 'bytearray'. |
| 933 | InsufficientDataException(UnpackException): |
| 934 | Insufficient data to unpack the serialized object. |
| 935 | InvalidStringException(UnpackException): |
| 936 | Invalid UTF-8 string encountered during unpacking. |
| 937 | ReservedCodeException(UnpackException): |
| 938 | Reserved code encountered during unpacking. |
| 939 | UnhashableKeyException(UnpackException): |
| 940 | Unhashable key encountered during map unpacking. |
| 941 | The serialized map cannot be deserialized into a Python dictionary. |
| 942 | DuplicateKeyException(UnpackException): |
| 943 | Duplicate key encountered during map unpacking. |
| 944 | |
| 945 | Example: |
| 946 | >>> umsgpack.unpackb(b'\x82\xa7compact\xc3\xa6schema\x00') |
| 947 | {'compact': True, 'schema': 0} |
| 948 | >>> |
| 949 | """ |
| 950 | if not isinstance(s, (bytes, bytearray)): |
| 951 | raise TypeError("packed data must be type 'bytes' or 'bytearray'") |
| 952 | return _unpack(io.BytesIO(s), options) |
| 953 | |
| 954 | ############################################################################# |
| 955 | # Module Initialization |