Skip to content
Myr

more thread safety in LRUCache

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 24db451 · Browse files · 7 files+83 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

7 files+83 added−16 removed

  • tests:+56 added−13 removed
  • other:+27 added−3 removed

7 files+83 added−16 removed

modified:docs/templates.rst+1 added-1 removed
1017 unmodified lines
1018~~10191020If the expression-statement extension is loaded a tag called `do` is available1021that works exactly like the regular variable expression (``{{ ... }}``) just1022that it doesn't print anything. This can be used to modify lists:1022that it doesn't print anything. This can be used to modify lists::10231024 {% do navigation.append('a string') %}
modified:jinja2/utils.py+26 added-2 removed
463 unmodified lines
464 self._remove(key)465 finally:466 self._wlock.release()467468 def __iter__(self):469 """Iterate over all values in the cache dict, ordered by468 def items(self):469 """Return a list of items."""470 result = [(key, self._mapping[key]) for key in list(self._queue)]471 result.reverse()472 return result473474 def iteritems(self):475 """Iterate over all items."""476 return iter(self.items())477478 def values(self):479 """Return a list of all values."""480 return [x[1] for x in self.items()]481482 def itervalue(self):483 """Iterate over all values."""484 return iter(self.values())485486 def keys(self):487 """Return a list of all keys ordered by most recent usage."""488 return list(self)489490 def iterkeys(self):491 """Iterate over all keys in the cache dict, ordered by492 the most recent usage.493 """494 return reversed(tuple(self._queue))495496 __iter__ = iterkeys497498 def __reversed__(self):499 """Iterate over the values in the cache dict, oldest items500 coming first.501 """
46 unmodified lines
modified:tests/test_filters.py+11 added-1 removed
11 unmodified lines
1213 :copyright: 2007 by Armin Ronacher.14 :license: BSD, see LICENSE for more details.15"""16from jinja2 import Markup1718CAPITALIZE = '''{{ "foo bar"|capitalize }}'''19CENTER = '''{{ "foo"|center(9) }}'''20DEFAULT = '''{{ missing|default("no") }}|{{ false|default('no') }}|\
48 unmodified lines
69{% endfor %}'''70FILTERTAG = '''{% filter upper|replace('FOO', 'foo') %}foobar{% endfilter %}'''71727273def test_capitalize(env):74 tmpl = env.from_string(CAPITALIZE)75 assert tmpl.render() == 'Foo bar'76
213 unmodified lines
290291def test_filtertag(env):292 tmpl = env.from_string(FILTERTAG)293 assert tmpl.render() == 'fooBAR'294295296def test_replace(env):297 tmpl = env.from_string('{{ "foo"|replace("o", 42)}}')298 assert tmpl.render() == 'f4242'299300301def test_forceescape(env):302 tmpl = env.from_string('{{ x|forceescape }}')303 assert tmpl.render(x=Markup('<div />')) == u'&lt;div /&gt;'
modified:tests/test_imports.py+15 added
44 unmodified lines
45 test_env.from_string('{% from "foo" import bar, baz, with context %}')46 test_env.from_string('{% from "foo" import bar, with context %}')47 test_env.from_string('{% from "foo" import bar, with, context %}')48 test_env.from_string('{% from "foo" import bar, with with context %}')495051def test_exports():52 m = test_env.from_string('''53 {% macro toplevel() %}...{% endmacro %}54 {% macro __private() %}...{% endmacro %}55 {% set variable = 42 %}56 {% for item in [1] %}57 {% macro notthere() %}{% endmacro %}58 {% endfor %}59 ''').module60 assert m.toplevel() == '...'61 assert not hasattr(m, '__missing')62 assert m.variable == 4263 assert not hasattr(m, 'notthere')
modified:tests/test_inheritance.py+5 added
91 unmodified lines
929394def test_working(env):95 tmpl = env.get_template('working')969798def test_reuse_blocks(env):99 tmpl = env.from_string('{{ self.foo() }}|{% block foo %}42{% endblock %}|{{ self.foo() }}')100 assert tmpl.render() == '42|42|42'
added:tests/test_lrucache.py+25 added
1# -*- coding: utf-8 -*-2"""3 Tests the LRUCache4 ~~~~~~~~~~~~~~~~~~56 This module tests the LRU Cache78 :copyright: Copyright 2008 by Armin Ronacher.9 :license: GNU GPL.10"""11import thread12import time13import random14from jinja2.utils import LRUCache151617def test_simple():18 d = LRUCache(3)19 d["a"] = 120 d["b"] = 221 d["c"] = 322 d["a"]23 d["d"] = 424 assert len(d) == 325 assert 'a' in d and 'c' in d and 'd' in d and 'b' not in d
modified:tests/test_various.py-12 removed
28 unmodified lines
29 tmpl = env.from_string(RAW)30 assert tmpl.render() == '{{ FOO }} and {% BAR %}'313233def test_lru_cache():34 from jinja2.utils import LRUCache35 d = LRUCache(3)36 d["a"] = 137 d["b"] = 238 d["c"] = 339 d["a"]40 d["d"] = 441 assert len(d) == 342 assert 'a' in d and 'c' in d and 'd' in d and 'b' not in d434433def test_const(env):34 tmpl = env.from_string(CONST)35 assert tmpl.render() == 'True|False|None|True|False'36
14 unmodified lines