Mercurial > libervia-web
diff src/server/server.py @ 927:bb4dfc2802c0
server (pages): added getPagePathFromURI method to retrieve page handling an URI
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 16 Apr 2017 18:06:05 +0200 |
parents | 612e33fd32a8 |
children | 8a393ae90f8c |
line wrap: on
line diff
--- 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")