a `)@sdZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z dd l m Z dd l mZd d Zd dZddZddZddZddZddZe ddZddZd0ddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+ZGd,d-d-e Zd1d.d/Z edS)2zWThe code for async support. Importing this patches Jinja on supported Python versions. Nupdate_wrapper)Markup)TemplateModule) LoopContextconcat internalcode)missingcs&gfdd}|IdHtS)Ncs"2z3dHW}|q6dSN)append)event async_genrv7/usr/lib/python3.9/site-packages/jinja2/asyncsupport.pycollectszconcat_async..collectr)rrrrr concat_asyncs rcOs\t|i|}z*|||2z3dHW}|Vq 6WntyV|jVYn0dSr )dictroot_render_func new_context Exception environmenthandle_exception)selfargskwargsvarsrrrrgenerate_asyncs  r!cs ddfdd}t|S)Ncss>|j|i|}z||VqWnty8Yn0dSr )r!run_until_complete __anext__StopAsyncIteration)rlooprrrrrr_convert_generator's  z.wrap_generate_func.._convert_generatorcs0|jjs|g|Ri|S|t||Sr )ris_asyncasyncioget_event_loop)rrrr&original_generaterrgenerate/sz$wrap_generate_func..generater)r+r,rr*rwrap_generate_func&sr-cs`|jjstdt|i|}||}zt||IdHWStyZ|jYS0dS)Nz8The environment was not created with async mode enabled.) rr' RuntimeErrorrrrrrr)rrrr ctxrrr render_async7s  r0csfdd}t|S)Ncs<|jjs|g|Ri|St}||j|i|Sr )rr'r(r)r"r0)rrrr%original_renderrrrenderEsz wrap_render_func..renderr)r2r3rr1rwrap_render_funcDs r4cs(tddtfdd}t|S)Ncs2t|j|j|jIdH}|jjjr.t|}|Sr )rZ_stackZ_depth_contextZeval_ctx autoescaperrrrrr async_callOs z-wrap_block_reference_call..async_callcs|jjjs|S|Sr )r5rr'rr8 original_callrr__call__Vs z+wrap_block_reference_call..__call__r r)r;r<rr:rwrap_block_reference_callNs  r>cs(tddtfdd}t|S)Ncs |j|IdH}|rt|}|Sr )Z_funcr)r argumentsr6rrrr async_invoke`sz'wrap_macro_invoke..async_invokecs |jjs|||S|||Sr )Z _environmentr')rr?r6r@original_invokerr_invokegs z"wrap_macro_invoke.._invoker=)rBrCrrArwrap_macro_invoke_s  rDcs(|jdur|jS|IdH|_}|Sr )_modulemake_module_asyncr7rrrget_default_module_asyncps rGcstfdd}|S)Ncs|jjrtd|S)Nz6Template module attribute is unavailable in async mode)rr'r.r9original_default_modulerr_get_default_moduleysz0wrap_default_module.._get_default_moduler )rIrJrrHrwrap_default_modulexsrKFcsB||||}g}||2z3dHW}||q6t|||Sr )rrrr)rr ZsharedlocalscontextZ body_streamitemrrrrFs rFcCsdddlm}t|j|_tt|j|_tt|j|_t|j|_t |j |_ t |_ tt |j |_ dS)NrTemplate)rPr-r,rr!r0r4r3rKrJrGZ_get_default_module_asyncrFrOrrrpatch_templates    rRcCs,ddlm}m}t|j|_t|j|_dS)NrBlockReferenceMacro)runtimerTrUr>r<rDrCrSrrr patch_runtimes rWcCs&ddlm}ddlm}||dS)Nr)FILTERS) ASYNC_FILTERS)filtersrXZ asyncfiltersrYupdate)rXrYrrr patch_filterss  r\cCstttdSr )rRrWr\rrrr patch_allsr]cst|r|IdHS|Sr )inspectZ isawaitable)valuerrr auto_awaits  r`cCs<t|dr(|2z3dHW}|Vq6dS|D] }|Vq,dS)N __aiter__)hasattr)iterablerNrrr auto_aiters   rdc@sheZdZeeZeddZeddZeddZ ddZ ed d Z ed d Z d dZ ddZdS)AsyncLoopContextcsv|jdur|jSzt|j|_WnNtyndd|j2IdH}|||_t||j|jtu|_Yn0|jS)Ncsg|z3dHW}|q6Sr r).0xrrr z+AsyncLoopContext.length..) Z_lengthlenZ _iterable TypeError _iterator _to_iteratorindex_afterr )rrcrrrlengths    zAsyncLoopContext.lengthcs|jIdH|jSr )rprnr9rrr revindex0szAsyncLoopContext.revindex0cs|jIdH|jSr )rpindex0r9rrrrevindexszAsyncLoopContext.revindexcsF|jtur|jSz|jIdH|_Wnty>t|_Yn0|jSr )ror rlr#r$r9rrr _peek_nexts   zAsyncLoopContext._peek_nextcs|IdHtuSr )rtr r9rrrlastszAsyncLoopContext.lastcs$|IdH}|tur |dS|S)Nzthere is no next item)rtr Z _undefinedr7rrrnextitems zAsyncLoopContext.nextitemcCs|Sr rr9rrrraszAsyncLoopContext.__aiter__csL|jtur|j}t|_n|jIdH}|jd7_|j|_||_||fS)Nr)ror rlr#rrZ_currentZ_beforer7rrrr#s zAsyncLoopContext.__anext__N)__name__ __module__ __qualname__ staticmethodrdrmpropertyrprqrsrtrurvrar#rrrrres      recs&ddl}|jdtddt||||S)NrzRThis template must be recompiled with at least Jinja 2.11, or it will fail in 3.0.) stacklevel)warningswarnDeprecationWarningre)rcZ undefinedZrecurseZdepth0r~rrrmake_async_loop_contextsr)NFN)Nr)!__doc__r(r^ functoolsrZ markupsaferrrrVrZutilsr r r rr!r-r0r4r>rDrGrKrFrRrWr\r]r`rdrerrrrrs:              A