
    +b                     >   U d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ej                  r
ddlZdd	lmZ  ej                   d
ej"                  ej$                        Z ej                   dej(                  ej*                        Z eg d      Z eg d      Zej4                  ej6                  ej8                  ej:                  ej<                  ej>                  dZ ejB                  e"ejF                  ejH                     f   e%d<    G d d      Z&y)z8Parse tokens from the lexer into nodes for the compiler.    N   )nodes)TemplateAssertionError)TemplateSyntaxError)describe_token)describe_token_expr)Environment_ImportInclude
_MacroCall)forifblockextendsprintmacroincludefromimportsetwith
autoescape)eqneltlteqgtgteq)addsubmuldivfloordivmod_math_nodesc                   P   e Zd ZdZ	 	 	 dSdddedej                  e   dej                  e   dej                  e   d	dfd
Zdefdedej                  e	   dej                  e   d	dfdZdej                  e   dej                  ej                  edf      dej                  e	   d	dfdZ	 dTdedej                  e	   d	dfdZ	 	 dUdej                  ej                  edf      dej                  e	   d	dfdZ	 dTdej                  ej                  edf      d	efdZdTdej                  e	   d	ej(                  fdZd	ej,                  ej.                  ej                  ej.                     f   fdZ	 dVdej                  edf   ded	ej                  ej.                     fdZd	ej,                  ej4                  ej6                  f   fdZd	ej:                  fdZd	ej>                  fdZ d	ejB                  fdZ"d	ejF                  fd Z$d	ejJ                  fd!Z&d	ejN                  fd"Z(d#e)d$ed	e)fd%Z*d	ejV                  fd&Z,d	ejZ                  fd'Z.d	ej^                  fd(Z0d#e1d	dfd)Z2d	ejf                  fd*Z4d	ejj                  fd+Z6d	ejn                  fd,Z8d	ejr                  fd-Z:e;jx                  	 dWd.ed/d0d	ejz                  fd1       Z>e;jx                  	 	 	 	 dXd.ed/edej                  ej                  edf      d2ed	ej,                  ej~                  ejz                  ej                  f   f
d3       Z>	 	 	 	 dXd.ed/edej                  ej                  edf      d2ed	ej,                  ej~                  ejz                  ej                  f   f
d4Z>dYd5ed	ej                  fd6ZAd	ej                  fd7ZBd	ej                  fd8ZCd	ej                  fd9ZDd	ej                  fd:ZEd	ej                  fd;ZFd	ej                  fd<ZGd	ej                  fd=ZHd	ej                  fd>ZId	ej                  fd?ZJdYd@ed	ej                  fdAZKd	ej                  fdBZL	 	 	 	 dZdCed5edej                  ej                  edf      dDed	ej,                  ej                  ej                  f   f
dEZMd	ej                  fdFZNd	ej                  fdGZPd#ej                  d	ej                  fdHZQd#ej                  d	ej                  fdIZRd#ej                  d	ej,                  ej                  ej                  f   fdJZUd	ej                  fdKZVd	ej                  fdLZWd#ej                  d	ej                  fdMZY	 dVd#ej                  ej                     dNed	ej                  ej                     fdOZZd#ej                  d	ej                  fdPZ[	 dTdej                  ej                  edf      d	ej                  ej.                     fdQZ\d	ej                  fdRZ^y)[ParserzThis is the central parsing class Jinja uses.  It's passed to
    extensions and can be used to parse expressions or statements.
    Nenvironmentr	   sourcenamefilenamestatereturnc                 $   || _         |j                  ||||      | _        || _        || _        d| _        i | _        |j                         D ],  }|j                  D ]  }|j                  | j                  |<    . d| _
        g | _        g | _        y )NFr   )r'   	_tokenizestreamr)   r*   closed
extensionsiter_extensionstagsparse_last_identifier
_tag_stack_end_token_stack)selfr'   r(   r)   r*   r+   	extensiontags           //usr/lib/python3/dist-packages/jinja2/parser.py__init__zParser.__init__3   s     '!++FD(EJ	   	 %446 	7I ~~ 7'0$7	7 !"');=    msglinenoexczte.NoReturnc                     | | j                   j                  j                  } |||| 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/   currentr?   r)   r*   )r8   r>   r?   r@   s       r;   failzParser.failJ   s7     >[[((//F#vtyy$--88r=   end_token_stack.c           
         t               }|D ]!  }|j                  t        t        |             # |r1dj	                  t        t
        t        t        |d                     }nd }|dg}nd|dg}|r1|||v r|j                  d| d       n|j                  d| d       | j                  r"|j                  d| j                  d   d       | j                  d	j	                  |      |       y )
Nz or zUnexpected end of template.zEncountered unknown tag .z\You probably made a nesting mistake. Jinja is expecting this tag, but currently looking for z*Jinja was looking for the following tags: z/The innermost block that needs to be closed is  )	r   updatemapr   joinreprappendr6   rC   )r8   r)   rD   r?   expectedexprscurrently_lookingmessages           r;   _fail_ut_eofzParser._fail_ut_eofX   s     #u$ 	=EOOC 3U;<	=17D#1?23FGH2 !%<45G1$;<GDH$422C1DAG
 @AR@SSTU ??NNOOB'*!-
 			#((7#V,r=   c                 >    | j                  || j                  |       y)zCalled if the parser encounters an unknown tag.  Tries to fail
        with a human readable error message that could help to identify
        the problem.
        N)rR   r7   )r8   r)   r?   s      r;   fail_unknown_tagzParser.fail_unknown_tag   s     	$ 5 5v>r=   
end_tokensc                 z    t        | j                        }||j                  |       | j                  d||       y)z9Like fail_unknown_tag but for end of template situations.N)listr7   rM   rR   )r8   rU   r?   stacks       r;   fail_eofzParser.fail_eof   s8     T**+!LL$$v.r=   extra_end_rulesc                     | j                   j                  j                  dv ry|%| j                   j                  j                  |      S y)zAre we at the end of a tuple?)variable_end	block_endrparenTF)r/   rB   typetest_any)r8   rZ   s     r;   is_tuple_endzParser.is_tuple_end   sD     ;;##'NN(;;&&//@@r=   c                     | xj                   dz  c_         t        j                  t        j                        }t        j
                  j                  |d| j                    |       |S )zDReturn a new free identifier as :class:`~jinja2.nodes.InternalName`.r   fir?   )r5   object__new__r   InternalNameNoder<   )r8   r?   rvs      r;   free_identifierzParser.free_identifier   sS    "^^E../

B"T%:%:$; <VL	r=   c                 &   | j                   j                  }|j                  dk7  r| j                  d|j                         | j
                  j                  |j                         d}	 |j                  t        v rQt        | d| j                   j                  j                         } |       |r| j
                  j                          S S |j                  dk(  r-| j                         |r| j
                  j                          S S |j                  dk(  r-| j                         |r| j
                  j                          S S | j                  j                  |j                        }|% ||       |r| j
                  j                          S S | j
                  j                          d}| j                  |j                  |j                         |r| j
                  j                          yy# |r| j
                  j                          w w xY w)	zParse a single statement.r)   ztag name expectedTparse_callfilterNF)r/   rB   r_   rC   r?   r6   rM   value_statement_keywordsgetattrpopparse_call_blockparse_filter_blockr1   getrT   )r8   tokenpop_tagfexts        r;   parse_statementzParser.parse_statement   s   ##::II)5<<8u{{+	&{{11DF4;;+>+>+D+D*E"FGs  ##%  {{f$,,. ##%  {{h&..0 ##%  //%%ekk2C4y ##% 	 OO!G!!%++u||<##% w##% s&   *AG1 G1 	G1 .G1 AG1 1Hdrop_needlec                 *   | j                   j                  d       | j                   j                  d       | j                  |      }| j                   j                  j
                  dk(  r| j                  |       |rt        | j                          |S )aR  Parse 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.
        colonr]   eof)r/   skip_ifexpectsubparserB   r_   rY   next)r8   rU   r{   results       r;   parse_statementszParser.parse_statements   sr     	G$ 	;'z* ;;##u,MM*%r=   c                 d   t        | j                        j                  }| j                  d      }| j                  j	                  d      r(| j                         }t        j                  |||      S | j                  d      }| j                  dd      }t        j                  ||||      S )zParse an assign statement.T)with_namespaceassignrd   N)zname:endsetr{   )r   r/   r?   parse_assign_targetr   parse_tupler   Assignparse_filterr   AssignBlock)r8   r?   targetexprfilter_nodebodys         r;   	parse_setzParser.parse_set   s    dkk")))))>;;x(##%D<<V<<''-$$%54$H  d6JJr=   c           	      &   | j                   j                  d      j                  }| j                  d      }| j                   j                  d       | j	                  dd      }d}| j                   j                  d	      r| j                         }| j                   j                  d
      }| j                  d      }t        | j                         j                  dk(  rg }n| j                  dd      }t        j                  |||||||      S )zParse a for loop.zname:for)name:in)rZ   r   F)name:recursive)with_condexprrZ   Nname:ifr   )name:endfor	name:elseendfor)r   Tr   rd   )r/   r   r?   r   r   r   parse_expressionr   r   ro   r   For)r8   r?   r   itertest	recursiver   else_s           r;   	parse_forzParser.parse_for   s    ##J/66)),)G9%1D   
 ;;y)((*DKK''(89	$$%AB""h.E))*:)MEyytUD)FSSr=   c                 4   t        j                  | j                  j                  d      j                        x}}	 | j                  d      |_        | j                  d      |_        g |_	        g |_
        t        | j                        }|j                  d      rPt        j                  | j                  j                  j                        }|j                  j                  |       |j                  d      r| j                  d	d
      |_
        	 |S )zParse an if construct.r   rd   TFr   )	name:elifr   
name:endifr   r   )r   r   )r   Ifr/   r   r?   r   r   r   r   elif_r   r   rB   rM   )r8   noder   rv   s       r;   parse_ifzParser.parse_if   s    (:(:9(E(L(LMMv((u(=DI--.VWDIDJDJ%Ezz+&xxt{{':':'A'AB##D)K(#44_RV4Wr=   c                 `   t        j                  t        | j                        j                        }g }g }| j                  j
                  j                  dk7  r|r| j                  j                  d       | j                         }|j                  d       |j                  |       | j                  j                  d       |j                  | j                                | j                  j
                  j                  dk7  r||_        ||_        | j                  dd      |_        |S )	Nrd   r]   commaparamr   )zname:endwithTr   )r   Withr   r/   r?   rB   r_   r   r   set_ctxrM   r   targetsvaluesr   r   )r8   r   r   r   r   s        r;   
parse_withzParser.parse_with  s    zzdkk!2!9!9:&(%'kk!!&&+5""7+--/FNN7#NN6"KKx(MM$//12 kk!!&&+5 ))*;)N	r=   c                    t        j                  t        | j                        j                        }t        j
                  d| j                               g|_        | j                  dd      |_	        t        j                  |g      S )Nrd   r   )zname:endautoescapeTr   )r   ScopedEvalContextModifierr   r/   r?   Keywordr   optionsr   r   Scoper8   r   s     r;   parse_autoescapezParser.parse_autoescape   sh    ..d4;;6G6N6NOlD4I4I4KLM))*At)T	{{D6""r=   c                    t        j                  t        | j                        j                        }| j                  j                  d      j                  |_        | j                  j                  d      |_	        | j                  j                  d      |_
        | j                  j                  j                  dk(  r| j                  d       | j                  dd	      |_        |j                  r-t!        d
 |j                  D              s| j                  d       | j                  j                  d|j                  z          |S )Nrd   r)   zname:scopedzname:requiredr   zpBlock names in Jinja have to be valid Python identifiers and may not contain hyphens, use an underscore instead.)zname:endblockTr   c              3      K   | ]K  }|j                   D ]:  }t        |t         j                        xr |j                  j	                          < M y wN)r   
isinstanceTemplateDatadataisspace).0r   childs      r;   	<genexpr>z%Parser.parse_block.<locals>.<genexpr>:  sS      %
%
  ue001Jejj6H6H6JJ%
J%
s   AAz7Required blocks can only contain comments or whitespacezname:)r   Blockr   r/   r?   r   ro   r)   r   scopedrequiredrB   r_   rC   r   r   allr   s     r;   parse_blockzParser.parse_block&  s    {{$t{{"3":":;KK&&v.44	kk))-8++O<
 ;;##u,II?
 ))*<$)O	
 == %
		%
 "

 IIOPGdii/0r=   c                     t        j                  t        | j                        j                        }| j                         |_        |S Nrd   )r   Extendsr   r/   r?   r   templater   s     r;   parse_extendszParser.parse_extendsD  s4    }}D$5$<$<=--/r=   r   defaultc                 8   | j                   j                  j                  dd      rl| j                   j                         j	                  d      rCt        | j                         j                  dk(  |_        | j                   j                          |S ||_        |S )Nz	name:withzname:withoutname:contextr   )	r/   rB   r`   lookr   r   ro   with_contextskip)r8   r   r   s      r;   parse_import_contextzParser.parse_import_contextI  s~     ;;''
kk %%n5 $T[[ 1 7 76 ADKK  !(Dr=   c                    t        j                  t        | j                        j                        }| j                         |_        | j                  j                  j                  d      rL| j                  j                         j                  d      r#d|_
        | j                  j                  d       nd|_
        | j                  |d      S )Nrd   zname:ignorezname:missingT   F)r   Includer   r/   r?   r   r   rB   r   r   ignore_missingr   r   r   s     r;   parse_includezParser.parse_includeU  s    }}D$5$<$<=--/;;##M2t{{7G7G7I7N7N8
 #'DKKQ"'D((t44r=   c                 .   t        j                  t        | j                        j                        }| j                         |_        | j                  j                  d       | j                  d      j                  |_
        | j                  |d      S )Nrd   name:asT	name_onlyF)r   Importr   r/   r?   r   r   r   r   r)   r   r   r   s     r;   parse_importzParser.parse_importa  so    ||4#4#;#;<--/9%...>CC((u55r=   c                     t        j                  t         j                        j                         j                         _         j                  j                  d       g _        dt        f fd}	 j                  r j                  j                  d        j                  j                  j                  dk(  r |       rn j                  d      }|j                  j                  d	      r" j                  d
|j                  t                 j                  j#                  d      rD j                  d      }j                  j%                  |j                  |j                  f       n%j                  j%                  |j                          |       s# j                  j                  j                  dk7  rn j                  j                  d       ot'        d      sd_        S )Nrd   zname:importr,   c                      j                   j                  j                  dv rkj                   j                         j	                  d      rBt        j                         j                  dk(   _        j                   j                          yy)N>   r   withoutr   r   TF)r/   rB   ro   r   r   r   r   r   )r   r8   s   r;   parse_contextz(Parser.parse_from.<locals>.parse_contextn  so    {{""(( -  ++""$)).9$($5$;$;v$E!  "r=   Tr   r)   r   _z4names starting with an underline can not be imported)r@   r   r   F)r   
FromImportr   r/   r?   r   r   r   namesboolrB   r_   r   r)   
startswithrC   r   r   rM   hasattrr   )r8   r   r   aliasr   s   `   @r;   
parse_fromzParser.parse_fromh  s   tDKK'8'?'?@--/=)
	t 	 zz""7+{{""''61 ?11D1A;;))#.IIN2  
 ;;&&y1 44t4DEJJ%%v{{EJJ&?@JJ%%fkk2 ?dkk&9&9&>&>'&I""6*+ , t^, %Dr=   c                 `   g x}|_         g x}|_        | j                  j                  d       | j                  j                  j
                  dk7  r|r| j                  j                  d       | j                  d      }|j                  d       | j                  j                  d      r |j                  | j                                n|r| j                  d       |j                  |       | j                  j                  j
                  dk7  r| j                  j                  d       y )	Nlparenr^   r   Tr   r   r   z-non-default argument follows default argument)argsdefaultsr/   r   rB   r_   r   r   r   rM   r   rC   )r8   r   r   r   args        r;   parse_signaturezParser.parse_signature  s    ty#%%4=8$kk!!&&(2""7+**T*:CKK {{""8, 5 5 78		IJKK kk!!&&(2 	8$r=   c                    t        j                  t        | j                        j                        }| j                  j
                  j                  dk(  r| j                  |       ng |_        g |_	        | j                         }t        |t         j                        s| j                  d|j                         ||_        | j                  dd      |_        |S )Nrd   r   zexpected call)zname:endcallTr   )r   	CallBlockr   r/   r?   rB   r_   r   r   r   r   r   CallrC   rm   r   r   )r8   r   	call_nodes      r;   rs   zParser.parse_call_block  s    d4;;&7&>&>?;;##x/  &DIDM))+	)UZZ0IIot{{3	))*;)N	r=   c                     t        j                  t        | j                        j                        }| j                  d d      |_        | j                  dd      |_        |S )Nrd   T)start_inline)zname:endfilterr   )	r   FilterBlockr   r/   r?   r   rn   r   r   r   s     r;   rt   zParser.parse_filter_block  sU      T[[(9(@(@A''4'@))*=4)P	r=   c                     t        j                  t        | j                        j                        }| j                  d      j                  |_        | j                  |       | j                  dd      |_	        |S )Nrd   Tr   )zname:endmacror   )
r   Macror   r/   r?   r   r)   r   r   r   r   s     r;   parse_macrozParser.parse_macro  se    {{$t{{"3":":;,,t,<AA	T"))*<$)O	r=   c                    t        j                  t        | j                        j                        }g |_         | j                  j
                  j                  dk7  rt|j                   r| j                  j                  d       |j                   j                  | j                                | j                  j
                  j                  dk7  rt|S )Nrd   r]   r   )
r   Outputr   r/   r?   rB   r_   r   rM   r   r   s     r;   parse_printzParser.parse_print  s    ||4#4#;#;<
kk!!&&+5zz""7+JJd3356 kk!!&&+5 r=   
with_tupler   zte.Literal[True]c                      y r    )r8   r   r   s      r;   r   zParser.parse_assign_target  s     	r=   r   c                      y r   r   )r8   r   r   rZ   r   s        r;   r   zParser.parse_assign_target  s     	r=   c                    |r| j                   j                         j                  dk(  r| j                   j                  d      }t	        | j                          | j                   j                  d      }t        j                  |j                  |j                  |j                        }n|rH| j                   j                  d      }t        j                  |j                  d|j                        }n7|r| j                  d|      }n| j                         }|j                  d       |j                         s@| j                  dt        |      j                  j!                         |j                         |S )a  Parse 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)   rd   storeT)
simplifiedrZ   zcan't assign to )r/   r   r_   r   r   r   NSRefro   r?   Namer   parse_primaryr   
can_assignrC   __name__lower)r8   r   r   rZ   r   rv   attrr   s           r;   r   zParser.parse_assign_target  s    " dkk..055>KK&&v.E;;%%f-D[[djjNFKK&&v.EZZWU\\JF))#_ *  ++-NN7#  "II"4<#8#8#>#>#@"CDfmm r=   r   c                 F    |r| j                         S | j                         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_condexprparse_or)r8   r   s     r;   r   zParser.parse_expression  s"    
 &&((}}r=   c                    | j                   j                  j                  }| j                         }| j                   j	                  d      r| j                         }| j                   j	                  d      r| j                         }nd }t        j                  ||||      }| j                   j                  j                  }| j                   j	                  d      r|S )Nr   r   rd   )r/   rB   r?   r  r   r  r   CondExpr)r8   r?   expr1expr2expr3s        r;   r  zParser.parse_condexpr
  s    $$++ kk!!),MMOE{{"";/++-NN5%vFE[[((//F kk!!), r=   c                 d   | j                   j                  j                  }| j                         }| j                   j	                  d      rd| j                         }t        j                  |||      }| j                   j                  j                  }| j                   j	                  d      rd|S )Nname:orrd   )r/   rB   r?   	parse_andr   r   Orr8   r?   leftrights       r;   r  zParser.parse_or  s    $$++~~kk!!),NN$E88D%7D[[((//F kk!!), r=   c                 d   | j                   j                  j                  }| j                         }| j                   j	                  d      rd| j                         }t        j                  |||      }| j                   j                  j                  }| j                   j	                  d      rd|S )Nname:andrd   )r/   rB   r?   	parse_notr   r   Andr  s       r;   r  zParser.parse_and"  s    $$++~~kk!!*-NN$E99T58D[[((//F kk!!*- r=   c                     | j                   j                  j                  d      rDt        | j                         j                  }t        j                  | j                         |      S | j                         S )Nname:notrd   )	r/   rB   r   r   r?   r   Notr  parse_compare)r8   r?   s     r;   r  zParser.parse_not+  sU    ;;##J/$++&--F99T^^-f==!!##r=   c                    | j                   j                  j                  }| j                         }g }	 | j                   j                  j                  }|t
        v rIt        | j                          |j                  t        j                  || j                                      n| j                   j                  d      r4|j                  t        j                  d| j                                      n| j                   j                  j                  d      rx| j                   j                         j                  d      rO| j                   j                  d       |j                  t        j                  d| j                                      nn"| j                   j                  j                  }|s|S t        j                  |||      S )Nr   inr!  r   notinrd   )r/   rB   r?   parse_math1r_   _compare_operatorsr   rM   r   Operandr   r   r   r   Compare)r8   r?   r   ops
token_types        r;   r#  zParser.parse_compare1  sL   $$++!,,11J//T[[!

5==T5E5E5GHI$$Y/

5==t/?/?/ABC$$))*5$++:J:J:L:Q:Q;   #

5==$2B2B2DEF[[((//F  K}}T3v66r=   c                    | j                   j                  j                  }| j                         }| j                   j                  j                  dv rt
        | j                   j                  j                     }t        | j                          | j                         } ||||      }| j                   j                  j                  }| j                   j                  j                  dv r|S )N)r   r   rd   )r/   rB   r?   parse_concatr_   r$   r   r8   r?   r  clsr  s        r;   r'  zParser.parse_math1H  s    $$++  "kk!!&&.8dkk11667C%%'EtU62D[[((//F kk!!&&.8 r=   c                    | j                   j                  j                  }| j                         g}| j                   j                  j                  dk(  rXt        | j                          |j                  | j                                | j                   j                  j                  dk(  rXt        |      dk(  r|d   S t        j                  ||      S )Ntilder   r   rd   )
r/   rB   r?   parse_math2r_   r   rM   lenr   Concat)r8   r?   r   s      r;   r.  zParser.parse_concatS  s    $$++  "#kk!!&&'1KK((*+ kk!!&&'1 t9>7N||D00r=   c                    | j                   j                  j                  }| j                         }| j                   j                  j                  dv rt
        | j                   j                  j                     }t        | j                          | j                         } ||||      }| j                   j                  j                  }| j                   j                  j                  dv r|S )N)r    r!   r"   r#   rd   )r/   rB   r?   	parse_powr_   r$   r   r/  s        r;   r3  zParser.parse_math2]  s    $$++~~kk!!&&*KKdkk11667CNN$EtU62D[[((//F kk!!&&*KK r=   c                    | j                   j                  j                  }| j                         }| j                   j                  j                  dk(  rt        | j                          | j                         }t        j                  |||      }| j                   j                  j                  }| j                   j                  j                  dk(  r|S )Npowrd   )r/   rB   r?   parse_unaryr_   r   r   Powr  s       r;   r7  zParser.parse_powh  s    $$++!kk!!&&%/$$&E99T58D[[((//F	 kk!!&&%/
 r=   with_filterc                    | j                   j                  j                  }| j                   j                  j                  }|dk(  r<t	        | j                          t        j                  | j                  d      |      }nQ|dk(  r<t	        | j                          t        j                  | j                  d      |      }n| j                         }| j                  |      }|r| j                  |      }|S )Nr   Frd   r   )r/   rB   r_   r?   r   r   Negr:  Posr  parse_postfixparse_filter_expr)r8   r<  r,  r?   r   s        r;   r:  zParser.parse_unaryr  s    [[((--
$$++ 99T--e4VDD5 99T--e4VDD%%'D!!$'))$/Dr=   c                    | j                   j                  }|j                  dk(  r|j                  dv r.t	        j
                  |j                  dv |j                        }n\|j                  dv r"t	        j
                  d |j                        }n,t	        j                  |j                  d|j                        }t        | j                          |S |j                  dk(  rt        | j                          |j                  g}|j                  }| j                   j                  j                  dk(  rh|j                  | j                   j                  j                         t        | j                          | j                   j                  j                  dk(  rht	        j
                  dj                  |      |      }|S |j                  d	v rBt        | j                          t	        j
                  |j                  |j                        }|S |j                  d
k(  rDt        | j                          | j                  d      }| j                   j                  d       |S |j                  dk(  r| j                         }|S |j                  dk(  r| j                         }|S | j                  dt!        |      |j                         S )Nr)   )truefalseTrueFalse)rC  rE  rd   )noneNoneloadstring )integerfloatr   T)explicit_parenthesesr^   lbracketlbracezunexpected )r/   rB   r_   ro   r   Constr?   r  r   rM   rK   r   r   
parse_list
parse_dictrC   r   )r8   rv   r   bufr?   s        r;   r  zParser.parse_primary  s'   ##::{{@@{{5;;2B#B5<<X 00{{4=zz%++vellK, + ZZ8#;;-C\\F++%%**h6

4;;..445T[[! ++%%**h6 ;;rwws|F;D  ZZ//;;u{{5<<@D  ZZ8####>DKKx(  ZZ:%??$D
 	 ZZ8#??$D  IIN5$9#<=u||Lr=   r  rN  c                 x     j                   j                  j                  }|r j                  }n%|r j                  }ndt
        j                  f fd}g }d}	 |r j                   j                  d        j                  |      rn^|j                   |               j                   j                  j                  dk(  rd}nn! j                   j                  j                  }|s:|r|d   S |s1 j                  dt         j                   j                               t        j                  |d|	      S )
a  Works 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.
        r,   c                  (     j                  d      S )NFr   )r   )r8   s   r;   r4   z!Parser.parse_tuple.<locals>.parse  s    ,,5,AAr=   FTr   r   zExpected an expression, got rI  rd   )r/   rB   r?   r  r   r   Exprr   ra   rM   r_   rC   r   Tuple)	r8   r  r   rZ   rN  r?   r4   r   is_tuples	   `        r;   r   zParser.parse_tuple  s   2 $$++&&E))EB5:: B $&""7+  1KK {{""''72[[((//F  Aw (		*4;;+>+>?BD
 {{477r=   c                    | j                   j                  d      }g }| j                   j                  j                  dk7  r|r| j                   j                  d       | j                   j                  j                  dk(  rnC|j	                  | j                                | j                   j                  j                  dk7  r| j                   j                  d       t        j                  ||j                        S )NrO  rbracketr   rd   )	r/   r   rB   r_   rM   r   r   Listr?   )r8   rv   itemss      r;   rR  zParser.parse_list  s    "":.$&kk!!&&*4""7+{{""'':5LL..01 kk!!&&*4 	:&zz%55r=   c                    | j                   j                  d      }g }| j                   j                  j                  dk7  r|r| j                   j                  d       | j                   j                  j                  dk(  rn| j	                         }| j                   j                  d       | j	                         }|j                  t        j                  |||j                               | j                   j                  j                  dk7  r| j                   j                  d       t        j                  ||j                        S )NrP  rbracer   r}   rd   )
r/   r   rB   r_   r   rM   r   Pairr?   Dict)r8   rv   r]  keyro   s        r;   rS  zParser.parse_dict  s    ""8,$&kk!!&&(2""7+{{""''83'')CKKw'))+ELLCszzBC kk!!&&(2 	8$zz%55r=   c                     	 | j                   j                  j                  }|dk(  s|dk(  r| j                  |      }n|dk(  r| j	                  |      }n	 |S W)Nr  rO  r   )r/   rB   r_   parse_subscript
parse_callr8   r   r,  s      r;   r@  zParser.parse_postfix  s^    ,,11JU"jJ&>++D1 x't, r=   c                    	 | j                   j                  j                  }|dk(  r| j                  |      }nT|dk(  r5| j                   j                  j                  dk(  r| j                  |      }n|dk(  r| j                  |      }n	 |S )Npiper)   isr   )r/   rB   r_   r   ro   
parse_testre  rf  s      r;   rA  zParser.parse_filter_expr  s    ,,11JV#((.v%$++*=*=*C*Ct*Kt, x't, r=   c                 T   t        | j                        }|j                  dk(  r| j                  j                  }t        | j                         |j                  dk(  r-t	        j
                  ||j                  d|j                        S |j                  dk7  r| j                  d|j                         t	        j                  |j                  |j                        }t	        j                  ||d|j                        S |j                  dk(  rg }| j                  j                  j                  dk7  r`|r| j                  j                  d	       |j                  | j                                | j                  j                  j                  dk7  r`| j                  j                  d       t        |      d
k(  r|d   }n"t	        j                  |d|j                        }t	        j                  ||d|j                        S | j                  d|j                         y )Nr  r)   rI  rd   rL  zexpected name or numberrO  r[  r   r   r   zexpected subscript expression)r   r/   r_   rB   r   Getattrro   r?   rC   rQ  Getitemr   rM   parse_subscribedr4  rX  )r8   r   rv   
attr_tokenr   r   s         r;   rd  zParser.parse_subscript  s    T[[! ::,,J&(}}***F5<<  I-		3Z5F5FG++j..z7H7HIC==sF5<<HH::#')D++%%**j8KK&&w/D1134 ++%%**j8 KKz*4yA~1gkk$u||D==sF5<<HH		15<<@r=   c                    | j                   j                  j                  }| j                   j                  j                  dk(  rt	        | j                          d g}nM| j                         }| j                   j                  j                  dk7  r|S t	        | j                          |g}| j                   j                  j                  dk(  r|j                  d        nS| j                   j                  j                  dvr |j                  | j                                n|j                  d        | j                   j                  j                  dk(  rit	        | j                          | j                   j                  j                  dvr |j                  | j                                n#|j                  d        n|j                  d        t        j                  |d|iS )Nr}   )r[  r   r?   )	r/   rB   r?   r_   r   r   rM   r   Slice)r8   r?   r   r   s       r;   rn  zParser.parse_subscribed>  s^   $$++ ;;##w.6D((*D{{""''726D;;##w.KK[[  %%-BBKK--/0KK;;##w.{{""''/DDD1134D!KK{{40&00r=   c                 0   	  j                   j                  d      	g }g }d }d }d}dt        dd f 	fd} j                   j                  j                  dk7  r|r@ j                   j                  d        j                   j                  j                  dk(  rnډ j                   j                  j                  dk(  r7 ||d u xr |d u        t         j                           j                         }nY j                   j                  j                  d	k(  r1 ||d u        t         j                           j                         }n j                   j                  j                  d
k(  r j                   j                         j                  dk(  r ||d u         j                   j                  j                  } j                   j                  d        j                         }|j                  t        j                  |||j                               n4 ||d u xr	 |d u xr |        |j                   j                                d} j                   j                  j                  dk7  r j                   j                  d       ||||fS )Nr   Fr   r,   c                 D    | sj                  dj                         y y )Nz+invalid syntax for function call expression)rC   r?   )r   r8   rv   s    r;   ensurez&Parser.parse_call_args.<locals>.ensuref  s    		GV r=   r^   r   r    r9  r)   r   r   rd   T)r/   r   r   rB   r_   r   r   r   ro   r   rM   r   r   r?   )
r8   r   kwargsdyn_args
dyn_kwargsrequire_commart  rb  ro   rv   s
   `        @r;   parse_call_argszParser.parse_call_args^  s)   ""8,
	W 	W$ 	W kk!!&&(2""7+ ;;&&++x7{{""''50x4'>J$,>?T[[!002$$))U2zT)*T[[!!224
 KK'',,6((*//8; :-.++--33CKK$$Q' 113EMM%--U5<<"PQ 8t+Q
d0BQ6zRKK 5 5 78 MA kk!!&&(2D 	8$VXz11r=   c                     | j                   j                  }| j                         \  }}}}t        j                  ||||||j
                        S r   )r/   rB   ry  r   r   r?   )r8   r   rv   r   ru  rv  rw  s          r;   re  zParser.parse_call  sG     ##-1-A-A-C*fh
zz$fh
5<<XXr=   r   c           	          | j                   j                  j                  dk(  s|rW|st        | j                          | j                   j	                  d      }|j
                  }| j                   j                  j                  dk(  rdt        | j                          |d| j                   j	                  d      j
                  z   z  }| j                   j                  j                  dk(  rd| j                   j                  j                  dk(  r| j                         \  }}}}ng }g }d x}}t        j                  |||||||j                        }d}| j                   j                  j                  dk(  rS|rW|S )Nrh  r)   r  rG   r   rd   F)
r/   rB   r_   r   r   ro   ry  r   Filterr?   )	r8   r   r   rv   r)   r   ru  rv  rw  s	            r;   r   zParser.parse_filter  s<    kk!!&&&0LT[[!KK&&v.E;;D++%%**e3T[[!dkk008>>>> ++%%**e3 {{""''83595I5I5K2fh
(,,:<<dD&(Ju||D !L# kk!!&&&0L$ r=   c           	      b   t        | j                        }| j                  j                  j                  d      rt        | j                         d}nd}| j                  j	                  d      j
                  }| j                  j                  j                  dk(  rdt        | j                         |d| j                  j	                  d      j
                  z   z  }| j                  j                  j                  dk(  rdd x}}g }| j                  j                  j                  dk(  r| j                         \  }}}}n| j                  j                  j                  dv r| j                  j                  j                  d	d
d      s[| j                  j                  j                  d      r| j                  d       | j                         }	| j                  |	      }	|	g}ng }t        j                  |||||||j                        }|r!t        j                  ||j                        }|S )Nr!  TFr)   r  rG   r   >   r)   rM  rP  r   rJ  rL  rO  r   r  r  zname:isz'You cannot chain multiple tests with isrd   )r   r/   rB   r   r   ro   r_   ry  r`   rC   r  r@  r   Testr?   r"  )
r8   r   rv   negatedr)   rv  rw  ru  r   arg_nodes
             r;   rj  zParser.parse_test  s   T[[!;;##J/GG{{!!&)//kk!!&&%/C$++,,V4::::D kk!!&&%/ !%$:;;##x/151E1E1G.D&(J[[  %% *
 
 ++%%..{IzR{{""''	2		CD))+H))(3H:DDzz$fh
5<<
 99T%,,7Dr=   c                    g g j                   }|| j                  j                  |       dfd}	 | j                  r| j                  j                  }|j                  dk(  rT|j
                  r1 |t        j                  |j
                  |j                               t        | j                         n1|j                  dk(  rIt        | j                          || j                  d             | j                  j                  d       n|j                  dk(  r |        t        | j                         |B | j                  j                  j                  | r|| j                  j                          S S | j                         }t        |t               rj#                  |       nj                  |       | j                  j                  d	       nt%        d
      | j                  r |        || j                  j                          S # || j                  j                          w w xY w)Nc                      r>d   j                   } j                  t        j                  d d  |              d d = y y )Nr   rd   )r?   rM   r   r   )r?   r   data_buffers    r;   
flush_dataz#Parser.subparse.<locals>.flush_data  s<    $Q..ELLQGHN r=   r   rd   variable_beginTr   r\   block_beginr]   zinternal parsing error)r,   N)rM   r7   r/   rB   r_   ro   r   r   r?   r   r   r   r`   rr   rz   r   rW   extendAssertionError)r8   rU   add_datar  rv   ri   r   r  s         @@r;   r   zParser.subparse  s    $&*,%%!!!((4	#	,++++::'{{ !3!3EKK!UV%ZZ#33%T--D-ABKK&&~6ZZ=0L%!-2N$++2E2E2N2N#3  $ %%%))+ & --/B!"d+BBKK&&{3()ABB1 ++4 L%%%))+ %%%))+ &s   D/H" A6H" =H" "Ic                     t        j                  | j                         d      }|j                  | j                         |S )z0Parse the whole template into a `Template` node.r   rd   )r   Templater   set_environmentr'   )r8   r   s     r;   r4   zParser.parse  s1    :t//0r=   )NNNr   )NN)F)..)TFNF)T)FTNF)_r
  
__module____qualname____doc__strtOptionalr<   r   intTyperC   r\  rX  rR   rT   rY   r   ra   r   rg   rj   Unionrh   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   r   r   r   r   r   r   r   r   r   r   rs   r   rt   r   r   r   r   typingoverloadr  r   r  rW  r   r  r  r  r  r#  r'  r.  r3  r7  r:  r  r   rR  ra  rS  r@  rA  rl  rm  rd  rn  ry  r   re  r   rj  r   r  r4   r   r=   r;   r&   r&   .   sD    !%$(!%>"> > jjo	>
 **S/> zz#> 
>4 #'+>	99 

39 VV'(	9
 
9&-jjo&- S 12&- 

3	&-
 
&-R 48??!"C?	? 59"&	/JJqwwsCx01	/ 

3	/ 
		/ @D zz!''#s(*;<	ajjo ASAS &QVVEJJ5G)G!H &< BG''#s(+:>	


	:	K1775<<1B1B#BC 	KT599 T&%(( $EJJ "#%++ #U[[ <u}} 

"
-1
	

5u}} 
56ell 6(E,, (T%J %4 % %// E$5$5 U[[ U\\  __FI1C	 
 __  9=$  AGGCH$56	
  
ejj%++5	6   9=$(( ( AGGCH$56	(
 ( 
ejj%++5	6(Td ejj 

 %** 5:: $5:: $7uzz 7.	UZZ 	1ejj 1	UZZ 	5:: t uzz $ uzz  H !"9=%*@8@8 @8 AGGCH$56	@8
 #@8 
ejj(	)@8D
6EJJ 
66EJJ 6%**  ejj UZZ AJJA	
-	.A>1%** 1@/2 /2bYuzz Yejj Y BGJJuzz*:>	
EJJ	.$uzz $ejj $N ;?/**QWWS#X%67/	


	/bu~~ r=   r&   )'r  r  r  rK  r   
exceptionsr   r   lexerr   r   TYPE_CHECKINGtyping_extensionster'   r	   TypeVarr   r   r
   r   r   r   	frozensetrp   r(  AddSubMulDivFloorDivModr$   ra  r  r  rW  __annotations__r&   r   r=   r;   <module>r     s    >    . + ! &??"(+U\\5==IQYY|U[[%//B
   GH  99999999990QVVC

++, Z Zr=   