From 2d075adba1ad2091fadcfeb36f3e2030cffe07a6 Mon Sep 17 00:00:00 2001 From: Rafal Malinowski Date: Wed, 27 Mar 2013 18:40:01 +0100 Subject: [PATCH] Added passive option for Exchange --- kombu/entity.py | 8 +++++--- kombu/tests/test_entities.py | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/kombu/entity.py b/kombu/entity.py index 32b199c3..7b0ed0dc 100644 --- a/kombu/entity.py +++ b/kombu/entity.py @@ -123,6 +123,7 @@ class Exchange(MaybeChannelBound): type = 'direct' durable = True auto_delete = False + passive = False delivery_mode = PERSISTENT_DELIVERY_MODE attrs = ( @@ -134,16 +135,17 @@ class Exchange(MaybeChannelBound): ('delivery_mode', lambda m: DELIVERY_MODES.get(m) or m), ) - def __init__(self, name='', type='', channel=None, **kwargs): + def __init__(self, name='', type='', channel=None, passive=None, **kwargs): super(Exchange, self).__init__(**kwargs) self.name = name or self.name self.type = type or self.type + self.passive = passive or self.passive self.maybe_bind(channel) def __hash__(self): return hash('E|%s' % (self.name, )) - def declare(self, nowait=False, passive=False): + def declare(self, nowait=False): """Declare the exchange. Creates the exchange on the broker. @@ -156,7 +158,7 @@ class Exchange(MaybeChannelBound): return self.channel.exchange_declare( exchange=self.name, type=self.type, durable=self.durable, auto_delete=self.auto_delete, arguments=self.arguments, - nowait=nowait, passive=passive, + nowait=nowait, passive=self.passive, ) def bind_to(self, exchange='', routing_key='', diff --git a/kombu/tests/test_entities.py b/kombu/tests/test_entities.py index 8e89f84e..242e89c0 100644 --- a/kombu/tests/test_entities.py +++ b/kombu/tests/test_entities.py @@ -16,7 +16,6 @@ from .utils import Mock def get_conn(): return Connection(transport=Transport) - class test_binding(TestCase): def test_constructor(self): @@ -130,6 +129,10 @@ class test_Exchange(TestCase): exc = Exchange('foo', 'direct', delivery_mode='transient') self.assertEqual(exc.delivery_mode, Exchange.TRANSIENT_DELIVERY_MODE) + def test_set_passive_mode(self): + exc = Exchange('foo', 'direct', passive=True) + self.assertTrue(exc.passive) + def test_set_persistent_delivery_mode(self): exc = Exchange('foo', 'direct', delivery_mode='persistent') self.assertEqual(exc.delivery_mode, Exchange.PERSISTENT_DELIVERY_MODE)