From 0815ee15769f3136fc6b9f1990c7c3a7cdaab3a1 Mon Sep 17 00:00:00 2001 From: Goffi Date: Sat, 23 Jan 2016 19:53:16 +0100 Subject: [PATCH] plugin XEP-0060, XEP-0277: added getNodeURI method --- src/plugins/plugin_xep_0060.py | 18 ++++++++++++++++++ src/plugins/plugin_xep_0277.py | 5 +---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/plugins/plugin_xep_0060.py b/src/plugins/plugin_xep_0060.py index 198525f5..31dd9091 100755 --- a/src/plugins/plugin_xep_0060.py +++ b/src/plugins/plugin_xep_0060.py @@ -31,6 +31,7 @@ from wokkel import disco from wokkel import data_form from zope.interface import implements from collections import namedtuple +import urllib import datetime from dateutil import tz # XXX: tmp.wokkel.pubsub is actually use instead of wokkel version @@ -400,6 +401,23 @@ class XEP_0060(object): client = self.host.getClient(profile_key) return client.pubsub_client.subscriptions(service, nodeIdentifier) + ## misc tools ## + + def getNodeURI(self, service, node, item=None): + """Return XMPP URI of a PubSub node + + @param service(jid.JID, None): PubSub service, + @param node(unicode): node + @return (unicode): URI of the node + """ + query_data = [('node', node.encode('utf-8'))] + if item is not None: + query_data.append(('item', item.encode('utf-8'))) + return "xmpp:{service}?{query}".format( + service=service.userhost(), + query=urllib.urlencode(query_data) + ).decode('utf-8') + ## methods to manage several stanzas/jids at once ## # generic # diff --git a/src/plugins/plugin_xep_0277.py b/src/plugins/plugin_xep_0277.py index 9d596adb..4c2e7fdb 100755 --- a/src/plugins/plugin_xep_0277.py +++ b/src/plugins/plugin_xep_0277.py @@ -533,10 +533,7 @@ class XEP_0277(object): if 'comments_node' in mb_data or 'comments_service' in mb_data: raise exceptions.DataError(u"You can't use comments_service/comments_node and comments at the same time") else: - mb_data['comments'] = u"xmpp:%(service)s?%(query)s" % { - 'service': comments_service.userhost(), - 'query': urllib.urlencode([('node', comments_node.encode('utf-8'))]) - } + mb_data['comments'] = self._p.getNodeURI(comments_service, comments_node) def _mbSend(self, service, node, data, profile_key): service = jid.JID(service) if service else None