comparison 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
comparison
equal deleted inserted replaced
926:612e33fd32a8 927:bb4dfc2802c0
37 from sat.core.i18n import _, D_ 37 from sat.core.i18n import _, D_
38 from sat.core import exceptions 38 from sat.core import exceptions
39 from sat.tools import utils 39 from sat.tools import utils
40 from sat.tools.common import regex 40 from sat.tools.common import regex
41 from sat.tools.common import template 41 from sat.tools.common import template
42 from sat.tools.common import uri as common_uri
42 43
43 import re 44 import re
44 import glob 45 import glob
45 import os.path 46 import os.path
46 import sys 47 import sys
1565 if uri_tuple in cls.uri_callbacks: 1566 if uri_tuple in cls.uri_callbacks:
1566 log.info(_(u"{}/{} URIs are already handled, replacing by the new handler").format(*uri_tuple)) 1567 log.info(_(u"{}/{} URIs are already handled, replacing by the new handler").format(*uri_tuple))
1567 cls.uri_callbacks[uri_tuple] = {u'callback': get_uri_cb, 1568 cls.uri_callbacks[uri_tuple] = {u'callback': get_uri_cb,
1568 u'pre_path': pre_path} 1569 u'pre_path': pre_path}
1569 1570
1571 def getPagePathFromURI(self, uri):
1572 """Retrieve page URL from xmpp: URI
1573
1574 @param uri(unicode): URI with a xmpp: scheme
1575 @return (unicode,None): absolute path (starting from root "/") to page handling the URI
1576 None is returned if not page has been registered for this URI
1577 """
1578 uri_data = common_uri.parseXMPPUri(uri)
1579 try:
1580 callback_data = self.uri_callbacks[uri_data['type'], uri_data.get('sub_type')]
1581 except KeyError:
1582 return
1583 else:
1584 url = os.path.join(u'/', u'/'.join(callback_data['pre_path']), callback_data['callback'](self, uri_data))
1585 return url
1586
1570 def getChildWithDefault(self, path, request): 1587 def getChildWithDefault(self, path, request):
1571 # we handle children ourselves 1588 # we handle children ourselves
1572 raise exceptions.InternalError(u"this method should not be used with LiberviaPage") 1589 raise exceptions.InternalError(u"this method should not be used with LiberviaPage")
1573 1590
1574 def nextPath(self, request): 1591 def nextPath(self, request):