Skip to content
Myr

Fixed bug in finalizer

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 80b7895 · Browse files · 3 files+21 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+21 added−1 removed

  • tests:+13 added−0 removed
  • other:+8 added−1 removed

3 files+21 added−1 removed

modified:jinja2/compiler.py+6 added-1 removed
1043 unmodified lines
1044 # if we have a known extends statement, we don't output anything1045 if self.has_known_extends and frame.toplevel:1046 return10471048 if self.environment.finalize:1049 finalize = lambda x: unicode(self.environment.finalize(x))1050 else:1051 finalize = unicode10521053 self.newline(node)10541055 # if we are in the toplevel scope and there was already an extends1056 # statement we have to add a check that disables our yield(s) here
18 unmodified lines
1075 if hasattr(const, '__html__'):1076 const = const.__html__()1077 else:1078 const = escape(const)1074 const = unicode(const)1079 const = finalize(const)1080 except:1081 # if something goes wrong here we evaluate the node1082 # at runtime for easier debugging1083 body.append(child)
330 unmodified lines
modified:tests/test_various.py+13 added
69 unmodified lines
70 tmpl = env.from_string('{{ foo|attr("items")() }}')71 assert tmpl.render(foo={'items': 42}) == "[('items', 42)]"72 tmpl = env.from_string('{{ foo["items"] }}')73 assert tmpl.render(foo={'items': 42}) == '42'747576def test_finalizer():77 from jinja2 import Environment78 def finalize_none_empty(value):79 if value is None:80 value = u''81 return value82 env = Environment(finalize=finalize_none_empty)83 tmpl = env.from_string('{% for item in seq %}|{{ item }}{% endfor %}')84 assert tmpl.render(seq=(None, 1, "foo")) == '||1|foo'85 tmpl = env.from_string('<{{ none }}>')86 assert tmpl.render() == '<>'
modified:CHANGES+2 added
28 unmodified lines
2930- `filesizeformat` filter uses decimal prefixes now per default and can be31 set to binary mode with the second parameter.3233- fixed bug in finalizer3435Version 2.0rc136--------------37(no codename, released on June 9th 2008)38
1 unmodified line