Mercurial > libervia-backend
comparison src/tools/common/uri.py @ 2242:e5e54ff0b775
core (tools/common/uri): don't display finale "?" if no extra data is specified
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 19 May 2017 12:40:03 +0200 |
parents | 761fa220a717 |
children | 91a14dab924d |
comparison
equal
deleted
inserted
replaced
2241:f87b673c7d17 | 2242:e5e54ff0b775 |
---|---|
75 | 75 |
76 def addPairs(uri, pairs): | 76 def addPairs(uri, pairs): |
77 for k,v in pairs.iteritems(): | 77 for k,v in pairs.iteritems(): |
78 uri.append(u';' + urllib.quote_plus(k) + u'=' + urllib.quote_plus(v)) | 78 uri.append(u';' + urllib.quote_plus(k) + u'=' + urllib.quote_plus(v)) |
79 | 79 |
80 def buildXMPPUri(type, **kwargs): | 80 def buildXMPPUri(type_, **kwargs): |
81 uri = [u'xmpp:'] | 81 uri = [u'xmpp:'] |
82 subtype = kwargs.pop('subtype', None) | 82 subtype = kwargs.pop('subtype', None) |
83 path = kwargs.pop('path') | 83 path = kwargs.pop('path') |
84 uri.append(urllib.quote_plus(path).replace(u'%40', '@')) | 84 uri.append(urllib.quote_plus(path).replace(u'%40', '@')) |
85 | 85 |
86 if type == u'pubsub': | 86 if type_ == u'pubsub': |
87 if subtype == 'microblog' and not 'node' in kwargs: | 87 if subtype == 'microblog' and not 'node' in kwargs: |
88 kwargs[u'node'] = 'urn:xmpp:microblog:0' | 88 kwargs[u'node'] = 'urn:xmpp:microblog:0' |
89 uri.append(u'?') | 89 if kwargs: |
90 addPairs(uri, kwargs) | 90 uri.append(u'?') |
91 addPairs(uri, kwargs) | |
91 else: | 92 else: |
92 raise NotImplementedError(u'{type} URI are not handled yet'.format(type=type)) | 93 raise NotImplementedError(u'{type_} URI are not handled yet'.format(type_=type_)) |
93 | 94 |
94 return u''.join(uri) | 95 return u''.join(uri) |