comparison idavoll/pubsub.py @ 60:f6b7a06b8870

Implement retrieving affiliations. Fixed some inconsistencies in the creation of new XML elements. Fixed reply of return_create_response to be a singleton list.
author Ralph Meijer <ralphm@ik.nu>
date Sat, 06 Nov 2004 21:01:29 +0000
parents 3e2e0040e3e0
children a3d67cbab9c4
comparison
equal deleted inserted replaced
59:0fa161c00ed9 60:f6b7a06b8870
22 PUBSUB_UNSUBSCRIBE = PUBSUB_SET + '/unsubscribe' 22 PUBSUB_UNSUBSCRIBE = PUBSUB_SET + '/unsubscribe'
23 PUBSUB_OPTIONS_GET = PUBSUB_GET + '/options' 23 PUBSUB_OPTIONS_GET = PUBSUB_GET + '/options'
24 PUBSUB_OPTIONS_SET = PUBSUB_SET + '/options' 24 PUBSUB_OPTIONS_SET = PUBSUB_SET + '/options'
25 PUBSUB_CONFIGURE_GET = PUBSUB_GET + '/configure' 25 PUBSUB_CONFIGURE_GET = PUBSUB_GET + '/configure'
26 PUBSUB_CONFIGURE_SET = PUBSUB_SET + '/configure' 26 PUBSUB_CONFIGURE_SET = PUBSUB_SET + '/configure'
27 PUBSUB_AFFILIATIONS = PUBSUB_GET + '/affiliations'
27 28
28 class Error(Exception): 29 class Error(Exception):
29 pubsub_error = None 30 pubsub_error = None
30 stanza_error = None 31 stanza_error = None
31 msg = '' 32 msg = ''
223 d = self.backend.subscribe(node_id, subscriber, requestor) 224 d = self.backend.subscribe(node_id, subscriber, requestor)
224 d.addCallback(self.return_subscription) 225 d.addCallback(self.return_subscription)
225 return d 226 return d
226 227
227 def return_subscription(self, result): 228 def return_subscription(self, result):
228 reply = domish.Element((NS_PUBSUB, "pubsub"), NS_PUBSUB) 229 reply = domish.Element((NS_PUBSUB, "pubsub"))
229 entity = reply.addElement("entity") 230 entity = reply.addElement("entity")
230 entity["node"] = result["node"] 231 entity["node"] = result["node"]
231 entity["jid"] = result["jid"].full() 232 entity["jid"] = result["jid"].full()
232 entity["affiliation"] = result["affiliation"] or 'none' 233 entity["affiliation"] = result["affiliation"] or 'none'
233 entity["subscription"] = result["subscription"] 234 entity["subscription"] = result["subscription"]
293 d.addCallback(self.return_create_response, iq) 294 d.addCallback(self.return_create_response, iq)
294 return d 295 return d
295 296
296 def return_create_response(self, result, iq): 297 def return_create_response(self, result, iq):
297 if iq.pubsub.create["node"] is None: 298 if iq.pubsub.create["node"] is None:
298 reply = domish.Element('pubsub', NS_PUBSUB) 299 reply = domish.Element((NS_PUBSUB, 'pubsub'))
299 entity = reply.addElement('create') 300 entity = reply.addElement('create')
300 entity['node'] = result['node_id'] 301 entity['node'] = result['node_id']
301 return reply 302 return [reply]
302 303
303 def onConfigureGet(self, iq): 304 def onConfigureGet(self, iq):
304 self.handler_wrapper(self._onConfigureGet, iq) 305 self.handler_wrapper(self._onConfigureGet, iq)
305 306
306 def _onConfigureGet(self, iq): 307 def _onConfigureGet(self, iq):
311 312
312 def _onConfigureSet(self, iq): 313 def _onConfigureSet(self, iq):
313 raise NodeNotConfigurable 314 raise NodeNotConfigurable
314 315
315 components.registerAdapter(ComponentServiceFromNodeCreationService, backend.INodeCreationService, component.IService) 316 components.registerAdapter(ComponentServiceFromNodeCreationService, backend.INodeCreationService, component.IService)
317
318 class ComponentServiceFromAffiliationsService(Service):
319
320 def componentConnected(self, xmlstream):
321 xmlstream.addObserver(PUBSUB_AFFILIATIONS, self.onAffiliations)
322
323 def onAffiliations(self, iq):
324 self.handler_wrapper(self._onAffiliations, iq)
325
326 def _onAffiliations(self, iq):
327 d = self.backend.get_affiliations(jid.JID(iq["from"]).userhostJID())
328 d.addCallback(self._return_affiliations_response, iq)
329 return d
330
331 def _return_affiliations_response(self, result, iq):
332 reply = domish.Element((NS_PUBSUB, 'pubsub'))
333 affiliations = reply.addElement('affiliations')
334 for r in result:
335 entity = affiliations.addElement('entity')
336 entity['node'] = r['node']
337 entity['jid'] = r['jid'].full()
338 entity['affiliation'] = r['affiliation'] or 'none'
339 entity['subscription'] = r['subscription'] or 'none'
340 return [reply]
341
342 components.registerAdapter(ComponentServiceFromAffiliationsService, backend.IAffiliationsService, component.IService)