def loads(data, content_type="application/json", encoding="utf-8"): """Deserializes data using Kombu deserializer, default format is JSON. """ try: return k_registry.loads(data, content_type, encoding) except DecodeError as e: raise TypeError(e)
def _eager_serialize_args(self, args=None, kwargs=None, **kwargs_): # Perform a noop serialization backtrip to assert args and kwargs # will be serialized appropriately when an async call through kombu # is actually performed. This is done to make sure we catch the # serializations errors with our test suite which runs with the # CELERY_ALWAYS_EAGER setting set to True. See the following Celery # issue for details https://github.com/celery/celery/issues/4008. app = self._app producer = kwargs_.get('producer') if kwargs else None with app.producer_or_acquire(producer) as producer: serializer = kwargs_.get('serializer', producer.serializer) or self._task_serializer registry.enable(serializer) args_content_type, args_content_encoding, args_data = registry.dumps(args, serializer) kwargs_content_type, kwargs_content_encoding, kwargs_data = registry.dumps(kwargs, serializer) args = registry.loads(args_data, args_content_type, args_content_encoding) kwargs = registry.loads(kwargs_data, kwargs_content_type, kwargs_content_encoding) return args, kwargs
def _eager_serialize_result(self, result, **kwargs_): app = self._app producer = kwargs_.get('producer') if kwargs_ else None result_value = result._result with app.producer_or_acquire(producer) as producer: serializer = kwargs_.get('serializer', producer.serializer) or self._task_serializer registry.enable(serializer) dtype, encoding, data = registry.dumps(result_value, serializer) result._result = registry.loads(data, dtype, encoding) return result