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


Python exceptions.html_error_template方法代码示例

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


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

示例1: _render_error

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import html_error_template [as 别名]
def _render_error(template, context, error):
    if template.error_handler:
        result = template.error_handler(context, error)
        if not result:
            compat.reraise(*sys.exc_info())
    else:
        error_template = exceptions.html_error_template()
        if context._outputting_as_unicode:
            context._buffer_stack[:] = [
                util.FastEncodingBuffer(as_unicode=True)
            ]
        else:
            context._buffer_stack[:] = [
                util.FastEncodingBuffer(
                    error_template.output_encoding,
                    error_template.encoding_errors,
                )
            ]

        context._set_with_template(error_template)
        error_template.render_context(context, error=error) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:23,代码来源:runtime.py

示例2: _render_error

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import html_error_template [as 别名]
def _render_error(template, context, error):
    if template.error_handler:
        result = template.error_handler(context, error)
        if not result:
            compat.reraise(*sys.exc_info())
    else:
        error_template = exceptions.html_error_template()
        if context._outputting_as_unicode:
            context._buffer_stack[:] = [
                util.FastEncodingBuffer(as_unicode=True)]
        else:
            context._buffer_stack[:] = [util.FastEncodingBuffer(
                error_template.output_encoding,
                error_template.encoding_errors)]

        context._set_with_template(error_template)
        error_template.render_context(context, error=error) 
开发者ID:jpush,项目名称:jbox,代码行数:19,代码来源:runtime.py

示例3: test_py_utf8_html_error_template

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import html_error_template [as 别名]
def test_py_utf8_html_error_template(self):
        try:
            foo = u("日本")  # noqa
            raise RuntimeError("test")
        except:
            html_error = exceptions.html_error_template().render()
            if compat.py3k:
                assert "RuntimeError: test" in html_error.decode("utf-8")
                assert "foo = u("日本")" in html_error.decode(
                    "utf-8"
                ) or "foo = u("日本")" in html_error.decode("utf-8")
            else:
                assert "RuntimeError: test" in html_error
                assert (
                    "foo = u("日本")" in html_error
                    or "foo = u("日本")" in html_error
                ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:19,代码来源:test_exceptions.py

示例4: test_custom_tback

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import html_error_template [as 别名]
def test_custom_tback(self):
        try:
            raise RuntimeError("error 1")
            foo("bar")  # noqa
        except:
            t, v, tback = sys.exc_info()

        try:
            raise RuntimeError("error 2")
        except:
            html_error = exceptions.html_error_template().render_unicode(
                error=v, traceback=tback
            )

        # obfuscate the text so that this text
        # isn't in the 'wrong' exception
        assert (
            "".join(reversed(");touq&rab;touq&(oof")) in html_error
            or "".join(reversed(");43#&rab;43#&(oof")) in html_error
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:22,代码来源:test_exceptions.py

示例5: test_tback_no_trace_from_py_file

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import html_error_template [as 别名]
def test_tback_no_trace_from_py_file(self):
        try:
            t = self._file_template("runtimeerr.html")
            t.render()
        except:
            t, v, tback = sys.exc_info()

        if not compat.py3k:
            # blow away tracebaack info
            sys.exc_clear()

        # and don't even send what we have.
        html_error = exceptions.html_error_template().render_unicode(
            error=v, traceback=None
        )
        assert (
            "local variable 'y' referenced before assignment"
            in html_error
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:21,代码来源:test_exceptions.py

示例6: test_custom_tback

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import html_error_template [as 别名]
def test_custom_tback(self):
        try:
            raise RuntimeError("error 1")
            foo('bar')
        except:
            t, v, tback = sys.exc_info()

        try:
            raise RuntimeError("error 2")
        except:
            html_error = exceptions.html_error_template().\
                        render_unicode(error=v, traceback=tback)

        # obfuscate the text so that this text
        # isn't in the 'wrong' exception
        assert "".join(reversed(");93#&rab;93#&(oof")) in html_error 
开发者ID:jhpyle,项目名称:docassemble,代码行数:18,代码来源:test_exceptions.py

示例7: test_escapes_html_tags

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import html_error_template [as 别名]
def test_escapes_html_tags(self):
        from mako.exceptions import html_error_template

        x = Template("""
        X:
        <% raise Exception('<span style="color:red">Foobar</span>') %>
        """)

        try:
            x.render()
        except:
            # <h3>Exception: <span style="color:red">Foobar</span></h3>
            markup = html_error_template().render(full=False, css=False)
            if compat.py3k:
                assert '<span style="color:red">Foobar</span></h3>'\
                            .encode('ascii') not in markup
                assert '&lt;span style=&#34;color:red&#34;'\
                            '&gt;Foobar&lt;/span&gt;'\
                            .encode('ascii') in markup
            else:
                assert '<span style="color:red">Foobar</span></h3>' \
                            not in markup
                assert '&lt;span style=&#34;color:red&#34;'\
                            '&gt;Foobar&lt;/span&gt;' in markup 
开发者ID:jhpyle,项目名称:docassemble,代码行数:26,代码来源:test_template.py

示例8: serve_template

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import html_error_template [as 别名]
def serve_template(templatename, **kwargs):
    if plexpy.CONFIG.NEWSLETTER_CUSTOM_DIR:
        template_dir = plexpy.CONFIG.NEWSLETTER_CUSTOM_DIR
    else:
        interface_dir = os.path.join(str(plexpy.PROG_DIR), 'data/interfaces/')
        template_dir = os.path.join(str(interface_dir), plexpy.CONFIG.NEWSLETTER_TEMPLATES)

        if not plexpy.CONFIG.NEWSLETTER_INLINE_STYLES:
            templatename = templatename.replace('.html', '.internal.html')

    _hplookup = TemplateLookup(directories=[template_dir], default_filters=['unicode', 'h'])

    try:
        template = _hplookup.get_template(templatename)
        return template.render(**kwargs), False
    except:
        return exceptions.html_error_template().render(), True 
开发者ID:Tautulli,项目名称:Tautulli,代码行数:19,代码来源:newsletters.py

示例9: _render_error

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import html_error_template [as 别名]
def _render_error(template, context, error):
    if template.error_handler:
        result = template.error_handler(context, error)
        if not result:
            compat.reraise(*sys.exc_info())
    else:
        error_template = exceptions.html_error_template()
        if context._outputting_as_unicode:
            context._buffer_stack[:] = [
                                    util.FastEncodingBuffer(as_unicode=True)]
        else:
            context._buffer_stack[:] = [util.FastEncodingBuffer(
                                            error_template.output_encoding,
                                            error_template.encoding_errors)]

        context._set_with_template(error_template)
        error_template.render_context(context, error=error) 
开发者ID:fboender,项目名称:ansible-cmdb,代码行数:19,代码来源:runtime.py

示例10: serve

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import html_error_template [as 别名]
def serve(environ, start_response):
    """serves requests using the WSGI callable interface."""
    fieldstorage = cgi.FieldStorage(
            fp = environ['wsgi.input'],
            environ = environ,
            keep_blank_values = True
    )
    d = dict([(k, getfield(fieldstorage[k])) for k in fieldstorage])

    uri = environ.get('PATH_INFO', '/')
    if not uri:
        uri = '/index.html'
    else:
        uri = re.sub(r'^/$', '/index.html', uri)

    if re.match(r'.*\.html$', uri):
        try:
            template = lookup.get_template(uri)
        except exceptions.TopLevelLookupException:
            start_response("404 Not Found", [])
            return [str.encode("Cant find template '%s'" % uri)]

        start_response("200 OK", [('Content-type','text/html')])

        try:
            return [template.render(**d)]
        except:
            return [exceptions.html_error_template().render()]
    else:
        u = re.sub(r'^\/+', '', uri)
        filename = os.path.join(root, u)
        if os.path.isfile(filename):
            start_response("200 OK", [('Content-type',guess_type(uri))])
            return [open(filename, 'rb').read()]
        else:
            start_response("404 Not Found", [])
            return [str.encode("File not found: '%s'" % filename)] 
开发者ID:sqlalchemy,项目名称:mako,代码行数:39,代码来源:run_wsgi.py

示例11: test_html_error_template

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import html_error_template [as 别名]
def test_html_error_template(self):
        """test the html_error_template"""
        code = """
% i = 0
"""
        try:
            template = Template(code)
            template.render_unicode()
            assert False
        except exceptions.CompileException:
            html_error = exceptions.html_error_template().render_unicode()
            assert (
                "CompileException: Fragment &#39;i = 0&#39; is not "
                "a partial control statement at line: 2 char: 1"
            ) in html_error
            assert "<style>" in html_error
            html_error_stripped = html_error.strip()
            assert html_error_stripped.startswith("<html>")
            assert html_error_stripped.endswith("</html>")

            not_full = exceptions.html_error_template().render_unicode(
                full=False
            )
            assert "<html>" not in not_full
            assert "<style>" in not_full

            no_css = exceptions.html_error_template().render_unicode(css=False)
            assert "<style>" not in no_css
        else:
            assert False, (
                "This function should trigger a CompileException, "
                "but didn't"
            ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:35,代码来源:test_exceptions.py

示例12: test_py_unicode_error_html_error_template

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import html_error_template [as 别名]
def test_py_unicode_error_html_error_template(self):
        try:
            raise RuntimeError(u("日本"))
        except:
            html_error = exceptions.html_error_template().render()
            assert (
                u("RuntimeError: 日本").encode("ascii", "ignore") in html_error
            ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:10,代码来源:test_exceptions.py

示例13: test_mod_no_encoding

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import html_error_template [as 别名]
def test_mod_no_encoding(self):

        mod = __import__("test.foo.mod_no_encoding").foo.mod_no_encoding
        try:
            mod.run()
        except:
            t, v, tback = sys.exc_info()
            exceptions.html_error_template().render_unicode(
                error=v, traceback=tback
            ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:12,代码来源:test_exceptions.py

示例14: test_escapes_html_tags

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import html_error_template [as 别名]
def test_escapes_html_tags(self):
        from mako.exceptions import html_error_template

        x = Template(
            """
        X:
        <% raise Exception('<span style="color:red">Foobar</span>') %>
        """
        )

        try:
            x.render()
        except:
            # <h3>Exception: <span style="color:red">Foobar</span></h3>
            markup = html_error_template().render(full=False, css=False)
            if compat.py3k:
                assert (
                    '<span style="color:red">Foobar</span></h3>'.encode(
                        "ascii"
                    )
                    not in markup
                )
                assert (
                    "&lt;span style=&#34;color:red&#34;"
                    "&gt;Foobar&lt;/span&gt;".encode("ascii") in markup
                )
            else:
                assert (
                    '<span style="color:red">Foobar</span></h3>' not in markup
                )
                assert (
                    "&lt;span style=&#34;color:red&#34;"
                    "&gt;Foobar&lt;/span&gt;" in markup
                ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:36,代码来源:test_template.py

示例15: serve_template

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import html_error_template [as 别名]
def serve_template(templatename, **kwargs):
    html_dir = 'public/html/'
    _hplookup = TemplateLookup(directories=[html_dir])
    try:
        template = _hplookup.get_template(templatename)
        return template.render(**kwargs)
    except:
        return exceptions.html_error_template().render() 
开发者ID:hubbcaps,项目名称:gazee,代码行数:10,代码来源:gazee.py


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