本文整理匯總了Python中ambari_jinja2.Environment.compile方法的典型用法代碼示例。如果您正苦於以下問題:Python Environment.compile方法的具體用法?Python Environment.compile怎麽用?Python Environment.compile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ambari_jinja2.Environment
的用法示例。
在下文中一共展示了Environment.compile方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_volatile_scoping
# 需要導入模塊: from ambari_jinja2 import Environment [as 別名]
# 或者: from ambari_jinja2.Environment import compile [as 別名]
def test_volatile_scoping(self):
env = Environment(extensions=['ambari_jinja2.ext.autoescape'])
tmplsource = '''
{% autoescape val %}
{% macro foo(x) %}
[{{ x }}]
{% endmacro %}
{{ foo().__class__.__name__ }}
{% endautoescape %}
{{ '<testing>' }}
'''
tmpl = env.from_string(tmplsource)
assert tmpl.render(val=True).split()[0] == 'Markup'
assert tmpl.render(val=False).split()[0] == unicode.__name__
# looking at the source we should see <testing> there in raw
# (and then escaped as well)
env = Environment(extensions=['ambari_jinja2.ext.autoescape'])
pysource = env.compile(tmplsource, raw=True)
assert '<testing>\\n' in pysource
env = Environment(extensions=['ambari_jinja2.ext.autoescape'],
autoescape=True)
pysource = env.compile(tmplsource, raw=True)
assert '<testing>\\n' in pysource