From 449167d991baeac11f6985166c8b21b83737ac87 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Fri, 11 Apr 2008 17:55:05 +0200 Subject: [PATCH] fixed a bug in the compiler --HG-- branch : trunk --- bench.py | 19 +++++++++++++++++++ jinja2/compiler.py | 1 + jinja2/environment.py | 3 +-- jinja2/utils.py | 8 +++----- test.py | 35 ++++++++++++++++++++++++++--------- 5 files changed, 50 insertions(+), 16 deletions(-) create mode 100644 bench.py diff --git a/bench.py b/bench.py new file mode 100644 index 0000000..1ead1ec --- /dev/null +++ b/bench.py @@ -0,0 +1,19 @@ +from jinja import Environment as E1 +from jinja2 import Environment as E2 +from mako.template import Template as M + +t1, t2 = [e.from_string(""" + +""") for e in E1(), E2()] + +m = M(""" + +""") diff --git a/jinja2/compiler.py b/jinja2/compiler.py index c9aa0ca..3d4c655 100644 --- a/jinja2/compiler.py +++ b/jinja2/compiler.py @@ -165,6 +165,7 @@ class FrameIdentifierVisitor(NodeVisitor): self.identifiers.undeclared.add(node.name) def visit_Filter(self, node): + self.generic_visit(node) if node.name not in self.identifiers.filters: self.identifiers.filters.add(node.name) diff --git a/jinja2/environment.py b/jinja2/environment.py index 6ee6a95..417a035 100644 --- a/jinja2/environment.py +++ b/jinja2/environment.py @@ -145,5 +145,4 @@ class Template(object): return u''.join(self.stream(*args, **kwargs)) def stream(self, *args, **kwargs): - context = dict(*args, **kwargs) - return self.root_render_func(context) + return self.root_render_func(dict(*args, **kwargs)) diff --git a/jinja2/utils.py b/jinja2/utils.py index 23a3b15..4ee245d 100644 --- a/jinja2/utils.py +++ b/jinja2/utils.py @@ -14,10 +14,8 @@ def escape(obj, attribute=False): """HTML escape an object.""" if hasattr(obj, '__html__'): return obj.__html__() - s = unicode(obj) \ + return unicode(obj) \ .replace('&', '&') \ .replace('>', '>') \ - .replace('<', '<') - if attribute: - s = s.replace('"', '"') - return s + .replace('<', '<') \ + .replace('"', '"') diff --git a/test.py b/test.py index e6e7dc8..fcdf050 100644 --- a/test.py +++ b/test.py @@ -1,10 +1,27 @@ -from jinja import Environment as E1 -from jinja2 import Environment as E2 +from jinja2 import Environment -t1, t2 = [e.from_string(""" - -""") for e in E1(), E2()] +env = Environment() +tmpl = env.from_string(""" + + + {{ page_title|e }} + + + +
+ {{ body }} +
+ +\ +""") + + +print tmpl.render(page_title='', body='

Hello World

') -- 2.26.2