Skip to content
Myr

*now* we have no overhead :)

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 75cfb86 · Browse files · 1 file+30 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

1 file+30 added−16 removed

  • other:+30 added−16 removed

1 file+30 added−16 removed

modified:jinja2/compiler.py+30 added-16 removed
202 unmodified lines
203 self.blocks = {}204 self.indentation = 0205 self.new_lines = 0206 self.last_identifier = 0207 self.extends_so_far = 0208 self.has_known_extends = False209 self._last_line = 0210 self._first_write = True211
147 unmodified lines
359 raise TemplateAssertionError('cannot use extend from a non '360 'top-level scope', node.lineno,361 self.filename)362362 # if we have a known extends we just add a template runtime363 # error into the generated code. We could catch that at compile364 # time too, but i welcome it not to confuse users by throwing the365 # same error at different times just "because we can".366 if not self.has_known_extends:367 self.writeline('if parent_root is not None:')368 self.indent()369 self.writeline('raise TemplateRuntimeError(%r)' %370 'extended multiple times')363 # if the number of extends statements in general is zero so364 # far, we don't have to add a check if something extended365 # the template before this one.366 if self.extends_so_far > 0:367372 # if we have a known extends already we don't need that code here373 # as we know that the template execution will end here.374 if self.has_known_extends:375 raise CompilerExit()368 # if we have a known extends we just add a template runtime369 # error into the generated code. We could catch that at compile370 # time too, but i welcome it not to confuse users by throwing the371 # same error at different times just "because we can".372 if not self.has_known_extends:373 self.writeline('if parent_root is not None:')374 self.indent()375 self.writeline('raise TemplateRuntimeError(%r)' %376 'extended multiple times')377378 # if we have a known extends already we don't need that code here379 # as we know that the template execution will end here.380 if self.has_known_extends:381 raise CompilerExit()377 self.outdent()382 self.outdent()383384 self.writeline('parent_root = extends(', node, 1)385 self.visit(node.template, frame)386 self.write(', context)')387
1 unmodified line
389 # advantage of that information and simplify the generated code390 # in the top level from this point onwards391 self.has_known_extends = True392393 # and now we have one more394 self.extends_so_far += 1395396 def visit_For(self, node, frame):397 loop_frame = frame.inner()398 loop_frame.inspect(node.iter_child_nodes())399 extended_loop = bool(node.else_) or \
114 unmodified lines
514 finalizer = 'unicode'515 else:516 finalizer = 'context.finalize'517509 if frame.toplevel:518 # if we are in the toplevel scope and there was already an extends519 # statement we have to add a check that disables our yield(s) here520 # so that they don't appear in the output.521 outdent_later = False522 if frame.toplevel and self.extends_so_far != 0:523 self.writeline('if parent_root is None:')524 self.indent()525 outdent_later = True526527 # try to evaluate as many chunks as possible into a static528 # string at compile time.529 body = []
40 unmodified lines
570 if finalizer != 'unicode':571 self.write(')')572 self.write(idx == 0 and ',)' or ')')573560 if frame.toplevel:574 if outdent_later:575 self.outdent()576577 def visit_Assign(self, node, frame):578 self.newline(node)
158 unmodified lines