Merge branch 'master' into NATIVE_TYPES
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by GitHub · parents 68820c3, 31f92b5 · Browse files · 13 files·+56 added−22 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
13 files+56 added−22 removed
- tests:+16 added−6 removed
- other:+40 added−16 removed
Provenance
- Commit
6a7a263- Tree
9849547- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
68820c3- Parent 2
31f92b5
13 files changed+56 added−22 removed
modified:jinja2/compiler.py+7 added
1157 unmodified lines1158 self.write(':')1159 self.indent()1160 self.blockvisit(node.body, if_frame)1161 self.outdent()1162+ for elif_ in node.elif_:1163+ self.writeline('elif ', elif_)1164+ self.visit(elif_.test, if_frame)1165+ self.write(':')1166+ self.indent()1167+ self.blockvisit(elif_.body, if_frame)1168+ self.outdent()1169 if node.else_:1170 self.writeline('else:')1171 self.indent()1172 self.blockvisit(node.else_, if_frame)544 unmodified linesmodified:jinja2/debug.py+1 added-1 removed
196 unmodified lines197 198 def get_jinja_locals(real_locals):199 ctx = real_locals.get('context')200 if ctx:201- locals = ctx.get_all()201+ locals = ctx.get_all().copy()202 else:203 locals = {}204 205 local_overrides = {}167 unmodified linesmodified:jinja2/environment.py+1 added-1 removed
807 unmodified lines808 809 @internalcode810 def get_template(self, name, parent=None, globals=None):811 """Load a template from the loader. If a loader is configured this812- method ask the loader for the template and returns a :class:`Template`.812+ method asks the loader for the template and returns a :class:`Template`.813 If the `parent` parameter is not `None`, :meth:`join_path` is called814 to get the real template name before loading.815 816 The `globals` parameter can be used to provide template wide globals.460 unmodified linesmodified:jinja2/filters.py+1 added-1 removed
337 unmodified lines338 339 340 @environmentfilter341 def do_max(environment, value, case_sensitive=False, attribute=None):342- """Return the smallest item from the sequence.342+ """Return the largest item from the sequence.343 344 .. sourcecode:: jinja345 346 {{ [1, 2, 3]|max }}844 unmodified linesmodified:jinja2/idtracking.py+2 added-1 removed
229 unmodified lines230 self.symbols = original_symbols231 return rv232 233 body_symbols = inner_visit(node.body)234+ elif_symbols = inner_visit(node.elif_)235 else_symbols = inner_visit(node.else_ or ())236 236- self.symbols.branch_update([body_symbols, else_symbols])237+ self.symbols.branch_update([body_symbols, elif_symbols, else_symbols])238 239 def visit_Macro(self, node, **kwargs):240 self.symbols.store(node.name)241 45 unmodified linesmodified:jinja2/nodes.py+1 added-1 removed
312 unmodified lines313 314 315 class If(Stmt):316 """If `test` is true, `body` is rendered, else `else_`."""317- fields = ('test', 'body', 'else_')317+ fields = ('test', 'body', 'elif_', 'else_')318 319 320 class Macro(Stmt):321 """A macro definition. `name` is the name of the macro, `args` a list of678 unmodified linesmodified:jinja2/parser.py+6 added-7 removed
208 unmodified lines209 while 1:210 node.test = self.parse_tuple(with_condexpr=False)211 node.body = self.parse_statements(('name:elif', 'name:else',212 'name:endif'))213+ node.elif_ = []214+ node.else_ = []215 token = next(self.stream)216 if token.test('name:elif'):215- new_node = nodes.If(lineno=self.stream.current.lineno)216- node.else_ = [new_node]217- node = new_node217+ node = nodes.If(lineno=self.stream.current.lineno)218+ result.elif_.append(node)219 continue220 elif token.test('name:else'):220- node.else_ = self.parse_statements(('name:endif',),221- drop_needle=True)222- else:223- node.else_ = []221+ result.else_ = self.parse_statements(('name:endif',),222+ drop_needle=True)223 break224 return result225 226 def parse_with(self):676 unmodified linesmodified:jinja2/utils.py+1 added-1 removed
565 unmodified lines566 .replace(u'<', u'\\u003c') \567 .replace(u'>', u'\\u003e') \568 .replace(u'&', u'\\u0026') \569 .replace(u"'", u'\\u0027')570- return rv570+ return Markup(rv)571 572 573 @implements_iterator574 class Cycler(object):73 unmodified linesmodified:tests/test_core_tags.py+9 added
247 unmodified lines248 tmpl = env.from_string('''{% if false %}XXX{% elif true249 %}...{% else %}XXX{% endif %}''')250 assert tmpl.render() == '...'251 252+ def test_elif_deep(self, env):253+ elifs = '\n'.join('{{% elif a == {0} %}}{0}'.format(i)254+ for i in range(1, 1000))255+ tmpl = env.from_string('{{% if a == 0 %}}0{0}{{% else %}}x{{% endif %}}'256+ .format(elifs))257+ for x in (0, 10, 999):258+ assert tmpl.render(a=x).strip() == str(x)259+ assert tmpl.render(a=1000).strip() == 'x'260+261 def test_else(self, env):262 tmpl = env.from_string('{% if false %}XXX{% else %}...{% endif %}')263 assert tmpl.render() == '...'264 213 unmodified linesmodified:tests/test_filters.py+3 added-2 removed
638 unmodified lines639 640 def test_json_dump(self):641 env = Environment(autoescape=True)642 t = env.from_string('{{ x|tojson }}')643- assert t.render(x={'foo': 'bar'}) == '{"foo": "bar"}'644- assert t.render(x='"bar\'') == r'"\"bar\u0027"'643+ assert t.render(x={'foo': 'bar'}) == '{"foo": "bar"}'644+ assert t.render(x='"ba&r\'') == r'"\"ba\u0026r\u0027"'645+ assert t.render(x='<bar>') == r'"\u003cbar\u003e"'646 647 def my_dumps(value, **options):648 assert options == {'foo': 'bar'}649 return '42'3 unmodified linesmodified:tests/test_idtracking.py+4 added-4 removed
59 unmodified lines60 'upper', [], [], None, None)),61 nodes.Output([62 nodes.Name('title_upper', 'load'),63 nodes.Call(nodes.Name('render_title', 'load'), [64- nodes.Const('Aha')], [], None, None)])], [])])])64+ nodes.Const('Aha')], [], None, None)])], [], [])])])65 66 for_loop = nodes.For(67 nodes.Name('item', 'store'),68 nodes.Name('seq', 'load'), [85 unmodified lines154 def test_if_branching_stores():155 tmpl = nodes.Template([156 nodes.If(nodes.Name('expression', 'load'), [157 nodes.Assign(nodes.Name('variable', 'store'),158- nodes.Const(42))], [])])158+ nodes.Const(42))], [], [])])159 160 sym = symbols_for_node(tmpl)161 assert sym.refs == {162 'variable': 'l_0_variable',13 unmodified lines176 tmpl = nodes.Template([177 nodes.Assign(nodes.Name('variable', 'store'), nodes.Const(23)),178 nodes.If(nodes.Name('expression', 'load'), [179 nodes.Assign(nodes.Name('variable', 'store'),180- nodes.Const(42))], [])])180+ nodes.Const(42))], [], [])])181 182 sym = symbols_for_node(tmpl)183 assert sym.refs == {184 'variable': 'l_0_variable',11 unmodified lines196 197 def test_if_branching_multi_scope():198 for_loop = nodes.For(nodes.Name('item', 'store'), nodes.Name('seq', 'load'), [199 nodes.If(nodes.Name('expression', 'load'), [200- nodes.Assign(nodes.Name('x', 'store'), nodes.Const(42))], []),200+ nodes.Assign(nodes.Name('x', 'store'), nodes.Const(42))], [], []),201 nodes.Include(nodes.Const('helper.html'), True, False)202 ], [], None, False)203 204 tmpl = nodes.Template([12 unmodified linesmodified:CHANGES+18 added-3 removed
22 unmodified lines23 surrounding whitespace. Also added a new policy to enable this for all24 `trans` blocks.25 - The ``random`` filter is no longer incorrectly constant folded and will26 produce a new random choice each time the template is rendered. (`#478`_)27-- Add a ``unique`` filter. (`#469`_)28-- Add ``min`` and ``max`` filters. (`#475`_)29-- Add tests for all comparison operators: ``eq``, ``ne``, ``lt``, ``le``,27+- Added a ``unique`` filter. (`#469`_)28+- Added ``min`` and ``max`` filters. (`#475`_)29+- Added tests for all comparison operators: ``eq``, ``ne``, ``lt``, ``le``,30 ``gt``, ``ge``. (`#665`_)31 - ``import`` statement cannot end with a trailing comma. (`#617`_, `#618`_)32 - ``indent`` filter will not indent blank lines by default. (`#685`_)33 - Add ``reverse`` argument for ``dictsort`` filter. (`#692`_)9 unmodified lines43 .. _#685: https://github.com/pallets/jinja/pull/68544 .. _#692: https://github.com/pallets/jinja/pull/69245 .. _#708: https://github.com/pallets/jinja/pull/70846 47+Version 2.9.748+-------------49+50+(bugfix release, in development)51+52+- ``tojson`` filter marks output as safe to match documented behavior.53+ (`#718`_)54+- Resolved a bug where getting debug locals for tracebacks could55+ modify template context.56+- Fixed a bug where having many `{% elif ... %}` blocks resulted in a57+ "too many levels of indentation" error. These blocks now compile to58+ native `elif ..:` instead of `else: if ..:` (#759)59+60+.. _#718: https://github.com/pallets/jinja/pull/71861+62 Version 2.9.663 -------------64 (bugfix release, released on April 3rd 2017)65 503 unmodified linesmodified:tox.ini+2 added
32 unmodified lines33 passenv = CI TRAVIS TRAVIS_*34 deps = codecov35 skip_install = true36 commands =37+ # install argparse for 2.638+ python -c 'import sys, pip; sys.version_info < (2, 7) and pip.main(["install", "argparse", "-q"])'39 coverage combine40 coverage report41 codecov