Add async flags
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 4fa3712 · Browse files · 2 files·+19 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
2 files+19 added−3 removed
- other:+19 added−3 removed
Provenance
- Commit
e908a58- Tree
661e419- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
4fa3712
2 files changed+19 added−3 removed
modified:jinja2/compiler.py+7 added
45 unmodified lines46 code_features.append('generator_stop')47 except SyntaxError:48 pass49 50+# does this python version support async for in and async generators?51+try:52+ exec('async def _():\n async for _ in ():\n yield _')53+ have_async_gen = True54+except SyntaxError:55+ have_async_gen = False56 57+58 # does if 0: dummy(x) get us x into the scope?59 def unoptimize_before_dead_code():60 x = 4261 def f():1641 unmodified linesmodified:jinja2/environment.py+12 added-3 removed
215 unmodified lines216 cache for the internal Jinja bytecode so that templates don't217 have to be parsed if they were not changed.218 219 See :ref:`bytecode-cache` for more information.220+221+ `enable_async`222+ If set to true this enables async template execution which allows223+ you to take advantage of newer Python features. This requires224+ Python 3.6 or later.225 """226 227 #: if this environment is sandboxed. Modifying this variable won't make228 #: the environment sandboxed though. For a real sandboxed environment43 unmodified lines272 autoescape=False,273 loader=None,274 cache_size=400,275 auto_reload=True,271- bytecode_cache=None):276+ bytecode_cache=None,277+ enable_async=False):278 # !!Important notice!!279 # The constructor accepts quite a few arguments that should be280 # passed by keyword rather than position. However it's important to281 # not change the order of arguments because it's used at least37 unmodified lines319 320 # load extensions321 self.extensions = load_extensions(self, extensions)322 323+ self.enable_async = enable_async324+325 _environment_sanity_check(self)326 327 def add_extension(self, extension):328 """Adds an extension after the environment was created.586 unmodified lines915 extensions=(),916 optimized=True,917 undefined=Undefined,918 finalize=None,911- autoescape=False):919+ autoescape=False,920+ enable_async=False):921 env = get_spontaneous_environment(922 block_start_string, block_end_string, variable_start_string,923 variable_end_string, comment_start_string, comment_end_string,924 line_statement_prefix, line_comment_prefix, trim_blocks,925 lstrip_blocks, newline_sequence, keep_trailing_newline,926 frozenset(extensions), optimized, undefined, finalize, autoescape,918- None, 0, False, None)927+ None, 0, False, None, enable_async)928 return env.from_string(source, template_class=cls)929 930 @classmethod931 def from_code(cls, environment, code, globals, uptodate=None):284 unmodified lines