Skip to content
Myr

Merge branch '2.11.x'

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

authored by David Lord · committed by David Lord · parents c074fd5, 786867a · Browse files · 5 files+41 added−3 removed
This commit

State

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

Diff stats

5 files+41 added−3 removed

  • tests:+29 added−0 removed
  • other:+12 added−3 removed

5 files+41 added−3 removed

modified:src/jinja2/lexer.py+6 added-2 removed
634 unmodified lines
635 statetokens = self.rules[stack[-1]]636 source_length = len(source)637 balancing_stack = []638 lstrip_unless_re = self.lstrip_unless_re639 newlines_stripped = 0640641 while 1:642 # tokenizer loop643 for regex, tokens, new_state in statetokens:
28 unmodified lines
672 strip_sign = next(g for g in groups[2::2] if g is not None)673674 if strip_sign == "-":675 # Strip all whitespace between the text and the tag.676 stripped = text.rstrip()677 newlines_stripped = text[len(stripped) :].count("\n")675 groups = (text.rstrip(),) + groups[1:]678 groups = (stripped,) + groups[1:]679 elif (680 # Not marked for preserving whitespace.681 strip_sign != "+"682 # lstrip is enabled.
31 unmodified lines
714 else:715 data = groups[idx]716 if data or token not in ignore_if_empty:717 yield lineno, token, data715 lineno += data.count("\n")718 lineno += data.count("\n") + newlines_stripped719 newlines_stripped = 0720721 # strings as token just are yielded as it.722 else:723 data = m.group()
71 unmodified lines
modified:src/jinja2/utils.py+2 added-1 removed
641 unmodified lines
642 self, args = args[0], args[1:]643 self.__attrs = dict(*args, **kwargs)644645 def __getattribute__(self, name):646 if name == "_Namespace__attrs":646 # __class__ is needed for the awaitable check in async mode647 if name in {"_Namespace__attrs", "__class__"}:648 return object.__getattribute__(self, name)649 try:650 return self.__attrs[name]651 except KeyError:
15 unmodified lines
modified:tests/test_async.py+11 added
575 unmodified lines
576577 def test_awaitable_property_slicing(self, test_env_async):578 t = test_env_async.from_string("{% for x in a.b[:1] %}{{ x }}{% endfor %}")579 assert t.render(a=dict(b=[1, 2, 3])) == "1"580581582def test_namespace_awaitable(test_env_async):583 async def _test():584 t = test_env_async.from_string(585 '{% set ns = namespace(foo="Bar") %}{{ ns.foo }}'586 )587 actual = await t.render_async()588 assert actual == "Bar"589590 run(_test())
modified:tests/test_lexnparse.py+18 added
161 unmodified lines
162 env.from_string(t)163 else:164 pytest.raises(TemplateSyntaxError, env.from_string, t)165166 def test_lineno_with_strip(self, env):167 tokens = env.lex(168 """\169<html>170 <body>171 {%- block content -%}172 <hr>173 {{ item }}174 {% endblock %}175 </body>176</html>"""177 )178 for tok in tokens:179 lineno, token_type, value = tok180 if token_type == "name" and value == "item":181 assert lineno == 5182 break183184185class TestParser:186 def test_php_syntax(self, env):187 env = Environment("<?", "?>", "<?=", "?>", "<!--", "-->")188 tmpl = env.from_string(
625 unmodified lines
modified:CHANGES.rst+4 added
30 unmodified lines
31 limited support for namespace packages. The changes caused issues32 when using Pytest. Due to the difficulty in supporting Python 2 and33 :pep:`451` simultaneously, the changes are reverted until 3.0.34 :pr:`1182`35- Fix line numbers in error messages when newlines are stripped.36 :pr:`1178`37- The special ``namespace()`` assignment object in templates works in38 async environments. :issue:`1180`394041Version 2.11.142--------------
737 unmodified lines