Esempio n. 1
0
    def __call__(self, environ, start_response):
        try:
            try:
                res=dispatch_from_environ(environ)
            except Punt:
                res=None

            if res is None:
                if self.wrapped_app:
                    return self.wrapped_app(environ, start_response)
                else:
                    return handle_error(httplib.NOT_FOUND,
                                        environ,
                                        start_response)

            return res(environ, start_response)
        except:
            return handle_error(httplib.INTERNAL_SERVER_ERROR,
                                environ,
                                start_response)
Esempio n. 2
0
            return webob.Request(environ)

    def __call__(self, environ, start_response):
        try:
            request = self.get_request(environ)
            path, realpath, statinfo = self.check_path(request.path)
            app = self.serve_file(path, realpath, statinfo, request)
            if app:
                return app(environ, start_response)
            exc = get_http_exception(httplib.NOT_FOUND)
            return exc(environ, start_response)
        except webob.exc.HTTPException, exc:
            return exc(environ, start_response)
        except:
            log.exception("error in serving file")
            return handle_error(httplib.INTERNAL_SERVER_ERROR, environ, start_response)

    def serve_file(self, path, realpath, statinfo, request):
        raise NotImplementedError

    def is_hidden(self, path, realpath, statinfo):
        """
        return True if the file in question (which should exist)
        is allowed to be seen.

        by default, this matches each pattern in
        Configuration.hiddenFilePatterns against the path and returns
        True if one of them matches.  The patterns can either be
        callables that take three positional arguments (path,
        realpath, statinfo) or regexes (either strings or compiled).
        """