當前位置: 首頁>>代碼示例>>Python>>正文


Python ambari_jinja2.Environment類代碼示例

本文整理匯總了Python中ambari_jinja2.Environment的典型用法代碼示例。如果您正苦於以下問題:Python Environment類的具體用法?Python Environment怎麽用?Python Environment使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Environment類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_preserve_blocks

 def test_preserve_blocks(self):
     env = Environment(loader=DictLoader({
         'a': '{% if false %}{% block x %}A{% endblock %}{% endif %}{{ self.x() }}',
         'b': '{% extends "a" %}{% block x %}B{{ super() }}{% endblock %}'
     }))
     tmpl = env.get_template('b')
     assert tmpl.render() == 'BA'
開發者ID:OpenPOWER-BigData,項目名稱:HDP-ambari,代碼行數:7,代碼來源:inheritance.py

示例2: test_volatile

 def test_volatile(self):
     env = Environment(extensions=['ambari_jinja2.ext.autoescape'],
                       autoescape=True)
     tmpl = env.from_string('{% autoescape foo %}{{ {"foo": "<test>"}'
                            '|xmlattr|escape }}{% endautoescape %}')
     assert tmpl.render(foo=False) == ' foo=&#34;&amp;lt;test&amp;gt;&#34;'
     assert tmpl.render(foo=True) == ' foo="&lt;test&gt;"'
開發者ID:OpenPOWER-BigData,項目名稱:HDP-ambari,代碼行數:7,代碼來源:ext.py

示例3: test_correct_prefix_loader_name

 def test_correct_prefix_loader_name(self):
     env = Environment(loader=PrefixLoader({
         'foo':  DictLoader({})
     }))
     try:
         env.get_template('foo/bar.html')
     except TemplateNotFound, e:
         assert e.name == 'foo/bar.html'
開發者ID:OpenPOWER-BigData,項目名稱:HDP-ambari,代碼行數:8,代碼來源:regression.py

示例4: test_erb_syntax

    def test_erb_syntax(self):
        env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>')
        tmpl = env.from_string('''\
<%# I'm a comment, I'm not interesting %>\
<% for item in seq -%>
    <%= item %>
<%- endfor %>''')
        assert tmpl.render(seq=range(5)) == '01234'
開發者ID:OpenPOWER-BigData,項目名稱:HDP-ambari,代碼行數:8,代碼來源:lexnparse.py

示例5: test_php_syntax

    def test_php_syntax(self):
        env = Environment('<?', '?>', '<?=', '?>', '<!--', '-->')
        tmpl = env.from_string('''\
<!-- I'm a comment, I'm not interesting -->\
<? for item in seq -?>
    <?= item ?>
<?- endfor ?>''')
        assert tmpl.render(seq=range(5)) == '01234'
開發者ID:OpenPOWER-BigData,項目名稱:HDP-ambari,代碼行數:8,代碼來源:lexnparse.py

示例6: test_join

    def test_join(self):
        tmpl = env.from_string('{{ [1, 2, 3]|join("|") }}')
        out = tmpl.render()
        assert out == '1|2|3'

        env2 = Environment(autoescape=True)
        tmpl = env2.from_string('{{ ["<foo>", "<span>foo</span>"|safe]|join }}')
        assert tmpl.render() == '&lt;foo&gt;<span>foo</span>'
開發者ID:OpenPOWER-BigData,項目名稱:HDP-ambari,代碼行數:8,代碼來源:filters.py

示例7: test_super_in_scoped_block

 def test_super_in_scoped_block(self):
     env = Environment(loader=DictLoader({
         'master.html': '{% for item in seq %}[{% block item scoped %}'
                        '{{ item }}{% endblock %}]{% endfor %}'
     }))
     t = env.from_string('{% extends "master.html" %}{% block item %}'
                         '{{ super() }}|{{ item * 2 }}{% endblock %}')
     assert t.render(seq=range(5)) == '[0|0][1|2][2|4][3|6][4|8]'
開發者ID:OpenPOWER-BigData,項目名稱:HDP-ambari,代碼行數:8,代碼來源:inheritance.py

示例8: test_comment_syntax

    def test_comment_syntax(self):
        env = Environment('<!--', '-->', '${', '}', '<!--#', '-->')
        tmpl = env.from_string('''\
<!--# I'm a comment, I'm not interesting -->\
<!-- for item in seq --->
    ${item}
<!--- endfor -->''')
        assert tmpl.render(seq=range(5)) == '01234'
開發者ID:OpenPOWER-BigData,項目名稱:HDP-ambari,代碼行數:8,代碼來源:lexnparse.py

示例9: test_do

 def test_do(self):
     env = Environment(extensions=['ambari_jinja2.ext.do'])
     tmpl = env.from_string('''
         {%- set items = [] %}
         {%- for char in "foo" %}
             {%- do items.append(loop.index0 ~ char) %}
         {%- endfor %}{{ items|join(', ') }}''')
     assert tmpl.render() == '0f, 1o, 2o'
開發者ID:OpenPOWER-BigData,項目名稱:HDP-ambari,代碼行數:8,代碼來源:ext.py

示例10: test_extension_ordering

 def test_extension_ordering(self):
     class T1(Extension):
         priority = 1
     class T2(Extension):
         priority = 2
     env = Environment(extensions=[T1, T2])
     ext = list(env.iter_extensions())
     assert ext[0].__class__ is T1
     assert ext[1].__class__ is T2
開發者ID:OpenPOWER-BigData,項目名稱:HDP-ambari,代碼行數:9,代碼來源:ext.py

示例11: test_dynamic_inheritance

 def test_dynamic_inheritance(self):
     env = Environment(loader=DictLoader({
         'master1': 'MASTER1{% block x %}{% endblock %}',
         'master2': 'MASTER2{% block x %}{% endblock %}',
         'child': '{% extends master %}{% block x %}CHILD{% endblock %}'
     }))
     tmpl = env.get_template('child')
     for m in range(1, 3):
         assert tmpl.render(master='master%d' % m) == 'MASTER%dCHILD' % m
開發者ID:OpenPOWER-BigData,項目名稱:HDP-ambari,代碼行數:9,代碼來源:inheritance.py

示例12: test_autoescape_support

 def test_autoescape_support(self):
     env = Environment(extensions=['ambari_jinja2.ext.autoescape',
                                   'ambari_jinja2.ext.i18n'])
     env.install_gettext_callables(lambda x: u'<strong>Wert: %(name)s</strong>',
                                   lambda s, p, n: s, newstyle=True)
     t = env.from_string('{% autoescape ae %}{{ gettext("foo", name='
                         '"<test>") }}{% endautoescape %}')
     assert t.render(ae=True) == '<strong>Wert: &lt;test&gt;</strong>'
     assert t.render(ae=False) == '<strong>Wert: <test></strong>'
開發者ID:OpenPOWER-BigData,項目名稱:HDP-ambari,代碼行數:9,代碼來源:ext.py

示例13: test_extends_output_bugs

    def test_extends_output_bugs(self):
        env = Environment(loader=DictLoader({
            'parent.html': '(({% block title %}{% endblock %}))'
        }))

        t = env.from_string('{% if expr %}{% extends "parent.html" %}{% endif %}'
                            '[[{% block title %}title{% endblock %}]]'
                            '{% for item in [1, 2, 3] %}({{ item }}){% endfor %}')
        assert t.render(expr=False) == '[[title]](1)(2)(3)'
        assert t.render(expr=True) == '((title))'
開發者ID:OpenPOWER-BigData,項目名稱:HDP-ambari,代碼行數:10,代碼來源:regression.py

示例14: test_finalizer

 def test_finalizer(self):
     def finalize_none_empty(value):
         if value is None:
             value = u''
         return value
     env = Environment(finalize=finalize_none_empty)
     tmpl = env.from_string('{% for item in seq %}|{{ item }}{% endfor %}')
     assert tmpl.render(seq=(None, 1, "foo")) == '||1|foo'
     tmpl = env.from_string('<{{ none }}>')
     assert tmpl.render() == '<>'
開發者ID:OpenPOWER-BigData,項目名稱:HDP-ambari,代碼行數:10,代碼來源:api.py

示例15: test_comments

    def test_comments(self):
        env = Environment('<!--', '-->', '{', '}')
        tmpl = env.from_string('''\
<ul>
<!--- for item in seq -->
  <li>{item}</li>
<!--- endfor -->
</ul>''')
        assert tmpl.render(seq=range(3)) == ("<ul>\n  <li>0</li>\n  "
                                             "<li>1</li>\n  <li>2</li>\n</ul>")
開發者ID:OpenPOWER-BigData,項目名稱:HDP-ambari,代碼行數:10,代碼來源:lexnparse.py


注:本文中的ambari_jinja2.Environment類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。