def _generate_cgitb_error(self, request, original_response, exc_type, exc_value, tb): error_file = StringIO.StringIO() hook = cgitb.Hook(file=error_file) hook(exc_type, exc_value, tb) error_file.write('<h2>Original Request</h2>') error_file.write(str(util.dump_request(request))) error_file.write('<h2>Original Response</h2><pre>') original_response.write(error_file) error_file.write('</pre>') return error_file.getvalue()
def format_page(title, content): request = htmltext('<div style="font-size: smaller;background:#eee">' '<h1>Request:</h1>%s</div>') % dump_request() return htmltext( '<html><head><title>%(title)s</title>' '<style type="text/css">\n' 'body { border: thick solid green; padding: 2em; }\n' 'h1 { font-size: larger; }\n' 'th { background: #aaa; text-align:left; font-size: smaller; }\n' 'td { background: #ccc; font-size: smaller; }\n' '</style>' '</head><body>%(content)s%(request)s</body></html>') % locals()
def format_page(title, content): request = htmltext( '<div style="font-size: smaller;background:#eee">' '<h1>Request:</h1>%s</div>') % dump_request() return htmltext( '<html><head><title>%(title)s</title>' '<style type="text/css">\n' 'body { border: thick solid green; padding: 2em; }\n' 'h1 { font-size: larger; }\n' 'th { background: #aaa; text-align:left; font-size: smaller; }\n' 'td { background: #ccc; font-size: smaller; }\n' '</style>' '</head><body>%(content)s%(request)s</body></html>') % locals()
def _generate_cgitb_error(self, request, original_response, exc_type, exc_value, tb): # let cgitb.Hook have the type it wants... error_file = io.StringIO() hook = cgitb.Hook(file=error_file) hook(exc_type, exc_value, tb) byte_error_file = io.BytesIO() byte_error_file.write(b'<h2>Original Request</h2>') # dump_request returns an HTMLText object s = str(util.dump_request(request)) byte_error_file.write(s.encode('latin-1', 'strict')) byte_error_file.write(b'<h2>Original Response</h2><pre>') original_response.write(byte_error_file) byte_error_file.write(b'</pre>') # Now we push the bytes to the "real" error file... s = byte_error_file.getvalue().decode('latin-1') error_file.write(s) return error_file.getvalue()
def format_request(): return format_page('Request', dump_request())
def qtest(self): """ For testing quixote. """ from quixote.util import dump_request return dump_request()