Skip to content
Myr

improved thread safety of the LRUCache and fixed a bug in for loops

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 8a1d27f · Browse files · 4 files+42 added−26 removed
This commit

State

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

Diff stats

4 files+42 added−26 removed

  • other:+42 added−26 removed

4 files+42 added−26 removed

modified:docs/switching.rst+4 added
77 unmodified lines
78instead. Includes no longer import macros and variable assignments, for79that the new `import` tag is used. This concept is explained in the80:ref:`import` documentation.8182Another small change happened in the `for`-tag. The special loop variable83doesn't have a `parent` attribute, instead you have to alias the loop84yourself. See :ref:`accessing-the-parent-loop` for more details.858687Django88------8990If you have previously worked with Django templates, you should find
124 unmodified lines
modified:docs/tricks.rst+19 added
77 unmodified lines
78 %}><a href="{{ href|e }}">{{ caption|e }}</a>/li>79 {% endfor %}80 </ul>81 ...8283.. _accessing-the-parent-loop:8485Accessing the parent Loop86-------------------------8788The special `loop` variable always points to the innermost loop. If it's89desired to have access to an outer loop it's possible to alias it::9091 <table>92 {% for row in table %}93 <tr>94 {% set rowloop = loop %}95 {% for cell in row %}96 <td id="cell-{{ rowloop.index }}-{{ loop.index }}>{{ cell }}</td>97 {% endfor %}98 </tr>99 {% endfor %}100 </table>
modified:jinja2/compiler.py+17 added-24 removed
350 unmodified lines
351352 # the current indentation353 self._indentation = 0354355 def fail(self, msg, lineno):356 """Fail with a `TemplateAssertionError`."""357 raise TemplateAssertionError(msg, lineno, self.name, self.filename)358359 def temporary_identifier(self):360 """Get a new unique identifier."""361 self._last_identifier += 1362 return 't_%d' % self._last_identifier363364 def buffer(self, frame):365 """Enable buffering for the frame from that point onwards."""362 frame.buffer = buf = self.temporary_identifier()363 self.writeline('%s = []' % buf)364 return buf366 frame.buffer = self.temporary_identifier()367 self.writeline('%s = []' % frame.buffer)368369 def return_buffer_contents(self, frame):370 """Return the buffer contents of the frame."""371 if self.environment.autoescape:
173 unmodified lines
545 (func_frame.identifiers.declared_locally |546 func_frame.identifiers.declared_parameter)547 )548 if overriden_closure_vars:546 vars = ', '.join(sorted(overriden_closure_vars))547 raise TemplateAssertionError('It\'s not possible to set and '548 'access variables derived from '549 'an outer scope! (affects: %s' %550 vars, node.lineno, self.name,551 self.filename)549 self.fail('It\'s not possible to set and access variables '550 'derived from an outer scope! (affects: %s' %551 ', '.join(sorted(overriden_closure_vars)), node.lineno)552553 # remove variables from a closure from the frame's undeclared554 # identifiers.555 func_frame.identifiers.undeclared -= (
40 unmodified lines
596597 # find all blocks598 for block in node.find_all(nodes.Block):599 if block.name in self.blocks:600 raise TemplateAssertionError('block %r defined twice' %601 block.name, block.lineno,602 self.name, self.filename)600 self.fail('block %r defined twice' % block.name, block.lineno)601 self.blocks[block.name] = block602603 # find all imports and import them604 for import_ in node.find_all(nodes.ImportedName):
92 unmodified lines
697698 def visit_Extends(self, node, frame):699 """Calls the extender."""700 if not frame.toplevel:703 raise TemplateAssertionError('cannot use extend from a non '704 'top-level scope', node.lineno,705 self.name, self.filename)701 self.fail('cannot use extend from a non top-level scope',702 node.lineno)703704 # if the number of extends statements in general is zero so705 # far, we don't have to add a check if something extended706 # the template before this one.
120 unmodified lines
827828 def visit_For(self, node, frame):829 # when calculating the nodes for the inner frame we have to exclude830 # the iterator contents from it834 children = node.iter_child_nodes(exclude=('iter',))831 children = list(node.iter_child_nodes(exclude=('iter',)))832833 if node.recursive:834 loop_frame = self.function_scoping(node, frame, children,835 find_special=False)836 else:837 loop_frame = frame.inner()838 loop_frame.inspect(children)839843 extended_loop = node.recursive or node.else_ or \844 'loop' in loop_frame.identifiers.undeclared840 undeclared = find_undeclared(children, ('loop',))841 extended_loop = node.recursive or node.else_ or 'loop' in undeclared842 if extended_loop:843 loop_frame.identifiers.add_special('loop')844845 # if we don't have an recursive loop we have to find the shadowed
444 unmodified lines
1290 def visit_Filter(self, node, frame, initial=None):1291 self.write(self.filters[node.name] + '(')1292 func = self.environment.filters.get(node.name)1293 if func is None:1297 raise TemplateAssertionError('no filter named %r' % node.name,1298 node.lineno, self.name,1299 self.filename)1294 self.fail('no filter named %r' % node.name, node.lineno)1295 if getattr(func, 'contextfilter', False):1296 self.write('context, ')1297 elif getattr(func, 'environmentfilter', False):1298 self.write('environment, ')
8 unmodified lines
13071308 def visit_Test(self, node, frame):1309 self.write(self.tests[node.name] + '(')1310 if node.name not in self.environment.tests:1316 raise TemplateAssertionError('no test named %r' % node.name,1317 node.lineno, self.name,1318 self.filename)1311 self.fail('no test named %r' % node.name, node.lineno)1312 self.visit(node.node, frame)1313 self.signature(node, frame)1314 self.write(')')1315
54 unmodified lines
modified:jinja2/utils.py+2 added-2 removed
467 unmodified lines
468 def __iter__(self):469 """Iterate over all values in the cache dict, ordered by470 the most recent usage.471 """472 return reversed(self._queue)472 return reversed(tuple(self._queue))473474 def __reversed__(self):475 """Iterate over the values in the cache dict, oldest items476 coming first.477 """478 return iter(self._queue)478 return iter(tuple(self._queue))479480 __copy__ = copy481482
41 unmodified lines