# HG changeset patch # User Goffi # Date 1492358765 -7200 # Node ID bb4dfc2802c0aa1eab7ce80f187bf8183018e4f8 # Parent 612e33fd32a8c527dfde595563d02482064bc508 server (pages): added getPagePathFromURI method to retrieve page handling an URI diff -r 612e33fd32a8 -r bb4dfc2802c0 src/server/server.py --- a/src/server/server.py Mon Apr 03 01:00:29 2017 +0200 +++ b/src/server/server.py Sun Apr 16 18:06:05 2017 +0200 @@ -39,6 +39,7 @@ from sat.tools import utils from sat.tools.common import regex from sat.tools.common import template +from sat.tools.common import uri as common_uri import re import glob @@ -1567,6 +1568,22 @@ cls.uri_callbacks[uri_tuple] = {u'callback': get_uri_cb, u'pre_path': pre_path} + def getPagePathFromURI(self, uri): + """Retrieve page URL from xmpp: URI + + @param uri(unicode): URI with a xmpp: scheme + @return (unicode,None): absolute path (starting from root "/") to page handling the URI + None is returned if not page has been registered for this URI + """ + uri_data = common_uri.parseXMPPUri(uri) + try: + callback_data = self.uri_callbacks[uri_data['type'], uri_data.get('sub_type')] + except KeyError: + return + else: + url = os.path.join(u'/', u'/'.join(callback_data['pre_path']), callback_data['callback'](self, uri_data)) + return url + def getChildWithDefault(self, path, request): # we handle children ourselves raise exceptions.InternalError(u"this method should not be used with LiberviaPage")