Mercurial > libervia-pubsub
comparison idavoll/generic_backend.py @ 153:753b8432460f
Work towards JEP-0060 1.8
- Remove subscription information from <affiliations/> result.
- Add handling of <subscriptions/> entity use case.
- Make <subscribe/> return <subscription/> instead of <entity/>.
- Move <purge/> and <delete/> to owner namespace.
- Don't use 'self' in interfaces.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Sat, 06 May 2006 19:47:53 +0000 |
parents | ea8b4189ae3b |
children | 5191ba7c4df8 |
comparison
equal
deleted
inserted
replaced
152:ea8b4189ae3b | 153:753b8432460f |
---|---|
160 raise backend.NotAuthorized | 160 raise backend.NotAuthorized |
161 | 161 |
162 d = node.add_subscription(subscriber, 'subscribed') | 162 d = node.add_subscription(subscriber, 'subscribed') |
163 d.addCallback(lambda _: 'subscribed') | 163 d.addCallback(lambda _: 'subscribed') |
164 d.addErrback(self._get_subscription, node, subscriber) | 164 d.addErrback(self._get_subscription, node, subscriber) |
165 d.addCallback(self._return_subscription, affiliation, node.id) | 165 d.addCallback(self._return_subscription, node.id) |
166 return d | 166 return d |
167 | 167 |
168 def _get_subscription(self, failure, node, subscriber): | 168 def _get_subscription(self, failure, node, subscriber): |
169 failure.trap(storage.SubscriptionExists) | 169 failure.trap(storage.SubscriptionExists) |
170 return node.get_subscription(subscriber) | 170 return node.get_subscription(subscriber) |
171 | 171 |
172 def _return_subscription(self, result, affiliation, node_id): | 172 def _return_subscription(self, result, node_id): |
173 return {'affiliation': affiliation, | 173 return node_id, result |
174 'node': node_id, | |
175 'state': result} | |
176 | 174 |
177 def unsubscribe(self, node_id, subscriber, requestor): | 175 def unsubscribe(self, node_id, subscriber, requestor): |
178 if subscriber.userhostJID() != requestor: | 176 if subscriber.userhostJID() != requestor: |
179 raise backend.NotAuthorized | 177 raise backend.NotAuthorized |
180 | 178 |
181 d = self.parent.storage.get_node(node_id) | 179 d = self.parent.storage.get_node(node_id) |
182 d.addCallback(lambda node: node.remove_subscription(subscriber)) | 180 d.addCallback(lambda node: node.remove_subscription(subscriber)) |
183 return d | 181 return d |
182 | |
183 def get_subscriptions(self, entity): | |
184 return self.parent.storage.get_subscriptions(entity) | |
184 | 185 |
185 class NodeCreationService(service.Service): | 186 class NodeCreationService(service.Service): |
186 | 187 |
187 implements(backend.INodeCreationService) | 188 implements(backend.INodeCreationService) |
188 | 189 |
244 class AffiliationsService(service.Service): | 245 class AffiliationsService(service.Service): |
245 | 246 |
246 implements(backend.IAffiliationsService) | 247 implements(backend.IAffiliationsService) |
247 | 248 |
248 def get_affiliations(self, entity): | 249 def get_affiliations(self, entity): |
249 d1 = self.parent.storage.get_affiliations(entity) | 250 return self.parent.storage.get_affiliations(entity) |
250 d2 = self.parent.storage.get_subscriptions(entity) | |
251 d = defer.DeferredList([d1, d2], fireOnOneErrback=1, consumeErrors=1) | |
252 d.addErrback(lambda x: x.value[0]) | |
253 d.addCallback(self._affiliations_result, entity) | |
254 return d | |
255 | |
256 def _affiliations_result(self, result, entity): | |
257 affiliations = result[0][1] | |
258 subscriptions = result[1][1] | |
259 | |
260 new_affiliations = {} | |
261 | |
262 for node, affiliation in affiliations: | |
263 new_affiliations[(node, entity.full())] = {'node': node, | |
264 'jid': entity, | |
265 'affiliation': affiliation, | |
266 'subscription': None | |
267 } | |
268 | |
269 for node, subscriber, subscription in subscriptions: | |
270 key = node, subscriber.full() | |
271 if new_affiliations.has_key(key): | |
272 new_affiliations[key]['subscription'] = subscription | |
273 else: | |
274 new_affiliations[key] = {'node': node, | |
275 'jid': subscriber, | |
276 'affiliation': None, | |
277 'subscription': subscription} | |
278 | |
279 return new_affiliations.values() | |
280 | 251 |
281 class ItemRetrievalService(service.Service): | 252 class ItemRetrievalService(service.Service): |
282 | 253 |
283 implements(backend.IItemRetrievalService) | 254 implements(backend.IItemRetrievalService) |
284 | 255 |