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
Provenance
- Commit
0a37031- Tree
a291ea5- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
c074fd5- Parent 2
786867a
5 files changed+41 added−3 removed
modified:src/jinja2/lexer.py+6 added-2 removed
634 unmodified lines635 statetokens = self.rules[stack[-1]]636 source_length = len(source)637 balancing_stack = []638 lstrip_unless_re = self.lstrip_unless_re639+ newlines_stripped = 0640 641 while 1:642 # tokenizer loop643 for regex, tokens, new_state in statetokens:28 unmodified lines672 strip_sign = next(g for g in groups[2::2] if g is not None)673 674 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 lines714 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 = 0720 721 # strings as token just are yielded as it.722 else:723 data = m.group()71 unmodified linesmodified:src/jinja2/utils.py+2 added-1 removed
641 unmodified lines642 self, args = args[0], args[1:]643 self.__attrs = dict(*args, **kwargs)644 645 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 linesmodified:tests/test_async.py+11 added
575 unmodified lines576 577 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"580+581+582+def 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"589+590+ run(_test())modified:tests/test_lexnparse.py+18 added
161 unmodified lines162 env.from_string(t)163 else:164 pytest.raises(TemplateSyntaxError, env.from_string, t)165 166+ 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+ break183 184+185 class TestParser:186 def test_php_syntax(self, env):187 env = Environment("<?", "?>", "<?=", "?>", "<!--", "-->")188 tmpl = env.from_string(625 unmodified linesmodified:CHANGES.rst+4 added
30 unmodified lines31 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`39 40 41 Version 2.11.142 --------------737 unmodified lines