summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael H. Schloming <rhs@apache.org>2010-03-23 15:32:48 +0000
committerRafael H. Schloming <rhs@apache.org>2010-03-23 15:32:48 +0000
commit20c6e290c0bbb2865821ec7c50af923c974350c5 (patch)
treece736fe83ecf0e4a5238285fa49747b846ed8d2d
parentfe99d24c4084b2cb2479b820a5b44378d1812ffc (diff)
downloadqpid-python-20c6e290c0bbb2865821ec7c50af923c974350c5.tar.gz
provide default codec for unknown content types
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@926623 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--python/qpid/messaging/message.py8
-rw-r--r--python/qpid/tests/messaging/message.py4
2 files changed, 9 insertions, 3 deletions
diff --git a/python/qpid/messaging/message.py b/python/qpid/messaging/message.py
index a9660b05b1..d89fa00dc3 100644
--- a/python/qpid/messaging/message.py
+++ b/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/python/qpid/tests/messaging/message.py b/python/qpid/tests/messaging/message.py
index 654076588b..f2701af64b 100644
--- a/python/qpid/tests/messaging/message.py
+++ b/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)