• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.flatten_result函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中test.util.flatten_result函数的典型用法代码示例。如果您正苦于以下问题:Python flatten_result函数的具体用法?Python flatten_result怎么用?Python flatten_result使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_nested_call_4

    def test_nested_call_4(self):
        base = """
        <%def name="A()">
        A_def
        ${caller.body()}
        </%def>

        <%def name="B()">
        B_def
        ${caller.body()}
        </%def>
        """

        template = Template(base + """
        <%def name="C()">
         C_def
         <%self:B>
           <%self:A>
              A_body
           </%self:A>
            B_body
           ${caller.body()}
         </%self:B>
        </%def>

        <%self:C>
        C_body
        </%self:C>
        """)

        eq_(
            flatten_result(template.render()),
            "C_def B_def A_def A_body B_body C_body"
        )

        template = Template(base + """
        <%def name="C()">
         C_def
         <%self:B>
            B_body
           ${caller.body()}
           <%self:A>
              A_body
           </%self:A>
         </%self:B>
        </%def>

        <%self:C>
        C_body
        </%self:C>
        """)

        eq_(
            flatten_result(template.render()),
            "C_def B_def B_body C_body A_def A_body"
        )
开发者ID:whiteclover,项目名称:Choco,代码行数:56,代码来源:test_call.py


示例2: test_basic

    def test_basic(self):
        template = Template("""
            <%page args="x, y, z=7"/>

            this is page, ${x}, ${y}, ${z}
""")

        assert flatten_result(template.render(x=5, y=10)) == "this is page, 5, 10, 7"
        assert flatten_result(template.render(x=5, y=10, z=32)) == "this is page, 5, 10, 32"
        assert_raises(TypeError, template.render, y=10)
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:10,代码来源:test_template.py


示例3: test_builtins

    def test_builtins(self):
        t = Template("""
            ${"this is <text>" | h}
""")
        assert flatten_result(t.render()) == "this is &lt;text&gt;"

        t = Template("""
            http://foo.com/arg1=${"hi! this is a string." | u}
""")
        assert flatten_result(t.render()) == "http://foo.com/arg1=hi%21+this+is+a+string."
开发者ID:JasonZengJ,项目名称:puzzle,代码行数:10,代码来源:test_filters.py


示例4: test_unicode_file_lookup

 def test_unicode_file_lookup(self):
     lookup = TemplateLookup(directories=[template_base], output_encoding="utf-8", default_filters=["decode.utf8"])
     if compat.py3k:
         template = lookup.get_template("/chs_unicode_py3k.html")
     else:
         template = lookup.get_template("/chs_unicode.html")
     eq_(flatten_result(template.render_unicode(name="毛泽东")), u("毛泽东 是 新中国的主席<br/> Welcome 你 to 北京."))
开发者ID:JasonZengJ,项目名称:puzzle,代码行数:7,代码来源:test_template.py


示例5: test_overload

    def test_overload(self):
        collection = lookup.TemplateLookup()

        collection.put_string('main.html', """
        <%namespace name="comp" file="defs.html">
            <%def name="def1(x, y)">
                overridden def1 ${x}, ${y}
            </%def>
        </%namespace>

        this is main.  ${comp.def1("hi", "there")}
        ${comp.def2("there")}
    """)

        collection.put_string('defs.html', """
        <%def name="def1(s)">
            def1: ${s}
        </%def>

        <%def name="def2(x)">
            def2: ${x}
        </%def>
    """)

        assert flatten_result(collection.get_template('main.html').render()) == "this is main. overridden def1 hi, there def2: there"
开发者ID:whiteclover,项目名称:Choco,代码行数:25,代码来源:test_namespace.py


示例6: test_scope_ten

    def test_scope_ten(self):
        t = Template("""
            <%def name="a()">
                <%def name="b()">
                    <%
                        y = 19
                    %>
                    b/c: ${c()}
                    b/y: ${y}
                </%def>
                <%def name="c()">
                    c/y: ${y}
                </%def>

                <%
                    # we assign to "y".  but the 'enclosing
                    # scope' of "b" and "c" is from
                    # the "y" on the outside
                    y = 10
                %>
                a/y: ${y}
                a/b: ${b()}
            </%def>

            <%
                y = 7
            %>
            main/a: ${a()}
            main/y: ${y}
    """)
        eq_(
            flatten_result(t.render()),
            "main/a: a/y: 10 a/b: b/c: c/y: 10 b/y: 19 main/y: 7"
        )
开发者ID:whiteclover,项目名称:Choco,代码行数:34,代码来源:test_def.py


示例7: test_scope_five

    def test_scope_five(self):
        """test that variables are pulled from
        'enclosing' scope before context."""
        # same as test four, but adds a scope around it.
        t = Template("""
            <%def name="enclosing()">
            <%
                x = 5
            %>
            <%def name="a()">
                this is a. x is ${x}.
            </%def>

            <%def name="b()">
                <%
                    x = 9
                %>
                this is b. x is ${x}.
                calling a. ${a()}
            </%def>

            ${b()}
            </%def>
            ${enclosing()}
""")
        eq_(
            flatten_result(t.render()),
            "this is b. x is 9. calling a. this is a. x is 5."
        )
开发者ID:whiteclover,项目名称:Choco,代码行数:29,代码来源:test_def.py


示例8: test_scope_eight

    def test_scope_eight(self):
        """test that the initial context counts
        as 'enclosing' scope, for nested defs"""
        t = Template("""
        <%def name="enclosing()">
            <%def name="a()">
                a: x is ${x}
            </%def>

            <%def name="b()">
                <%
                    x = 10
                %>

                b. x is ${x}.  ${a()}
            </%def>

            ${b()}
        </%def>
        ${enclosing()}
    """)
        eq_(
            flatten_result(t.render(x=5)),
            "b. x is 10. a: x is 5"
        )
开发者ID:whiteclover,项目名称:Choco,代码行数:25,代码来源:test_def.py


示例9: test_inter_def

    def test_inter_def(self):
        """test defs calling each other"""
        template = Template("""
        ${b()}

        <%def name="a()">\
        im a
        </%def>

        <%def name="b()">
        im b
        and heres a:  ${a()}
        </%def>

        <%def name="c()">
        im c
        </%def>
""")
        # check that "a" is declared in "b", but not in "c"
        if compat.py3k:
            assert "a" not in template.module.render_c.__code__.co_varnames
            assert "a" in template.module.render_b.__code__.co_varnames
        else:
            assert "a" not in template.module.render_c.func_code.co_varnames
            assert "a" in template.module.render_b.func_code.co_varnames

        # then test output
        eq_(
            flatten_result(template.render()),
            "im b and heres a: im a"
        )
开发者ID:whiteclover,项目名称:Choco,代码行数:31,代码来源:test_def.py


示例10: test_outer_scope

    def test_outer_scope(self):
        t = Template("""
        <%def name="a()">
            a: x is ${x}
        </%def>

        <%def name="b()">
            <%def name="c()">
            <%
                x = 10
            %>
            c. x is ${x}.  ${a()}
            </%def>

            b. ${c()}
        </%def>

        ${b()}

        x is ${x}
""")
        eq_(
            flatten_result(t.render(x=5)),
            "b. c. x is 10. a: x is 5 x is 5"
        )
开发者ID:whiteclover,项目名称:Choco,代码行数:25,代码来源:test_def.py


示例11: test_crlf

 def test_crlf(self):
     template = util.read_file(self._file_path("crlf.html"))
     nodes = Lexer(template).parse()
     self._compare(
         nodes,
         TemplateNode({}, [
             Text('<html>\r\n\r\n', (1, 1)),
             PageTag('page', {
                         'args': "a=['foo',\n                'bar']"
                     }, (3, 1), []),
             Text('\r\n\r\nlike the name says.\r\n\r\n', (4, 26)),
             ControlLine('for', 'for x in [1,2,3]:', False, (8, 1)),
             Text('        ', (9, 1)),
             Expression('x', [], (9, 9)),
             ControlLine('for', 'endfor', True, (10, 1)),
             Text('\r\n', (11, 1)),
             Expression("trumpeter == 'Miles' and "
                             "trumpeter or \\\n      'Dizzy'",
                             [], (12, 1)),
             Text('\r\n\r\n', (13, 15)),
             DefTag('def', {'name': 'hi()'}, (15, 1), [
                 Text('\r\n    hi!\r\n', (15, 19))]),
                 Text('\r\n\r\n</html>\r\n', (17, 8))
             ])
     )
     assert flatten_result(Template(template).render()) \
         == """<html> like the name says. 1 2 3 Dizzy </html>"""
开发者ID:whiteclover,项目名称:Choco,代码行数:27,代码来源:test_lexer.py


示例12: test_unbuffered_def

    def test_unbuffered_def(self):
        t = Template("""
            <%def name="foo()" buffered="False">
                this is foo
            </%def>
            ${"hi->" + foo() + "<-hi"}
""")
        assert flatten_result(t.render()) == "this is foo hi-><-hi"
开发者ID:JasonZengJ,项目名称:puzzle,代码行数:8,代码来源:test_filters.py


示例13: test_overrides_builtins

    def test_overrides_builtins(self):
        template = Template("""
            <%page args="id"/>

            this is page, id is ${id}
        """)

        assert flatten_result(template.render(id="im the id")) == "this is page, id is im the id"
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:8,代码来源:test_template.py


示例14: test_capture

    def test_capture(self):
        t = Template("""
            <%def name="foo()" buffered="False">
                this is foo
            </%def>
            ${"hi->" + capture(foo) + "<-hi"}
""")
        assert flatten_result(t.render()) == "hi-> this is foo <-hi"
开发者ID:JasonZengJ,项目名称:puzzle,代码行数:8,代码来源:test_filters.py


示例15: test_with_context

    def test_with_context(self):
        template = Template("""
            <%page args="x, y, z=7"/>

            this is page, ${x}, ${y}, ${z}, ${w}
""")
        #print template.code
        assert flatten_result(template.render(x=5, y=10, w=17)) == "this is page, 5, 10, 7, 17"
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:8,代码来源:test_template.py


示例16: test_expr

    def test_expr(self):
        """test filters that are themselves expressions"""
        t = Template("""
        ${x | myfilter(y)}
""")
        def myfilter(y):
            return lambda x: "MYFILTER->%s<-%s" % (x, y)
        assert flatten_result(t.render(x="this is x", myfilter=myfilter, y="this is y")) == "MYFILTER->this is x<-this is y"
开发者ID:JasonZengJ,项目名称:puzzle,代码行数:8,代码来源:test_filters.py


示例17: test_url_escaping

    def test_url_escaping(self):
        t = Template("""
            http://example.com/?bar=${bar | u}&v=1
        """)

        eq_(
            flatten_result(t.render(bar=u"酒吧bar")),
            "http://example.com/?bar=%E9%85%92%E5%90%A7bar&v=1"
        )
开发者ID:whiteclover,项目名称:Choco,代码行数:9,代码来源:test_filters.py


示例18: test_quoting

    def test_quoting(self):
        t = Template("""
            foo ${bar | h}
        """)

        eq_(
            flatten_result(t.render(bar="<'some bar'>")),
            "foo &lt;&#39;some bar&#39;&gt;"
        )
开发者ID:JasonZengJ,项目名称:puzzle,代码行数:9,代码来源:test_filters.py


示例19: test_multiline_control

    def test_multiline_control(self):
        t = Template("""
    % for x in \\
        [y for y in [1,2,3]]:
        ${x}
    % endfor
""")
        #print t.code
        assert flatten_result(t.render()) == "1 2 3"
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:9,代码来源:test_template.py


示例20: test_builtin_names_dont_clobber_defaults_in_includes

    def test_builtin_names_dont_clobber_defaults_in_includes(self):
        lookup = TemplateLookup()
        lookup.put_string("test.mako",
        """
        <%include file="test1.mako"/>

        """)

        lookup.put_string("test1.mako", """
        <%page args="id='foo'"/>

        ${id}
        """)

        for template in ("test.mako", "test1.mako"):
            assert flatten_result(lookup.get_template(template).render()) == "foo"
            assert flatten_result(lookup.get_template(template).render(id=5)) == "5"
            assert flatten_result(lookup.get_template(template).render(id=id)) == "<built-in function id>"
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:18,代码来源:test_template.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.read_file函数代码示例发布时间:2022-05-27
下一篇:
Python util.build_spider函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap