From 3642ae7fef491222fb81fa3c0ae01bffca25fa41 Mon Sep 17 00:00:00 2001 From: remidebette Date: Tue, 2 Mar 2021 23:12:30 +0100 Subject: NativeEnvironment supports async mode --- src/jinja2/nativetypes.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src') diff --git a/src/jinja2/nativetypes.py b/src/jinja2/nativetypes.py index 3ac70cf..8867a31 100644 --- a/src/jinja2/nativetypes.py +++ b/src/jinja2/nativetypes.py @@ -93,5 +93,19 @@ class NativeTemplate(Template): except Exception: return self.environment.handle_exception() + async def render_async(self, *args, **kwargs): + if not self.environment.is_async: + raise RuntimeError( + "The environment was not created with async mode enabled." + ) + + vars = dict(*args, **kwargs) + ctx = self.new_context(vars) + + try: + return native_concat([n async for n in self.root_render_func(ctx)]) + except Exception: + return self.environment.handle_exception() + NativeEnvironment.template_class = NativeTemplate -- cgit v1.2.1