changeset 120:8892331314c8

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.
author Ralph Meijer <ralphm@ik.nu>
date Tue, 12 Apr 2005 12:20:01 +0000
parents 3e7a7426f518
children 4f0113adb7ed
files idavoll/memory_storage.py
diffstat 1 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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)