コード例 #1
0
ファイル: middleware.py プロジェクト: terrasea/paste
    def respond(self, environ, start_response):
        if environ.get('paste.throw_errors'):
            return self.application(environ, start_response)
        base_path = request.construct_url(environ, with_path_info=False,
                                          with_query_string=False)
        environ['paste.throw_errors'] = True
        started = []
        def detect_start_response(status, headers, exc_info=None):
            try:
                return start_response(status, headers, exc_info)
            except:
                raise
            else:
                started.append(True)
        try:
            __traceback_supplement__ = errormiddleware.Supplement, self, environ
            app_iter = self.application(environ, detect_start_response)
            try:
                return_iter = list(app_iter)
                return return_iter
            finally:
                if hasattr(app_iter, 'close'):
                    app_iter.close()
        except:
            exc_info = sys.exc_info()
            for expected in environ.get('paste.expected_exceptions', []):
                if isinstance(exc_info[1], expected):
                    raise

            # Tell the Registry to save its StackedObjectProxies current state
            # for later restoration
            registry.restorer.save_registry_state(environ)

            count = get_debug_count(environ)
            view_uri = self.make_view_url(environ, base_path, count)
            if not started:
                headers = [('content-type', 'text/html')]
                headers.append(('X-Debug-URL', view_uri))
                start_response('500 Internal Server Error',
                               headers,
                               exc_info)
            environ['wsgi.errors'].write('Debug at: %s\n' % view_uri)

            exc_data = collector.collect_exception(*exc_info)
            debug_info = DebugInfo(count, exc_info, exc_data, base_path,
                                   environ, view_uri)
            assert count not in self.debug_infos
            self.debug_infos[count] = debug_info

            if self.xmlhttp_key:
                get_vars = wsgilib.parse_querystring(environ)
                if dict(get_vars).get(self.xmlhttp_key):
                    exc_data = collector.collect_exception(*exc_info)
                    html = formatter.format_html(
                        exc_data, include_hidden_frames=False,
                        include_reusable=False, show_extra_data=False)
                    return [html]

            # @@: it would be nice to deal with bad content types here
            return debug_info.content()
コード例 #2
0
ファイル: middleware.py プロジェクト: terrasea/paste
 def exception_handler(self, exc_info, environ):
     simple_html_error = False
     if self.xmlhttp_key:
         get_vars = wsgilib.parse_querystring(environ)
         if dict(get_vars).get(self.xmlhttp_key):
             simple_html_error = True
     return errormiddleware.handle_exception(
         exc_info, environ['wsgi.errors'],
         html=True,
         debug_mode=True,
         simple_html_error=simple_html_error)
コード例 #3
0
 def exception_handler(self, exc_info, environ):
     simple_html_error = False
     if self.xmlhttp_key:
         get_vars = wsgilib.parse_querystring(environ)
         if dict(get_vars).get(self.xmlhttp_key):
             simple_html_error = True
     return errormiddleware.handle_exception(
         exc_info,
         environ['wsgi.errors'],
         html=True,
         debug_mode=True,
         simple_html_error=simple_html_error)
コード例 #4
0
ファイル: errormiddleware.py プロジェクト: thraxil/gtreed
 def exception_handler(self, exc_info, environ):
     simple_html_error = False
     if self.xmlhttp_key:
         get_vars = wsgilib.parse_querystring(environ)
         if dict(get_vars).get(self.xmlhttp_key):
             simple_html_error = True
     return handle_exception(
         exc_info, environ['wsgi.errors'],
         html=True,
         debug_mode=self.debug_mode,
         error_email=self.error_email,
         error_log=self.error_log,
         show_exceptions_in_wsgi_errors=self.show_exceptions_in_wsgi_errors,
         error_email_from=self.from_address,
         smtp_server=self.smtp_server,
         error_subject_prefix=self.error_subject_prefix,
         error_message=self.error_message,
         simple_html_error=simple_html_error)
コード例 #5
0
 def exception_handler(self, exc_info, environ):
     simple_html_error = False
     if self.xmlhttp_key:
         get_vars = wsgilib.parse_querystring(environ)
         if dict(get_vars).get(self.xmlhttp_key):
             simple_html_error = True
     return handle_exception(
         exc_info, environ['wsgi.errors'],
         html=True,
         debug_mode=self.debug_mode,
         error_email=self.error_email,
         error_log=self.error_log,
         show_exceptions_in_wsgi_errors=self.show_exceptions_in_wsgi_errors,
         error_email_from=self.from_address,
         smtp_server=self.smtp_server,
         error_subject_prefix=self.error_subject_prefix,
         error_message=self.error_message,
         simple_html_error=simple_html_error)
コード例 #6
0
def get_info(environ, start_response):
    #    command = dict(parse_querystring(environ)).get('command','')
    page = str(parse_querystring(environ))

    #    if command == 'clear':
    #        if 'REMOTE_USER' in environ:
    #            del environ['REMOTE_USER']
    #        if 'REMOTE_SESSION' in environ:
    #            del environ['REMOTE_SESSION']
    #    else:
    #        environ['REMOTE_SESSION'] = authfunc(environ, my_realm, environ['REMOTE_USER'] )

    #    if environ.get('REMOTE_USER'):
    #        page = '<html><body>Welcome %s (%s)</body></html>'
    #        page %= (environ['REMOTE_USER'], environ['REMOTE_SESSION'])
    #    else:
    #        page = ('<html><body><form><input name="user" />'
    #                '<input type="submit" /></form></body></html>')
    return DataApp(page, content_type="text/plain")(environ, start_response)
コード例 #7
0
def get_info(environ, start_response):
#    command = dict(parse_querystring(environ)).get('command','')
    page = str(parse_querystring(environ))

#    if command == 'clear':
#        if 'REMOTE_USER' in environ:
#            del environ['REMOTE_USER']
#        if 'REMOTE_SESSION' in environ:
#            del environ['REMOTE_SESSION']
#    else:
#        environ['REMOTE_SESSION'] = authfunc(environ, my_realm, environ['REMOTE_USER'] )

#    if environ.get('REMOTE_USER'):
#        page = '<html><body>Welcome %s (%s)</body></html>'
#        page %= (environ['REMOTE_USER'], environ['REMOTE_SESSION'])
#    else:
#        page = ('<html><body><form><input name="user" />'
#                '<input type="submit" /></form></body></html>')
    return DataApp(page, content_type="text/plain")(
                   environ, start_response)
コード例 #8
0
    def respond(self, environ, start_response):
        if environ.get('paste.throw_errors'):
            return self.application(environ, start_response)
        base_path = request.construct_url(environ,
                                          with_path_info=False,
                                          with_query_string=False)
        environ['paste.throw_errors'] = True
        started = []

        def detect_start_response(status, headers, exc_info=None):
            try:
                return start_response(status, headers, exc_info)
            except:
                raise
            else:
                started.append(True)

        try:
            __traceback_supplement__ = errormiddleware.Supplement, self, environ
            app_iter = self.application(environ, detect_start_response)
            try:
                return_iter = list(app_iter)
                return return_iter
            finally:
                if hasattr(app_iter, 'close'):
                    app_iter.close()
        except:
            exc_info = sys.exc_info()
            for expected in environ.get('paste.expected_exceptions', []):
                if isinstance(exc_info[1], expected):
                    raise

            # Tell the Registry to save its StackedObjectProxies current state
            # for later restoration
            registry.restorer.save_registry_state(environ)

            count = get_debug_count(environ)
            view_uri = self.make_view_url(environ, base_path, count)
            if not started:
                headers = [('content-type', 'text/html')]
                headers.append(('X-Debug-URL', view_uri))
                start_response('500 Internal Server Error', headers, exc_info)
            environ['wsgi.errors'].write('Debug at: %s\n' % view_uri)

            exc_data = collector.collect_exception(*exc_info)
            debug_info = DebugInfo(count, exc_info, exc_data, base_path,
                                   environ, view_uri)
            assert count not in self.debug_infos
            self.debug_infos[count] = debug_info

            if self.xmlhttp_key:
                get_vars = wsgilib.parse_querystring(environ)
                if dict(get_vars).get(self.xmlhttp_key):
                    exc_data = collector.collect_exception(*exc_info)
                    html = formatter.format_html(exc_data,
                                                 include_hidden_frames=False,
                                                 include_reusable=False,
                                                 show_extra_data=False)
                    return [html]

            # @@: it would be nice to deal with bad content types here
            return debug_info.content()