From: Armin Ronacher Date: Fri, 11 Apr 2008 15:55:05 +0000 (+0200) Subject: fixed a bug in the compiler X-Git-Tag: 2.0rc1~184 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=449167d991baeac11f6985166c8b21b83737ac87;p=jinja2.git fixed a bug in the compiler --HG-- branch : trunk --- 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

')