Exemple #1
0
 def __init__(self, location=None, errors={}):
     if hasattr(state, 'controller'):
         cfg = _cfg(state.controller)
     else:
         cfg = {}
     if location is None and 'error_handler' in cfg:
         location = cfg['error_handler']
         if callable(location):
             location = location()
     merge_dicts(request.pecan['validation_errors'], errors)
     if 'pecan.params' not in request.environ:
         request.environ['pecan.params'] = dict(request.str_params)
     request.environ['pecan.validation_errors'] = request.pecan['validation_errors']
     if cfg.get('htmlfill') is not None:
         request.environ['pecan.htmlfill'] = cfg['htmlfill']
     request.environ['REQUEST_METHOD'] = 'GET'
     ForwardRequestException.__init__(self, location)
Exemple #2
0
def error_docs_app(environ, start_response):
    if environ['PATH_INFO'] == '/not_found':
        start_response("404 Not found", [('Content-type', 'text/plain')])
        return [b'Not found']
    elif environ['PATH_INFO'] == '/error':
        start_response("200 OK", [('Content-type', 'text/plain')])
        return [b'Page not found']
    elif environ['PATH_INFO'] == '/recurse':
        raise ForwardRequestException('/recurse')
    else:
        return simple_app(environ, start_response)
Exemple #3
0
        def __call__(self, environ, start_response):
            if environ['PATH_INFO'] != '/not_found':
                return self.app(environ, start_response)
            environ['PATH_INFO'] = self.url

            def factory(app):
                return StatusKeeper(app,
                                    status='404 Not Found',
                                    url='/error',
                                    headers=[])

            raise ForwardRequestException(factory=factory)
Exemple #4
0
    def __call__(self, environ, start_response, action, vars):
        '''A requirement of the controller object, is that it is callable.
        Most of the routing is done in the RouteFactory.

        '''
        resp = None

        if 'REMOTE_USER' in environ:
            self.auth_id = environ['AUTH_ID']
            self.permissions = environ['PERMISSIONS']
        else: # we have deleted the REMOTE_USER so delete the other keys
            if 'AUTH_ID' in environ:
                del environ['AUTH_ID']
                self.auth_id = None
            if 'PERMISSIONS' in environ:
                del environ['PERMISSIONS']
                self.permissions = None

        # setup req
        self.request = Request(environ)

        # set session from cache
        self.request.session = environ[self._session_key]

        # Local this thread and register variables for this request.
        self._setup_registery(environ, start_response)

        try:
            if self._has_method(action):
                # Get the method from the derived class
                resp = getattr(self, action)(**vars)
            else:
                raise exc.HTTPNotFound("Method not found for controller: %s"
                                       % self.__class__.__name__)

            if isinstance(resp, dict):
                # Deprecated mostly...
                if 'redirect_login' in resp:
                    raise ForwardRequestException(self.globals.login_path)

            # See if it is just a string output
            if isinstance(resp, basestring):
                resp = Response(body=resp)

            if resp is None:
                resp = Response(body="Failed!")

            return resp(environ, start_response)

        except AttributeError, e:
            resp = Response(body="Failed: %s" % e)
Exemple #5
0
def remove_auth(req, session):

    if 'REMOTE_USER' in req.environ:
        del req.environ["AUTH_ID"]
        del req.environ["REMOTE_USER"]
        del req.environ['PERMISSIONS']

    g = bootstrappy.app_globals._current_obj()

    if 'user' in session:
        del session['user']
    session.invalidate()
    session.delete()

    raise ForwardRequestException(g.login_path)
    def __call__(self, environ, start_response):
        url = []
        writer = []

        def change_response(status, headers, exc_info=None):
            status_code = status.split(' ')
            try:
                code = int(status_code[0])
            except (ValueError, TypeError):
                raise Exception(
                    'StatusBasedForward middleware '
                    'received an invalid status code %s'%repr(status_code[0])
                )
            message = ' '.join(status_code[1:])
            new_url = self.mapper(
                code,
                message,
                environ,
                self.global_conf,
                **self.params
            )
            if not (new_url == None or isinstance(new_url, str)):
                raise TypeError(
                    'Expected the url to internally '
                    'redirect to in the StatusBasedForward mapper'
                    'to be a string or None, not %r' % new_url)
            if new_url:
                url.append([new_url, status, headers])
                # We have to allow the app to write stuff, even though
                # we'll ignore it:
                return [].append
            else:
                return start_response(status, headers, exc_info)

        app_iter = self.application(environ, change_response)
        if url:
            if hasattr(app_iter, 'close'):
                app_iter.close()

            def factory(app):
                return StatusKeeper(app, status=url[0][1], url=url[0][0],
                                    headers=url[0][2])
            raise ForwardRequestException(factory=factory)
        else:
            return app_iter
Exemple #7
0
 def __call__(self, environ, start_response):
     if environ['PATH_INFO'] != '/not_found':
         return self.app(environ, start_response)
     environ['PATH_INFO'] = self.url
     raise ForwardRequestException(environ=environ)
Exemple #8
0
 def __call__(self, environ, start_response):
     raise ForwardRequestException(self.url)
Exemple #9
0
def forward(url, code=301):
    raise ForwardRequestException(url)