当前位置: 首页>>代码示例>>Python>>正文


Python cgitb.html方法代码示例

本文整理汇总了Python中cgitb.html方法的典型用法代码示例。如果您正苦于以下问题:Python cgitb.html方法的具体用法?Python cgitb.html怎么用?Python cgitb.html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cgitb的用法示例。


在下文中一共展示了cgitb.html方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import html [as 别名]
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 
开发者ID:linuxscout,项目名称:mishkal,代码行数:19,代码来源:cgitb_catcher.py

示例2: test_app

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import html [as 别名]
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' 
开发者ID:uwdata,项目名称:termite-visualizations,代码行数:27,代码来源:fcgi.py

示例3: __call__

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import html [as 别名]
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() 
开发者ID:PacktPublishing,项目名称:Modern-Python-Standard-Library-Cookbook,代码行数:27,代码来源:web_08.py

示例4: __call__

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import html [as 别名]
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] 
开发者ID:linuxscout,项目名称:mishkal,代码行数:13,代码来源:cgitb_catcher.py

示例5: make_cgitb_middleware

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import html [as 别名]
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) 
开发者ID:linuxscout,项目名称:mishkal,代码行数:33,代码来源:cgitb_catcher.py

示例6: ErrorHandler

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import html [as 别名]
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. 
开发者ID:kdart,项目名称:pycopia,代码行数:13,代码来源:fcgiserver.py

示例7: test_html

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import html [as 别名]
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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_cgitb.py

示例8: dump_exception

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import html [as 别名]
def dump_exception(self, einfo):
        self.print(cgitb.html(einfo)) 
开发者ID:windelbouwman,项目名称:ppci,代码行数:4,代码来源:reporting.py

示例9: tcell

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import html [as 别名]
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)) 
开发者ID:windelbouwman,项目名称:ppci,代码行数:9,代码来源:reporting.py

示例10: error

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import html [as 别名]
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())) 
开发者ID:uwdata,项目名称:termite-visualizations,代码行数:10,代码来源:fcgi.py

示例11: format_exceptions

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import html [as 别名]
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) 
开发者ID:napari,项目名称:napari,代码行数:56,代码来源:exceptions.py


注:本文中的cgitb.html方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。