summaryrefslogtreecommitdiff
path: root/qpid/python
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
commit8c02c2599ddfe95dac4a9bb4a3dc5086ab76ad8c (patch)
treeee5167b027e088e1050d363b2317ad7a2dd031e1 /qpid/python
parent7cb8419e424299eb49cd76a701b829abbd3663f1 (diff)
downloadqpid-python-8c02c2599ddfe95dac4a9bb4a3dc5086ab76ad8c.tar.gz
provide default codec for unknown content types
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@926623 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/python')
-rw-r--r--qpid/python/qpid/messaging/message.py8
-rw-r--r--qpid/python/qpid/tests/messaging/message.py4
2 files changed, 9 insertions, 3 deletions
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)