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


Python exceptions.text_error_template方法代码示例

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


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

示例1: template_to_file

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import text_error_template [as 别名]
def template_to_file(template_file, dest, output_encoding, **kw):
    template = Template(filename=template_file)
    try:
        output = template.render_unicode(**kw).encode(output_encoding)
    except:
        with tempfile.NamedTemporaryFile(suffix='.txt', delete=False) as ntf:
            ntf.write(
                exceptions.text_error_template().
                render_unicode().encode(output_encoding))
            fname = ntf.name
        raise CommandError(
            "Template rendering failed; see %s for a "
            "template-oriented traceback." % fname)
    else:
        with open(dest, 'wb') as f:
            f.write(output) 
开发者ID:jpush,项目名称:jbox,代码行数:18,代码来源:pyfiles.py

示例2: template_to_file

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import text_error_template [as 别名]
def template_to_file(template_file, dest, output_encoding, **kw):
    template = Template(filename=template_file)
    try:
        output = template.render_unicode(**kw).encode(output_encoding)
    except:
        with tempfile.NamedTemporaryFile(suffix=".txt", delete=False) as ntf:
            ntf.write(
                exceptions.text_error_template()
                .render_unicode()
                .encode(output_encoding)
            )
            fname = ntf.name
        raise CommandError(
            "Template rendering failed; see %s for a "
            "template-oriented traceback." % fname
        )
    else:
        with open(dest, "wb") as f:
            f.write(output) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:21,代码来源:pyfiles.py

示例3: test_code_block_line_number

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import text_error_template [as 别名]
def test_code_block_line_number(self):
        l = TemplateLookup()
        l.put_string(
            "foo.html",
            """
<%
msg = "Something went wrong."
raise RuntimeError(msg)  # This is the line.
%>
            """,
        )
        t = l.get_template("foo.html")
        try:
            t.render()
        except:
            text_error = exceptions.text_error_template().render_unicode()
            assert 'File "foo.html", line 4, in render_body' in text_error
            assert "raise RuntimeError(msg)  # This is the line." in text_error
        else:
            assert False 
开发者ID:sqlalchemy,项目名称:mako,代码行数:22,代码来源:test_exceptions.py

示例4: test_module_block_line_number

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import text_error_template [as 别名]
def test_module_block_line_number(self):
        l = TemplateLookup()
        l.put_string(
            "foo.html",
            """
<%!
def foo():
    msg = "Something went wrong."
    raise RuntimeError(msg)  # This is the line.
%>
${foo()}
            """,
        )
        t = l.get_template("foo.html")
        try:
            t.render()
        except:
            text_error = exceptions.text_error_template().render_unicode()
            assert 'File "foo.html", line 7, in render_body' in text_error
            assert 'File "foo.html", line 5, in foo' in text_error
            assert "raise RuntimeError(msg)  # This is the line." in text_error
        else:
            assert False 
开发者ID:sqlalchemy,项目名称:mako,代码行数:25,代码来源:test_exceptions.py

示例5: _exit

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import text_error_template [as 别名]
def _exit():
    sys.stderr.write(exceptions.text_error_template().render())
    sys.exit(1) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:5,代码来源:cmd.py

示例6: render_string

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import text_error_template [as 别名]
def render_string(template_name, request, context, *, app_key):
    lookup = request.app.get(app_key)

    if lookup is None:
        raise web.HTTPInternalServerError(
            text=("Template engine is not initialized, "
                  "call aiohttp_mako.setup(app_key={}) first"
                  "".format(app_key)))
    try:
        template = lookup.get_template(template_name)
    except TemplateLookupException as e:
        raise web.HTTPInternalServerError(
            text="Template '{}' not found".format(template_name)) from e
    if not isinstance(context, Mapping):
        raise web.HTTPInternalServerError(
            text="context should be mapping, not {}".format(type(context)))
    if request.get(REQUEST_CONTEXT_KEY):
        context = dict(request[REQUEST_CONTEXT_KEY], **context)
    try:
        text = template.render_unicode(**context)
    except Exception:  # pragma: no cover
        exc_info = sys.exc_info()
        errtext = text_error_template().render(
            error=exc_info[1],
            traceback=exc_info[2])
        exc = MakoRenderingException(errtext).with_traceback(exc_info[2])
        raise exc

    return text 
开发者ID:aio-libs,项目名称:aiohttp-mako,代码行数:31,代码来源:__init__.py

示例7: test_text_error_template

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import text_error_template [as 别名]
def test_text_error_template(self):
        code = """
% i = 0
"""
        try:
            template = Template(code)
            template.render_unicode()
            assert False
        except exceptions.CompileException:
            text_error = exceptions.text_error_template().render_unicode()
            assert "Traceback (most recent call last):" in text_error
            assert (
                "CompileException: Fragment 'i = 0' is not a partial "
                "control statement"
            ) in text_error 
开发者ID:sqlalchemy,项目名称:mako,代码行数:17,代码来源:test_exceptions.py

示例8: test_alternating_file_names

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import text_error_template [as 别名]
def test_alternating_file_names(self):
        l = TemplateLookup()
        l.put_string(
            "base.html",
            """
<%!
def broken():
    raise RuntimeError("Something went wrong.")
%> body starts here
<%block name="foo">
    ${broken()}
</%block>
            """,
        )
        l.put_string(
            "foo.html",
            """
<%inherit file="base.html"/>
<%block name="foo">
    ${parent.foo()}
</%block>
            """,
        )
        t = l.get_template("foo.html")
        try:
            t.render()
        except:
            text_error = exceptions.text_error_template().render_unicode()
            assert """
  File "base.html", line 5, in render_body
    %> body starts here
  File "foo.html", line 4, in render_foo
    ${parent.foo()}
  File "base.html", line 7, in render_foo
    ${broken()}
  File "base.html", line 4, in broken
    raise RuntimeError("Something went wrong.")
""" in text_error
        else:
            assert False 
开发者ID:sqlalchemy,项目名称:mako,代码行数:42,代码来源:test_exceptions.py

示例9: doTemplate

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import text_error_template [as 别名]
def doTemplate(tmpl, namespace = {}, leftMargin = 0, rightMargin = 80, formatExceptions = True, encoding = 'utf-8'):
    buf = StringIO()
    ctx = Context(buf, **namespace)
    try:
        tobj = Template(filename = tmpl, output_encoding = encoding,  format_exceptions = formatExceptions) #, imports ='re' # TODO: imports parameter.
        tobj.render_context(ctx)
    except:
        print(exceptions.text_error_template().render())
        return None
    ##return strings.reformat(buf.getvalue(), leftMargin, rightMargin)
    return buf.getvalue() 
开发者ID:christoph2,项目名称:pyA2L,代码行数:13,代码来源:templates.py

示例10: doTemplateFromText

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import text_error_template [as 别名]
def doTemplateFromText(tmpl, namespace = {}, leftMargin = 0, rightMargin = 80, formatExceptions = True, encoding = 'utf-8'):
    buf = StringIO()
    ctx = Context(buf, **namespace)
    try:
        tobj = Template(text = tmpl, output_encoding = encoding, format_exceptions = formatExceptions) #, imports ='re'
        tobj.render_context(ctx)
    except:
        print(exceptions.text_error_template().render())
        return None
    return indentText(buf.getvalue(), leftMargin) #, rightMargin) 
开发者ID:christoph2,项目名称:pyA2L,代码行数:12,代码来源:templates.py

示例11: render

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import text_error_template [as 别名]
def render(bv):
    try:
        show_markdown_report("{} Writeup".format(name), template.render(bv=bv, images=images))
    except:
        show_plain_text_report("{}: Error in Rendering".format(name), exceptions.text_error_template().render()) 
开发者ID:nccgroup,项目名称:binja_sensei,代码行数:7,代码来源:__init__.py

示例12: render

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import text_error_template [as 别名]
def render(bv):
    try:
        show_markdown_report("{} Writeup".format(name), template.render(bv=bv))
    except:
        show_plain_text_report("{}: Error in Rendering".format(name), exceptions.text_error_template().render()) 
开发者ID:nccgroup,项目名称:binja_sensei,代码行数:7,代码来源:__init__.py

示例13: render_with_template

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import text_error_template [as 别名]
def render_with_template(text=None, filename=None, preprocessor=None, template_kwargs={}):
    from mako.template import Template
    from mako import exceptions

    tmpl = Template(text=text, filename=filename, preprocessor=preprocessor)
    try:
        return tmpl.render(**template_kwargs)
    except Exception as e:
        import sys
        print('-' * 78, file=sys.stderr)
        print('Template exceptions', file=sys.stderr)
        print('-' * 78, file=sys.stderr)
        print(exceptions.text_error_template().render(), file=sys.stderr)
        print('-' * 78, file=sys.stderr)
        raise e 
开发者ID:sony,项目名称:nnabla,代码行数:17,代码来源:code_generator_utils.py

示例14: render

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import text_error_template [as 别名]
def render(template, dest, **kwargs):
        """
        Render a Mako template passing it optional arguments
        """
        log.debug('Generating %s\n' % dest)
        try:
            text = Template(filename=template).render(**kwargs)
            with closing(open(dest, 'w')) as f:
                f.write(text)
        except:
            # Display template errors in a less cryptic way
            log.error('Couldn''t render a config file (%s)',
                      os.path.basename(template))
            log.error(exceptions.text_error_template().render()) 
开发者ID:Fibbing,项目名称:FibbingNode,代码行数:16,代码来源:router.py

示例15: mkorendertpl

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import text_error_template [as 别名]
def mkorendertpl(tpl,outfile,*args,**kwargs):
  with open(outfile,"w") as f:
    try:
      f.write(tpl.render(*args,**kwargs));
    except:
      print((exceptions.text_error_template().render()))
      raise; 
开发者ID:cdoersch,项目名称:deepcontext,代码行数:9,代码来源:utils.py


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