Esempio n. 1
0
 def rewrite_uri(self, uri, force_rewrite=False):
     """Pass on extended Draco URI components."""
     if callable(uri):
         extension = self.m_api.options['extension']
         uri = dracouri.uri_from_method(uri, extension)
     scheme, host, path, query = urimod.parse_uri(uri)
     if scheme and scheme != 'http':
         return uri
     docroot = self.m_request.docroot()
     extension = self.m_api.options['extension']
     servername = self.m_request.servername()
     parts = dracouri.parse_draco_uri(uri, docroot)
     if not force_rewrite and (parts[1] and parts[1] != servername) \
                 or not parts[3].endswith('.' + extension):
         return uri
     locale = self.m_request.locale()
     if hasattr(self.m_api, 'session'):
         sessionid = self.m_api.session.sessionid()
     else:
         sessionid = None
     if sessionid:
         sessionid = list(sessionid)
         # subsession if not default
         if self.m_rewrite_link_level == 0:
             sessionid[0] = None
             if sessionid[1] == 0:
                 sessionid[1] = None
         # subsession unconditionally
         elif self.m_rewrite_link_level == 1:
             sessionid[0] = None
         session = dump_sessionid(sessionid)
     else:
         session = None
     uri = self.paste_uri(uri, locale=locale, session=session)
     return uri
Esempio n. 2
0
 def resolve_uri(self, method):
     """Return the URI of a handler method."""
     if not callable(method) and not isinstance(method, basestring):
         raise TypeError, 'Expecting method or string.'
     if callable(method):
         extension = self.m_api.options['extension']
         method = dracouri.uri_from_method(method, extension)
     elif not method.startswith('/'):
         parts = method.split('/')
         extension = self.m_api.options['extension']
         if not parts[0].endswith('.' + extension):
             parts[0] += '.%s' % extension
         method = '/%s/%s' % (self.m_request.directory(), '/'.join(parts))
     return method
Esempio n. 3
0
    def paste_uri(self, uri, scheme=None, host=None, directory=None,
                  filename=None, locale=None, session=None, pathinfo=None,
                  args=None):
        """Paste into an URI.

        The arguments specify values to paste into `uri' in case it does
        not contain that component.
        """
        if callable(uri):
            extension = self.m_api.options['extension']
            uri = dracouri.uri_from_method(uri, extension)
        if isinstance(pathinfo, list):
            pathinfo = '/'.join(pathinfo)
        if isinstance(args, dict):
            args = urimod.create_query(args)
        docroot = self.m_request.docroot()
        return dracouri.paste_draco_uri(uri, docroot, scheme, host, directory,
                                        filename, locale, session, pathinfo,
                                        args)
Esempio n. 4
0
    def patch_uri(self, uri, scheme=None, host=None, directory=None,
                  filename=None, locale=None, session=None, pathinfo=None,
                  args=None):
        """Patch an URI.

        The arguments specify with components of the URI to patch.
        Components that are not specified are left untouched.
        """
        if callable(uri):
            extension = self.m_api.options['extension']
            uri = dracouri.uri_from_method(uri, extension)
        if isinstance(pathinfo, list):
            pathinfo = '/'.join(pathinfo)
        if isinstance(args, dict):
            args = urimod.create_query(args)
        docroot = self.m_request.docroot()
        return dracouri.patch_draco_uri(uri, docroot, scheme, host, directory,
                                        filename, locale, session, pathinfo,
                                        args)