Skip to content
Myr

Added untested support for imports and includes in async mode

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 1259162 · Browse files · 3 files+24 added−7 removed
This commit

State

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

Diff stats

3 files+24 added−7 removed

  • other:+24 added−7 removed

3 files+24 added−7 removed

modified:jinja2/asyncsupport.py+8 added
62 unmodified lines
63 self._module = rv = await self.make_module_async()64 return rv656667@internalcode68def get_default_module_impl(self):69 if self.environment._async:70 return self._get_default_module_async()71 return self._get_default_module()727374def wrap_default_module(original_default_module):75 @internalcode76 def _get_default_module(self):77 if self.environment._async:
17 unmodified lines
95 Template.render = wrap_render_func(Template.render)96 Template._get_default_module = wrap_default_module(97 Template._get_default_module)98 Template._get_default_module_async = get_default_module_async99 Template._get_default_module_impl = get_default_module_impl100 Template.make_module_async = make_module_async101102103def patch_runtime():
13 unmodified lines
modified:jinja2/compiler.py+12 added-7 removed
975 unmodified lines
976 self.writeline('%s event in template.root_render_func('977 'template.new_context(context.parent, True, '978 'locals())):' % loop)979 else:980 self.writeline('for event in template._get_default_module()'981 '._body_stream:')980 self.writeline('%s event in template._get_default_module_impl()'981 '._body_stream:' % loop)982983 self.indent()984 self.simple_write('event', frame)985 self.outdent()
7 unmodified lines
993 self.unoptimize_scope(frame)994 self.writeline('l_%s = ' % node.target, node)995 if frame.toplevel:996 self.write('context.vars[%r] = ' % node.target)997 if self.environment._async:998 self.write('await ')999 self.write('environment.get_template(')1000 self.visit(node.template, frame)1001 self.write(', %r).' % self.name)1002 if node.with_context:1001 self.write('make_module(context.parent, True, locals())')1003 self.write('make_module%s(context.parent, True, locals())'1004 % (self.environment._async and '_async' or ''))1005 else:1003 self.write('_get_default_module()')1006 self.write('_get_default_module_impl()')1007 if frame.toplevel and not node.target.startswith('_'):1008 self.writeline('context.exported_vars.discard(%r)' % node.target)1009 frame.assigned_names.add(node.target)10101011 def visit_FromImport(self, node, frame):1012 """Visit named imports."""1013 self.newline(node)1011 self.write('included_template = environment.get_template(')1014 self.write('included_template = %senvironment.get_template('1015 % (self.environment._async and 'await ' or ''))1016 self.visit(node.template, frame)1017 self.write(', %r).' % self.name)1018 if node.with_context:1015 self.write('make_module(context.parent, True)')1019 self.write('make_module%s(context.parent, True)'1020 % (self.environment._async and '_async' or ''))1021 else:1017 self.write('_get_default_module()')1022 self.write('_get_default_module_impl()')10231024 var_names = []1025 discarded_names = []1026 for name in node.names:
691 unmodified lines
modified:jinja2/environment.py+4 added
1040 unmodified lines
1041 return self._module1042 self._module = rv = self.make_module()1043 return rv10441045 # This is what the compiler dispatches to from generated code. It1046 # might get swapped out by the async support1047 _get_default_module_impl = _get_default_module10481049 @property1050 def module(self):1051 """The template as module. This is used for imports in the1052 template runtime but is also useful if one wants to access
179 unmodified lines