我们从Python开源项目中,提取了以下24个代码示例,用于说明如何使用cgitb.html()。
def error(self, req): """ Called by Request if an exception occurs within the handler. May and should be overridden. """ if self.debug: import cgitb req.stdout.write('Content-Type: text/html\r\n\r\n' + cgitb.html(sys.exc_info())) else: errorpage = """<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>Unhandled Exception</title> </head><body> <h1>Unhandled Exception</h1> <p>An unhandled exception was thrown by the application.</p> </body></html> """ req.stdout.write('Content-Type: text/html\r\n\r\n' + errorpage)
def error(self, request): """ Override to provide custom error handling. Ideally, however, all errors should be caught at the application level. """ if self.debug: import cgitb request.stdout.write('Content-Type: text/html\r\n\r\n' + cgitb.html(sys.exc_info())) else: errorpage = """<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>Unhandled Exception</title> </head><body> <h1>Unhandled Exception</h1> <p>An unhandled exception was thrown by the application.</p> </body></html> """ request.stdout.write('Content-Type: text/html\r\n\r\n' + errorpage)
def error(self, request): """ Override to provide custom error handling. Ideally, however, all errors should be caught at the application level. """ if self.debug: request.startResponse(200, 'OK', [('Content-Type', 'text/html')]) import cgitb request.write(cgitb.html(sys.exc_info())) else: errorpage = """<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>Unhandled Exception</title> </head><body> <h1>Unhandled Exception</h1> <p>An unhandled exception was thrown by the application.</p> </body></html> """ request.startResponse(200, 'OK', [('Content-Type', 'text/html')]) request.write(errorpage)
def test_app(environ, start_response): """Probably not the most efficient example.""" import cgi start_response('200 OK', [('Content-Type', 'text/html')]) yield '<html><head><title>Hello World!</title></head>\n' \ '<body>\n' \ '<p>Hello World!</p>\n' \ '<table border="1">' names = environ.keys() names.sort() for name in names: yield '<tr><td>%s</td><td>%s</td></tr>\n' % ( name, cgi.escape(`environ[name]`)) form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ, keep_blank_values=1) if form.list: yield '<tr><th colspan="2">Form data</th></tr>' for field in form.list: yield '<tr><td>%s</td><td>%s</td></tr>\n' % ( field.name, field.value) yield '</table>\n' \ '</body></html>\n'
def __call_service(self, query): """Execute service method implemented by child class. When either a GET or POST request is received, this method is called with a string representing the query. Request and response objects are created for the child's service method, and an answer is sent back to the client with errors automatically being caught.""" request = _HttpServletRequest(query) response = _HttpServletResponse() try: self.service(request, response) except Exception: if self.__debug: self.send_response(500) self.send_header('Content-Type', 'text/html') self.send_header('Connection', 'close') self.end_headers() klass, value, trace = sys.exc_info() # The next function call may raise an exception. html = cgitb.html((klass, value, trace.tb_next)) self.wfile.write(html.encode()) else: self.send_error(500) else: response_value = response._value self.send_response(200) self.send_header('Content-Type', response._type) self.send_header('Content-Length', str(len(response_value))) self.end_headers() self.wfile.write(response_value)
def error(self, req): """ Called by Request if an exception occurs within the handler. May and should be overridden. """ import cgitb req.stdout.write('Content-Type: text/html\r\n\r\n' + cgitb.html(sys.exc_info()))
def test_html(self): try: raise ValueError("Hello World") except ValueError as err: # If the html was templated we could do a bit more here. # At least check that we get details on what we just raised. html = cgitb.html(sys.exc_info()) self.assertIn("ValueError", html) self.assertIn(str(err), html)