lfLdZddlmZddlmZddlmZddlmZddlm Z ddlm Z e gdZ e gd Z ejejejejejejd ZGd d eZd S)z8Parse tokens from the lexer into nodes for the compiler.)nodes)imap)TemplateAssertionError)TemplateSyntaxError)describe_tokendescribe_token_expr) forifblockextendsprintmacroincludefromimportsetwith autoescape)eqneltlteqgtgteq)addsubmuldivfloordivmodcleZdZdZd7dZdefdZdZd8dZd9dZ d8dZ d8d Z d Z d:d Z d ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ d;dZdParserzThis is the central parsing class Jinja uses. It's passed to extensions and can be used to parse expressions or statements. Nc||_||||||_||_||_d|_i|_|D]}|jD]}|j |j|<d|_ g|_ g|_ dS)NF) environment _tokenizestreamnamefilenameclosed extensionsiter_extensionstagsparse_last_identifier _tag_stack_end_token_stack)selfr&sourcer)r*state extensiontags m/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/jinja2/parser.py__init__zParser.__init__+s&!++FD(EJJ     $4466 7 7I ~ 7 7'0$$ 7 ! "cX||jjj}||||j|j)zConvenience method that raises `exc` with the message, passed line number or last line number as well as the current name and filename. )r(currentlinenor)r*)r3msgr=excs r8failz Parser.fail9s0 >[(/Fc#vty$-888r:cg}|D]*}|tt|+|r&dd|dD}nd}|dg}nd|zg}|r7|||vr|d|zn|d|z|jr#|d|jdz|d ||dS) Nz or c3:K|]}dt|zVdS)z'%s'Nr).0exprs r8 z&Parser._fail_ut_eof..GsA,,7;,T222,,,,,,r:zUnexpected end of template.zEncountered unknown tag '%s'.z_You probably made a nesting mistake. Jinja is expecting this tag, but currently looking for %s.z-Jinja was looking for the following tags: %s.z4The innermost block that needs to be closed is '%s'. )extendrr joinappendr1r@)r3r)end_token_stackr=expectedexprscurrently_lookingmessages r8 _fail_ut_eofzParser._fail_ut_eofBs]$ > >E OOD!4e<< = = = =  % & ,,?Nr?R,,,!!  !%  <45GG6=>G  DH$4$4 12 -. ?  NN"$(OB$78    #((7##V,,,,,r:c:|||j|S)zCalled if the parser encounters an unknown tag. Tries to fail with a human readable error message that could help to identify the problem. )rPr2)r3r)r=s r8fail_unknown_tagzParser.fail_unknown_taggs   t' >vNNN r:c|jj}|jdkr|d|j|j|jd} |jtvrFt|d|jjjz|r|j SS|jdkr0| |r|j SS|jdkr0| |r|j SS|j |j}|'|||r|j SS|j d}||j|j|r|j dSdS#|r|j wwxYw) zParse a single statement.r)ztag name expectedTparse_callfilterNF)r(r<r\r@r=r1rJvalue_statement_keywordsgetattrpopparse_call_blockparse_filter_blockr,getrR)r3tokenpop_tagexts r8parse_statementzParser.parse_statements # :   II)5< 8 8 8 u{+++ &{111JwtX 0C0I%IJJLL  &##%%%% &{f$$,,.. &##%%%% &{h&&..00 &##%%%% &/%%ek22Cs4yy &##%%%% & O   ! ! !G  ! !%+u| < < < &##%%%%% & &w &##%%%% &s$7G)G$G+G';GGFc|jd|jd||}|jjjdkr|||rt|j|S)aRParse multiple statements into a list until one of the end tokens is reached. This is used to parse the body of statements as it also parses template data if appropriate. The parser checks first if the current token is a colon and skips it if there is one. Then it checks for the block end and parses until if one of the `end_tokens` is reached. Per default the active token in the stream at the end of the call is the matched end token. If this is not wanted `drop_needle` can be set to `True` and the end token is removed. colonrZeof)r(skip_ifexpectsubparser<r\rWnext)r3rU drop_needleresults r8parse_statementszParser.parse_statementss G$$$ ;'''z** ;  #u , , MM* % % %       r:crt|jj}|d}|jdr+|}t j|||S|d}| dd}t j ||||S)zParse an assign statement.T)with_namespaceassignraN)z name:endsetr~) r}r(r=parse_assign_targetrz parse_tuplerAssign parse_filterr AssignBlock)r3r=targetrD filter_nodebodys r8 parse_setzParser.parse_setsdk""))))>> ;  x ( ( =##%%D<V<<< <''-- $$%54$HH d6JJJJr:c 0|jdj}|d}|jd|dd}d}|jd r|}|jd }|d }t|jj d krg}n|d d}tj |||||||S)zParse a for loop.zname:for)name:in)r^rF)name:recursive) with_condexprr^Nname:ifr) name:endfor name:elseendfor)rTrra) r(r{r=rrrzparse_expressionrr}rlrFor)r3r=ritertest recursiverelse_s r8 parse_forzParser.parse_fors##J//6)),)GG 9%%%1D    ;  y ) ) +((**DK''(899 $$%ABB    "h . .EE))*:)MMEytUD)FSSSSr:c*tj|jdjx}} |d|_|d|_g|_ g|_ t|j}|dr?tj|jj j}|j ||dr|d d |_ |S) zParse an if construct.rrarFr) name:elifr name:endifrr)rTr)rIfr(r{r=rrrrelif_rr}r<rJ)r3noderrss r8parse_ifzParser.parse_ifs (:(:9(E(E(LMMMMv ((u(==DI--.VWWDIDJDJ%%Ezz+&& Xxt{':'ABBB ##D)))K(( X#44_RV4WW  r:cDtjt|jj}g}g}|jjjdkr|r|jd|}| d| ||jd| | |jjjdk||_ ||_ |dd|_|S) NrarZcommaparamr)z name:endwithTr)rWithr}r(r=r<r\r{rset_ctxrJrtargetsvaluesrr)r3rrrrs r8 parse_withzParser.parse_withs zdk!2!2!9:::k!&+55 , ""7+++--//F NN7 # # # NN6 " " " K  x ( ( ( MM$//11 2 2 2k!&+55  ))*;)NN  r:ctjt|jj}tjd|g|_|dd|_ tj |gS)Nrar)zname:endautoescapeTr) rScopedEvalContextModifierr}r(r=KeywordroptionsrrScoper3rs r8parse_autoescapezParser.parse_autoescapesq.d4;6G6G6NOOO lD4I4I4K4KLLM ))*At)TT {D6"""r:ctjt|jj}|jdj|_|jd|_ |jj j dkr| d| dd|_|jd |jz|S) Nrar)z name:scopedrzpBlock names in Jinja have to be valid Python identifiers and may not contain hyphens, use an underscore instead.)z name:endblockTrzname:)rBlockr}r(r=r{rlr)rzscopedr<r\r@rrrs r8 parse_blockzParser.parse_blocks{$t{"3"3":;;;K&&v..4 k))-88 ;  #u , , II&    ))*<$)OO  Gdi/000 r:ctjt|jj}||_|S)Nra)rExtendsr}r(r=rtemplaters r8 parse_extendszParser.parse_extendss9}D$5$5$<===--//  r:c$|jjddrh|jdr>C ((u555r:ctjtjj_jdg_fd} jrjdjj j dkr|rn d}|j d r"d |jt jd r= d}j|j |j fnj|j |sjj j dkrnnjdGt%d sd_S)Nraz name:importcjjjdvrijdr=t jjdk_jdSdS)N)rwithoutrrTF)r(r<rlrrr}rr)rr3sr8 parse_contextz(Parser.parse_from..parse_context=s}{"(-+""$$)).99%)$5$5$;v$E!   """t5r:rrr)Tr_z4names starting with an underline can not be imported)r?rrF)r FromImportr}r(r=rrr{namesr<r\rr) startswithr@rrzrJhasattrr)r3rraliasrs` @r8 parse_fromzParser.parse_from7stDK'8'8'?@@@--//  =)))        +z , ""7+++{"'611 =??11D1AA;))#..IIN 2 ;&&y113 44t4DDEJ%%v{EJ&?@@@@J%%fk222 =??dk&9&>'&I&I'J ""6***+ +,t^,, & %D  r:cPgx|_}gx|_}|jd|jjjdkr|r|jd|d}|d|jdr(| | n|r| d| ||jjjdk|jddS) Nlparenr[rTrrrz-non-default argument follows default argument) argsdefaultsr(r{r<r\rrrzrJrr@)r3rrrargs r8parse_signaturezParser.parse_signatureas$ D#%%  8$$$k!&(22 , ""7+++**T*::C KK {""8,, K 5 5 7 78888 K IJJJ KK   k!&(22 8$$$$$r:ctjt|jj}|jjjdkr||ng|_g|_ | |_ t|j tj s|d|j|dd|_|S)Nrarz expected call)z name:endcallTr)r CallBlockr}r(r=r<r\rrrrrj isinstanceCallr@rrrs r8rpzParser.parse_call_blockqsd4;&7&7&>??? ;  #x / /   & & & &DIDM))++ $)UZ00 4 IIot{ 3 3 3))*;)NN  r:ctjt|jj}|dd|_|dd|_|S)NraT) start_inline)zname:endfilterr) r FilterBlockr}r(r=rrkrrrs r8rqzParser.parse_filter_blocks\ T[(9(9(@AAA''4'@@ ))*=4)PP  r:ctjt|jj}|dj|_|||dd|_ |S)NraTr)z name:endmacror) rMacror}r(r=rr)rrrrs r8 parse_macrozParser.parse_macrosp{$t{"3"3":;;;,,t,<<A  T"""))*<$)OO  r:cZtjt|jj}g|_|jjjdkrb|jr|jd|j| |jjjdkb|S)NrarZr) rOutputr}r(r=r<r\r{rJrrs r8 parse_printzParser.parse_prints|4 #4#4#;<<< k!&+55z , ""7+++ J  d3355 6 6 6k!&+55 r:Tc|r|jjdkro|jd}t |j|jd}t j|j|j|j}n|r<|jd}t j |jd|j}nC|r| d|}n| }| d| s:|d|jjz|j|S)aParse an assignment target. As Jinja allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`. If only assignments to names are wanted `name_only` can be set to `True`. The `extra_end_rules` parameter is forwarded to the tuple parsing function. If `with_namespace` is enabled, a namespace assignment may be parsed. dotr)rastoreT) simplifiedr^zcan't assign to %r)r(rr\r{r}rNSRefrlr=Namer parse_primaryr can_assignr@ __class____name__lower)r3 with_tuplerr^rrsattrrs r8rzParser.parse_assign_targetsU  $dk..005>>K&&v..E    ;%%f--D[djNNNFF  $K&&v..EZ WU\JJJFF .))#_*++-- NN7 # # #  ""  II$v'7'@'F'F'H'HH&-    r:cV|r|S|S)zParse an expression. Per default all expressions are parsed, if the optional `with_condexpr` parameter is set to `False` conditional expressions are not parsed. )parse_condexprparse_or)r3rs r8rzParser.parse_expressions,  )&&(( (}}r:c|jjj}|}|jdr|}|jdr|}nd}t j||||}|jjj}|jd|S)Nrrra)r(r<r=rrzrrCondExpr)r3r=expr1expr2expr3s r8rzParser.parse_condexprs$+ k!!),, 0MMOOE{"";// ++--N5%vFFFE[(/Fk!!),, 0 r:c0|jjj}|}|jdrV|}t j|||}|jjj}|jdV|S)Nname:orra)r(r<r= parse_andrzrOrr3r=leftrights r8rzParser.parse_ors$+~~k!!),, 0NN$$E8D%777D[(/Fk!!),, 0 r:c0|jjj}|}|jdrV|}t j|||}|jjj}|jdV|S)Nname:andra)r(r<r= parse_notrzrAndrs r8rzParser.parse_ands$+~~k!!*-- 0NN$$E9T5888D[(/Fk!!*-- 0 r:c|jjdrAt|jj}t j||S|S)Nname:notra) r(r<rr}r=rNotr  parse_compare)r3r=s r8r zParser.parse_nots` ;  # #J / / >$+&&-F9T^^--f=== =!!###r:cl|jjj}|}g} |jjj}|t vrOt |j|tj ||n|j dr;|tj d|n|jj dr|j drU|j d|tj d|nn|jjj}r|s|Stj|||S)Nrrinr rnotinra)r(r<r= parse_math1r\_compare_operatorsr}rJrOperandrzrrrCompare)r3r=rDops token_types r8rzParser.parse_compares$+!! 0,1J///T[!!! 5=T5E5E5G5GHHIIII$$Y//  5=t/?/?/A/ABBCCCC$))*55 $+:J:J:L:L:Q:Q;;    ### 5=$2B2B2D2DEEFFFF[(/F 0 K}T3v6666r:cb|jjj}|}|jjjdvrvt |jjj}t |j|}||||}|jjj}|jjjdvv|S)N)rrra)r(r<r= parse_concatr\ _math_nodesr}r3r=rclsrs r8rzParser.parse_math1s$+  ""k!&.88dk167C    %%''E3tU6222D[(/F k!&.88  r:cz|jjj}|g}|jjjdkrPt |j|||jjjdkPt|dkr|dStj ||S)Ntilderr%ra) r(r<r= parse_math2r\r}rJlenrConcat)r3r=rs r8rzParser.parse_concat s$+  ""#k!&'11     KK((** + + +k!&'11 t99>>7N|D0000r:cb|jjj}|}|jjjdvrvt |jjj}t |j|}||||}|jjj}|jjjdvv|S)N)rrr r!ra)r(r<r= parse_powr\rr}rs r8r zParser.parse_math2s$+~~k!&*KKKdk167C    NN$$E3tU6222D[(/F k!&*KKK  r:cD|jjj}|}|jjjdkret |j|}t j|||}|jjj}|jjjdke|S)Npowra)r(r<r= parse_unaryr\r}rPowrs r8r$zParser.parse_pows$+!!k!&%//    $$&&E9T5888D[(/F k!&%//  r:c|jjj}|jjj}|dkr>t |jt j|d|}nX|dkr>t |jt j|d|}n| }| |}|r| |}|S)NrFrar) r(r<r\r=r}rNegr'Posr parse_postfixparse_filter_expr)r3 with_filterrr=rs r8r'zParser.parse_unary)s[(- $+       9T--e44VDDDDD 5    9T--e44VDDDDD%%''D!!$''  0))$//D r:c|jj}|jdkr|jdvr#t j|jdv|j}nF|jdvrt jd|j}n!t j|jd|j}t|jn|jdkrt|j|jg}|j}|jjjdkrM| |jjjt|j|jjjdkMt jd ||}n|jd vr5t|jt j|j|j}n|jd krEt|j| d }|j d nk|jdkr| }nK|jdkr|}n+|dt!|z|j|S)Nr))truefalseTrueFalse)r0r2ra)noneNoneloadstring)integerfloatrT)explicit_parenthesesr[lbracketlbracezunexpected '%s')r(r<r\rlrConstr=rr}rJrIrr{ parse_list parse_dictr@r)r3rsrbufr=s r8rzParser.parse_primary9s$ # :  {@@@{5;2B#B5<XXX 000{4 ===z%+velKKK      Z8 # #    ;-C\F+%*h66 4;.4555T[!!!+%*h66;rwws||F;;;DD Z/ / /    ;u{5<@@@DD Z8 # #    ###>>D K  x ( ( ( ( Z: % %??$$DD Z8 # #??$$DD II'.*?*?? N N N r:cjjj}|rj}n|rj}nfd}g}d} |rjd|rnH||jjjdkrd}nnjjj}z|s;|r|dS|s/ dtjjztj |d| S) aWorks like `parse_expression` but if multiple expressions are delimited by a comma a :class:`~jinja2.nodes.Tuple` node is created. This method could also return a regular expression instead of a tuple if no commas where found. The default parsing mode is a full tuple. If `simplified` is `True` only names and literals are parsed. The `no_condexpr` parameter is forwarded to :meth:`parse_expression`. Because tuples do not require delimiters and may end in a bogus comma an extra hint is needed that marks the end of a tuple. For example for loops support tuples between `for` and `in`. In that case the `extra_end_rules` is set to ``['name:in']``. `explicit_parentheses` is true if the parsing was triggered by an expression in parentheses. This is used to figure out if an empty tuple is a valid expression or not. c0dS)NFr)r)r3sr8r/z!Parser.parse_tuple..parsezs,,5,AAAr:FrrTr%z Expected an expression, got '%s'r6ra) r(r<r=rrr{r_rJr\r@rrTuple) r3rrr^r;r=r/ris_tuples ` r8rzParser.parse_tupleZsQ2$+  B&EE  B)EE B B B B B 0 , ""7+++  11  KK {"'722[(/F 0  Aw (  6$T[%899: {47777r:c|jd}g}|jjjdkrn|r|jd|jjjdkrn<|||jjjdkn|jdt j||jS)Nr<rbracketrra) r(r{r<r\rJrrListr=)r3rsitemss r8r?zParser.parse_lists "":..k!&*44 , ""7+++{"':55 LL..00 1 1 1 k!&*44 :&&&z% 5555r:c>|jd}g}|jjjdkr|r|jd|jjjdkrn|}|jd|}|t j|||j|jjjdk|jdt j ||jS)Nr=rbracerrxra) r(r{r<r\rrJrPairr=Dict)r3rsrIkeyrls r8r@zParser.parse_dicts ""8,,k!&(22 , ""7+++{"'833''))C K  w ' ' '))++E LLCszBBB C C Ck!&(22 8$$$z% 5555r:c |jjj}|dks|dkr||}n|dkr||}nnQ|S)Nrrr<r)r(r<r\parse_subscript parse_callr3rrs r8r,zParser.parse_postfixsm ,1JU""jJ&>&>++D11x''t,,  r:c |jjj}|dkr||}nN|dkr+|jjjdkr||}n|dkr||}nn||S)Nrpiper)isr)r(r<r\rrl parse_testrQrRs r8r-zParser.parse_filter_exprs ,1JV##((..v%%$+*=*Ct*K*Kt,,x''t,,  r:ct|j}|jdkr|jj}t|j|jdkr"t j||jd|jS|jdkr|d|jt j |j|j}t j ||d|jS|jdkrg}|jjjdkrX|r|j d | | |jjjdkX|j dt|d kr |d }nt j|d|j}t j ||d|jS|d |jdS) Nrr)r6rar9zexpected name or numberr<rGrrr%zexpected subscript expression)r}r(r\r<rGetattrrlr=r@r>Getitemr{rJparse_subscribedr!rD)r3rrs attr_tokenrrs r8rPzParser.parse_subscriptsT[!! :  ,J    &((}**F5<I-- 3Z5FGGG+j.z7HIIIC=sF5<HHH H : # #D+%*j880K&&w/// D1133444+%*j88 K  z * * *4yyA~~1gk$u|DDD=sF5<HHH H 15<@@@@@r:c8|jjj}|jjjdkrt |jdg}nB|}|jjjdkr|St |j|g}|jjjdkr|dnP|jjjdvr(||n|d|jjjdkret |j|jjjdvr(||n+|dn|dtj|d|iS)Nrx)rGrr=) r(r<r=r\r}rrJrSlice)r3r=rrs r8rZzParser.parse_subscribeds~$+ ;  #w . .    6DD((**D{"'722    6D ;  #w . . KK     [ %-B B B KK--// 0 0 0 0 KK    ;  #w . .    {"'/DDD D11334444 D!!!! KK   {40&000r:c jd g}g}dx}}d} fd}jjjdkr|r1jdjjjdkrnjjjdkr;||duo|dut j}n9jjjdkr6||dut j}njjjdkrjjd kr|||dujjj}jd } | tj || | j n;||duo|duo| | d }jjjdkԉjd|||||fStj ||||| j S) NrFcF|sdjdSdS)Nz+invalid syntax for function call expression)r@r=)rDr3rss r8ensurez!Parser.parse_call..ensures5 W GVVVVV W Wr:r[rrr&r)rrraT)r(r{r<r\r}rrrlrrJrrr=r) r3rrkwargsdyn_args dyn_kwargs require_commar`rNrlrss ` @r8rQzParser.parse_call s ""8,, $$:  W W W W W Wk!&(22  ""7+++;&+x77{"'500x4'>J$,>???T[!!!0022$)U22zT)***T[!!!!2244 K',66 ((**/8;;F:-...+-3CK$$Q''' 1133EMM%-U5<"P"P"PQQQQF8t+Q d0BQ6zRRRKK 5 5 7 7888 M=k!&(22> 8$$$ <:5 5z$fh 5<XXXXr:c P|jjjdks|r |st|j|jd}|j}|jjjdkrNt|j|d|jdjzz }|jjjdkN|jjjdkr|d\}}}}ng}g}dx}}tj|||||||j }d}|jjjdk | |S)NrTr)r.rraF) r(r<r\r}r{rlrQrFilterr=) r3rrrsr)rrarbrcs r8rzParser.parse_filter<s<k!&&00L0 "T[!!!K&&v..E;D+%*e33T[!!!dk0088>>>+%*e33{"'83359__T5J5J2fh (,,:<dD&(Ju|D!L#k!&&00L0$ r:c t|j}|jjdrt|jd}nd}|jdj}|jjjdkrNt|j|d|jdjzz }|jjjdkNdx}}g}|jjjdkr|d\}}}}n|jjjdvr|jjd d d sa|jjd r| d | } | | } | g}ng}tj |||||||j}|rtj||j}|S)Nr TFr)rrfr)r)r7r9r:rr<r=rrr zname:isz'You cannot chain multiple tests with isra)r}r(r<rr{rlr\rQr]r@rr,rTestr=r) r3rrsnegatedr)rbrcrararg_nodes r8rVzParser.parse_testQsT[!! ;  # #J / /     GGG{!!&))/k!&%//     C$+,,V44:: :Dk!&%//!%$: ;  #x / /151F1F .D&(JJ [ %*   +%..{IzRR {"'' 22 E CDDD))++H))(33H:DDDz $fh 5<     89T%,777D r:c6ggj}||j|fd} |jr|jj}|jdkrF|jr)|t j|j|jt|jn4|jdkrNt|j|| d|j dn|jdkr|t|j|2|jjj |r||j SS|}t|t r|n||j d nt%d |j|||j n!#||j wwxYwS) NcrEdj}tjdd|dd=dSdS)Nr%ra)r=rJrr)r=r data_buffers r8 flush_dataz#Parser.subparse..flush_datasY #$Q. ELQQQGGGHHHNNN # #r:dataravariable_beginTrrY block_beginrZzinternal parsing error)rJr2r(r<r\rlr TemplateDatar=r}rr{r]rorvrrTrHAssertionError)r3rUadd_datarorsrfrrns @@r8r|zParser.subparsewsU %  !  ! ( ( 4 4 4 # # # # # #  ,+ C +:''{W !3EK !U!U!UVVV%%%%Z#333%%%HT--D-AABBBK&&~6666Z=00JLLL%%%!-2N$+2E2N#3- $%%))++++&--//B!"d++( B BK&&{3333()ABBB1+ C4 JLLL%%))+++%%))++++& sC>G8 BG88Hctj|d}||j|S)z0Parse the whole template into a `Template` node.rra)rTemplater|set_environmentr&)r3rs r8r/z Parser.parses: :::t/000 r:)NNN)N)NN)F)TFNF)T)FTNF)7r __module__ __qualname____doc__r9rr@rPrRrWr_rgrvrrrrrrrrrrrrrrprqrrrrrrrr rrrr r$r'rrr?r@r,r-rPrZrQrrVr|r/r:r8r#r#&s # # # # $)<9999#-#-#-JFFFF6666&&&86 K K KTTT&$"### &  5 5 5666(((T%%%     ####J   $$$ 777.   111    F" ?8?8?8?8B 6 6 6 6 6 6      AAA6111>.Y.Y.Y`*$$$L....`r:r#N)r{r8r_compatr exceptionsrrlexerrr frozensetrmrAddSubMulDivFloorDivModrrbr#r|r:r8rs>>......++++++!!!!!!&&&&&&i    YGGGHH 9 9 9 9 9  EEEEEVEEEEEr: