Merge branch 'master' of github.com:mitsuhiko/jinja2
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parents e7e14cf, b42f535 · Browse files · 24 files·+177 added−134 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
24 files+177 added−134 removed
- tests:+53 added−15 removed
- other:+124 added−119 removed
Provenance
- Commit
67d015e- Tree
3dd5523- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent 1
e7e14cf- Parent 2
b42f535
24 files changed+177 added−134 removed
added:.github/ISSUE_TEMPLATE.rst+2 added
1+The issue tracker is a tool to address bugs.2+Please use the #pocoo IRC channel on freenode or Stack Overflow for questions.modified:docs/_templates/sidebarintro.html+1 added-1 removed
14 unmodified lines1516171819192014 unmodified lines<h3>Useful Links</h3><ul> <li><a href="http://jinja.pocoo.org/">The Jinja2 Website</a></li> <li><a href="http://pypi.python.org/pypi/Jinja2">Jinja2 @ PyPI</a></li> <li><a href="http://github.com/mitsuhiko/jinja2">Jinja2 @ github</a></li> <li><a href="http://github.com/pallets/jinja">Jinja2 @ github</a></li></ul>modified:docs/api.rst+2 added-2 removed
17 unmodified lines18 :class:`Template` class, an environment is created automatically for you,19 albeit a shared one.20 21 Most applications will create one :class:`Environment` object on application22-initialization and use that to load templates. In some cases it's however22+initialization and use that to load templates. In some cases however, it's 23 useful to have multiple environments side by side, if different configurations24 are in use.25 26 The simplest way to configure Jinja2 to load templates for your application553 unmodified lines580 Custom Filters581 --------------582 583 Custom filters are just regular Python functions that take the left side of584-the filter as first argument and the the arguments passed to the filter as584+the filter as first argument and the arguments passed to the filter as585 extra arguments or keyword arguments.586 587 For example in the filter ``{{ 42|myfilter(23) }}`` the function would be588 called with ``myfilter(42, 23)``. Here for example a simple filter that can220 unmodified linesmodified:docs/extensions.rst+1 added-1 removed
105 unmodified lines106 The usage of the `i18n` extension for template designers is covered as part107 :ref:`of the template documentation <i18n-in-templates>`.108 109 .. _gettext: http://docs.python.org/dev/library/gettext110-.. _Babel: http://babel.edgewall.org/110+.. _Babel: http://babel.pocoo.org/111 112 .. _newstyle-gettext:113 114 Newstyle Gettext232 unmodified linesmodified:docs/faq.rst+2 added-2 removed
139 unmodified lines140 work in production environments::141 142 import os143 if os.environ.get('SERVER_SOFTWARE', '').startswith('Dev'):144- from google.appengine.tools.dev_appserver import HardenedModulesHook145- HardenedModulesHook._WHITE_LIST_C_MODULES += ['_ctypes', 'gestalt']144+ from google.appengine.tools.devappserver2.python import sandbox145+ sandbox._WHITE_LIST_C_MODULES += ['_ctypes', 'gestalt']146 147 Credit for this snippet goes to `Thomas Johansson148 <http://stackoverflow.com/questions/3086091/debug-jinja2-in-google-app-engine/3694434#3694434>`_149 42 unmodified linesmodified:docs/integration.rst+6 added-5 removed
4 unmodified lines5 the `Babel`_ library or your favourite editor for fancy code highlighting.6 This is a brief description of whats included.7 8 Files to help integration are available9-`here. <https://github.com/mitsuhiko/jinja2/tree/master/ext>`_9+`here. <https://github.com/pallets/jinja/tree/master/ext>`_10 11 .. _babel-integration:12 13 Babel Integration35 unmodified lines49 testsuites will catch syntax errors in templates anyways. If you don't50 want that behavior you can add ``silent=false`` to the settings and51 exceptions are propagated.52 53-.. _mapping file: http://babel.edgewall.org/wiki/Documentation/messages.html#extraction-method-mapping-and-configuration53+.. _mapping file: http://babel.pocoo.org/en/latest/messages.html#extraction-method-mapping-and-configuration54 55 Pylons56 ------57 22 unmodified lines80 81 TextMate82 --------83 84-Inside the `ext` folder at the root of the Jinja2 project there is a bundle for85-TextMate that supports syntax highlighting for Jinja1 and Jinja2 for text based84+There is a `bundle for TextMate`_ that supports syntax highlighting for Jinja1 and Jinja2 for text based85 templates as well as HTML. It also contains a few often used snippets.86 87+.. _bundle for TextMate: https://github.com/mitsuhiko/jinja2-tmbundle88+89 Vim90 ---91 92 A syntax plugin for `Vim`_ exists in the Vim-scripts directory as well as the3 unmodified lines96 The first one for text based templates, the latter for HTML templates.97 98 Copy the files into your `syntax` folder.99 99-.. _Babel: http://babel.edgewall.org/100+.. _Babel: http://babel.pocoo.org/101 .. _Vim: http://www.vim.org/modified:docs/intro.rst+3 added-6 removed
34 unmodified lines35 36 This will install a Jinja2 egg in your Python installation's site-packages37 directory.38 39-(If you are installing from the Windows command line omit the `sudo` and make40-sure to run the command as user with administrator rights)41-39 From the tarball release40 ~~~~~~~~~~~~~~~~~~~~~~~~~41 42 1. Download the most recent tarball from the `download page`_43 2. Unpack the tarball47-3. ``sudo python setup.py install``44+3. ``python setup.py install``45 46 Note that you either have to have `setuptools` or `distribute` installed;47 the latter is preferred.48 2 unmodified lines51 Installing the development version52 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~53 54 1. Install `git`_58-2. ``git clone git://github.com/mitsuhiko/jinja2.git``55+2. ``git clone git://github.com/pallets/jinja.git``56 3. ``cd jinja2``57 4. ``ln -s jinja2 /usr/lib/python2.X/site-packages``58 59 As an alternative to steps 4 you can also do ``python setup.py develop``56 unmodified lines116 in mind, so you will have to adapt the shown code examples to Python 3 syntax117 for yourself.118 119 123-.. _Jinja bug tracker: http://github.com/mitsuhiko/jinja2/issues120+.. _Jinja bug tracker: http://github.com/pallets/jinja/issuesmodified:docs/templates.rst+2 added-2 removed
604 unmodified lines605 +-----------------------+---------------------------------------------------+606 | `loop.cycle` | A helper function to cycle between a list of |607 | | sequences. See the explanation below. |608 +-----------------------+---------------------------------------------------+609-| `loop.depth` | Indicates how deep in deep in a recursive loop |609+| `loop.depth` | Indicates how deep in a recursive loop |610 | | the rendering currently is. Starts at level 1 |611 +-----------------------+---------------------------------------------------+612-| `loop.depth0` | Indicates how deep in deep in a recursive loop |612+| `loop.depth0` | Indicates how deep in a recursive loop |613 | | the rendering currently is. Starts at level 0 |614 +-----------------------+---------------------------------------------------+615 616 Within a for-loop, it's possible to cycle among a list of strings/variables893 unmodified linesmodified:jinja2/_compat.py-3 removed
43 unmodified lines44 45 implements_iterator = _identity46 implements_to_string = _identity47 encode_filename = _identity48- get_next = lambda x: x.__next__48 49 else:50 unichr = unichr51 text_type = unicode23 unmodified lines75 cls.__unicode__ = cls.__str__76 cls.__str__ = lambda x: x.__unicode__().encode('utf-8')77 return cls78 80- get_next = lambda x: x.next81-79 def encode_filename(filename):80 if isinstance(filename, unicode):81 return filename.encode('utf-8')82 return filename17 unmodified linesmodified:jinja2/environment.py+30 added-37 removed
8 unmodified lines9 :license: BSD, see LICENSE for more details.10 """11 import os12 import sys13+import weakref14+from functools import reduce, partial15 from jinja2 import nodes16 from jinja2.defaults import BLOCK_START_STRING, \17 BLOCK_END_STRING, VARIABLE_START_STRING, VARIABLE_END_STRING, \18 COMMENT_START_STRING, COMMENT_END_STRING, LINE_STATEMENT_PREFIX, \11 unmodified lines30 from jinja2.utils import import_string, LRUCache, Markup, missing, \31 concat, consume, internalcode32 from jinja2._compat import imap, ifilter, string_types, iteritems, \33 text_type, reraise, implements_iterator, implements_to_string, \32- get_next, encode_filename, PY2, PYPY33-from functools import reduce34+ encode_filename, PY2, PYPY35 36 37 # for direct template usage we have up to ten living environments38 _spontaneous_environments = LRUCache(10)128 unmodified lines167 as strings or extension classes. For more information have a168 look at :ref:`the extensions documentation <jinja-extensions>`.169 170 `optimized`170- should the optimizer be enabled? Default is `True`.171+ should the optimizer be enabled? Default is ``True``.172 173 `undefined`174 :class:`Undefined` or a subclass of it that is used to represent175 undefined values in the template.176 177 `finalize`178 A callable that can be used to process the result of a variable179 expression before it is output. For example one can convert179- `None` implicitly into an empty string here.180+ ``None`` implicitly into an empty string here.181 182 `autoescape`182- If set to true the XML/HTML autoescaping feature is enabled by183+ If set to ``True`` the XML/HTML autoescaping feature is enabled by184 default. For more details about autoescaping see185 :class:`~jinja2.utils.Markup`. As of Jinja 2.4 this can also186 be a callable that is passed the template name and has to186- return `True` or `False` depending on autoescape should be187+ return ``True`` or ``False`` depending on autoescape should be188 enabled by default.189 190 .. versionchanged:: 2.4191 `autoescape` can now be a function13 unmodified lines205 206 `auto_reload`207 Some loaders load templates from locations where the template208 sources may change (ie: file system or database). If208- `auto_reload` is set to `True` (default) every time a template is209+ ``auto_reload`` is set to ``True`` (default) every time a template is210 requested the loader checks if the source changed and if yes, it211 will reload the template. For higher performance it's possible to212 disable that.213 555 unmodified lines769 @internalcode770 def _load_template(self, name, globals):771 if self.loader is None:772 raise TypeError('no loader for this environment specified')772- try:773- # use abs path for cache key774- cache_key = self.loader.get_source(self, name)[1]775- except RuntimeError:776- # if loader does not implement get_source()777- cache_key = None778- # if template is not file, use name for cache key779- if cache_key is None:780- cache_key = name773+ cache_key = (weakref.ref(self.loader), name)774 if self.cache is not None:775 template = self.cache.get(cache_key)776 if template is not None and (not self.auto_reload or777 template.is_up_to_date):385 unmodified lines1163 fp.close()1164 1165 def disable_buffering(self):1166 """Disable the output buffering."""1174- self._next = get_next(self._gen)1167+ self._next = partial(next, self._gen)1168 self.buffered = False1169 1170+ def _buffered_generator(self, size):1171+ buf = []1172+ c_size = 01173+ push = buf.append1174+1175+ while 1:1176+ try:1177+ while c_size < size:1178+ c = next(self._gen)1179+ push(c)1180+ if c:1181+ c_size += 11182+ except StopIteration:1183+ if not c_size:1184+ return1185+ yield concat(buf)1186+ del buf[:]1187+ c_size = 01188+1189 def enable_buffering(self, size=5):1190 """Enable buffering. Buffer `size` items before yielding them."""1191 if size <= 1:1192 raise ValueError('buffer size too small')1193 1182- def generator(next):1183- buf = []1184- c_size = 01185- push = buf.append1186-1187- while 1:1188- try:1189- while c_size < size:1190- c = next()1191- push(c)1192- if c:1193- c_size += 11194- except StopIteration:1195- if not c_size:1196- return1197- yield concat(buf)1198- del buf[:]1199- c_size = 01200-1194 self.buffered = True1202- self._next = get_next(generator(get_next(self._gen)))1195+ self._next = partial(next, self._buffered_generator(size))1196 1197 def __iter__(self):1198 return self1199 7 unmodified linesmodified:jinja2/filters.py+35 added-29 removed
10 unmodified lines11 import re12 import math13 14 from random import choice15-from operator import itemgetter15 from itertools import groupby16+from collections import namedtuple17 from jinja2.utils import Markup, escape, pformat, urlize, soft_unicode, \18 unicode_urlencode19 from jinja2.runtime import Undefined20 from jinja2.exceptions import FilterArgumentError21 from jinja2._compat import imap, string_types, text_type, iteritems22 23 24-_word_re = re.compile(r'\w+(?u)')24+_word_re = re.compile(r'\w+', re.UNICODE)25+_word_beginning_split_re = re.compile(r'([-\s\(\{\[\<]+)', re.UNICODE)26 27 28 def contextfilter(f):29 """Decorator for marking context dependent filters. The current14 unmodified lines44 return f45 46 47 def environmentfilter(f):47- """Decorator for marking evironment dependent filters. The current48+ """Decorator for marking environment dependent filters. The current49 :class:`Environment` is passed to the filter as first argument.50 """51 f.environmentfilter = True52 return f130 unmodified lines183 def do_title(s):184 """Return a titlecased version of the value. I.e. words will start with185 uppercase letters, all remaining characters are lowercase.186 """186- rv = []187- for item in re.compile(r'([-\s]+)(?u)').split(soft_unicode(s)):188- if not item:189- continue190- rv.append(item[0].upper() + item[1:].lower())191- return ''.join(rv)187+ return ''.join(188+ [item[0].upper() + item[1:].lower()189+ for item in _word_beginning_split_re.split(soft_unicode(s))190+ if item])191 192 193 def do_dictsort(value, case_sensitive=False, by='key'):194 """Sort a dict and yield (key, value) pairs. Because python dicts are321 unmodified lines516 override this default using the first parameter. You517 can also override the default base (10) in the second518 parameter, which handles input with prefixes such as519 0b, 0o and 0x for bases 2, 8 and 16 respectively.520+ The base is ignored for decimal numbers and non-string values.521 """522 try:523+ if isinstance(value, string_types):523- return int(value, base)524+ return int(value, base)525+ return int(value)526 except (TypeError, ValueError):527 # this quirk is necessary so that "42.23"|int gives 42.528 try:529 return int(float(value))140 unmodified lines670 func = getattr(math, method)671 return func(value * (10 ** precision)) / (10 ** precision)672 673 674+_GroupTuple = namedtuple('_GroupTuple', ['grouper', 'list'])675+676 @environmentfilter677 def do_groupby(environment, value, attribute):678 """Group a sequence of objects by a common attribute.679 32 unmodified lines712 It's now possible to use dotted notation to group by the child713 attribute of another attribute.714 """715 expr = make_attrgetter(environment, attribute)712- return sorted(map(_GroupTuple, groupby(sorted(value, key=expr), expr)))716+ return [_GroupTuple(key, list(values)) for key, values in groupby(sorted(value, key=expr), expr)]717 718 715-class _GroupTuple(tuple):716- __slots__ = ()717- grouper = property(itemgetter(0))718- list = property(itemgetter(1))719-720- def __new__(cls, xxx_todo_changeme):721- (key, value) = xxx_todo_changeme722- return tuple.__new__(cls, (key, list(value)))723-724-719 @environmentfilter720 def do_sum(environment, iterable, attribute=None, start=0):721 """Returns the sum of a sequence of numbers plus the value of parameter722 'start' (which defaults to 0). When the sequence is empty it returns122 unmodified lines845 846 847 @contextfilter848 def do_select(*args, **kwargs):855- """Filters a sequence of objects by applying a test to the object and only856- selecting the ones with the test succeeding.849+ """Filters a sequence of objects by applying a test to each object,850+ and only selecting the objects with the test succeeding.851 852+ If no test is specified, each object will be evaluated as a boolean.853+854 Example usage:855 856 .. sourcecode:: jinja857 6 unmodified lines864 865 866 @contextfilter867 def do_reject(*args, **kwargs):872- """Filters a sequence of objects by applying a test to the object and873- rejecting the ones with the test succeeding.868+ """Filters a sequence of objects by applying a test to each object,869+ and rejecting the objects with the test succeeding.870 871+ If no test is specified, each object will be evaluated as a boolean.872+873 Example usage:874 875 .. sourcecode:: jinja876 5 unmodified lines882 883 884 @contextfilter885 def do_selectattr(*args, **kwargs):888- """Filters a sequence of objects by applying a test to an attribute of an889- object and only selecting the ones with the test succeeding.886+ """Filters a sequence of objects by applying a test to the specified887+ attribute of each object, and only selecting the objects with the888+ test succeeding.889 890+ If no test is specified, the attribute's value will be evaluated as891+ a boolean.892+893 Example usage:894 895 .. sourcecode:: jinja896 6 unmodified lines903 904 905 @contextfilter906 def do_rejectattr(*args, **kwargs):905- """Filters a sequence of objects by applying a test to an attribute of an906- object or the attribute and rejecting the ones with the test succeeding.907+ """Filters a sequence of objects by applying a test to the specified908+ attribute of each object, and rejecting the objects with the test909+ succeeding.910 911+ If no test is specified, the attribute's value will be evaluated as912+ a boolean.913+914 .. sourcecode:: jinja915 916 {{ users|rejectattr("is_active") }}917 {{ users|rejectattr("email", "none") }}85 unmodified linesmodified:jinja2/loaders.py+2 added-2 removed
349 unmodified lines350 loader, name = self.get_loader(template)351 try:352 return loader.get_source(environment, name)353 except TemplateNotFound:354- # re-raise the exception with the correct fileame here.354+ # re-raise the exception with the correct filename here.355 # (the one that includes the prefix)356 raise TemplateNotFound(template)357 358 @internalcode1 unmodified line360 loader, local_name = self.get_loader(name)361 try:362 return loader.load(environment, local_name, globals)363 except TemplateNotFound:364- # re-raise the exception with the correct fileame here.364+ # re-raise the exception with the correct filename here.365 # (the one that includes the prefix)366 raise TemplateNotFound(name)367 368 def list_templates(self):113 unmodified linesmodified:jinja2/utils.py+2 added-2 removed
107 unmodified lines108 def clear_caches():109 """Jinja2 keeps internal caches for environments and lexers. These are110 used so that Jinja2 doesn't have to recreate environments and lexers all111 the time. Normally you don't have to care about that but if you are112- messuring memory consumption you may want to clean the caches.112+ measuring memory consumption you may want to clean the caches.113 """114 from jinja2.environment import _spontaneous_environments115 from jinja2.lexer import _lexer_cache116 _spontaneous_environments.clear()85 unmodified lines202 or '')) or x203 words = _word_split_re.split(text_type(escape(text)))204 nofollow_attr = nofollow and ' rel="nofollow"' or ''205 if target is not None and isinstance(target, string_types):206- target_attr = ' target="%s"' % target206+ target_attr = ' target="%s"' % escape(target)207 else:208 target_attr = ''209 for i, word in enumerate(words):210 match = _punctuation_re.match(word)321 unmodified linesmodified:tests/test_ext.py+4 added-4 removed
97 unmodified lines98 )99 newstyle_i18n_env.install_gettext_callables(gettext, ngettext, newstyle=True)100 101 102-class TestExtension(Extension):102+class ExampleExtension(Extension):103 tags = set(['test'])104 ext_attr = 42105 106 def parse(self, parser):99 unmodified lines206 assert [x.strip() for x in tmpl.render(a=1, b=2).splitlines()] \207 == ['42 = 23', '1 = 2']208 209 def test_extension_nodes(self):210- env = Environment(extensions=[TestExtension])210+ env = Environment(extensions=[ExampleExtension])211 tmpl = env.from_string('{% test %}')212 assert tmpl.render() == 'False|42|23|{}'213 214 def test_identifier(self):215- assert TestExtension.identifier == __name__ + '.TestExtension'215+ assert ExampleExtension.identifier == __name__ + '.ExampleExtension'216 217 def test_rebinding(self):218- original = Environment(extensions=[TestExtension])218+ original = Environment(extensions=[ExampleExtension])219 overlay = original.overlay()220 for env in original, overlay:221 for ext in itervalues(env.extensions):222 assert ext.environment is env245 unmodified linesmodified:tests/test_filters.py+16 added-3 removed
131 unmodified lines132 assert out == ('foo bar foo bar\n foo bar foo bar| '133 'foo bar foo bar\n foo bar foo bar')134 135 def test_int(self, env):136+ class IntIsh(object):137+ def __int__(self):138+ return 42139+140 tmpl = env.from_string('{{ "42"|int }}|{{ "ajsghasjgd"|int }}|'141 '{{ "32.32"|int }}|{{ "0x4d32"|int(0, 16) }}|'138- '{{ "011"|int(0, 8)}}|{{ "0x33FU"|int(0, 16) }}')139- out = tmpl.render()140- assert out == '42|0|32|19762|9|0'142+ '{{ "011"|int(0, 8)}}|{{ "0x33FU"|int(0, 16) }}|'143+ '{{ obj|int }}')144+ out = tmpl.render(obj=IntIsh())145+ assert out == '42|0|32|19762|9|0|42'146 147 def test_join(self, env):148 tmpl = env.from_string('{{ [1, 2, 3]|join("|") }}')149 out = tmpl.render()62 unmodified lines212 tmpl = env.from_string('''{{ "foo\tbar"|title }}''')213 assert tmpl.render() == "Foo\tBar"214 tmpl = env.from_string('''{{ "FOO\tBAR"|title }}''')215 assert tmpl.render() == "Foo\tBar"216+ tmpl = env.from_string('''{{ "foo (bar)"|title }}''')217+ assert tmpl.render() == "Foo (Bar)"218+ tmpl = env.from_string('''{{ "foo {bar}"|title }}''')219+ assert tmpl.render() == "Foo {Bar}"220+ tmpl = env.from_string('''{{ "foo [bar]"|title }}''')221+ assert tmpl.render() == "Foo [Bar]"222+ tmpl = env.from_string('''{{ "foo <bar>"|title }}''')223+ assert tmpl.render() == "Foo <Bar>"224 225 class Foo:226 def __str__(self):227 return 'foo-bar'344 unmodified linesmodified:tests/test_loader.py+21 added-7 removed
11 unmodified lines12 import sys13 import tempfile14 import shutil15 import pytest16+import weakref17 18 from jinja2 import Environment, loaders19 from jinja2._compat import PYPY, PY220 from jinja2.loaders import split_template_path57 unmodified lines78 changed = True79 assert tmpl is not env.get_template('template')80 changed = False81 81- env = Environment(loader=TestLoader(), cache_size=0)82- assert env.get_template('template') \83- is not env.get_template('template')82+ def test_no_cache(self):83+ mapping = {'foo': 'one'}84+ env = Environment(loader=loaders.DictLoader(mapping), cache_size=0)85+ assert env.get_template('foo') is not env.get_template('foo')86 87+ def test_limited_size_cache(self):88+ mapping = {'one': 'foo', 'two': 'bar', 'three': 'baz'}89+ loader = loaders.DictLoader(mapping)85- env = Environment(loader=TestLoader(), cache_size=2)90+ env = Environment(loader=loader, cache_size=2)91 t1 = env.get_template('one')92 t2 = env.get_template('two')93 assert t2 is env.get_template('two')94 assert t1 is env.get_template('one')95 t3 = env.get_template('three')91- assert 'one' in env.cache92- assert 'two' not in env.cache93- assert 'three' in env.cache96+ loader_ref = weakref.ref(loader)97+ assert (loader_ref, 'one') in env.cache98+ assert (loader_ref, 'two') not in env.cache99+ assert (loader_ref, 'three') in env.cache100 101+ def test_cache_loader_change(self):102+ loader1 = loaders.DictLoader({'foo': 'one'})103+ loader2 = loaders.DictLoader({'foo': 'two'})104+ env = Environment(loader=loader1, cache_size=2)105+ assert env.get_template('foo').render() == 'one'106+ env.loader = loader2107+ assert env.get_template('foo').render() == 'two'108+109 def test_dict_loader_cache_invalidates(self):110 mapping = {'foo': "one"}111 env = Environment(loader=loaders.DictLoader(mapping))112 assert env.get_template('foo').render() == "one"122 unmodified linesmodified:tests/test_utils.py+12 added-1 removed
12 unmodified lines13 import pytest14 15 import pickle16 17-from jinja2.utils import LRUCache, escape, object_type_repr17+from jinja2.utils import LRUCache, escape, object_type_repr, urlize18 19 20 @pytest.mark.utils21 @pytest.mark.lrucache51 unmodified lines73 escape(u"foo")74 escape(u"<foo>")75 counts.add(len(gc.get_objects()))76 assert len(counts) == 1, 'ouch, c extension seems to leak objects'77+78+79+@pytest.mark.utils80+@pytest.mark.escapeUrlizeTarget81+class TestEscapeUrlizeTarget():82+ def test_escape_urlize_target(self):83+ url = "http://example.org"84+ target = "<script>"85+ assert urlize(url, target=target) == ('<a href="http://example.org"'86+ ' target="<script>">'87+ 'http://example.org</a>')modified:.gitignore+7 added-5 removed
1 *.so2-docs/_build2+docs/_build/3 *.pyc4 *.pyo5-*.egg-info5+*.egg-info/6 *.egg7-build8-dist7+build/8+dist/9 .DS_Store10-.tox10+.tox/11+.cache/12+.idea/modified:.travis.yml+5 added-7 removed
1+sudo: false2 language: python3 python:4 - "2.6"5 - "2.7"6+ - pypy7 - "3.3"8 - "3.4"9 - "3.5"8- - "pypy"9-10 install:11- - pip install tox11+ - pip install tox12 script:13- - tox -e \14- $(echo $TRAVIS_PYTHON_VERSION | sed 's/^\([0-9]\)\.\([0-9]\).*/py\1\2/')15-13+ - tox -e py14 notifications:15 email: false16 irc:17 channels:20- - "chat.freenode.net#pocoo"18+ - chat.freenode.net#pocoo19 on_success: change20 on_failure: always21 use_notice: true22 skip_join: truemodified:CHANGES+7 added-4 removed
2 unmodified lines3 4 Version 2.95 -----------6 7+- Change cache key definition in environment. This fixes a performance8+ regression introduced in 2.8.9 - Added support for `generator_stop` on supported Python versions10 (Python 3.5 and later)11 12 Version 2.8.11 unmodified line14 15 (unreleased bugfix release)16 17 - Fixed the `for_qs` flag for `urlencode`.18+- Fixed regression when applying `int` to non-string values.19 20 Version 2.821 -----------22 (codename Replacement, released on July 26th 2015)11 unmodified lines34 object that logs failures into a logger.35 - If unmarshalling of cached data fails the template will be36 reloaded now.37 - Implemented a block ``set`` tag.35-- Default cache size was incrased to 400 from a low 50.38+- Default cache size was increased to 400 from a low 50.39 - Fixed ``is number`` test to accept long integers in all Python versions.40 - Changed ``is number`` to accept Decimal as a number.41 - Added a check for default arguments followed by non-default arguments. This42 change makes ``{% macro m(x, y=1, z) %}...{% endmacro %}`` a syntax error. The97 unmodified lines140 to upgrade, it's enough to flush the bytecode cache. This just no longer141 makes this necessary, Jinja2 will automatically detect these cases now.142 - the sum filter can now sum up values by attribute. This is a backwards143 incompatible change. The argument to the filter previously was the141- optional starting index which defaultes to zero. This now became the144+ optional starting index which defaults to zero. This now became the145 second argument to the function because it's rarely used.146 - like sum, sort now also makes it possible to order items by attribute.147 - like sum and sort, join now also is able to join attributes of objects148 as string.49 unmodified lines198 compatibility the pure Python implementation still exists but is199 pulled from markupsafe by the Jinja2 developers. The debug support200 went into a separate feature called "debugsupport" and is disabled201 by default because it is only relevant for Python 2.4199-- fixed an issue with unary operators having the wrong precendence.202+- fixed an issue with unary operators having the wrong precedence.203 204 Version 2.5205 -----------203-(codename Incoherence, relased on May 29th 2010)206+(codename Incoherence, released on May 29th 2010)207 208 - improved the sort filter (should have worked like this for a209 long time) by adding support for case insensitive searches.210 - fixed a bug for getattribute constant folding.174 unmodified linesmodified:README.rst+9 added-7 removed
6 unmodified lines7 8 Nutshell9 --------10 11-Here a small example of a Jinja template::11+Here a small example of a Jinja template:12 13+.. code-block:: jinja14+15 {% extends 'base.html' %}16 {% block title %}Memberlist{% endblock %}17 {% block content %}18 <ul>10 unmodified lines29 life difficult by restricting functionality too much.30 31 For more information visit the new `Jinja2 webpage`_ and `documentation`_.32 31-The `Jinja2 tip`_ is installable via `easy_install` with ``easy_install32-Jinja2==dev``.33+The `Jinja2 tip`_ is installable via ``pip`` with ``pip install34+https://github.com/pallets/jinja/zipball/master``.35 36 .. _sandboxed: http://en.wikipedia.org/wiki/Sandbox_(computer_security)37 .. _Django: http://www.djangoproject.com/38 .. _Jinja2 webpage: http://jinja.pocoo.org/3 unmodified lines42 Builds43 ------44 45 +---------------------+------------------------------------------------------------------------------+44-| ``master`` | .. image:: https://travis-ci.org/mitsuhiko/jinja2.svg?branch=master |45-| | :target: https://travis-ci.org/mitsuhiko/jinja2 |46+| ``master`` | .. image:: https://travis-ci.org/pallets/jinja.svg?branch=master |47+| | :target: https://travis-ci.org/pallets/jinja |48 +---------------------+------------------------------------------------------------------------------+47-| ``2.7-maintenance`` | .. image:: https://travis-ci.org/mitsuhiko/jinja2.svg?branch=2.7-maintenance |48-| | :target: https://travis-ci.org/mitsuhiko/jinja2 |49+| ``2.7-maintenance`` | .. image:: https://travis-ci.org/pallets/jinja.svg?branch=2.7-maintenance |50+| | :target: https://travis-ci.org/pallets/jinja |51 +---------------------+------------------------------------------------------------------------------+modified:setup.cfg+3 added
1 [wheel]2 universal = 13 4+[metadata]5+license_file = LICENSE6+7 [aliases]8 release = egg_info -RDb ''9 10 [pytest]1 unmodified linemodified:setup.py+2 added
60 unmodified lines61 'Programming Language :: Python :: 2.6',62 'Programming Language :: Python :: 2.7',63 'Programming Language :: Python :: 3',64 'Programming Language :: Python :: 3.3',65+ 'Programming Language :: Python :: 3.4',66+ 'Programming Language :: Python :: 3.5',67 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',68 'Topic :: Software Development :: Libraries :: Python Modules',69 'Topic :: Text Processing :: Markup :: HTML'70 ],9 unmodified linesmodified:tox.ini+3 added-4 removed
1 [tox]2-envlist = py26, py27, pypy, py33, py34, py352+envlist = py26,py27,pypy,py33,py34,py353 4 [testenv]5-commands =6- py.test []5+commands = py.test {posargs}6 7 deps =9- pytest8+ pytest