From 2c459e4c8c63995a56e429ae767166147237fd76 Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Mon, 28 Nov 2011 13:09:23 +0000 Subject: [PATCH] Adds ability to disable content_types in the serializer registry --- kombu/serialization.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kombu/serialization.py b/kombu/serialization.py index 378cf5d7..916954c3 100644 --- a/kombu/serialization.py +++ b/kombu/serialization.py @@ -65,6 +65,7 @@ class SerializerRegistry(object): self._default_encode = None self._default_content_type = None self._default_content_encoding = None + self._disabled_content_types = set() self.type_to_name = {} def register(self, name, encoder, decoder, content_type, @@ -75,6 +76,11 @@ class SerializerRegistry(object): self._decoders[content_type] = decoder self.type_to_name[content_type] = name + def disable(self, name): + if '/' not in name: + name = self.type_to_name[name] + self._disabled_content_types.add(name) + def unregister(self, name): try: content_type = self._encoders[name][0] @@ -134,7 +140,10 @@ class SerializerRegistry(object): payload = encoder(data) return content_type, content_encoding, payload - def decode(self, data, content_type, content_encoding): + def decode(self, data, content_type, content_encoding, force=False): + if content_type in self._disabled_content_types: + raise SerializerNotInstalled( + "Content-type %r has been disabled." % (content_type, )) content_type = content_type or 'application/data' content_encoding = (content_encoding or 'utf-8').lower()