def test_autoescape_support(self): env = Environment( extensions=["jinja.ext.autoescape", "jinja.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.globals.update({ "_": gettext, "gettext": gettext, "ngettext": ngettext }) i18n_env_trimmed = Environment(extensions=["jinja.ext.i18n"]) i18n_env_trimmed.policies["ext.i18n.trimmed"] = True i18n_env_trimmed.globals.update({ "_": gettext, "gettext": gettext, "ngettext": ngettext }) newstyle_i18n_env = Environment(loader=DictLoader(newstyle_i18n_templates), extensions=["jinja.ext.i18n"]) newstyle_i18n_env.install_gettext_callables(gettext, ngettext, newstyle=True) class ExampleExtension(Extension): tags = set(["test"]) ext_attr = 42 context_reference_node_cls = nodes.ContextReference def parse(self, parser): return nodes.Output([ self.call_method( "_dump", [ nodes.EnvironmentAttribute("sandboxed"), self.attr("ext_attr"), nodes.ImportedName(__name__ + ".importable_object"),