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