# HG changeset patch # User Goffi # Date 1492358110 -7200 # Node ID bdc64c487e218637854db45936d3c1b86d6258e4 # Parent a6c9bc4d1de0032851b452051c7ced37a1db6d2c tools/common (uri): added a method to build URI diff -r a6c9bc4d1de0 -r bdc64c487e21 src/tools/common/uri.py --- a/src/tools/common/uri.py Mon Apr 03 00:23:01 2017 +0200 +++ b/src/tools/common/uri.py Sun Apr 16 17:55:10 2017 +0200 @@ -30,6 +30,7 @@ @param uri(unicode): uri to parse @return dict(unicode, unicode): data depending of the URI where key can be: type: one of ("pubsub", TODO) + type is always present sub_type: can be: - microblog only used for pubsub for now @@ -69,3 +70,23 @@ data[u'sub_type'] = 'microblog' return data + +def addPairs(uri, pairs): + for k,v in pairs.iteritems(): + uri.append(u';' + urllib.quote_plus(k) + u'=' + urllib.quote_plus(v)) + +def buildXMPPUri(type, **kwargs): + uri = [u'xmpp:'] + subtype = kwargs.pop('subtype', None) + path = kwargs.pop('path') + uri.append(urllib.quote_plus(path).replace(u'%40', '@')) + + if type == u'pubsub': + if subtype == 'microblog' and not 'node' in kwargs: + kwargs[u'node'] = 'urn:xmpp:microblog:0' + uri.append(u'?') + addPairs(uri, kwargs) + else: + raise NotImplementedError(u'{type} URI are not handled yet'.format(type=type)) + + return u''.join(uri)