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


Python lookup.TemplateLookup方法代码示例

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


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

示例1: __init__

# 需要导入模块: from mako import lookup [as 别名]
# 或者: from mako.lookup import TemplateLookup [as 别名]
def __init__(self, extra_vars_func=None, options=None, extension="mak"):
        self.extra_vars_func = extra_vars_func
        self.extension = extension
        if not options:
            options = {}

        # Pull the options out and initialize the lookup
        lookup_options = {}
        for k, v in options.items():
            if k.startswith("mako."):
                lookup_options[k[5:]] = v
            elif k in ["directories", "filesystem_checks", "module_directory"]:
                lookup_options[k] = v
        self.lookup = TemplateLookup(**lookup_options)

        self.tmpl_options = {}
        # transfer lookup args to template args, based on those available
        # in getargspec
        for kw in compat.inspect_getargspec(Template.__init__)[0]:
            if kw in lookup_options:
                self.tmpl_options[kw] = lookup_options[kw] 
开发者ID:remg427,项目名称:misp42splunk,代码行数:23,代码来源:turbogears.py

示例2: __init__

# 需要导入模块: from mako import lookup [as 别名]
# 或者: from mako.lookup import TemplateLookup [as 别名]
def __init__(self, extra_vars_func=None, options=None, extension='mak'):
        self.extra_vars_func = extra_vars_func
        self.extension = extension
        if not options:
            options = {}

        # Pull the options out and initialize the lookup
        lookup_options = {}
        for k, v in options.items():
            if k.startswith('mako.'):
                lookup_options[k[5:]] = v
            elif k in ['directories', 'filesystem_checks', 'module_directory']:
                lookup_options[k] = v
        self.lookup = TemplateLookup(**lookup_options)

        self.tmpl_options = {}
        # transfer lookup args to template args, based on those available
        # in getargspec
        for kw in compat.inspect_getargspec(Template.__init__)[0]:
            if kw in lookup_options:
                self.tmpl_options[kw] = lookup_options[kw] 
开发者ID:jpush,项目名称:jbox,代码行数:23,代码来源:turbogears.py

示例3: test_dynamic

# 需要导入模块: from mako import lookup [as 别名]
# 或者: from mako.lookup import TemplateLookup [as 别名]
def test_dynamic(self):
        collection = lookup.TemplateLookup()

        collection.put_string(
            "a",
            """
        <%namespace name="b" file="${context['b_def']}"/>

        a.  b: ${b.body()}
""",
        )

        collection.put_string(
            "b",
            """
        b.
""",
        )

        eq_(
            flatten_result(collection.get_template("a").render(b_def="b")),
            "a. b: b.",
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:25,代码来源:test_namespace.py

示例4: test_module

# 需要导入模块: from mako import lookup [as 别名]
# 或者: from mako.lookup import TemplateLookup [as 别名]
def test_module(self):
        collection = lookup.TemplateLookup()

        collection.put_string(
            "main.html",
            """
        <%namespace name="comp" module="test.sample_module_namespace"/>

        this is main.  ${comp.foo1()}
        ${comp.foo2("hi")}
""",
        )

        assert (
            flatten_result(collection.get_template("main.html").render())
            == "this is main. this is foo1. this is foo2, x is hi"
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:19,代码来源:test_namespace.py

示例5: test_module_imports

# 需要导入模块: from mako import lookup [as 别名]
# 或者: from mako.lookup import TemplateLookup [as 别名]
def test_module_imports(self):
        collection = lookup.TemplateLookup()

        collection.put_string(
            "main.html",
            """
        <%namespace import="*" module="test.foo.test_ns"/>

        this is main.  ${foo1()}
        ${foo2("hi")}
""",
        )

        assert (
            flatten_result(collection.get_template("main.html").render())
            == "this is main. this is foo1. this is foo2, x is hi"
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:19,代码来源:test_namespace.py

示例6: test_module_imports_2

# 需要导入模块: from mako import lookup [as 别名]
# 或者: from mako.lookup import TemplateLookup [as 别名]
def test_module_imports_2(self):
        collection = lookup.TemplateLookup()

        collection.put_string(
            "main.html",
            """
        <%namespace import="foo1, foo2" module="test.foo.test_ns"/>

        this is main.  ${foo1()}
        ${foo2("hi")}
""",
        )

        assert (
            flatten_result(collection.get_template("main.html").render())
            == "this is main. this is foo1. this is foo2, x is hi"
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:19,代码来源:test_namespace.py

示例7: test_getattr

# 需要导入模块: from mako import lookup [as 别名]
# 或者: from mako.lookup import TemplateLookup [as 别名]
def test_getattr(self):
        collection = lookup.TemplateLookup()
        collection.put_string(
            "main.html",
            """
            <%namespace name="foo" file="ns.html"/>
            <%
                 if hasattr(foo, 'lala'):
                     foo.lala()
                 if not hasattr(foo, 'hoho'):
                     context.write('foo has no hoho.')
            %>
         """,
        )
        collection.put_string(
            "ns.html",
            """
          <%def name="lala()">this is lala.</%def>
        """,
        )
        assert (
            flatten_result(collection.get_template("main.html").render())
            == "this is lala.foo has no hoho."
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:26,代码来源:test_namespace.py

示例8: test_loop_disabled_override_lookup

# 需要导入模块: from mako import lookup [as 别名]
# 或者: from mako.lookup import TemplateLookup [as 别名]
def test_loop_disabled_override_lookup(self):
        l = TemplateLookup(enable_loop=False)
        l.put_string(
            "x",
            """
            <%page enable_loop="True" />
            % for i in (1, 2, 3):
                ${i} ${loop.index}
            % endfor
        """,
        )

        self._do_test(
            l.get_template("x"),
            "1 0 2 1 3 2",
            template_args=dict(loop="hi"),
            filters=flatten_result,
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:20,代码来源:test_loop.py

示例9: test_loop_enabled_override_lookup

# 需要导入模块: from mako import lookup [as 别名]
# 或者: from mako.lookup import TemplateLookup [as 别名]
def test_loop_enabled_override_lookup(self):
        l = TemplateLookup()
        l.put_string(
            "x",
            """
            <%page enable_loop="True" />
            % for i in (1, 2, 3):
                ${i} ${loop.index}
            % endfor
        """,
        )

        self._do_test(
            l.get_template("x"),
            "1 0 2 1 3 2",
            template_args=dict(),
            filters=flatten_result,
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:20,代码来源:test_loop.py

示例10: test_block_args

# 需要导入模块: from mako import lookup [as 别名]
# 或者: from mako.lookup import TemplateLookup [as 别名]
def test_block_args(self):
        l = TemplateLookup()
        l.put_string(
            "caller",
            """

            <%include file="callee" args="val1='3', val2='4'"/>

        """,
        )
        l.put_string(
            "callee",
            """
            <%page args="val1, val2"/>
            <%block name="foob" args="val1, val2">
                foob, ${val1}, ${val2}
            </%block>
        """,
        )
        self._do_test(
            l.get_template("caller"), ["foob, 3, 4"], filters=result_lines
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:24,代码来源:test_block.py

示例11: test_block_pageargs

# 需要导入模块: from mako import lookup [as 别名]
# 或者: from mako.lookup import TemplateLookup [as 别名]
def test_block_pageargs(self):
        l = TemplateLookup()
        l.put_string(
            "caller",
            """

            <%include file="callee" args="val1='3', val2='4'"/>

        """,
        )
        l.put_string(
            "callee",
            """
            <%block name="foob">
                foob, ${pageargs['val1']}, ${pageargs['val2']}
            </%block>
        """,
        )
        self._do_test(
            l.get_template("caller"), ["foob, 3, 4"], filters=result_lines
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:23,代码来源:test_block.py

示例12: test_format_exceptions_pygments

# 需要导入模块: from mako import lookup [as 别名]
# 或者: from mako.lookup import TemplateLookup [as 别名]
def test_format_exceptions_pygments(self):
        l = TemplateLookup(format_exceptions=True)

        l.put_string(
            "foo.html",
            """
<%inherit file="base.html"/>
${foobar}
        """,
        )

        l.put_string(
            "base.html",
            """
        ${self.body()}
        """,
        )

        assert (
            '<div class="sourceline"><table class="syntax-highlightedtable">'
            in l.get_template("foo.html").render_unicode()
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:24,代码来源:test_exceptions.py

示例13: test_format_exceptions_no_pygments

# 需要导入模块: from mako import lookup [as 别名]
# 或者: from mako.lookup import TemplateLookup [as 别名]
def test_format_exceptions_no_pygments(self):
        l = TemplateLookup(format_exceptions=True)

        l.put_string(
            "foo.html",
            """
<%inherit file="base.html"/>
${foobar}
        """,
        )

        l.put_string(
            "base.html",
            """
        ${self.body()}
        """,
        )

        assert '<div class="sourceline">${foobar}</div>' in result_lines(
            l.get_template("foo.html").render_unicode()
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:23,代码来源:test_exceptions.py

示例14: test_utf8_format_exceptions_pygments

# 需要导入模块: from mako import lookup [as 别名]
# 或者: from mako.lookup import TemplateLookup [as 别名]
def test_utf8_format_exceptions_pygments(self):
        """test that htmlentityreplace formatting is applied to
           exceptions reported with format_exceptions=True"""

        l = TemplateLookup(format_exceptions=True)
        if compat.py3k:
            l.put_string(
                "foo.html", """# -*- coding: utf-8 -*-\n${'привет' + foobar}"""
            )
        else:
            l.put_string(
                "foo.html",
                """# -*- coding: utf-8 -*-\n${u'привет' + foobar}""",
            )

        if compat.py3k:
            assert "&#39;привет&#39;</span>" in l.get_template(
                "foo.html"
            ).render().decode("utf-8")
        else:
            assert (
                "&#39;&#x43F;&#x440;&#x438;&#x432;"
                "&#x435;&#x442;&#39;</span>"
            ) in l.get_template("foo.html").render().decode("utf-8") 
开发者ID:sqlalchemy,项目名称:mako,代码行数:26,代码来源:test_exceptions.py

示例15: test_module_block_line_number

# 需要导入模块: from mako import lookup [as 别名]
# 或者: from mako.lookup import TemplateLookup [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


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