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

Python util.flatten_result函数代码示例

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

本文整理汇总了Python中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:jamesduan,项目名称:devops,代码行数:56,代码来源:test_call.py


示例2: 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:AgentJay,项目名称:webapp-improved,代码行数:10,代码来源:test_filters.py


示例3: 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"
        try:
            template.render(y=10)
            assert False
        except TypeError, e:
            assert True
开发者ID:SjB,项目名称:mako,代码行数:14,代码来源:test_template.py


示例4: test_bytestring_passthru

    def test_bytestring_passthru(self):
        lookup = TemplateLookup(directories=['./test_htdocs'], default_filters=[], disable_unicode=True)
        template = lookup.get_template('/chs_utf8.html')
        self.assertEquals(flatten_result(template.render(name='毛泽东')), '毛泽东 是 新中国的主席<br/> Welcome 你 to 北京. Welcome 你 to 北京.')

        lookup = TemplateLookup(directories=['./test_htdocs'], disable_unicode=True)
        template = lookup.get_template('/chs_utf8.html')
        self.assertEquals(flatten_result(template.render(name='毛泽东')), '毛泽东 是 新中国的主席<br/> Welcome 你 to 北京. Welcome 你 to 北京.')
        
        self.assertRaises(UnicodeDecodeError, template.render_unicode, name='毛泽东')

        template = Template("""${'Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petit voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »'}""", disable_unicode=True, input_encoding='utf-8')
        assert template.render() == """Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petit voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""
        template = Template("""${'Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petit voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »'}""", input_encoding='utf8', output_encoding='utf8', disable_unicode=False, default_filters=[])
        self.assertRaises(UnicodeDecodeError, template.render)  # raises because expression contains an encoded bytestring which cannot be decoded
开发者ID:SjB,项目名称:mako,代码行数:15,代码来源:test_template.py


示例5: 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:2013Commons,项目名称:HUE-SHARK,代码行数:25,代码来源:test_def.py


示例6: 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"
        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:2013Commons,项目名称:HUE-SHARK,代码行数:27,代码来源:test_def.py


示例7: 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:2013Commons,项目名称:HUE-SHARK,代码行数:25,代码来源:test_def.py


示例8: 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:ConduitTeam,项目名称:hue,代码行数:25,代码来源:test_namespace.py


示例9: 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()}
""")
        assert flatten_result(t.render()) == "this is b. x is 9. calling a. this is a. x is 5."
开发者ID:SjB,项目名称:mako,代码行数:25,代码来源:test_def.py


示例10: 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}
    """)
        assert flatten_result(t.render()) == "main/a: a/y: 10 a/b: b/c: c/y: 10 b/y: 19 main/y: 7"
开发者ID:SjB,项目名称:mako,代码行数:29,代码来源:test_def.py


示例11: test_scope_four

    def test_scope_four(self):
        """test that variables are pulled
        from 'enclosing' scope before context."""
        t = Template("""
            <%
                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()}
""")
        eq_(
            flatten_result(t.render()),
            "this is b. x is 9. calling a. this is a. x is 5."
        )
开发者ID:2013Commons,项目名称:HUE-SHARK,代码行数:25,代码来源:test_def.py


示例12: test_crlf

 def test_crlf(self):
     template = open(self._file_path("crlf.html"), 'rb').read()
     nodes = Lexer(template).parse()
     self._compare(
         nodes,
         TemplateNode({}, [
             Text(u'<html>\r\n\r\n', (1, 1)), 
             PageTag(u'page', {
                         u'args': u"a=['foo',\n                'bar']"
                     }, (3, 1), []), 
             Text(u'\r\n\r\nlike the name says.\r\n\r\n', (4, 26)), 
             ControlLine(u'for', u'for x in [1,2,3]:', False, (8, 1)), 
             Text(u'        ', (9, 1)), 
             Expression(u'x', [], (9, 9)), 
             ControlLine(u'for', u'endfor', True, (10, 1)), 
             Text(u'\r\n', (11, 1)), 
             Expression(u"trumpeter == 'Miles' and "
                             "trumpeter or \\\n      'Dizzy'", 
                             [], (12, 1)), 
             Text(u'\r\n\r\n', (13, 15)), 
             DefTag(u'def', {u'name': u'hi()'}, (15, 1), [
                 Text(u'\r\n    hi!\r\n', (15, 19))]), 
                 Text(u'\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:2013Commons,项目名称:HUE-SHARK,代码行数:27,代码来源:test_lexer.py


示例13: test_unicode_literal_in_def

 def test_unicode_literal_in_def(self):
     template = Template(u"""## -*- coding: utf-8 -*-
     <%def name="bello(foo, bar)">
     Foo: ${ foo }
     Bar: ${ bar }
     </%def>
     <%call expr="bello(foo=u'árvíztűrő tükörfúrógép', bar=u'ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP')">
     </%call>""".encode('utf-8'))
     assert flatten_result(template.render_unicode()) == u"""Foo: árvíztűrő tükörfúrógép Bar: ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP"""
     
     template = Template(u"""## -*- coding: utf-8 -*-
     <%def name="hello(foo=u'árvíztűrő tükörfúrógép', bar=u'ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP')">
     Foo: ${ foo }
     Bar: ${ bar }
     </%def>
     ${ hello() }""".encode('utf-8'))
     assert flatten_result(template.render_unicode()) == u"""Foo: árvíztűrő tükörfúrógép Bar: ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP"""
开发者ID:SjB,项目名称:mako,代码行数:17,代码来源: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:AgentJay,项目名称:webapp-improved,代码行数:8,代码来源:test_filters.py


示例15: 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:AgentJay,项目名称:webapp-improved,代码行数:8,代码来源:test_filters.py


示例16: 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:AgentJay,项目名称:webapp-improved,代码行数:8,代码来源:test_filters.py


示例17: 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:SjB,项目名称:mako,代码行数:8,代码来源:test_template.py


示例18: 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:SjB,项目名称:mako,代码行数:8,代码来源:test_template.py


示例19: test_toplevel

    def test_toplevel(self):
        """test calling a def from the top level"""
        template = Template("""
        
            this is the body
        
            <%def name="a()">
                this is a
            </%def>

            <%def name="b(x, y)">
                this is b, ${x} ${y}
            </%def>
                
        """, output_encoding='utf-8')
        assert flatten_result(template.get_def("a").render()) == "this is a"
        assert flatten_result(template.get_def("b").render(x=10, y=15)) == "this is b, 10 15"
        assert flatten_result(template.get_def("body").render()) == "this is the body"
开发者ID:SjB,项目名称:mako,代码行数:18,代码来源:test_def.py


示例20: 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:AgentJay,项目名称:webapp-improved,代码行数:9,代码来源:test_filters.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python util.flipCoin函数代码示例发布时间:2022-05-27
下一篇:
Python util.flatten函数代码示例发布时间: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