Skip to content
Myr

fixed a bug in the compiler

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 d4c64f7 · Browse files · 5 files+50 added−16 removed
This commit

State

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

Diff stats

5 files+50 added−16 removed

  • other:+50 added−16 removed

5 files+50 added−16 removed

modified:jinja2/compiler.py+1 added
163 unmodified lines
164 if not self.identifiers.is_declared(node.name, self.hard_scope):165 self.identifiers.undeclared.add(node.name)166167 def visit_Filter(self, node):168 self.generic_visit(node)169 if node.name not in self.identifiers.filters:170 self.identifiers.filters.add(node.name)171172 def visit_Macro(self, node):
553 unmodified lines
modified:jinja2/environment.py+1 added-2 removed
143 unmodified lines
144 def render(self, *args, **kwargs):145 return u''.join(self.stream(*args, **kwargs))146147 def stream(self, *args, **kwargs):148 context = dict(*args, **kwargs)149 return self.root_render_func(context)148 return self.root_render_func(dict(*args, **kwargs))
modified:jinja2/utils.py+3 added-5 removed
12 unmodified lines
13def escape(obj, attribute=False):14 """HTML escape an object."""15 if hasattr(obj, '__html__'):16 return obj.__html__()17 s = unicode(obj) \17 return unicode(obj) \18 .replace('&', '&amp;') \19 .replace('>', '&gt;') \20 .replace('<', '&lt;')21 if attribute:22 s = s.replace('"', '&quot;')23 return s20 .replace('<', '&lt;') \21 .replace('"', '&quot;')
added:bench.py+19 added
1from jinja import Environment as E12from jinja2 import Environment as E23from mako.template import Template as M45t1, t2 = [e.from_string("""6<ul>7{%- for item in seq %}8 <li>{{ item|e }}</li>9{%- endfor %}10</ul>11""") for e in E1(), E2()]1213m = M("""14<ul>15% for item in seq:16 <li>${item|h}</li>17% endfor18</ul>19""")
modified:test.py+26 added-9 removed
1from jinja import Environment as E12from jinja2 import Environment as E21from jinja2 import Environment24t1, t2 = [e.from_string("""5<ul>6{%- for item in seq %}7 <li>{{ item|e }}</li>8{%- endfor %}9</ul>10""") for e in E1(), E2()]3env = Environment()4tmpl = env.from_string("""<!doctype html>5<html>6 <head>7 <title>{{ page_title|e }}</title>8 </head>9 <body>10 <ul class="navigation">11 {%- for href, caption in [12 ('index.html', 'Index'),13 ('projects.html', 'Projects'),14 ('about.html', 'About')15 ] %}16 <li><a href="{{ href|e }}">{{ caption|e }}</a></li>17 {%- endfor %}18 </ul>19 <div class="body">20 {{ body }}21 </div>22 </body>23</html>\24""")252627print tmpl.render(page_title='<foo>', body='<p>Hello World</p>')