diff options
author | Rafael H. Schloming <rhs@apache.org> | 2009-10-11 16:55:55 +0000 |
---|---|---|
committer | Rafael H. Schloming <rhs@apache.org> | 2009-10-11 16:55:55 +0000 |
commit | 3939eecd394157e89bf583988f8de48b24a9b88a (patch) | |
tree | e50f281871edcafc5d0e1700cf52629501656717 | |
parent | 89801ebb1a85df6aacbd0f5cdd42926c1be3a605 (diff) | |
download | qpid-python-3939eecd394157e89bf583988f8de48b24a9b88a.tar.gz |
use ewait on message fetch; added optional args to message constructor and improved message repr
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@824106 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | python/qpid/messaging.py | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/python/qpid/messaging.py b/python/qpid/messaging.py index 3264ee050c..3e3c8f36cb 100644 --- a/python/qpid/messaging.py +++ b/python/qpid/messaging.py @@ -381,8 +381,8 @@ class Session: @synchronized def _get(self, predicate, timeout=None): - if self._wait(lambda: ((self._peek(predicate) is not None) or self.closing), - timeout): + if self._ewait(lambda: ((self._peek(predicate) is not None) or self.closing), + timeout): msg = self._pop(predicate) if msg is not None: msg._receiver.returned += 1 @@ -816,6 +816,8 @@ def get_type(content): def get_codec(content_type): return TYPE_CODEC[content_type] +UNSPECIFIED = object() + class Message: """ @@ -840,7 +842,9 @@ class Message: @ivar content: the message content """ - def __init__(self, content=None): + def __init__(self, content=None, content_type=UNSPECIFIED, id=None, + subject=None, to=None, user_id=None, reply_to=None, + correlation_id=None, durable=None, properties=None): """ Construct a new message with the supplied content. The content-type of the message will be automatically inferred from @@ -848,20 +852,44 @@ class Message: @type content: str, unicode, buffer, dict, list @param content: the message content - """ - self.id = None - self.subject = None - self.user_id = None - self.to = None - self.reply_to = None - self.correlation_id = None - self.durable = None - self.properties = {} - self.content_type = get_type(content) + + @type content_type: str + @param content_type: the content-type of the message + """ + self.id = id + self.subject = subject + self.to = to + self.user_id = user_id + self.reply_to = reply_to + self.correlation_id = correlation_id + self.durable = durable + if properties is None: + self.properties = {} + else: + self.properties = properties + if content_type is UNSPECIFIED: + self.content_type = get_type(content) + else: + self.content_type = content_type self.content = content def __repr__(self): - return "Message(%r)" % self.content + args = [] + for name in ["id", "subject", "to", "user_id", "reply_to", + "correlation_id"]: + value = self.__dict__[name] + if value is not None: args.append("%s=%r" % (name, value)) + for name in ["durable", "properties"]: + value = self.__dict__[name] + if value: args.append("%s=%r" % (name, value)) + if self.content_type != get_type(self.content): + args.append("content_type=%r" % self.content_type) + if self.content is not None: + if args: + args.append("content=%r" % self.content) + else: + args.append(repr(self.content)) + return "Message(%s)" % ", ".join(args) __all__ = ["Connection", "Session", "Sender", "Receiver", "Pattern", "Message", "ConnectionError", "ConnectError", "SessionError", "Disconnected", |