Skip to content
Myr

Fixed async macro autoescape. Fixes #671

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 · parent 6295976 · Browse files · 4 files+38 added−1 removed
This commit

State

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

Diff stats

4 files+38 added−1 removed

  • tests:+15 added−0 removed
  • other:+23 added−1 removed

4 files+38 added−1 removed

modified:jinja2/asyncsupport.py+18 added-1 removed
94 unmodified lines
9596 return update_wrapper(__call__, original_call)979899def wrap_macro_invoke(original_invoke):100 @internalcode101 async def async_invoke(self, arguments, autoescape):102 rv = await self._func(*arguments)103 if autoescape:104 rv = Markup(rv)105 return rv106107 @internalcode108 def _invoke(self, arguments, autoescape):109 if not self._environment.is_async:110 return original_invoke(self, arguments, autoescape)111 return async_invoke(self, arguments, autoescape)112 return update_wrapper(_invoke, original_invoke)113114115@internalcode116async def get_default_module_async(self):117 if self._module is not None:118 return self._module
34 unmodified lines
153 make_module_async, Template.make_module_async)154155156def patch_runtime():141 from jinja2.runtime import BlockReference157 from jinja2.runtime import BlockReference, Macro158 BlockReference.__call__ = wrap_block_reference_call(159 BlockReference.__call__)160 Macro._invoke = wrap_macro_invoke(Macro._invoke)161162163def patch_filters():164 from jinja2.filters import FILTERS
90 unmodified lines
modified:jinja2/runtime.py+4 added
542 unmodified lines
543 elif len(args) > self._argument_count:544 raise TypeError('macro %r takes not more than %d argument(s)' %545 (self.name, len(self.arguments)))546547 return self._invoke(arguments, autoescape)548549 def _invoke(self, arguments, autoescape):550 """This method is being swapped out by the async implementation."""551 rv = self._func(*arguments)552 if autoescape:553 rv = Markup(rv)554 return rv
231 unmodified lines
modified:tests/test_async.py+15 added
241 unmodified lines
242 {{ outer("FOO") }}243 """)244 assert t.render().strip() == '(FOO)'245246 def test_unoptimized_scopes_autoescape(self):247 env = Environment(loader=DictLoader(dict(248 o_printer='({{ o }})',249 )), autoescape=True, enable_async=True)250 t = env.from_string("""251 {% macro outer(o) %}252 {% macro inner() %}253 {% include "o_printer" %}254 {% endmacro %}255 {{ inner() }}256 {% endmacro %}257 {{ outer("FOO") }}258 """)259 assert t.render().strip() == '(FOO)'260261262@pytest.mark.core_tags263@pytest.mark.for_loop264class TestAsyncForLoop(object):265
220 unmodified lines
modified:CHANGES+1 added
15 unmodified lines
16- Resolve an issue where the `{% extends %}` tag could not be used with17 async environments. (#668)18- Reduce memory footprint slightly by reducing our unicode database dump19 we use for identifier matching on Python 3 (#666)20- Fixed autoescaping not working for macros in async compilation mode. (#671)2122Version 2.9.423-------------24(bugfix release, released on January 10th 2017)
480 unmodified lines