summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsk Solem <ask@celeryproject.org>2013-09-22 18:13:31 +0100
committerAsk Solem <ask@celeryproject.org>2013-09-22 18:13:31 +0100
commitbdf0c74e2fad5873b9689692a00d3c36df8dfc5f (patch)
treee9dfbfff689f51a5d93a634965a83835c4c11f0a
parenta8d6ba6d17f9c43ce0082ec97f16fa6346d3717e (diff)
downloadpy-amqp-bdf0c74e2fad5873b9689692a00d3c36df8dfc5f.tar.gz
queue_declare and basic_return now gives namedtuples
-rw-r--r--amqp/channel.py25
-rw-r--r--amqp/protocol.py15
2 files changed, 28 insertions, 12 deletions
diff --git a/amqp/channel.py b/amqp/channel.py
index 48188a5..ba211a0 100644
--- a/amqp/channel.py
+++ b/amqp/channel.py
@@ -24,6 +24,7 @@ from warnings import warn
from .abstract_channel import AbstractChannel
from .exceptions import ChannelError, ConsumerCancelled, error_for_code
from .five import Queue
+from .protocol import basic_return_t, queue_declare_ok_t
from .serialization import AMQPWriter
__all__ = ['Channel']
@@ -1272,10 +1273,11 @@ class Channel(AbstractChannel):
this count.
"""
- queue = args.read_shortstr()
- message_count = args.read_long()
- consumer_count = args.read_long()
- return queue, message_count, consumer_count
+ return queue_declare_ok_t(
+ args.read_shortstr(),
+ args.read_long(),
+ args.read_long(),
+ )
def queue_delete(self, queue='',
if_unused=False, if_empty=False, nowait=False):
@@ -2334,14 +2336,13 @@ class Channel(AbstractChannel):
message was published.
"""
- reply_code = args.read_short()
- reply_text = args.read_shortstr()
- exchange = args.read_shortstr()
- routing_key = args.read_shortstr()
-
- self.returned_messages.put(
- (reply_code, reply_text, exchange, routing_key, msg)
- )
+ self.returned_messages.put(basic_return_t(
+ args.read_short(),
+ args.read_shortstr(),
+ args.read_shortstr(),
+ args.read_shortstr(),
+ msg,
+ ))
#############
#
diff --git a/amqp/protocol.py b/amqp/protocol.py
new file mode 100644
index 0000000..6b235f5
--- /dev/null
+++ b/amqp/protocol.py
@@ -0,0 +1,15 @@
+from __future__ import absolute_import
+
+from collections import namedtuple
+
+
+queue_declare_ok_t = namedtuple(
+ 'queue_declare_ok_t', ('queue', 'message_count', 'consumer_count'),
+)
+
+basic_return_t = namedtuple(
+ 'basic_return_t',
+ ('reply_code', 'reply_text', 'exchange', 'routing_key', 'message'),
+)
+
+