Python cgitb.html() Examples
The following are 13
code examples of cgitb.html().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cgitb
, or try the search function
.
Example #1
Source File: cgitb_catcher.py From mishkal with GNU General Public License v3.0 | 8 votes |
def __init__(self, app, global_conf=None, display=NoDefault, logdir=None, context=5, format="html"): self.app = app if global_conf is None: global_conf = {} if display is NoDefault: display = global_conf.get('debug') if isinstance(display, basestring): display = converters.asbool(display) self.display = display self.logdir = logdir self.context = int(context) self.format = format
Example #2
Source File: fcgi.py From termite-visualizations with BSD 3-Clause "New" or "Revised" License | 6 votes |
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'
Example #3
Source File: web_08.py From Modern-Python-Standard-Library-Cookbook with MIT License | 6 votes |
def __call__(self, environ, start_response): app_iter = None try: app_iter = self.app(environ, start_response) for item in app_iter: yield item except: try: start_response('500 INTERNAL SERVER ERROR', [ ('Content-Type', 'text/html; charset=utf-8'), ('X-XSS-Protection', '0'), ]) except Exception: # There has been output but an error occurred later on. # In that situation we can do nothing fancy anymore, # better log something into the error log and fallback. environ['wsgi.errors'].write( 'Debugging middleware caught exception in streamed ' 'response after response headers were already sent.\n' ) else: yield cgitb.html(sys.exc_info()).encode('utf-8') finally: if hasattr(app_iter, 'close'): app_iter.close()
Example #4
Source File: cgitb_catcher.py From mishkal with GNU General Public License v3.0 | 5 votes |
def __call__(self, environ, start_response): try: app_iter = self.app(environ, start_response) return self.catching_iter(app_iter, environ) except: exc_info = sys.exc_info() start_response('500 Internal Server Error', [('content-type', 'text/html')], exc_info) response = self.exception_handler(exc_info, environ) return [response]
Example #5
Source File: cgitb_catcher.py From mishkal with GNU General Public License v3.0 | 5 votes |
def make_cgitb_middleware(app, global_conf, display=NoDefault, logdir=None, context=5, format='html'): """ Wraps the application in the ``cgitb`` (standard library) error catcher. display: If true (or debug is set in the global configuration) then the traceback will be displayed in the browser logdir: Writes logs of all errors in that directory context: Number of lines of context to show around each line of source code """ from paste.deploy.converters import asbool if display is not NoDefault: display = asbool(display) if 'debug' in global_conf: global_conf['debug'] = asbool(global_conf['debug']) return CgitbMiddleware( app, global_conf=global_conf, display=display, logdir=logdir, context=context, format=format)
Example #6
Source File: fcgiserver.py From pycopia with Apache License 2.0 | 5 votes |
def ErrorHandler(exc_info, stream): import cgitb stream.write('Status: 500 fcgi error\r\n') stream.write('Content-Type: text/html\r\n') stream.write('\r\n') stream.write(cgitb.html(exc_info)) stream.flush() # Factory function creats a server instance with our interface # handlers.
Example #7
Source File: test_cgitb.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #8
Source File: test_cgitb.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #9
Source File: test_cgitb.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #10
Source File: reporting.py From ppci with BSD 2-Clause "Simplified" License | 5 votes |
def dump_exception(self, einfo): self.print(cgitb.html(einfo))
Example #11
Source File: reporting.py From ppci with BSD 2-Clause "Simplified" License | 5 votes |
def tcell(self, txt, indent=0): """ Inject a html table cell. """ if indent: style = ' style="padding-left: {}px;"'.format(indent) else: style = "" self.print("<td{}>{}</td>".format(style, txt))
Example #12
Source File: fcgi.py From termite-visualizations with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()))
Example #13
Source File: exceptions.py From napari with BSD 3-Clause "New" or "Revised" License | 4 votes |
def format_exceptions(plugin_name: str, as_html: bool = False): """Return formatted tracebacks for all exceptions raised by plugin. Parameters ---------- plugin_name : str The name of a plugin for which to retrieve tracebacks. as_html : bool Whether to return the exception string as formatted html, defaults to False. Returns ------- str A formatted string with traceback information for every exception raised by ``plugin_name`` during this session. """ _plugin_errors = PluginError.get(plugin_name=plugin_name) if not _plugin_errors: return '' from napari import __version__ format_exc_info = get_tb_formatter() _linewidth = 80 _pad = (_linewidth - len(plugin_name) - 18) // 2 msg = [ f"{'=' * _pad} Errors for plugin '{plugin_name}' {'=' * _pad}", '', f'{"napari version": >16}: {__version__}', ] err0 = _plugin_errors[0] if err0.plugin: package_meta = standard_metadata(err0.plugin) if package_meta: msg.extend( [ f'{"plugin package": >16}: {package_meta["package"]}', f'{"version": >16}: {package_meta["version"]}', f'{"module": >16}: {err0.plugin}', ] ) msg.append('') for n, err in enumerate(_plugin_errors): _pad = _linewidth - len(str(err)) - 10 msg += ['', f'ERROR #{n + 1}: {str(err)} {"-" * _pad}', ''] msg.append(format_exc_info(err.info(), as_html)) msg.append('=' * _linewidth) return ("<br>" if as_html else "\n").join(msg)