Beispiel #1
0
    def __call__(self, environ, start_response):
        """Pre-initialize WSGI env and call WSGI-callable."""
        # If you're calling this, then you're probably setting SCRIPT_NAME
        # to '' (some WSGI servers always set SCRIPT_NAME to '').
        # Try to look up the app using the full path.
        env1x = environ
        if six.PY2 and environ.get(ntou('wsgi.version')) == (ntou('u'), 0):
            env1x = _cpwsgi.downgrade_wsgi_ux_to_1x(environ)
        path = httputil.urljoin(env1x.get('SCRIPT_NAME', ''),
                                env1x.get('PATH_INFO', ''))
        sn = self.script_name(path or '/')
        if sn is None:
            start_response('404 Not Found', [])
            return []

        app = self.apps[sn]

        # Correct the SCRIPT_NAME and PATH_INFO environ entries.
        environ = environ.copy()
        if six.PY2 and environ.get(ntou('wsgi.version')) == (ntou('u'), 0):
            # Python 2/WSGI u.0: all strings MUST be of type unicode
            enc = environ[ntou('wsgi.url_encoding')]
            environ[ntou('SCRIPT_NAME')] = sn.decode(enc)
            environ[ntou('PATH_INFO')] = path[len(sn.rstrip('/')):].decode(enc)
        else:
            environ['SCRIPT_NAME'] = sn
            environ['PATH_INFO'] = path[len(sn.rstrip('/')):]
        return app(environ, start_response)
Beispiel #2
0
 def getPage(self, url, headers=None, method="GET", body=None,
             protocol=None):
     """Open the url. Return status, headers, body."""
     if self.script_name:
         url = httputil.urljoin(self.script_name, url)
     return webtest.WebCase.getPage(self, url, headers, method, body,
                                    protocol)
Beispiel #3
0
 def run(self):
     """Create a Request object using environ."""
     env = self.environ.get
     
     local = httputil.Host('', int(env('SERVER_PORT', 80)),
                        env('SERVER_NAME', ''))
     remote = httputil.Host(env('REMOTE_ADDR', ''),
                            int(env('REMOTE_PORT', -1)),
                            env('REMOTE_HOST', ''))
     scheme = env('wsgi.url_scheme')
     sproto = env('ACTUAL_SERVER_PROTOCOL', "HTTP/1.1")
     request, resp = self.cpapp.get_serving(local, remote, scheme, sproto)
     
     # LOGON_USER is served by IIS, and is the name of the
     # user after having been mapped to a local account.
     # Both IIS and Apache set REMOTE_USER, when possible.
     request.login = env('LOGON_USER') or env('REMOTE_USER') or None
     request.multithread = self.environ['wsgi.multithread']
     request.multiprocess = self.environ['wsgi.multiprocess']
     request.wsgi_environ = self.environ
     request.prev = env('cherrypy.previous_request', None)
     
     meth = self.environ['REQUEST_METHOD']
     
     path = httputil.urljoin(self.environ.get('SCRIPT_NAME', ''),
                             self.environ.get('PATH_INFO', ''))
     qs = self.environ.get('QUERY_STRING', '')
     rproto = self.environ.get('SERVER_PROTOCOL')
     headers = self.translate_headers(self.environ)
     rfile = self.environ['wsgi.input']
     request.run(meth, path, qs, rproto, headers, rfile)
Beispiel #4
0
    def __call__(self, environ, start_response):
        # If you're calling this, then you're probably setting SCRIPT_NAME
        # to '' (some WSGI servers always set SCRIPT_NAME to '').
        # Try to look up the app using the full path.
        env1x = environ
        if environ.get(ntou('wsgi.version')) == (ntou('u'), 0):
            env1x = _cpwsgi.downgrade_wsgi_ux_to_1x(environ)
        path = httputil.urljoin(env1x.get('SCRIPT_NAME', ''),
                                env1x.get('PATH_INFO', ''))
        sn = self.script_name(path or "/")
        if sn is None:
            start_response('404 Not Found', [])
            return []

        app = self.apps[sn]

        # Correct the SCRIPT_NAME and PATH_INFO environ entries.
        environ = environ.copy()
        if environ.get('wsgi.version') == ('u', 0):
            # Python 3/WSGI u.0: all strings MUST be full unicode
            environ['SCRIPT_NAME'] = sn
            environ['PATH_INFO'] = path[len(sn.rstrip("/")):]
        else:
            # Python 3/WSGI 1.x: all strings MUST be ISO-8859-1 str
            environ['SCRIPT_NAME'] = sn.encode('utf-8').decode('ISO-8859-1')
            environ['PATH_INFO'] = path[len(sn.rstrip("/")):].encode(
                'utf-8').decode('ISO-8859-1')
        return app(environ, start_response)
Beispiel #5
0
 def __call__(self, environ, start_response):
     # If you're calling this, then you're probably setting SCRIPT_NAME
     # to '' (some WSGI servers always set SCRIPT_NAME to '').
     # Try to look up the app using the full path.
     env1x = environ
     if environ.get(ntou('wsgi.version')) == (ntou('u'), 0):
         env1x = _cpwsgi.downgrade_wsgi_ux_to_1x(environ)
     path = httputil.urljoin(env1x.get('SCRIPT_NAME', ''),
                             env1x.get('PATH_INFO', ''))
     sn = self.script_name(path or "/")
     if sn is None:
         start_response('404 Not Found', [])
         return []
     
     app = self.apps[sn]
     
     # Correct the SCRIPT_NAME and PATH_INFO environ entries.
     environ = environ.copy()
     if environ.get('wsgi.version') == ('u', 0):
         # Python 3/WSGI u.0: all strings MUST be full unicode
         environ['SCRIPT_NAME'] = sn
         environ['PATH_INFO'] = path[len(sn.rstrip("/")):]
     else:
         # Python 3/WSGI 1.x: all strings MUST be ISO-8859-1 str
         environ['SCRIPT_NAME'] = sn.encode('utf-8').decode('ISO-8859-1')
         environ['PATH_INFO'] = path[len(sn.rstrip("/")):].encode('utf-8').decode('ISO-8859-1')
     return app(environ, start_response)
Beispiel #6
0
    def __call__(self, environ, start_response):
        # If you're calling this, then you're probably setting SCRIPT_NAME
        # to '' (some WSGI servers always set SCRIPT_NAME to '').
        # Try to look up the app using the full path.
        env1x = environ
        if environ.get(ntou('wsgi.version')) == (ntou('u'), 0):
            env1x = _cpwsgi.downgrade_wsgi_ux_to_1x(environ)
        path = httputil.urljoin(env1x.get('SCRIPT_NAME', ''),
                                env1x.get('PATH_INFO', ''))
        sn = self.script_name(path or "/")
        if sn is None:
            start_response('404 Not Found', [])
            return []

        app = self.apps[sn]

        # Correct the SCRIPT_NAME and PATH_INFO environ entries.
        environ = environ.copy()
        if not py3k:
            if environ.get(ntou('wsgi.version')) == (ntou('u'), 0):
                # Python 2/WSGI u.0: all strings MUST be of type unicode
                enc = environ[ntou('wsgi.url_encoding')]
                environ[ntou('SCRIPT_NAME')] = sn.decode(enc)
                environ[ntou('PATH_INFO')] = path[len(sn.rstrip("/")):].decode(enc)
            else:
                # Python 2/WSGI 1.x: all strings MUST be of type str
                environ['SCRIPT_NAME'] = sn
                environ['PATH_INFO'] = path[len(sn.rstrip("/")):]
        else:
            if environ.get(ntou('wsgi.version')) == (ntou('u'), 0):
                # Python 3/WSGI u.0: all strings MUST be full unicode
                environ['SCRIPT_NAME'] = sn
                environ['PATH_INFO'] = path[len(sn.rstrip("/")):]
            # for the wsgi 1.0 the environment is already encoded by the Gateway.
        return app(environ, start_response)
Beispiel #7
0
    def __call__(self, environ, start_response):
        """Pre-initialize WSGI env and call WSGI-callable."""
        # If you're calling this, then you're probably setting SCRIPT_NAME
        # to '' (some WSGI servers always set SCRIPT_NAME to '').
        # Try to look up the app using the full path.
        env1x = environ
        if six.PY2 and environ.get(ntou('wsgi.version')) == (ntou('u'), 0):
            env1x = _cpwsgi.downgrade_wsgi_ux_to_1x(environ)
        path = httputil.urljoin(env1x.get('SCRIPT_NAME', ''),
                                env1x.get('PATH_INFO', ''))
        sn = self.script_name(path or '/')
        if sn is None:
            start_response('404 Not Found', [])
            return []

        app = self.apps[sn]

        # Correct the SCRIPT_NAME and PATH_INFO environ entries.
        environ = environ.copy()
        if six.PY2 and environ.get(ntou('wsgi.version')) == (ntou('u'), 0):
            # Python 2/WSGI u.0: all strings MUST be of type unicode
            enc = environ[ntou('wsgi.url_encoding')]
            environ[ntou('SCRIPT_NAME')] = sn.decode(enc)
            environ[ntou('PATH_INFO')] = path[len(sn.rstrip('/')):].decode(enc)
        else:
            environ['SCRIPT_NAME'] = sn
            environ['PATH_INFO'] = path[len(sn.rstrip('/')):]
        return app(environ, start_response)
    def run(self):
        """Create a Request object using environ."""
        env = self.environ.get

        local = httputil.Host('', int(env('SERVER_PORT', 80)),
                              env('SERVER_NAME', ''))
        remote = httputil.Host(env('REMOTE_ADDR', ''),
                               int(env('REMOTE_PORT', -1)),
                               env('REMOTE_HOST', ''))
        scheme = env('wsgi.url_scheme')
        sproto = env('ACTUAL_SERVER_PROTOCOL', "HTTP/1.1")
        request, resp = self.cpapp.get_serving(local, remote, scheme, sproto)

        # LOGON_USER is served by IIS, and is the name of the
        # user after having been mapped to a local account.
        # Both IIS and Apache set REMOTE_USER, when possible.
        request.login = env('LOGON_USER') or env('REMOTE_USER') or None
        request.multithread = self.environ['wsgi.multithread']
        request.multiprocess = self.environ['wsgi.multiprocess']
        request.wsgi_environ = self.environ
        request.prev = env('cherrypy.previous_request', None)

        meth = self.environ['REQUEST_METHOD']

        path = httputil.urljoin(self.environ.get('SCRIPT_NAME', ''),
                                self.environ.get('PATH_INFO', ''))
        qs = self.environ.get('QUERY_STRING', '')
        rproto = self.environ.get('SERVER_PROTOCOL')
        headers = self.translate_headers(self.environ)
        rfile = self.environ['wsgi.input']
        request.run(meth, path, qs, rproto, headers, rfile)
Beispiel #9
0
    def run(self):
        """Create a Request object using environ."""
        env = self.environ.get

        local = httputil.Host('',
                              int(env('SERVER_PORT', 80) or -1),
                              env('SERVER_NAME', ''))
        remote = httputil.Host(env('REMOTE_ADDR', ''),
                               int(env('REMOTE_PORT', -1) or -1),
                               env('REMOTE_HOST', ''))
        scheme = env('wsgi.url_scheme')
        sproto = env('ACTUAL_SERVER_PROTOCOL', "HTTP/1.1")
        request, resp = self.cpapp.get_serving(local, remote, scheme, sproto)

        # LOGON_USER is served by IIS, and is the name of the
        # user after having been mapped to a local account.
        # Both IIS and Apache set REMOTE_USER, when possible.
        request.login = env('LOGON_USER') or env('REMOTE_USER') or None
        request.multithread = self.environ['wsgi.multithread']
        request.multiprocess = self.environ['wsgi.multiprocess']
        request.wsgi_environ = self.environ
        request.prev = env('cherrypy.previous_request', None)

        meth = self.environ['REQUEST_METHOD']

        path = httputil.urljoin(self.environ.get('SCRIPT_NAME', ''),
                                self.environ.get('PATH_INFO', ''))
        qs = self.environ.get('QUERY_STRING', '')

        if six.PY3:
            # This isn't perfect; if the given PATH_INFO is in the
            # wrong encoding, it may fail to match the appropriate config
            # section URI. But meh.
            old_enc = self.environ.get('wsgi.url_encoding', 'ISO-8859-1')
            new_enc = self.cpapp.find_config(self.environ.get('PATH_INFO', ''),
                                             "request.uri_encoding", 'utf-8')
            if new_enc.lower() != old_enc.lower():
                # Even though the path and qs are unicode, the WSGI server
                # is required by PEP 3333 to coerce them to ISO-8859-1
                # masquerading as unicode. So we have to encode back to
                # bytes and then decode again using the "correct" encoding.
                try:
                    u_path = path.encode(old_enc).decode(new_enc)
                    u_qs = qs.encode(old_enc).decode(new_enc)
                except (UnicodeEncodeError, UnicodeDecodeError):
                    # Just pass them through without transcoding and hope.
                    pass
                else:
                    # Only set transcoded values if they both succeed.
                    path = u_path
                    qs = u_qs

        rproto = self.environ.get('SERVER_PROTOCOL')
        headers = self.translate_headers(self.environ)
        rfile = self.environ['wsgi.input']
        request.run(meth, path, qs, rproto, headers, rfile)
Beispiel #10
0
    def run(self):
        """Create a Request object using environ."""
        env = self.environ.get

        local = httputil.Host('',
                              int(env('SERVER_PORT', 80) or -1),
                              env('SERVER_NAME', ''))
        remote = httputil.Host(env('REMOTE_ADDR', ''),
                               int(env('REMOTE_PORT', -1) or -1),
                               env('REMOTE_HOST', ''))
        scheme = env('wsgi.url_scheme')
        sproto = env('ACTUAL_SERVER_PROTOCOL', "HTTP/1.1")
        request, resp = self.cpapp.get_serving(local, remote, scheme, sproto)

        # LOGON_USER is served by IIS, and is the name of the
        # user after having been mapped to a local account.
        # Both IIS and Apache set REMOTE_USER, when possible.
        request.login = env('LOGON_USER') or env('REMOTE_USER') or None
        request.multithread = self.environ['wsgi.multithread']
        request.multiprocess = self.environ['wsgi.multiprocess']
        request.wsgi_environ = self.environ
        request.prev = env('cherrypy.previous_request', None)

        meth = self.environ['REQUEST_METHOD']

        path = httputil.urljoin(self.environ.get('SCRIPT_NAME', ''),
                                self.environ.get('PATH_INFO', ''))
        qs = self.environ.get('QUERY_STRING', '')

        if py3k:
            # This isn't perfect; if the given PATH_INFO is in the
            # wrong encoding, it may fail to match the appropriate config
            # section URI. But meh.
            old_enc = self.environ.get('wsgi.url_encoding', 'ISO-8859-1')
            new_enc = self.cpapp.find_config(self.environ.get('PATH_INFO', ''),
                                             "request.uri_encoding", 'utf-8')
            if new_enc.lower() != old_enc.lower():
                # Even though the path and qs are unicode, the WSGI server
                # is required by PEP 3333 to coerce them to ISO-8859-1
                # masquerading as unicode. So we have to encode back to
                # bytes and then decode again using the "correct" encoding.
                try:
                    u_path = path.encode(old_enc).decode(new_enc)
                    u_qs = qs.encode(old_enc).decode(new_enc)
                except (UnicodeEncodeError, UnicodeDecodeError):
                    # Just pass them through without transcoding and hope.
                    pass
                else:
                    # Only set transcoded values if they both succeed.
                    path = u_path
                    qs = u_qs

        rproto = self.environ.get('SERVER_PROTOCOL')
        headers = self.translate_headers(self.environ)
        rfile = self.environ['wsgi.input']
        request.run(meth, path, qs, rproto, headers, rfile)
Beispiel #11
0
 def getPage(self,
             url,
             headers=None,
             method='GET',
             body=None,
             protocol=None):
     if self.script_name:
         url = httputil.urljoin(self.script_name, url)
     return webtest.WebCase.getPage(self, url, headers, method, body,
                                    protocol)
Beispiel #12
0
    def getPage(self, url, headers=None, method="GET", body=None,
                protocol=None, raise_subcls=None):
        """Open the url. Return status, headers, body.

        `raise_subcls` must be a tuple with the exceptions classes
        or a single exception class that are not going to be considered
        a socket.error regardless that they were are subclass of a
        socket.error and therefore not considered for a connection retry.
        """
        if self.script_name:
            url = httputil.urljoin(self.script_name, url)
        return webtest.WebCase.getPage(self, url, headers, method, body,
                                       protocol, raise_subcls)
Beispiel #13
0
    def getPage(self, url, headers=None, method="GET", body=None,
                protocol=None, raise_subcls=None):
        """Open the url. Return status, headers, body.

        `raise_subcls` must be a tuple with the exceptions classes
        or a single exception class that are not going to be considered
        a socket.error regardless that they were are subclass of a
        socket.error and therefore not considered for a connection retry.
        """
        if self.script_name:
            url = httputil.urljoin(self.script_name, url)
        return webtest.WebCase.getPage(self, url, headers, method, body,
                                       protocol, raise_subcls)
Beispiel #14
0
    def script_name(self, path = None):
        if path is None:
            try:
                request = cherrypy.serving.request
                path = httputil.urljoin(request.script_name, request.path_info)
            except AttributeError:
                return

        while True:
            if path in self.apps:
                return path
            if path == '':
                return
            path = path[:path.rfind('/')]
Beispiel #15
0
    def script_name(self, path=None):
        if path is None:
            try:
                request = cherrypy.serving.request
                path = httputil.urljoin(request.script_name, request.path_info)
            except AttributeError:
                return

        while True:
            if path in self.apps:
                return path
            if path == '':
                return
            path = path[:path.rfind('/')]
 def vhost_dispatch(path_info):
     request = cherrypy.serving.request
     header = request.headers.get
     domain = header('Host', '')
     if use_x_forwarded_host:
         domain = header('X-Forwarded-Host', domain)
     prefix = domains.get(domain, '')
     if prefix:
         path_info = httputil.urljoin(prefix, path_info)
     result = next_dispatcher(path_info)
     section = request.config.get('tools.staticdir.section')
     if section:
         section = section[len(prefix):]
         request.config['tools.staticdir.section'] = section
     return result
Beispiel #17
0
 def vhost_dispatch(path_info):
     request = cherrypy.serving.request
     header = request.headers.get
     domain = header("Host", "")
     if use_x_forwarded_host:
         domain = header("X-Forwarded-Host", domain)
     prefix = domains.get(domain, "")
     if prefix:
         path_info = httputil.urljoin(prefix, path_info)
     result = next_dispatcher(path_info)
     section = request.config.get("tools.staticdir.section")
     if section:
         section = section[len(prefix) :]
         request.config["tools.staticdir.section"] = section
     return result
Beispiel #18
0
    def script_name(self, path = None):
        """The script_name of the app at the given path, or None.
        
        If path is None, cherrypy.request is used.
        """
        if path is None:
            try:
                request = cherrypy.serving.request
                path = httputil.urljoin(request.script_name, request.path_info)
            except AttributeError:
                return

        while True:
            if path in self.apps:
                return path
            if path == '':
                return
            path = path[:path.rfind('/')]
Beispiel #19
0
 def __call__(self, environ, start_response):
     env1x = environ
     if environ.get(ntou('wsgi.version')) == (ntou('u'), 0):
         env1x = _cpwsgi.downgrade_wsgi_ux_to_1x(environ)
     path = httputil.urljoin(env1x.get('SCRIPT_NAME', ''), env1x.get('PATH_INFO', ''))
     sn = self.script_name(path or '/')
     if sn is None:
         start_response('404 Not Found', [])
         return []
     app = self.apps[sn]
     environ = environ.copy()
     if environ.get(u'wsgi.version') == (u'u', 0):
         enc = environ[u'wsgi.url_encoding']
         environ[u'SCRIPT_NAME'] = sn.decode(enc)
         environ[u'PATH_INFO'] = path[len(sn.rstrip('/')):].decode(enc)
     else:
         environ['SCRIPT_NAME'] = sn
         environ['PATH_INFO'] = path[len(sn.rstrip('/')):]
     return app(environ, start_response)
Beispiel #20
0
 def __call__(self, environ, start_response):
     env1x = environ
     if environ.get(ntou('wsgi.version')) == (ntou('u'), 0):
         env1x = _cpwsgi.downgrade_wsgi_ux_to_1x(environ)
     path = httputil.urljoin(env1x.get('SCRIPT_NAME', ''), env1x.get('PATH_INFO', ''))
     sn = self.script_name(path or '/')
     if sn is None:
         start_response('404 Not Found', [])
         return []
     app = self.apps[sn]
     environ = environ.copy()
     if environ.get(u'wsgi.version') == (u'u', 0):
         enc = environ[u'wsgi.url_encoding']
         environ[u'SCRIPT_NAME'] = sn.decode(enc)
         environ[u'PATH_INFO'] = path[len(sn.rstrip('/')):].decode(enc)
     else:
         environ['SCRIPT_NAME'] = sn
         environ['PATH_INFO'] = path[len(sn.rstrip('/')):]
     return app(environ, start_response)
Beispiel #21
0
 def run(self):
     env = self.environ.get
     local = httputil.Host('', int(env('SERVER_PORT', 80)), env('SERVER_NAME', ''))
     remote = httputil.Host(env('REMOTE_ADDR', ''), int(env('REMOTE_PORT', -1) or -1), env('REMOTE_HOST', ''))
     scheme = env('wsgi.url_scheme')
     sproto = env('ACTUAL_SERVER_PROTOCOL', 'HTTP/1.1')
     request, resp = self.cpapp.get_serving(local, remote, scheme, sproto)
     request.login = env('LOGON_USER') or env('REMOTE_USER') or None
     request.multithread = self.environ['wsgi.multithread']
     request.multiprocess = self.environ['wsgi.multiprocess']
     request.wsgi_environ = self.environ
     request.prev = env('cherrypy.previous_request', None)
     meth = self.environ['REQUEST_METHOD']
     path = httputil.urljoin(self.environ.get('SCRIPT_NAME', ''), self.environ.get('PATH_INFO', ''))
     qs = self.environ.get('QUERY_STRING', '')
     rproto = self.environ.get('SERVER_PROTOCOL')
     headers = self.translate_headers(self.environ)
     rfile = self.environ['wsgi.input']
     request.run(meth, path, qs, rproto, headers, rfile)
Beispiel #22
0
    def __call__(self, environ, start_response):
        """Pre-initialize WSGI env and call WSGI-callable."""
        # If you're calling this, then you're probably setting SCRIPT_NAME
        # to '' (some WSGI servers always set SCRIPT_NAME to '').
        # Try to look up the app using the full path.
        env1x = environ
        path = httputil.urljoin(env1x.get('SCRIPT_NAME', ''),
                                env1x.get('PATH_INFO', ''))
        sn = self.script_name(path or '/')
        if sn is None:
            start_response('404 Not Found', [])
            return []

        app = self.apps[sn]

        # Correct the SCRIPT_NAME and PATH_INFO environ entries.
        environ = environ.copy()
        environ['SCRIPT_NAME'] = sn
        environ['PATH_INFO'] = path[len(sn.rstrip('/')):]
        return app(environ, start_response)
Beispiel #23
0
    def __call__(self, environ, start_response):
        """Pre-initialize WSGI env and call WSGI-callable."""
        # If you're calling this, then you're probably setting SCRIPT_NAME
        # to '' (some WSGI servers always set SCRIPT_NAME to '').
        # Try to look up the app using the full path.
        env1x = environ
        path = httputil.urljoin(env1x.get('SCRIPT_NAME', ''),
                                env1x.get('PATH_INFO', ''))
        sn = self.script_name(path or '/')
        if sn is None:
            start_response('404 Not Found', [])
            return []

        app = self.apps[sn]

        # Correct the SCRIPT_NAME and PATH_INFO environ entries.
        environ = environ.copy()
        environ['SCRIPT_NAME'] = sn
        environ['PATH_INFO'] = path[len(sn.rstrip('/')):]
        return app(environ, start_response)
Beispiel #24
0
    def vhost_dispatch(path_info):
        request = cherrypy.serving.request
        header = request.headers.get

        domain = header('Host', '')
        if use_x_forwarded_host:
            domain = header("X-Forwarded-Host", domain)

        prefix = domains.get(domain, "")
        if prefix:
            path_info = httputil.urljoin(prefix, path_info)

        result = next_dispatcher(path_info)

        # Touch up staticdir config. See http://www.cherrypy.org/ticket/614.
        section = request.config.get('tools.staticdir.section')
        if section:
            section = section[len(prefix):]
            request.config['tools.staticdir.section'] = section

        return result
Beispiel #25
0
    def script_name(self, path=None):
        """The script_name of the app at the given path, or None.
        
        If path is None, cherrypy.request is used.
        """
        if path is None:
            try:
                request = cherrypy.serving.request
                path = httputil.urljoin(request.script_name, request.path_info)
            except AttributeError:
                return None

        while True:
            if path in self.apps:
                return path

            if path == "":
                return None

            # Move one node up the tree and try again.
            path = path[:path.rfind("/")]
Beispiel #26
0
    def vhost_dispatch(path_info):
        request = cherrypy.serving.request
        header = request.headers.get

        domain = header('Host', '')
        if use_x_forwarded_host:
            domain = header("X-Forwarded-Host", domain)

        prefix = domains.get(domain, "")
        if prefix:
            path_info = httputil.urljoin(prefix, path_info)

        result = next_dispatcher(path_info)

        # Touch up staticdir config. See https://bitbucket.org/cherrypy/cherrypy/issue/614.
        section = request.config.get('tools.staticdir.section')
        if section:
            section = section[len(prefix):]
            request.config['tools.staticdir.section'] = section

        return result
Beispiel #27
0
    def script_name(self, path=None):
        """Return the script_name of the app at the given path, or None.

        If path is None, cherrypy.request is used.
        """
        if path is None:
            try:
                request = cherrypy.serving.request
                path = httputil.urljoin(request.script_name,
                                        request.path_info)
            except AttributeError:
                return None

        while True:
            if path in self.apps:
                return path

            if path == '':
                return None

            # Move one node up the tree and try again.
            path = path[:path.rfind('/')]
Beispiel #28
0
    def __call__(self, environ, start_response):
        # If you're calling this, then you're probably setting SCRIPT_NAME
        # to '' (some WSGI servers always set SCRIPT_NAME to '').
        # Try to look up the app using the full path.
        env1x = environ
        if environ.get(ntou('wsgi.version')) == (ntou('u'), 0):
            env1x = _cpwsgi.downgrade_wsgi_ux_to_1x(environ)
        path = httputil.urljoin(env1x.get('SCRIPT_NAME', ''),
                                env1x.get('PATH_INFO', ''))
        sn = self.script_name(path or "/")
        if sn is None:
            start_response('404 Not Found', [])
            return []

        app = self.apps[sn]

        # Correct the SCRIPT_NAME and PATH_INFO environ entries.
        environ = environ.copy()
        if not py3k:
            if environ.get(ntou('wsgi.version')) == (ntou('u'), 0):
                # Python 2/WSGI u.0: all strings MUST be of type unicode
                enc = environ[ntou('wsgi.url_encoding')]
                environ[ntou('SCRIPT_NAME')] = sn.decode(enc)
                environ[ntou('PATH_INFO')] = path[len(sn.rstrip("/")):].decode(
                    enc)
            else:
                # Python 2/WSGI 1.x: all strings MUST be of type str
                environ['SCRIPT_NAME'] = sn
                environ['PATH_INFO'] = path[len(sn.rstrip("/")):]
        else:
            if environ.get(ntou('wsgi.version')) == (ntou('u'), 0):
                # Python 3/WSGI u.0: all strings MUST be full unicode
                environ['SCRIPT_NAME'] = sn
                environ['PATH_INFO'] = path[len(sn.rstrip("/")):]
            # for the wsgi 1.0 the environment is already encoded by the Gateway.
        return app(environ, start_response)
Beispiel #29
0
def test_urljoin(script_name, path_info, expected_url):
    """Test all slash+atom combinations for SCRIPT_NAME and PATH_INFO."""
    actual_url = httputil.urljoin(script_name, path_info)
    assert actual_url == expected_url
 def test_urljoin(self):
     # Test all slash+atom combinations for SCRIPT_NAME and PATH_INFO
     self.assertEqual(httputil.urljoin("/sn/", "/pi/"), "/sn/pi/")
     self.assertEqual(httputil.urljoin("/sn/", "/pi"), "/sn/pi")
     self.assertEqual(httputil.urljoin("/sn/", "/"), "/sn/")
     self.assertEqual(httputil.urljoin("/sn/", ""), "/sn/")
     self.assertEqual(httputil.urljoin("/sn", "/pi/"), "/sn/pi/")
     self.assertEqual(httputil.urljoin("/sn", "/pi"), "/sn/pi")
     self.assertEqual(httputil.urljoin("/sn", "/"), "/sn/")
     self.assertEqual(httputil.urljoin("/sn", ""), "/sn")
     self.assertEqual(httputil.urljoin("/", "/pi/"), "/pi/")
     self.assertEqual(httputil.urljoin("/", "/pi"), "/pi")
     self.assertEqual(httputil.urljoin("/", "/"), "/")
     self.assertEqual(httputil.urljoin("/", ""), "/")
     self.assertEqual(httputil.urljoin("", "/pi/"), "/pi/")
     self.assertEqual(httputil.urljoin("", "/pi"), "/pi")
     self.assertEqual(httputil.urljoin("", "/"), "/")
     self.assertEqual(httputil.urljoin("", ""), "/")
Beispiel #31
0
 def test_urljoin(self):
     self.assertEqual(httputil.urljoin('/sn/', '/pi/'), '/sn/pi/')
     self.assertEqual(httputil.urljoin('/sn/', '/pi'), '/sn/pi')
     self.assertEqual(httputil.urljoin('/sn/', '/'), '/sn/')
     self.assertEqual(httputil.urljoin('/sn/', ''), '/sn/')
     self.assertEqual(httputil.urljoin('/sn', '/pi/'), '/sn/pi/')
     self.assertEqual(httputil.urljoin('/sn', '/pi'), '/sn/pi')
     self.assertEqual(httputil.urljoin('/sn', '/'), '/sn/')
     self.assertEqual(httputil.urljoin('/sn', ''), '/sn')
     self.assertEqual(httputil.urljoin('/', '/pi/'), '/pi/')
     self.assertEqual(httputil.urljoin('/', '/pi'), '/pi')
     self.assertEqual(httputil.urljoin('/', '/'), '/')
     self.assertEqual(httputil.urljoin('/', ''), '/')
     self.assertEqual(httputil.urljoin('', '/pi/'), '/pi/')
     self.assertEqual(httputil.urljoin('', '/pi'), '/pi')
     self.assertEqual(httputil.urljoin('', '/'), '/')
     self.assertEqual(httputil.urljoin('', ''), '/')
Beispiel #32
0
 def test_urljoin(self):
     # Test all slash+atom combinations for SCRIPT_NAME and PATH_INFO
     self.assertEqual(httputil.urljoin("/sn/", "/pi/"), "/sn/pi/")
     self.assertEqual(httputil.urljoin("/sn/", "/pi"), "/sn/pi")
     self.assertEqual(httputil.urljoin("/sn/", "/"), "/sn/")
     self.assertEqual(httputil.urljoin("/sn/", ""), "/sn/")
     self.assertEqual(httputil.urljoin("/sn", "/pi/"), "/sn/pi/")
     self.assertEqual(httputil.urljoin("/sn", "/pi"), "/sn/pi")
     self.assertEqual(httputil.urljoin("/sn", "/"), "/sn/")
     self.assertEqual(httputil.urljoin("/sn", ""), "/sn")
     self.assertEqual(httputil.urljoin("/", "/pi/"), "/pi/")
     self.assertEqual(httputil.urljoin("/", "/pi"), "/pi")
     self.assertEqual(httputil.urljoin("/", "/"), "/")
     self.assertEqual(httputil.urljoin("/", ""), "/")
     self.assertEqual(httputil.urljoin("", "/pi/"), "/pi/")
     self.assertEqual(httputil.urljoin("", "/pi"), "/pi")
     self.assertEqual(httputil.urljoin("", "/"), "/")
     self.assertEqual(httputil.urljoin("", ""), "/")
Beispiel #33
0
 def getPage(self, url, headers = None, method = 'GET', body = None, protocol = None):
     if self.script_name:
         url = httputil.urljoin(self.script_name, url)
     return webtest.WebCase.getPage(self, url, headers, method, body, protocol)
Beispiel #34
0
 def getPage(self, url, *args, **kwargs):
     """Open the url.
     """
     if self.script_name:
         url = httputil.urljoin(self.script_name, url)
     return webtest.WebCase.getPage(self, url, *args, **kwargs)
Beispiel #35
0
def test_urljoin(script_name, path_info, expected_url):
    """Test all slash+atom combinations for SCRIPT_NAME and PATH_INFO."""
    actual_url = httputil.urljoin(script_name, path_info)
    assert actual_url == expected_url
 def test_urljoin(self):
     self.assertEqual(httputil.urljoin('/sn/', '/pi/'), '/sn/pi/')
     self.assertEqual(httputil.urljoin('/sn/', '/pi'), '/sn/pi')
     self.assertEqual(httputil.urljoin('/sn/', '/'), '/sn/')
     self.assertEqual(httputil.urljoin('/sn/', ''), '/sn/')
     self.assertEqual(httputil.urljoin('/sn', '/pi/'), '/sn/pi/')
     self.assertEqual(httputil.urljoin('/sn', '/pi'), '/sn/pi')
     self.assertEqual(httputil.urljoin('/sn', '/'), '/sn/')
     self.assertEqual(httputil.urljoin('/sn', ''), '/sn')
     self.assertEqual(httputil.urljoin('/', '/pi/'), '/pi/')
     self.assertEqual(httputil.urljoin('/', '/pi'), '/pi')
     self.assertEqual(httputil.urljoin('/', '/'), '/')
     self.assertEqual(httputil.urljoin('/', ''), '/')
     self.assertEqual(httputil.urljoin('', '/pi/'), '/pi/')
     self.assertEqual(httputil.urljoin('', '/pi'), '/pi')
     self.assertEqual(httputil.urljoin('', '/'), '/')
     self.assertEqual(httputil.urljoin('', ''), '/')
Beispiel #37
0
 def test_urljoin(self):
     # Test all slash+atom combinations for SCRIPT_NAME and PATH_INFO
     self.assertEqual(httputil.urljoin('/sn/', '/pi/'), '/sn/pi/')
     self.assertEqual(httputil.urljoin('/sn/', '/pi'), '/sn/pi')
     self.assertEqual(httputil.urljoin('/sn/', '/'), '/sn/')
     self.assertEqual(httputil.urljoin('/sn/', ''), '/sn/')
     self.assertEqual(httputil.urljoin('/sn', '/pi/'), '/sn/pi/')
     self.assertEqual(httputil.urljoin('/sn', '/pi'), '/sn/pi')
     self.assertEqual(httputil.urljoin('/sn', '/'), '/sn/')
     self.assertEqual(httputil.urljoin('/sn', ''), '/sn')
     self.assertEqual(httputil.urljoin('/', '/pi/'), '/pi/')
     self.assertEqual(httputil.urljoin('/', '/pi'), '/pi')
     self.assertEqual(httputil.urljoin('/', '/'), '/')
     self.assertEqual(httputil.urljoin('/', ''), '/')
     self.assertEqual(httputil.urljoin('', '/pi/'), '/pi/')
     self.assertEqual(httputil.urljoin('', '/pi'), '/pi')
     self.assertEqual(httputil.urljoin('', '/'), '/')
     self.assertEqual(httputil.urljoin('', ''), '/')