Esempio n. 1
0
def dispatch_request(environ, start_response):
    """Main entry point for the Trac web interface.

    :param environ: the WSGI environment dict
    :param start_response: the WSGI callback for starting the response
    """

    global _warn_setuptools
    if _warn_setuptools is False:
        _warn_setuptools = True
        warn_setuptools_issue(out=environ.get('wsgi.errors'))

    # SCRIPT_URL is an Apache var containing the URL before URL rewriting
    # has been applied, so we can use it to reconstruct logical SCRIPT_NAME
    script_url = environ.get('SCRIPT_URL')
    if script_url is not None:
        path_info = environ.get('PATH_INFO')
        if not path_info:
            environ['SCRIPT_NAME'] = script_url
        else:
            # mod_wsgi squashes slashes in PATH_INFO (!)
            script_url = _slashes_re.sub('/', script_url)
            path_info = _slashes_re.sub('/', path_info)
            if script_url.endswith(path_info):
                environ['SCRIPT_NAME'] = script_url[:-len(path_info)]

    # If the expected configuration keys aren't found in the WSGI environment,
    # try looking them up in the process environment variables
    environ.setdefault('trac.env_path', os.getenv('TRAC_ENV'))
    environ.setdefault('trac.env_parent_dir', os.getenv('TRAC_ENV_PARENT_DIR'))
    environ.setdefault('trac.env_index_template',
                       os.getenv('TRAC_ENV_INDEX_TEMPLATE'))
    environ.setdefault('trac.template_vars', os.getenv('TRAC_TEMPLATE_VARS'))
    environ.setdefault('trac.locale', '')
    environ.setdefault('trac.base_url', os.getenv('TRAC_BASE_URL'))
    environ.setdefault('trac.bootstrap_handler',
                       os.getenv('TRAC_BOOTSTRAP_HANDLER'))

    locale.setlocale(locale.LC_ALL, environ['trac.locale'])
    # Load handler for environment lookup and instantiation of request objects
    from trac.hooks import load_bootstrap_handler
    bootstrap_ep = environ['trac.bootstrap_handler']
    bootstrap = load_bootstrap_handler(bootstrap_ep,
                                       environ.get('wsgi.errors'))

    # Determine the environment

    env = env_error = None
    try:
        env = bootstrap.open_environment(environ, start_response)
    except RequestDone:
        return []
    except EnvironmentError, e:
        if e.__class__ is EnvironmentError:
            raise
        else:
            env_error = e
Esempio n. 2
0
def dispatch_request(environ, start_response):
    """Main entry point for the Trac web interface.

    :param environ: the WSGI environment dict
    :param start_response: the WSGI callback for starting the response
    """

    # SCRIPT_URL is an Apache var containing the URL before URL rewriting
    # has been applied, so we can use it to reconstruct logical SCRIPT_NAME
    script_url = environ.get('SCRIPT_URL')
    if script_url is not None:
        path_info = environ.get('PATH_INFO')
        if not path_info:
            environ['SCRIPT_NAME'] = script_url
        else:
            # mod_wsgi squashes slashes in PATH_INFO (!)
            script_url = _slashes_re.sub('/', script_url)
            path_info = _slashes_re.sub('/', path_info)
            if script_url.endswith(path_info):
                environ['SCRIPT_NAME'] = script_url[:-len(path_info)]

    # If the expected configuration keys aren't found in the WSGI environment,
    # try looking them up in the process environment variables
    environ.setdefault('trac.env_path', os.getenv('TRAC_ENV'))
    environ.setdefault('trac.env_parent_dir',
                       os.getenv('TRAC_ENV_PARENT_DIR'))
    environ.setdefault('trac.env_index_template',
                       os.getenv('TRAC_ENV_INDEX_TEMPLATE'))
    environ.setdefault('trac.template_vars',
                       os.getenv('TRAC_TEMPLATE_VARS'))
    environ.setdefault('trac.locale', '')
    environ.setdefault('trac.base_url',
                       os.getenv('TRAC_BASE_URL'))
    environ.setdefault('trac.bootstrap_handler',
                       os.getenv('TRAC_BOOTSTRAP_HANDLER'))

    locale.setlocale(locale.LC_ALL, environ['trac.locale'])

    # Load handler for environment lookup and instantiation of request objects
    from trac.hooks import load_bootstrap_handler
    bootstrap = load_bootstrap_handler(environ['trac.bootstrap_handler'],
                                       environ.get('wsgi.errors'))

    # Determine the environment
    
    env = env_error = None
    try:
        env = bootstrap.open_environment(environ, start_response)
    except RequestDone:
        return []
    except EnvironmentError, e:
        if e.__class__ is EnvironmentError:
            raise
        else:
            env_error = e
Esempio n. 3
0
    def __call__(self, environ, start_response):
        bootstrap_ep = os.getenv('TRAC_BOOTSTRAP_HANDLER')
        environ.setdefault('trac.bootstrap_handler', bootstrap_ep)

        # Preserve original environ and probe dispatching
        temp_environ = environ.copy()
        bootstrap = load_bootstrap_handler(bootstrap_ep)
        bootstrap.probe_environment(temp_environ)

        path_info = temp_environ.get('PATH_INFO', '')
        path_parts = filter(None, path_info.split('/'))
        env_name = temp_environ.get('trac.env_name')
        if path_parts and path_parts[0] == 'login' and env_name:
            auth = self.auths.get(env_name, self.auths.get('*'))
            if auth:
                remote_user = auth.do_auth(environ, start_response)
                if not remote_user:
                    return []
                environ['REMOTE_USER'] = remote_user
        return self.application(environ, start_response)
Esempio n. 4
0
    def __call__(self, environ, start_response):
        bootstrap_ep = os.getenv('TRAC_BOOTSTRAP_HANDLER')
        environ.setdefault('trac.bootstrap_handler', bootstrap_ep)

        # Preserve original environ and probe dispatching
        temp_environ = environ.copy()
        bootstrap = load_bootstrap_handler(bootstrap_ep)
        bootstrap.probe_environment(temp_environ)

        path_info = temp_environ.get('PATH_INFO', '')
        path_parts = filter(None, path_info.split('/'))
        env_name = temp_environ.get('trac.env_name')
        if path_parts and path_parts[0] == 'login' and env_name:
            auth = self.auths.get(env_name, self.auths.get('*'))
            if auth:
                remote_user = auth.do_auth(environ, start_response)
                if not remote_user:
                    return []
                environ['REMOTE_USER'] = remote_user
        return self.application(environ, start_response)