comparison src/plugins/plugin_xep_0060.py @ 2226:6856b7225c5b

plugin XEP-0060: getNodeAffiliations use jid.JID as keys instead of jids as unicode
author Goffi <goffi@goffi.org>
date Mon, 17 Apr 2017 20:31:12 +0200
parents 6a2fa651d7fa
children b5befe7722d3
comparison
equal deleted inserted replaced
2225:301bb52c8715 2226:6856b7225c5b
481 return d 481 return d
482 482
483 def _getNodeAffiliations(self, service_s, nodeIdentifier, profile_key): 483 def _getNodeAffiliations(self, service_s, nodeIdentifier, profile_key):
484 client = self.host.getClient(profile_key) 484 client = self.host.getClient(profile_key)
485 d = self.getNodeAffiliations(client, jid.JID(service_s) if service_s else None, nodeIdentifier) 485 d = self.getNodeAffiliations(client, jid.JID(service_s) if service_s else None, nodeIdentifier)
486 d.addCallback(lambda affiliations: {j.full(): a for j, a in affiliations.iteritems()})
486 return d 487 return d
487 488
488 def getNodeAffiliations(self, client, service, nodeIdentifier): 489 def getNodeAffiliations(self, client, service, nodeIdentifier):
489 """Retrieve affiliations of a node owned by profile""" 490 """Retrieve affiliations of a node owned by profile"""
490 request = pubsub.PubSubRequest('affiliationsGet') 491 request = pubsub.PubSubRequest('affiliationsGet')
495 try: 496 try:
496 affiliations_elt = next(iq_elt.pubsub.elements((pubsub.NS_PUBSUB_OWNER, 'affiliations'))) 497 affiliations_elt = next(iq_elt.pubsub.elements((pubsub.NS_PUBSUB_OWNER, 'affiliations')))
497 except StopIteration: 498 except StopIteration:
498 raise ValueError(_(u"Invalid result: missing <affiliations> element: {}").format(iq_elt.toXml)) 499 raise ValueError(_(u"Invalid result: missing <affiliations> element: {}").format(iq_elt.toXml))
499 try: 500 try:
500 return {e['jid']: e['affiliation'] for e in affiliations_elt.elements((pubsub.NS_PUBSUB_OWNER, 'affiliation'))} 501 return {jid.JID(e['jid']): e['affiliation'] for e in affiliations_elt.elements((pubsub.NS_PUBSUB_OWNER, 'affiliation'))}
501 except KeyError: 502 except KeyError:
502 raise ValueError(_(u"Invalid result: bad <affiliation> element: {}").format(iq_elt.toXml)) 503 raise ValueError(_(u"Invalid result: bad <affiliation> element: {}").format(iq_elt.toXml))
503 504
504 d = request.send(client.xmlstream) 505 d = request.send(client.xmlstream)
505 d.addCallback(cb) 506 d.addCallback(cb)