Mercurial > libervia-pubsub
comparison idavoll/memory_storage.py @ 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 | 97f10cfea28c |
children | ffc3c706b0fb |
comparison
equal
deleted
inserted
replaced
119:3e7a7426f518 | 120:8892331314c8 |
---|---|
94 return defer.succeed(None) | 94 return defer.succeed(None) |
95 | 95 |
96 def get_affiliation(self, entity): | 96 def get_affiliation(self, entity): |
97 return defer.succeed(self._affiliations.get(entity.full())) | 97 return defer.succeed(self._affiliations.get(entity.full())) |
98 | 98 |
99 def get_subscription(self, subscriber): | |
100 try: | |
101 subscription = self._subscriptions[subscriber.full()] | |
102 except KeyError: | |
103 state = None | |
104 else: | |
105 state = subscription.state | |
106 return defer.succeed(state) | |
107 | |
99 def add_subscription(self, subscriber, state): | 108 def add_subscription(self, subscriber, state): |
100 try: | 109 if self._subscriptions.get(subscriber.full()): |
101 subscription = self._subscriptions[subscriber.full()] | 110 return defer.fail(storage.SubscriptionExists()) |
102 except: | 111 |
103 subscription = Subscription(state) | 112 subscription = Subscription(state) |
104 self._subscriptions[subscriber.full()] = subscription | 113 self._subscriptions[subscriber.full()] = subscription |
105 | 114 return defer.succeed(None) |
106 return defer.succeed({'node': self.id, | |
107 'jid': subscriber, | |
108 'subscription': subscription.state}) | |
109 | 115 |
110 def remove_subscription(self, subscriber): | 116 def remove_subscription(self, subscriber): |
111 del self._subscriptions[subscriber.full()] | 117 try: |
118 del self._subscriptions[subscriber.full()] | |
119 except KeyError: | |
120 return defer.fail(storage.SubscriptionNotFound()) | |
112 | 121 |
113 return defer.succeed(None) | 122 return defer.succeed(None) |
114 | 123 |
115 def get_subscribers(self): | 124 def get_subscribers(self): |
116 subscribers = [jid.JID(subscriber) for subscriber, subscription | 125 subscribers = [jid.JID(subscriber) for subscriber, subscription |