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


Python template.Template方法代码示例

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


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

示例1: test_break_continue

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Template [as 别名]
def test_break_continue(self):
        template = Template(
            utf8(
                """\
{% for i in range(10) %}
    {% if i == 2 %}
        {% continue %}
    {% end %}
    {{ i }}
    {% if i == 6 %}
        {% break %}
    {% end %}
{% end %}"""
            )
        )
        result = template.generate()
        # remove extraneous whitespace
        result = b"".join(result.split())
        self.assertEqual(result, b"013456") 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:21,代码来源:template_test.py

示例2: test_error_line_number_module

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Template [as 别名]
def test_error_line_number_module(self):
        loader = None  # type: typing.Optional[DictLoader]

        def load_generate(path, **kwargs):
            assert loader is not None
            return loader.load(path).generate(**kwargs)

        loader = DictLoader(
            {"base.html": "{% module Template('sub.html') %}", "sub.html": "{{1/0}}"},
            namespace={"_tt_modules": ObjectDict(Template=load_generate)},
        )
        try:
            loader.load("base.html").generate()
            self.fail("did not get expected exception")
        except ZeroDivisionError:
            exc_stack = traceback.format_exc()
            self.assertTrue("# base.html:1" in exc_stack)
            self.assertTrue("# sub.html:1" in exc_stack) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:20,代码来源:template_test.py

示例3: test_escaping

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Template [as 别名]
def test_escaping(self):
        self.assertRaises(ParseError, lambda: Template("{{"))
        self.assertRaises(ParseError, lambda: Template("{%"))
        self.assertEqual(Template("{{!").generate(), b"{{")
        self.assertEqual(Template("{%!").generate(), b"{%")
        self.assertEqual(Template("{{ 'expr' }} {{!jquery expr}}").generate(),
                         b"expr {{jquery expr}}") 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:9,代码来源:template_test.py

示例4: test_unicode_literal_expression

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Template [as 别名]
def test_unicode_literal_expression(self):
        # Unicode literals should be usable in templates.  Note that this
        # test simulates unicode characters appearing directly in the
        # template file (with utf8 encoding), i.e. \u escapes would not
        # be used in the template file itself.
        if str is unicode_type:
            # python 3 needs a different version of this test since
            # 2to3 doesn't run on template internals
            template = Template(utf8(u('{{ "\u00e9" }}')))
        else:
            template = Template(utf8(u('{{ u"\u00e9" }}')))
        self.assertEqual(template.generate(), utf8(u("\u00e9"))) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:14,代码来源:template_test.py

示例5: test_apply

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Template [as 别名]
def test_apply(self):
        def upper(s):
            return s.upper()
        template = Template(utf8("{% apply upper %}foo{% end %}"))
        self.assertEqual(template.generate(upper=upper), b"FOO") 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:7,代码来源:template_test.py

示例6: test_unicode_apply

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Template [as 别名]
def test_unicode_apply(self):
        def upper(s):
            return to_unicode(s).upper()
        template = Template(utf8(u("{% apply upper %}foo \u00e9{% end %}")))
        self.assertEqual(template.generate(upper=upper), utf8(u("FOO \u00c9"))) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:7,代码来源:template_test.py

示例7: test_try

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Template [as 别名]
def test_try(self):
        template = Template(utf8("""{% try %}
try{% set y = 1/x %}
{% except %}-except
{% else %}-else
{% finally %}-finally
{% end %}"""))
        self.assertEqual(template.generate(x=1), b"\ntry\n-else\n-finally\n")
        self.assertEqual(template.generate(x=0), b"\ntry-except\n-finally\n") 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:11,代码来源:template_test.py

示例8: test_simple

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Template [as 别名]
def test_simple(self):
        template = Template("Hello {{ name }}!")
        self.assertEqual(template.generate(name="Ben"),
                         b"Hello Ben!") 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:6,代码来源:template_test.py

示例9: test_bytes

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Template [as 别名]
def test_bytes(self):
        template = Template("Hello {{ name }}!")
        self.assertEqual(template.generate(name=utf8("Ben")),
                         b"Hello Ben!") 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:6,代码来源:template_test.py

示例10: test_expressions

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Template [as 别名]
def test_expressions(self):
        template = Template("2 + 2 = {{ 2 + 2 }}")
        self.assertEqual(template.generate(), b"2 + 2 = 4") 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:5,代码来源:template_test.py

示例11: test_comment

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Template [as 别名]
def test_comment(self):
        template = Template("Hello{# TODO i18n #} {{ name }}!")
        self.assertEqual(template.generate(name=utf8("Ben")),
                         b"Hello Ben!") 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:6,代码来源:template_test.py

示例12: test_bytes_apply

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Template [as 别名]
def test_bytes_apply(self):
        def upper(s):
            return utf8(to_unicode(s).upper())
        template = Template(utf8(u("{% apply upper %}foo \u00e9{% end %}")))
        self.assertEqual(template.generate(upper=upper), utf8(u("FOO \u00c9"))) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:7,代码来源:template_test.py

示例13: test_if

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Template [as 别名]
def test_if(self):
        template = Template(utf8("{% if x > 4 %}yes{% else %}no{% end %}"))
        self.assertEqual(template.generate(x=5), b"yes")
        self.assertEqual(template.generate(x=3), b"no") 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:6,代码来源:template_test.py

示例14: test_comment_directive

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Template [as 别名]
def test_comment_directive(self):
        template = Template(utf8("{% comment blah blah %}foo"))
        self.assertEqual(template.generate(), b"foo") 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:5,代码来源:template_test.py

示例15: test_break_continue

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Template [as 别名]
def test_break_continue(self):
        template = Template(utf8("""\
{% for i in range(10) %}
    {% if i == 2 %}
        {% continue %}
    {% end %}
    {{ i }}
    {% if i == 6 %}
        {% break %}
    {% end %}
{% end %}"""))
        result = template.generate()
        # remove extraneous whitespace
        result = b''.join(result.split())
        self.assertEqual(result, b"013456") 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:17,代码来源:template_test.py


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