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


Python MockLoader.import_方法代码示例

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


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

示例1: test_block

# 需要导入模块: from kajiki import MockLoader [as 别名]
# 或者: from kajiki.MockLoader import import_ [as 别名]
    def test_block(self):
        loader = MockLoader(
            {
                "parent.html": XMLTemplate(
                    """<div
><py:def function="greet(name)"
>Hello, $name!</py:def
><py:def function="sign(name)"
>Sincerely,<br/><em>$name</em></py:def
>${greet(to)}

<p py:block="body">It was good seeing you last Friday.
Thanks for the gift!</p>

${sign(from_)}
</div>"""
                ),
                "child.html": XMLTemplate(
                    """<py:extends href="parent.html"
><py:def function="greet(name)"
>Dear $name:</py:def
><py:block name="body">${parent_block()}
<p>And don't forget you owe me money!</p>
</py:block
></py:extends>
"""
                ),
            }
        )
        parent = loader.import_("parent.html")
        rsp = parent({"to": "Mark", "from_": "Rick"}).render()
        assert (
            rsp
            == """<div>Hello, Mark!

<p>It was good seeing you last Friday.
Thanks for the gift!</p>

Sincerely,<br/><em>Rick</em>
</div>"""
        ), rsp
        child = loader.import_("child.html")
        rsp = child({"to": "Mark", "from_": "Rick"}).render()
        assert (
            rsp
            == """<div>Dear Mark:

<p>It was good seeing you last Friday.
Thanks for the gift!</p>
<p>And don't forget you owe me money!</p>


Sincerely,<br/><em>Rick</em>
</div>"""
        ), rsp
开发者ID:moreati,项目名称:kajiki,代码行数:57,代码来源:test_xml.py

示例2: test_autoblocks_disabling

# 需要导入模块: from kajiki import MockLoader [as 别名]
# 或者: from kajiki.MockLoader import import_ [as 别名]
    def test_autoblocks_disabling(self):
        loader = MockLoader(
            {
                "parent.html": XMLTemplate(
                    """
<html py:strip="">
<head></head>
<body py:autoblock="False">
    <p py:block="body">It was good seeing you last Friday.
    Thanks for the gift!</p>
</body>
</html>""",
                    autoblocks=["body"],
                ),
                "child.html": XMLTemplate(
                    """
<html>
<py:extends href="parent.html"/>
<body><em>Great conference this weekend!</em></body>
</html>""",
                    autoblocks=["body"],
                ),
            }
        )

        parent = loader.import_("parent.html")
        rsp = parent().render()
        assert (
            rsp
            == """
<head/>
<body>
    <p>It was good seeing you last Friday.
    Thanks for the gift!</p>
</body>
"""
        ), rsp

        child = loader.import_("child.html")
        rsp = child().render()
        assert (
            rsp
            == """<html>

<head/>
<body>
    <em>Great conference this weekend!</em>
</body>


</html>"""
        ), rsp
开发者ID:moreati,项目名称:kajiki,代码行数:54,代码来源:test_xml.py

示例3: test_import_auto

# 需要导入模块: from kajiki import MockLoader [as 别名]
# 或者: from kajiki.MockLoader import import_ [as 别名]
    def test_import_auto(self):
        lib = TextTemplate(
            """%def evenness(n)
%if n % 2 == 0
even\\
%else
odd\\
%end
%end
%def half_evenness(n)
 half of $n is ${evenness(n/2)}\\
%end"""
        )
        tpl = TextTemplate(
            """%import "lib.txt"
%for i in range(4)
$i is ${lib.evenness(i)}${lib.half_evenness(i)}
%end"""
        )
        loader = MockLoader({"lib.txt": lib, "tpl.txt": tpl})
        tpl = loader.import_("tpl.txt")
        rsp = tpl(dict(name="Rick")).render()
        assert (
            rsp == "0 is even half of 0 is even\n"
            "1 is odd half of 1 is odd\n"
            "2 is even half of 2 is odd\n"
            "3 is odd half of 3 is odd\n"
        ), rsp
开发者ID:ollyc,项目名称:kajiki,代码行数:30,代码来源:test_text.py

示例4: test_substituting_gettext_with_lambda_extending

# 需要导入模块: from kajiki import MockLoader [as 别名]
# 或者: from kajiki.MockLoader import import_ [as 别名]
 def test_substituting_gettext_with_lambda_extending(self):
     gettext = lambda x: 'egg'
     loader = MockLoader({
         'parent.html': XMLTemplate('''<div>parent</div>'''),
         'child.html': XMLTemplate('''<py:extends href="parent.html"><div>child</div></py:extends>''')})
     tpl = loader.import_('child.html')
     rsp = tpl(dict(gettext=gettext)).render()
     assert rsp == '''<div>egg</div><div>egg</div>''', rsp
开发者ID:nandoflorestan,项目名称:kajiki,代码行数:10,代码来源:test_xml.py

示例5: test_include

# 需要导入模块: from kajiki import MockLoader [as 别名]
# 或者: from kajiki.MockLoader import import_ [as 别名]
    def test_include(self):
        loader = MockLoader({
            'hdr.txt': TextTemplate('# header\n'),
            'tpl.txt': TextTemplate('''a
%include "hdr.txt"
b
''')})
        tpl = loader.import_('tpl.txt')
        rsp = tpl(dict(name='Rick')).render()
        assert rsp == 'a\n# header\nb\n', rsp
开发者ID:nandoflorestan,项目名称:kajiki,代码行数:12,代码来源:test_text.py

示例6: test_substituting_gettext_with_lambda_extending_twice

# 需要导入模块: from kajiki import MockLoader [as 别名]
# 或者: from kajiki.MockLoader import import_ [as 别名]
 def test_substituting_gettext_with_lambda_extending_twice(self):
     gettext = lambda x: 'egg'
     loader = MockLoader({
         'parent.html': XMLTemplate('''<div>parent</div>'''),
         'mid.html': XMLTemplate('''<py:extends href="parent.html"><div>${variable}</div></py:extends>'''),
         'child.html': XMLTemplate('''<py:extends href="mid.html"><div>child</div></py:extends>''')})
     tpl = loader.import_('child.html')
     rsp = tpl(dict(variable='spam', gettext=gettext)).render()
     # variables must not be translated
     assert rsp == '''<div>egg</div><div>spam</div><div>egg</div>''', rsp
开发者ID:nandoflorestan,项目名称:kajiki,代码行数:12,代码来源:test_xml.py

示例7: test_block

# 需要导入模块: from kajiki import MockLoader [as 别名]
# 或者: from kajiki.MockLoader import import_ [as 别名]
    def test_block(self):
        loader = MockLoader({
            'parent.html': XMLTemplate('''<div
><py:def function="greet(name)"
>Hello, $name!</py:def
><py:def function="sign(name)"
>Sincerely,<br/><em>$name</em></py:def
>${greet(to)}

<p py:block="body">It was good seeing you last Friday.
Thanks for the gift!</p>

${sign(from_)}
</div>'''),
            'child.html': XMLTemplate('''<py:extends href="parent.html"
><py:def function="greet(name)"
>Dear $name:</py:def
><py:block name="body">${parent_block()}
<p>And don't forget you owe me money!</p>
</py:block
></py:extends>
''')})
        parent = loader.import_('parent.html')
        rsp = parent({'to': 'Mark', 'from_': 'Rick'}).render()
        assert rsp == '''<div>Hello, Mark!

<p>It was good seeing you last Friday.
Thanks for the gift!</p>

Sincerely,<br/><em>Rick</em>
</div>''', rsp
        child = loader.import_('child.html')
        rsp = child({'to': 'Mark', 'from_': 'Rick'}).render()
        assert rsp == '''<div>Dear Mark:

<p>It was good seeing you last Friday.
Thanks for the gift!</p>
<p>And don't forget you owe me money!</p>


Sincerely,<br/><em>Rick</em>
</div>''', rsp
开发者ID:ollyc,项目名称:kajiki,代码行数:44,代码来源:test_xml.py

示例8: test_basic

# 需要导入模块: from kajiki import MockLoader [as 别名]
# 或者: from kajiki.MockLoader import import_ [as 别名]
    def test_basic(self):
        parent = TextTemplate(
            """
%def header()
# Header name=$name
%end
%def footer()
# Footer
%end
%def body()
## Parent Body
id() = ${id()}
local.id() = ${local.id()}
self.id() = ${self.id()}
child.id() = ${child.id()}
%end
%def id()
parent\\
%end
${header()}${body()}${footer()}"""
        )
        mid = TextTemplate(
            """%extends "parent.txt"
%def id()
mid\\
%end
"""
        )
        child = TextTemplate(
            """%extends "mid.txt"
%def id()
child\\
%end
%def body()
## Child Body
${parent.body()}\\
%end
"""
        )
        loader = MockLoader({"parent.txt": parent, "mid.txt": mid, "child.txt": child})
        tpl = loader.import_("child.txt")
        rsp = tpl(dict(name="Rick")).render()
        assert (
            rsp == "# Header name=Rick\n"
            "## Child Body\n"
            "## Parent Body\n"
            "id() = child\n"
            "local.id() = parent\n"
            "self.id() = child\n"
            "child.id() = mid\n"
            "# Footer\n"
        ), rsp
开发者ID:ollyc,项目名称:kajiki,代码行数:54,代码来源:test_text.py

示例9: test_basic

# 需要导入模块: from kajiki import MockLoader [as 别名]
# 或者: from kajiki.MockLoader import import_ [as 别名]
    def test_basic(self):
        loader = MockLoader(
            {
                "parent.html": XMLTemplate(
                    """<div
><h1 py:def="header()">Header name=$name</h1
><h6 py:def="footer()">Footer</h6
><div py:def="body()">
id() = ${id()}
local.id() = ${local.id()}
self.id() = ${self.id()}
child.id() = ${child.id()}
</div><span py:def="id()">parent</span>
${header()}
${body()}
${footer()}
</div>"""
                ),
                "mid.html": XMLTemplate(
                    """<py:extends href="parent.html"
><span py:def="id()">mid</span
></py:extends>"""
                ),
                "child.html": XMLTemplate(
                    """<py:extends href="mid.html"
><span py:def="id()">child</span
><div py:def="body()">
<h2>Child Body</h2>
${parent.body()}
</div></py:extends>"""
                ),
            }
        )
        tpl = loader.import_("child.html")
        rsp = tpl(dict(name="Rick")).render()
        assert (
            rsp
            == """<div>
<h1>Header name=Rick</h1>
<div>
<h2>Child Body</h2>
<div>
id() = <span>child</span>
local.id() = <span>parent</span>
self.id() = <span>child</span>
child.id() = <span>mid</span>
</div>
</div>
<h6>Footer</h6>
</div>"""
        ), rsp
开发者ID:moreati,项目名称:kajiki,代码行数:53,代码来源:test_xml.py

示例10: test_include

# 需要导入模块: from kajiki import MockLoader [as 别名]
# 或者: from kajiki.MockLoader import import_ [as 别名]
    def test_include(self):
        loader = MockLoader({
                'hdr.html':XMLTemplate('<h1>Header</h1>\n'),
                'tpl.html':XMLTemplate('''<html><body>
<py:include href="hdr.html"/>
<p>This is the body</p>
</body></html>''')
                })
        tpl = loader.import_('tpl.html')
        rsp = tpl(dict(name='Rick')).render()
        assert rsp == '''<html><body>
<h1>Header</h1>
<p>This is the body</p>
</body></html>''', rsp
开发者ID:gdrius,项目名称:kajiki,代码行数:16,代码来源:test_xml.py

示例11: test_include

# 需要导入模块: from kajiki import MockLoader [as 别名]
# 或者: from kajiki.MockLoader import import_ [as 别名]
 def test_include(self):
     '''Must NOT result in: NameError: global name 'name' is not defined'''
     loader = MockLoader({
         'included.html': XMLTemplate('<p>The included template must also '
             'access Kajiki globals and the template context: '
             '${value_of("name")}</p>\n'),
         'tpl.html': XMLTemplate('<html><body><p>This is the body</p>\n'
             '<py:include href="included.html"/></body></html>')
     })
     tpl = loader.import_('tpl.html')
     rsp = tpl(dict(name='Rick')).render()
     assert ('<html><body><p>This is the body</p>\n'
         '<p>The included template must also access Kajiki globals and '
         'the template context: Rick</p></body></html>' == rsp)
开发者ID:ollyc,项目名称:kajiki,代码行数:16,代码来源:test_xml.py

示例12: test_autoblocks_disabling

# 需要导入模块: from kajiki import MockLoader [as 别名]
# 或者: from kajiki.MockLoader import import_ [as 别名]
    def test_autoblocks_disabling(self):
        loader = MockLoader({
            'parent.html': XMLTemplate('''
<html py:strip="">
<head></head>
<body py:autoblock="False">
    <p py:block="body">It was good seeing you last Friday.
    Thanks for the gift!</p>
</body>
</html>''', autoblocks=['body']),
            'child.html': XMLTemplate('''
<html>
<py:extends href="parent.html"/>
<body><em>Great conference this weekend!</em></body>
</html>''', autoblocks=['body'])})

        parent = loader.import_('parent.html')
        rsp = parent().render()
        assert rsp == '''
<head/>
<body>
    <p>It was good seeing you last Friday.
    Thanks for the gift!</p>
</body>
''', rsp

        child = loader.import_('child.html')
        rsp = child().render()
        assert rsp == '''<html>

<head/>
<body>
    <em>Great conference this weekend!</em>
</body>


</html>''', rsp
开发者ID:ollyc,项目名称:kajiki,代码行数:39,代码来源:test_xml.py

示例13: test_include

# 需要导入模块: from kajiki import MockLoader [as 别名]
# 或者: from kajiki.MockLoader import import_ [as 别名]
    def test_include(self):
        loader = MockLoader(
            {
                "hdr.txt": TextTemplate("# header\n"),
                "tpl.txt": TextTemplate(
                    """a
%include "hdr.txt"
b
"""
                ),
            }
        )
        tpl = loader.import_("tpl.txt")
        rsp = tpl(dict(name="Rick")).render()
        assert rsp == "a\n# header\nb\n", rsp
开发者ID:ollyc,项目名称:kajiki,代码行数:17,代码来源:test_text.py

示例14: test_dynamic

# 需要导入模块: from kajiki import MockLoader [as 别名]
# 或者: from kajiki.MockLoader import import_ [as 别名]
    def test_dynamic(self):
        loader = MockLoader({
            'parent0.html': XMLTemplate('<span>Parent 0</span>'),
            'parent1.html': XMLTemplate('<span>Parent 1</span>'),
            'child.html': XMLTemplate('''<div
><py:if test="p == 0"><py:extends href="parent0.html"/></py:if
><py:else><py:extends href="parent1.html"/></py:else
></div>
''')
        })
        tpl = loader.import_('child.html')
        rsp = tpl(dict(p=0)).render()
        assert rsp == '<div><span>Parent 0</span></div>', rsp
        rsp = tpl(dict(p=1)).render()
        assert rsp == '<div><span>Parent 1</span></div>', rsp
开发者ID:ollyc,项目名称:kajiki,代码行数:17,代码来源:test_xml.py

示例15: test_dynamic

# 需要导入模块: from kajiki import MockLoader [as 别名]
# 或者: from kajiki.MockLoader import import_ [as 别名]
    def test_dynamic(self):
        loader = MockLoader({
            'parent0.txt': TextTemplate('Parent 0'),
            'parent1.txt': TextTemplate('Parent 1'),
            'child.txt': TextTemplate('''%if p == 0
%extends "parent0.txt"
%else
%extends "parent1.txt"
%end
''')
        })
        tpl = loader.import_('child.txt')
        rsp = tpl(dict(p=0)).render()
        assert rsp == 'Parent 0', rsp
        rsp = tpl(dict(p=1)).render()
        assert rsp == 'Parent 1', rsp
开发者ID:nandoflorestan,项目名称:kajiki,代码行数:18,代码来源:test_text.py


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