# HG changeset patch # User Ralph Meijer # Date 1113308401 0 # Node ID 8892331314c8d449c2c0b22434b9e6c004cdfb20 # Parent 3e7a7426f5188c87bed9084ab1501526595981c2 Change Node.add_subscription() to return a Failure when a subscription already exists or return nothing on success. Added get_subscription(). Return Failure from Node.remove_subscription() when subscription does not exist. diff -r 3e7a7426f518 -r 8892331314c8 idavoll/memory_storage.py --- a/idavoll/memory_storage.py Tue Apr 12 12:16:54 2005 +0000 +++ b/idavoll/memory_storage.py Tue Apr 12 12:20:01 2005 +0000 @@ -96,19 +96,28 @@ def get_affiliation(self, entity): return defer.succeed(self._affiliations.get(entity.full())) - def add_subscription(self, subscriber, state): + def get_subscription(self, subscriber): try: subscription = self._subscriptions[subscriber.full()] - except: - subscription = Subscription(state) - self._subscriptions[subscriber.full()] = subscription + except KeyError: + state = None + else: + state = subscription.state + return defer.succeed(state) - return defer.succeed({'node': self.id, - 'jid': subscriber, - 'subscription': subscription.state}) + def add_subscription(self, subscriber, state): + if self._subscriptions.get(subscriber.full()): + return defer.fail(storage.SubscriptionExists()) + + subscription = Subscription(state) + self._subscriptions[subscriber.full()] = subscription + return defer.succeed(None) def remove_subscription(self, subscriber): - del self._subscriptions[subscriber.full()] + try: + del self._subscriptions[subscriber.full()] + except KeyError: + return defer.fail(storage.SubscriptionNotFound()) return defer.succeed(None)