當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。