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: <test></strong>' assert t.render(ae=False) == '<strong>Wert: <test></strong>'
i18n_env = Environment( loader=DictLoader(i18n_templates), extensions=['ambari_jinja2.ext.i18n'] ) i18n_env.globals.update({ '_': gettext, 'gettext': gettext, 'ngettext': ngettext }) newstyle_i18n_env = Environment( loader=DictLoader(newstyle_i18n_templates), extensions=['ambari_jinja2.ext.i18n'] ) newstyle_i18n_env.install_gettext_callables(gettext, ngettext, newstyle=True) class TestExtension(Extension): tags = set(['test']) ext_attr = 42 def parse(self, parser): return nodes.Output([self.call_method('_dump', [ nodes.EnvironmentAttribute('sandboxed'), self.attr('ext_attr'), nodes.ImportedName(__name__ + '.importable_object'), nodes.ContextReference() ])]).set_lineno(next(parser.stream).lineno) def _dump(self, sandboxed, ext_attr, imported_object, context): return '%s|%s|%s|%s' % (