Пример #1
0
    def __call__(self,environ, start_response):
        try:
            return self._wrapped(environ,start_response)
        except Exception as error_instance:
            if isinstance(error_instance,NoMatchingURL):
                status = '404 NOT FOUND'
                standard_error = settings.VIEW_404
            else:
                status = '500 INTERNAL SERVER ERROR'
                standard_error = settings.VIEW_500

            response_headers = [('Content-type','text/html')]
            start_response(status, response_headers)

            if settings.DEBUG:
                return [func_from_str(settings.DEBUG_ERROR_VIEW)(settings, environ, error_instance).encode('latin-1')]
            return [func_from_str(standard_error)(None).encode('latin-1')]
Пример #2
0
 def parse_url(rel_url):
     for url in url_seq:
         match = re.match(url[0],rel_url)
         if match:
             # using 'args' to pull named groups from the url and passing them to the view, if any.
             args = match.groupdict()
             try:
                 return_view = func_from_str(url[1])
             except (AttributeError, ImportError) as error_instance:
                 # If there is an import error or attribute error, the function probably
                 # doesn't exist, throw our own appropriate error
                 view_error = ViewFunctionDoesNotExist(url[0],url[1])
                 view_error.with_traceback(error_instance.__traceback__)
                 raise view_error
             else:
                 return return_view, args
     raise NoMatchingURL(rel_url)