Beispiel #1
0
def loads(blob, excp_cls=coordination.SerializationError):
    """Deserializes provided data using msgpack (from a prior byte string)."""
    try:
        return msgpackutils.loads(blob)
    except (msgpack.UnpackException, ValueError) as e:
        coordination.raise_with_cause(excp_cls, exception_message(e),
                                      cause=e)
Beispiel #2
0
def loads(blob, excp_cls=SerializationError):
    """Deserializes provided data using msgpack (from a prior byte string)."""
    try:
        return msgpackutils.loads(blob)
    except (msgpack.UnpackException, ValueError) as e:
        raise_with_cause(excp_cls,
                         encodeutils.exception_to_unicode(e),
                         cause=e)
Beispiel #3
0
 def deserialize(self, data):
     revoke_event_data = msgpackutils.loads(data, registry=self._registry)
     try:
         revoke_event = RevokeEvent(**revoke_event_data)
     except Exception:
         LOG.debug("Failed to deserialize RevokeEvent. Data is %s",
                   revoke_event_data)
         raise
     return revoke_event
Beispiel #4
0
    def _get_local_cache(self, key):
        # Return the version from our local request cache if it exists.
        ctx = self._get_request_context()
        try:
            value = getattr(ctx, self._get_request_key(key))
        except AttributeError:
            return api.NO_VALUE

        value = msgpackutils.loads(value)
        return api.CachedValue(payload=value["payload"], metadata=value["metadata"])
Beispiel #5
0
    def test_custom_register(self):
        registry = msgpackutils.default_registry.copy(unfreeze=True)
        registry.register(ColorHandler())

        c = Color(255, 254, 253)
        c_b = msgpackutils.dumps(c, registry=registry)
        c = msgpackutils.loads(c_b, registry=registry)

        self.assertEqual(255, c.r)
        self.assertEqual(254, c.g)
        self.assertEqual(253, c.b)
Beispiel #6
0
 def deserialize(self, data):
     token_data = msgpackutils.loads(data, registry=self._registry)
     try:
         token_model = TokenModel()
         for k, v in iter(token_data.items()):
             setattr(token_model, k, v)
     except Exception:
         LOG.debug(
             "Failed to deserialize TokenModel. Data is %s", token_data
         )
         raise exception.CacheDeserializationError(
             TokenModel.__name__, token_data
         )
     return token_model
Beispiel #7
0
 def deserialize(self, data):
     receipt_data = msgpackutils.loads(data, registry=self._registry)
     try:
         receipt_model = ReceiptModel()
         for k, v in iter(receipt_data.items()):
             setattr(receipt_model, k, v)
     except Exception:
         LOG.debug(
             "Failed to deserialize ReceiptModel. Data is %s", receipt_data
         )
         raise exception.CacheDeserializationError(
             ReceiptModel.__name__, receipt_data
         )
     return receipt_model
Beispiel #8
0
def decode_msgpack(raw_data, root_types=(dict,)):
    """Parse raw data to get decoded object.

    Decodes a msgback encoded 'blob' from a given raw data binary string and
    checks that the root type of that decoded object is in the allowed set of
    types (by default a dict should be the root type).
    """
    try:
        data = msgpackutils.loads(raw_data)
    except Exception as e:
        # TODO(harlowja): fix this when msgpackutils exposes the msgpack
        # exceptions so that we can avoid catching just exception...
        raise ValueError("Expected msgpack decodable data: %s" % e)
    else:
        return _check_decoded_type(data, root_types=root_types)
Beispiel #9
0
 def deserialize(self, data):
     revoke_event_data = msgpackutils.loads(data, registry=self._registry)
     revoke_event = RevokeEvent(**revoke_event_data)
     return revoke_event
Beispiel #10
0
 def load_from_bytes(self, s):
     return msgpackutils.loads(s, registry=self._registry)
Beispiel #11
0
 def _unserialize_measures(data):
     return msgpackutils.loads(data)
def _dumps_loads(obj):
    obj = msgpackutils.dumps(obj)
    return msgpackutils.loads(obj)