From 8c02c2599ddfe95dac4a9bb4a3dc5086ab76ad8c Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Tue, 23 Mar 2010 15:32:48 +0000 Subject: provide default codec for unknown content types git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@926623 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/qpid/messaging/message.py | 8 +++++--- qpid/python/qpid/tests/messaging/message.py | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'qpid/python') diff --git a/qpid/python/qpid/messaging/message.py b/qpid/python/qpid/messaging/message.py index a9660b05b1..d89fa00dc3 100644 --- a/qpid/python/qpid/messaging/message.py +++ b/qpid/python/qpid/messaging/message.py @@ -47,20 +47,22 @@ TYPE_MAPPINGS={ None.__class__: None } +DEFAULT_CODEC = (lambda x: x, lambda x: x) + TYPE_CODEC={ "amqp/map": codec("map"), "amqp/list": codec("list"), "text/plain; charset=utf8": (lambda x: x.encode("utf8"), lambda x: x.decode("utf8")), "text/plain": (lambda x: x.encode("utf8"), lambda x: x.decode("utf8")), - "": (lambda x: x, lambda x: x), - None: (lambda x: x, lambda x: x) + "": DEFAULT_CODEC, + None: DEFAULT_CODEC } def get_type(content): return TYPE_MAPPINGS[content.__class__] def get_codec(content_type): - return TYPE_CODEC[content_type] + return TYPE_CODEC.get(content_type, DEFAULT_CODEC) UNSPECIFIED = object() diff --git a/qpid/python/qpid/tests/messaging/message.py b/qpid/python/qpid/tests/messaging/message.py index 654076588b..f2701af64b 100644 --- a/qpid/python/qpid/tests/messaging/message.py +++ b/qpid/python/qpid/tests/messaging/message.py @@ -107,3 +107,7 @@ class MessageEchoTests(Base): msg.properties = MessageEchoTests.TEST_MAP msg.reply_to = "reply-address" self.check(msg) + + def testContentTypeUnknown(self): + msg = Message(content_type = "this-content-type-does-not-exist") + self.check(msg) -- cgit v1.2.1