Exemple #1
0
    def __call__(self, environ, start_response):
        assert not environ['wsgi.multiprocess'], (
            "Dozer middleware is not usable in a "
            "multi-process environment")
        req = Request(environ)
        req.base_path = req.application_url + self.path
        if (req.path_info.startswith(self.path+'/')
            or req.path_info == self.path):
            req.script_name += self.path
            req.path_info = req.path_info[len(self.path):]
            try:
                return self.dowse(req)(environ, start_response)
            except Exception as ex:
                error_text = traceback.format_exc()

                acceptable_offers = req.accept.acceptable_offers(
                    offers=['text/html', 'application/json']
                )
                match = acceptable_offers[0][0] if acceptable_offers else None
                if match != 'application/json':
                    # Strangely, webob.exc.WSGIHTTPException.plain_body replaces newlines
                    # to spaces for plain/text, but replaces "<br/>" tags to newlines.
                    error_text = error_text.replace('\n', '<br/>')

                return exc.HTTPInternalServerError(
                    str(ex), body_template=error_text
                )(environ, start_response)
        else:
            return self.app(environ, start_response)
Exemple #2
0
 def make_request(self):
     req = Request({
         'PATH_INFO': '/whatevs',
         'wsgi.url_scheme': 'http',
         'HTTP_HOST': 'localhost'
     })
     req.base_path = '/_dozer'
     return req
Exemple #3
0
 def __call__(self, environ, start_response):
     assert not environ["wsgi.multiprocess"], "Dozer middleware is not usable in a " "multi-process environment"
     req = Request(environ)
     req.base_path = req.application_url + self.path
     if req.path_info.startswith(self.path + "/") or req.path_info == self.path:
         req.script_name += self.path
         req.path_info = req.path_info[len(self.path) :]
         return self.dowse(req)(environ, start_response)
     else:
         return self.app(environ, start_response)
Exemple #4
0
 def __call__(self, environ, start_response):
     assert not environ['wsgi.multiprocess'], (
         "Dozer middleware is not usable in a "
         "multi-process environment")
     req = Request(environ)
     req.base_path = req.application_url + '/_profiler'
     if req.path_info_peek() == '_profiler':
         return self.profiler(req)(environ, start_response)
     for regex in self.ignored_paths:
         if regex.match(environ['PATH_INFO']) is not None:
             return self.app(environ, start_response)
     return self.run_profile(environ, start_response)
Exemple #5
0
 def __call__(self, environ, start_response):
     assert not environ['wsgi.multiprocess'], (
         "Dozer middleware is not usable in a "
         "multi-process environment")
     req = Request(environ)
     req.base_path = req.application_url + '/_profiler'
     if req.path_info_peek() == '_profiler':
         return self.profiler(req)(environ, start_response)
     for regex in self.ignored_paths:
         if regex.match(environ['PATH_INFO']) is not None:
             return self.app(environ, start_response)
     return self.run_profile(environ, start_response)
Exemple #6
0
 def __call__(self, environ, start_response):
     assert not environ['wsgi.multiprocess'], (
         "Dozer middleware is not usable in a "
         "multi-process environment")
     req = Request(environ)
     req.base_path = req.application_url + self.path
     if (req.path_info.startswith(self.path + '/')
             or req.path_info == self.path):
         req.script_name += self.path
         req.path_info = req.path_info[len(self.path):]
         return self.dowse(req)(environ, start_response)
     else:
         return self.app(environ, start_response)
Exemple #7
0
 def __call__(self, environ, start_response):
     assert not environ['wsgi.multiprocess'], (
         "Leak middleware is not usable in a "
         "multi-process environment")
     if self.inupy_config['ipfilter'] and not check_ipfilter(environ,
             self.inupy_config['ipfilter']):
         # then we want to filter on ip and this one failed
         return self.app(environ, start_response)
     else:
         req = Request(environ)
         req.base_path = req.application_url + self.path
         if (req.path_info.startswith(self.path+'/')
             or req.path_info == self.path):
             req.script_name += self.path
             req.path_info = req.path_info[len(self.path):]
             return self.dowse(req)(environ, start_response)
         else:
             return self.app(environ, start_response)
Exemple #8
0
    def __call__(self, environ, start_response):
        assert not environ['wsgi.multiprocess'], (
            "Inupy middleware is not usable in a "
            "multi-process environment")

        if self.inupy_config['ipfilter'] and not check_ipfilter(environ,
                self.inupy_config['ipfilter']):
            # then we want to filter on ip and this one failed
            return self.app(environ, start_response)

        else:
            req = Request(environ)
            req.base_path = req.application_url + '/_profiler'
            if req.path_info_peek() == '_profiler':
                return self.profiler(req)(environ, start_response)
            for regex in self.ignored_paths:
                if regex.match(environ['PATH_INFO']) is not None:
                    return self.app(environ, start_response)
            return self.run_profile(environ, start_response)
Exemple #9
0
 def make_request(self, subpath='/', base_path='/_dozer'):
     req = Request(dict(PATH_INFO=subpath))
     req.base_path = base_path
     return req
Exemple #10
0
 def make_request(self, subpath='/', base_path='/_dozer'):
     req = Request(dict(PATH_INFO=subpath))
     req.base_path = base_path
     return req
Exemple #11
0
 def make_request(self):
     req = Request({'PATH_INFO': '/whatevs', 'wsgi.url_scheme': 'http',
                    'HTTP_HOST': 'localhost'})
     req.base_path = '/_dozer'
     return req