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

Python util.result_lines函数代码示例

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

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



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

示例1: test_strict

    def test_strict(self):
        t = Template("""
            % if x is UNDEFINED:
                undefined
            % else:
                x: ${x}
            % endif
        """, strict_undefined=True)
 
        assert result_lines(t.render(x=12)) == ['x: 12']
 
        assert_raises(
            NameError,
            t.render, y=12
        )
 
        l = TemplateLookup(strict_undefined=True)
        l.put_string("a", "some template")
        l.put_string("b", """
            <%namespace name='a' file='a' import='*'/>
            % if x is UNDEFINED:
                undefined
            % else:
                x: ${x}
            % endif
        """)

        assert result_lines(t.render(x=12)) == ['x: 12']
 
        assert_raises(
            NameError,
            t.render, y=12
        )
开发者ID:jamesduan,项目名称:devops,代码行数:33,代码来源:test_template.py


示例2: test_interpret_expression_from_arg_two

    def test_interpret_expression_from_arg_two(self):
        """test that cache_key=${foo} gets its value from
        the 'foo' argument regardless of it being passed
        from the context.

        This is here testing that there's no change
        to existing behavior before and after #191.

        """
        t = Template("""
        <%def name="layout(foo)" cached="True" cache_key="${foo}">
        foo: ${value}
        </%def>

        ${layout(3)}
        """, cache_impl="plain")

        eq_(
            result_lines(t.render(foo='foo', value=1)),
            ["foo: 1"]
        )
        eq_(
            result_lines(t.render(foo='bar', value=2)),
            ["foo: 1"]
        )
开发者ID:2013Commons,项目名称:HUE-SHARK,代码行数:25,代码来源:test_def.py


示例3: test_utf8_format_exceptions_pygments

    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 util.py3k:
            l.put_string("foo.html", """# -*- coding: utf-8 -*-\n${'привет' + foobar}""")
        else:
            l.put_string("foo.html", """# -*- coding: utf-8 -*-\n${u'привет' + foobar}""")

        if util.py3k:
            assert '<table class="error syntax-highlightedtable"><tr><td '\
                    'class="linenos"><div class="linenodiv"><pre>2</pre>'\
                    '</div></td><td class="code"><div class="error '\
                    'syntax-highlighted"><pre><span class="cp">${</span>'\
                    '<span class="s">&#39;привет&#39;</span> <span class="o">+</span> '\
                    '<span class="n">foobar</span><span class="cp">}</span>'\
                    '<span class="x"></span>' in \
                result_lines(l.get_template("foo.html").render().decode('utf-8'))
        else:
            assert '<table class="error syntax-highlightedtable"><tr><td '\
                    'class="linenos"><div class="linenodiv"><pre>2</pre>'\
                    '</div></td><td class="code"><div class="error '\
                    'syntax-highlighted"><pre><span class="cp">${</span>'\
                    '<span class="s">u&#39;&#x43F;&#x440;&#x438;&#x432;'\
                    '&#x435;&#x442;&#39;</span> <span class="o">+</span> '\
                    '<span class="n">foobar</span><span class="cp">}</span>'\
                    '<span class="x"></span>' in \
                result_lines(l.get_template("foo.html").render().decode('utf-8'))
开发者ID:2013Commons,项目名称:HUE-SHARK,代码行数:29,代码来源:test_exceptions.py


示例4: test_module_roundtrip

    def test_module_roundtrip(self):
        lookup = TemplateLookup()

        template = Template("""
        <%inherit file="base.html"/>
        
        % for x in range(5):
            ${x}
        % endfor
""", lookup=lookup)

        base = Template("""
        This is base.
        ${self.body()}
""", lookup=lookup)

        lookup.put_template("base.html", base)
        lookup.put_template("template.html", template)
        
        assert result_lines(template.render()) == [
            "This is base.", "0", "1", "2", "3", "4"
        ]
        
        lookup = TemplateLookup()
        template = ModuleTemplate(template.module, lookup=lookup)
        base = ModuleTemplate(base.module, lookup=lookup)

        lookup.put_template("base.html", base)
        lookup.put_template("template.html", template)
        
        assert result_lines(template.render()) == [
            "This is base.", "0", "1", "2", "3", "4"
        ]
开发者ID:SjB,项目名称:mako,代码行数:33,代码来源:test_template.py


示例5: test_pageargs

    def test_pageargs(self):
        collection = lookup.TemplateLookup()
        collection.put_string("base", """
            this is the base.

            <%
            sorted_ = pageargs.items()
            sorted_ = sorted(sorted_)
            %>
            pageargs: (type: ${type(pageargs)}) ${sorted_}
            <%def name="foo()">
                ${next.body(**context.kwargs)}
            </%def>
 
            ${foo()}
        """)
        collection.put_string("index", """
            <%inherit file="base"/>
            <%page args="x, y, z=7"/>
            print ${x}, ${y}, ${z}
        """)
 
        if util.py3k:
            assert result_lines(collection.get_template('index').render_unicode(x=5,y=10)) == [
                "this is the base.",
                "pageargs: (type: <class 'dict'>) [('x', 5), ('y', 10)]",
                "print 5, 10, 7"
            ]
        else:
            assert result_lines(collection.get_template('index').render_unicode(x=5,y=10)) == [
                "this is the base.",
                "pageargs: (type: <type 'dict'>) [('x', 5), ('y', 10)]",
                "print 5, 10, 7"
            ]
开发者ID:2013Commons,项目名称:HUE-SHARK,代码行数:34,代码来源:test_inheritance.py


示例6: test_dynamic_key_with_context

    def test_dynamic_key_with_context(self):
        t = Template("""
            <%block name="foo" cached="True" cache_key="${mykey}">
                some block
            </%block>
        """)
        m = self._install_mock_cache(t)
        t.render(mykey="thekey")
        t.render(mykey="thekey")
        eq_(
            result_lines(t.render(mykey="thekey")),
            ["some block"]
        )
        eq_(m.key, "thekey")

        t = Template("""
            <%def name="foo()" cached="True" cache_key="${mykey}">
                some def
            </%def>
            ${foo()}
        """)
        m = self._install_mock_cache(t)
        t.render(mykey="thekey")
        t.render(mykey="thekey")
        eq_(
            result_lines(t.render(mykey="thekey")),
            ["some def"]
        )
        eq_(m.key, "thekey")
开发者ID:2013Commons,项目名称:HUE-SHARK,代码行数:29,代码来源:test_cache.py


示例7: test_lookup

 def test_lookup(self):
     l = TemplateLookup(cache_impl='mock')
     l.put_string("x", """
         <%page cached="True" />
         ${y}
     """)
     t = l.get_template("x")
     assert result_lines(t.render(y=5)) == ["5"]
     assert result_lines(t.render(y=7)) == ["5"]
     assert isinstance(t.cache.impl, MockCacheImpl)
开发者ID:2013Commons,项目名称:HUE-SHARK,代码行数:10,代码来源:test_cache.py


示例8: test_undefined

    def test_undefined(self):
        t = Template("""
            % if x is UNDEFINED:
                undefined
            % else:
                x: ${x}
            % endif
        """)
 
        assert result_lines(t.render(x=12)) == ["x: 12"]
        assert result_lines(t.render(y=12)) == ["undefined"]
开发者ID:jamesduan,项目名称:devops,代码行数:11,代码来源:test_template.py


示例9: test_invalidate

    def test_invalidate(self):
        t = Template("""
            <%%def name="foo()" cached="True">
                foo: ${x}
            </%%def>

            <%%def name="bar()" cached="True" cache_type='dbm' cache_dir='%s'>
                bar: ${x}
            </%%def>
            ${foo()} ${bar()}
        """ % module_base)
        assert result_lines(t.render(x=1)) == ["foo: 1", "bar: 1"]
        assert result_lines(t.render(x=2)) == ["foo: 1", "bar: 1"]
        t.cache.invalidate_def('foo')
        assert result_lines(t.render(x=3)) == ["foo: 3", "bar: 1"]
        t.cache.invalidate_def('bar')
        assert result_lines(t.render(x=4)) == ["foo: 3", "bar: 4"]
 
        t = Template("""
            <%%page cached="True" cache_type="dbm" cache_dir="%s"/>
 
            page: ${x}
        """ % module_base)
        assert result_lines(t.render(x=1)) == ["page: 1"]
        assert result_lines(t.render(x=2)) == ["page: 1"]
        t.cache.invalidate_body()
        assert result_lines(t.render(x=3)) == ["page: 3"]
        assert result_lines(t.render(x=4)) == ["page: 3"]
开发者ID:AgentJay,项目名称:webapp-improved,代码行数:28,代码来源:test_cache.py


示例10: test_in_remote_def

    def test_in_remote_def(self):
        collection = lookup.TemplateLookup()
        collection.put_string("main.html", """
            <%namespace name="foo" file="ns.html"/>

            this is main.  ${bar()}
            <%def name="bar()">
                this is bar, foo is ${foo.bar()}
            </%def>
        """)

        collection.put_string("ns.html", """
            <%def name="bar()">
                this is ns.html->bar
            </%def>
        """)
        
        collection.put_string("index.html", """
            <%namespace name="main" file="main.html"/>
            
            this is index
            ${main.bar()}
        """)

        assert result_lines(collection.get_template("index.html").render()) == [  
            "this is index",
            "this is bar, foo is" ,
            "this is ns.html->bar"
        ]
开发者ID:ConduitTeam,项目名称:hue,代码行数:29,代码来源:test_namespace.py


示例11: test_compound_call

    def test_compound_call(self):
        t = Template("""

        <%def name="bar()">
            this is bar
        </%def>
 
        <%def name="comp1()">
            this comp1 should not be called
        </%def>
 
        <%def name="foo()">
            foo calling comp1: ${caller.comp1(x=5)}
            foo calling body: ${caller.body()}
        </%def>
 
        <%call expr="foo()">
            <%def name="comp1(x)">
                this is comp1, ${x}
            </%def>
            this is the body, ${comp1(6)}
        </%call>
        ${bar()}

""")
        assert result_lines(t.render()) == ['foo calling comp1:', 'this is comp1, 5', 'foo calling body:', 'this is the body,', 'this is comp1, 6', 'this is bar']
开发者ID:jamesduan,项目名称:devops,代码行数:26,代码来源:test_call.py


示例12: test_chained_call_in_nested

    def test_chained_call_in_nested(self):
        t = Template("""
            <%def name="embedded()">
            <%def name="a()">
                this is a. 
                <%call expr="b()">
                    this is a's ccall.  heres my body: ${caller.body()}
                </%call>
            </%def>
            <%def name="b()">
                this is b.  heres  my body: ${caller.body()}
                whats in the body's caller's body ? ${context.caller_stack[-2].body()}
            </%def>

            <%call expr="a()">
                heres the main templ call
            </%call>
            </%def>
            ${embedded()}
""")
        #print t.code
        #print result_lines(t.render())
        assert result_lines(t.render()) == [
            'this is a.',
            'this is b. heres my body:',
            "this is a's ccall. heres my body:",
            'heres the main templ call',
            "whats in the body's caller's body ?",
            'heres the main templ call'
        ]
开发者ID:jamesduan,项目名称:devops,代码行数:30,代码来源:test_call.py


示例13: test_custom_tag_2

 def test_custom_tag_2(self):
     collection = lookup.TemplateLookup()
     collection.put_string("base.html", """
         <%def name="foo(x, y)">
             foo: ${x} ${y}
         </%def>
         
         <%def name="bat(g)"><%
             return "the bat! %s" % g
         %></%def>
         
         <%def name="bar(x)">
             ${caller.body(z=x)}
         </%def>
     """)
     
     collection.put_string("index.html", """
         <%namespace name="myns" file="base.html"/>
         
         <%myns:foo x="${'some x'}" y="some y"/>
         
         <%myns:bar x="${myns.bat(10)}" args="z">
             record: ${z}
         </%myns:bar>
     
     """)
     
     assert result_lines(collection.get_template("index.html").render()) == [
         'foo: some x some y', 
         'record: the bat! 10'
     ]
开发者ID:ConduitTeam,项目名称:hue,代码行数:31,代码来源:test_namespace.py


示例14: test_closure_import

 def test_closure_import(self):
     collection = lookup.TemplateLookup()
     collection.put_string("functions.html","""
         <%def name="foo()">
             this is foo
         </%def>
         
         <%def name="bar()">
             this is bar
         </%def>
     """)
     
     collection.put_string("index.html", """
         <%namespace file="functions.html" import="*"/>
         <%def name="cl1()">
             ${foo()}
         </%def>
         
         <%def name="cl2()">
             ${bar()}
         </%def>
         
         ${cl1()}
         ${cl2()}
     """)
     assert result_lines(collection.get_template("index.html").render(bar="this is bar", x="this is x")) == [
         "this is foo",
         "this is bar",
     ]
开发者ID:ConduitTeam,项目名称:hue,代码行数:29,代码来源:test_namespace.py


示例15: test_ccall_caller

    def test_ccall_caller(self):
        t = Template("""
        <%def name="outer_func()">
        OUTER BEGIN
            <%call expr="caller.inner_func()">
                INNER CALL
            </%call>
        OUTER END
        </%def>

        <%call expr="outer_func()">
            <%def name="inner_func()">
                INNER BEGIN
                ${caller.body()}
                INNER END
            </%def>
        </%call>

        """)
        #print t.code
        assert result_lines(t.render()) == [
            "OUTER BEGIN",
            "INNER BEGIN",
            "INNER CALL",
            "INNER END",
            "OUTER END",
        ]
开发者ID:jamesduan,项目名称:devops,代码行数:27,代码来源:test_call.py


示例16: test_basic

    def test_basic(self):
        t = Template("""
        <%!
            cached = None
        %>
        <%def name="foo()">
            <% 
                global cached
                if cached:
                    return "cached: " + cached
                __M_writer = context._push_writer()
            %>
            this is foo
            <%
                buf, __M_writer = context._pop_buffer_and_writer()
                cached = buf.getvalue()
                return cached
            %>
        </%def>
 
        ${foo()}
        ${foo()}
""")
        assert result_lines(t.render()) == [
            "this is foo",
            "cached:",
            "this is foo"
        ]
开发者ID:jamesduan,项目名称:devops,代码行数:28,代码来源:test_call.py


示例17: test_new_syntax

    def test_new_syntax(self):
        """test foo:bar syntax, including multiline args and expression eval."""
 
        # note the trailing whitespace in the bottom ${} expr, need to strip
        # that off < python 2.7
 
        t = Template("""
            <%def name="foo(x, y, q, z)">
                ${x}
                ${y}
                ${q}
                ${",".join("%s->%s" % (a, b) for a, b in z)}
            </%def>
 
            <%self:foo x="this is x" y="${'some ' + 'y'}" q="
                this
                is
                q"
 
                z="${[
                (1, 2),
                (3, 4),
                (5, 6)
            ]
 
            }"/>
        """)
 
        eq_(
            result_lines(t.render()),
             ['this is x', 'some y', 'this', 'is', 'q', '1->2,3->4,5->6']
        )
开发者ID:jamesduan,项目名称:devops,代码行数:32,代码来源:test_call.py


示例18: test_call_in_nested_2

    def test_call_in_nested_2(self):
        t = Template("""
            <%def name="a()">
                <%def name="d()">
                    not this d
                </%def>
                this is a ${b()}
                <%def name="b()">
                    <%def name="d()">
                        not this d either
                    </%def>
                    this is b
                    <%call expr="c()">
                        <%def name="d()">
                            this is d
                        </%def>
                        this is the body in b's call
                    </%call>
                </%def>
                <%def name="c()">
                    this is c: ${caller.body()}
                    the embedded "d" is: ${caller.d()}
                </%def>
            </%def>
        ${a()}
""")
        assert result_lines(t.render()) == ['this is a', 'this is b', 'this is c:', "this is the body in b's call", 'the embedded "d" is:', 'this is d']
开发者ID:jamesduan,项目名称:devops,代码行数:27,代码来源:test_call.py


示例19: test_inheritance

    def test_inheritance(self):
        """test namespace initialization in a base inherited template that doesnt otherwise access the namespace"""
        collection = lookup.TemplateLookup()
        collection.put_string("base.html", """
            <%namespace name="foo" file="ns.html" inheritable="True"/>
            
            ${next.body()}
""")
        collection.put_string("ns.html", """
            <%def name="bar()">
                this is ns.html->bar
            </%def>
        """)

        collection.put_string("index.html", """
            <%inherit file="base.html"/>
    
            this is index
            ${self.foo.bar()}
        """)
        
        assert result_lines(collection.get_template("index.html").render()) == [
            "this is index",
            "this is ns.html->bar"
        ]
开发者ID:ConduitTeam,项目名称:hue,代码行数:25,代码来源:test_namespace.py


示例20: test_includes

    def test_includes(self):
        """test that an included template also has its full hierarchy invoked."""
        collection = lookup.TemplateLookup()
        
        collection.put_string("base", """
        <%def name="a()">base_a</%def>
        This is the base.
        ${next.body()}
        End base.
""")

        collection.put_string("index","""
        <%inherit file="base"/>
        this is index.
        a is: ${self.a()}
        <%include file="secondary"/>
""")

        collection.put_string("secondary","""
        <%inherit file="base"/>
        this is secondary.
        a is: ${self.a()}
""")

        assert result_lines(collection.get_template("index").render()) == [
            'This is the base.', 
            'this is index.',
             'a is: base_a',
             'This is the base.',
             'this is secondary.',
             'a is: base_a',
             'End base.',
             'End base.'
            ]
开发者ID:SjB,项目名称:mako,代码行数:34,代码来源:test_inheritance.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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