Lazy asyncsupport.patch_all()

fixes #765
This commit is contained in:
INADA Naoki 2018-02-06 21:52:57 +09:00
parent c0c3b7879e
commit 2c49d14cec
3 changed files with 5 additions and 11 deletions

View File

@ -70,14 +70,3 @@ __all__ = [
'evalcontextfilter', 'evalcontextfunction', 'make_logging_undefined',
'select_autoescape',
]
def _patch_async():
from jinja2.utils import have_async_gen
if have_async_gen:
from jinja2.asyncsupport import patch_all
patch_all()
_patch_async()
del _patch_async

View File

@ -254,3 +254,6 @@ async def make_async_loop_context(iterable, undefined, recurse=None, depth0=0):
after = _last_iteration
return AsyncLoopContext(async_iterator, undefined, after, length, recurse,
depth0)
patch_all()

View File

@ -334,6 +334,8 @@ class Environment(object):
self.enable_async = enable_async
self.is_async = self.enable_async and have_async_gen
if self.is_async:
import jinja2.asyncsupport # runs patch_all() once
_environment_sanity_check(self)