comparison idavoll/backend.py @ 61:ad08e021b4d5

Implement AffiliationsService.
author Ralph Meijer <ralphm@ik.nu>
date Sat, 06 Nov 2004 21:02:33 +0000
parents 0fa161c00ed9
children d617f8d19263
comparison
equal deleted inserted replaced
60:f6b7a06b8870 61:ad08e021b4d5
273 raise NoInstantNodes 273 raise NoInstantNodes
274 274
275 d = self.parent.storage.create_node(node_id, requestor) 275 d = self.parent.storage.create_node(node_id, requestor)
276 d.addCallback(lambda _: node_id) 276 d.addCallback(lambda _: node_id)
277 return d 277 return d
278
279 class AffiliationsService(service.Service):
280
281 __implements__ = IAffiliationsService,
282
283 def get_affiliations(self, entity):
284 d1 = self.parent.storage.get_affiliations(entity)
285 d2 = self.parent.storage.get_subscriptions(entity)
286 d = defer.DeferredList([d1, d2], fireOnOneErrback=1)
287 d.addErrback(lambda x: x.value[0])
288 d.addCallback(self._affiliations_result, entity)
289 return d
290
291 def _affiliations_result(self, result, entity):
292 affiliations = result[0][1]
293 subscriptions = result[1][1]
294
295 new_affiliations = {}
296
297 for node, affiliation in affiliations:
298 new_affiliations[(node, entity.full())] = {'node': node,
299 'jid': entity,
300 'affiliation': affiliation,
301 'subscription': None
302 }
303
304 for node, subscriber, subscription in subscriptions:
305 key = node, subscriber.full()
306 if new_affiliations.has_key(key):
307 new_affiliations[key]['subscription'] = subscription
308 else:
309 new_affiliations[key] = {'node': node,
310 'jid': subscriber,
311 'affiliation': None,
312 'subscription': subscription}
313
314 return new_affiliations.values()