
     fқ                        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j        ej        ej        ej        ej        ej        dZ ej!        e"ej#        ej$                 f         e%d<    G d d          Z&dS )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                    
   e Zd ZdZ	 	 	 dUd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	 dVdedej        e	         d	dfdZ	 	 dWdej        ej        edf                  dej        e	         d	dfdZ	 dVdej        ej        edf                  d	efdZdVdej        e	         d	ej        fdZd	ej        ej        ej        ej                 f         fdZ	 dXdej        edf         ded	ej        ej                 fdZd	ej        ej        ej        f         fdZd	ej        fdZd	ej        fdZ d	ej!        fd Z"d	ej#        fd!Z$d	ej%        fd"Z&d	ej'        fd#Z(d$e)d%ed	e)fd&Z*d	ej+        fd'Z,d	ej-        fd(Z.d	ej/        fd)Z0d$e1d	dfd*Z2d	ej3        fd+Z4d	ej5        fd,Z6d	ej7        fd-Z8d	ej9        fd.Z:e;j<        	 dYd/ed0d1d	ej=        fd2            Z>e;j<        	 	 	 	 dZd/ed0edej        ej        edf                  d4ed	ej        ej?        ej=        ej        f         f
d5            Z>	 	 	 	 dZd/ed0edej        ej        edf                  d4ed	ej        ej?        ej=        ej        f         f
d6Z>d[d7ed	ej@        fd8ZAd	ej@        fd9ZBd	ej@        fd:ZCd	ej@        fd;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dAZJd[dBed	ej@        fdCZKd	ej@        fdDZL	 	 	 	 d\dEed7edej        ej        edf                  dFed	ej        ej        ej@        f         f
dGZMd	ej        fdHZNd	ejO        fdIZPd$ej@        d	ej@        fdJZQd$ej@        d	ej@        fdKZRd$ej@        d	ej        ejS        ejT        f         fdLZUd	ej@        fdMZVd	ej        ej        ej@                 ej        ejW                 ej        ej@                 ej        ej@                 f         fdNZXd$ej@        d	ejY        fdOZZ	 dXd$ej        ej@                 dPed	ej        ej@                 fdQZ[d$ej@        d	ej@        fdRZ\	 dVdej        ej        edf                  d	ej        ej                 fdSZ]d	ej^        fdTZ_dS )]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                    || _         |                    ||||          | _        || _        || _        d| _        i | _        |                                D ]}|j        D ]}|j	        | j        |<   d| _
        g | _        g | _        d S )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           P/var/www/api.educacionweb.es/myenv/lib/python3.11/site-packages/jinja2/parser.py__init__zParser.__init__5   s     '!++FD(EJJ	   	 %4466 	7 	7I ~ 7 7'0$$7 !');=    msglinenoexczte.NoReturnc                 X    || 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.failL   s0     >[(/Fc#vty$-888r=   end_token_stack.c           
      @   t                      }|D ]*}|                    t          t          |                     +|rBd                    t          t
          t          t          |d                                       }nd }|dg}nd|dg}|r9|||v r|                    d| d           n|                    d| d           | j        r$|                    d| j        d         d           |                     d	                    |          |           d S )
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_eofZ   s     #uu$ 	= 	=EOOC 3U;;<<<< 	%17D#1?23FGGHH2 2 !%<45GG;$;;;<G 		DH$4$4G2CG G G   
 UARUUU   ? 	NN-OB'- - -  
 			#((7##V,,,,,r=   c                 >    |                      || j        |           d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.
        N)rR   r7   )r8   r)   r?   s      r;   fail_unknown_tagzParser.fail_unknown_tag   s%     	$ 5v>>>>>r=   
end_tokensc                     t          | j                  }||                    |           |                     d||           dS )z9Like fail_unknown_tag but for end of template situations.N)listr7   rM   rR   )r8   rU   r?   stacks       r;   fail_eofzParser.fail_eof   sJ     T*++!LL$$$$v.....r=   extra_end_rulesc                 r    | j         j        j        dv rdS || j         j                            |          S dS )zAre we at the end of a tuple?)variable_end	block_endrparenTNF)r/   rB   typetest_any)r8   rZ   s     r;   is_tuple_endzParser.is_tuple_end   sA     ;#'NNN4(;&//@@@ur=   c                     | xj         dz  c_         t                              t          j                  }t          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   sX    "^^E.//
B <T%: < <VLLL	r=   c                    | j         j        }|j        dk    r|                     d|j                   | j                            |j                   d}	 |j        t          v rHt          | d| j         j        j                   } |            |r| j        
                                 S S |j        dk    r0|                                 |r| j        
                                 S S |j        dk    r0|                                 |r| j        
                                 S S | j                            |j                  }|' ||           |r| j        
                                 S S | j        
                                 d}|                     |j        |j                   |r| j        
                                 dS dS # |r| 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88u{+++	&{111D"F4;+>+D"F"FGGqss   &##%%%%& {f$$,,..  &##%%%%& {h&&..00  &##%%%%& /%%ek22Cs4yy  &##%%%%&	 O!!!G!!%+u|<<< &##%%%%%& &w &##%%%%&s$   9G +G &G !+G );G G!Fdrop_needlec                    | j                             d           | j                             d           |                     |          }| j         j        j        dk    r|                     |           |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   s     	G$$$ 	;'''z** ;#u,,MM*%%% 	r=   c                 r   t          | j                  j        }|                     d          }| j                            d          r+|                                 }t          j        |||          S |                     d          }| 	                    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    dk""))))>>;x(( 	=##%%D<V<<<<''--$$%54$HH d6JJJJr=   c           	      0   | j                             d          j        }|                     d          }| j                             d           |                     dd          }d}| j                             d	          r|                                 }| j                             d
          }|                     d          }t          | j                   j	        dk    rg }n|                     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)),)GG9%%%1D   
 
 ;y)) 	+((**DK''(899	$$%ABB"h..EE))*:)MMEytUD)FSSSSr=   c                 *   t          j        | j                            d          j                  x}}	 |                     d          |_        |                     d          |_        g |_	        g |_
        t          | j                  }|                    d          r?t          j        | j        j        j                  }|j	                            |           |                    d          r|                     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(E(LMMMMv	((u(==DI--.VWWDIDJDJ%%Ezz+&& Xxt{':'ABBB##D)))K(( X#44_RV4WWr=   c                 D   t          j        t          | j                  j                  }g }g }| j        j        j        dk    r|r| j                            d           |                                 }|	                    d           |
                    |           | j                            d           |
                    |                                            | j        j        j        dk    ||_        ||_        |                     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
   zdk!2!2!9:::&(%'k!&+55 ,""7+++--//FNN7###NN6"""Kx(((MM$//11222 k!&+55 ))*;)NN	r=   c                    t          j        t          | j                  j                  }t          j        d|                                           g|_        |                     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"  sq    .d4;6G6G6NOOOlD4I4I4K4KLLM))*At)TT	{D6"""r=   c                    t          j        t          | j                  j                  }| j                            d          j        |_        | j                            d          |_	        | j                            d          |_
        | j        j        j        dk    r|                     d           |                     dd	          |_        |j
        rW|j        D ]O}t!          |t           j                  rt%          d
 |j         D                       r|                     d           P| 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   | ]9}t          |t          j                   p|j                                         V  :d S N)
isinstancer   TemplateDatadataisspace).0output_nodes     r;   	<genexpr>z%Parser.parse_block.<locals>.<genexpr>>  sj       B B $ #;0BCCC 6&+33555B B B B B Br=   z7Required blocks can only contain comments or whitespacezname:)r   Blockr   r/   r?   r   ro   r)   r   scopedrequiredrB   r_   rC   r   r   r   Outputany)r8   r   	body_nodes      r;   parse_blockzParser.parse_block(  sZ   {$t{"3"3":;;;K&&v..4	k))-88++O<<
 ;#u,,II?  
 ))*<$)OO	
 = 	Y!Y Y Y	!)U\:: Yc B B (1B B B ? ? Y
 IIWXXXGdi/000r=   c                     t          j        t          | j                  j                  }|                                 |_        |S Nrd   )r   Extendsr   r/   r?   r   templater   s     r;   parse_extendszParser.parse_extendsH  s9    }D$5$5$<===--//r=   r   defaultc                 $   | j         j                            dd          rh| j                                                             d          r<t          | j                   j        dk    |_        | j                                          n||_        |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_contextM  s     ;''
 
 	(k  %%n55	( !%T[ 1 1 76 ADK 'Dr=   c                    t          j        t          | j                  j                  }|                                 |_        | j        j                            d          rN| j        	                                                    d          r"d|_
        | j                            d           nd|_
        |                     |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_includeY  s    }D$5$5$<===--//;##M22 	(t{7G7G7I7I7N7N8
 8
 	( #'DKQ"'D((t444r=   c                 ,   t          j        t          | j                  j                  }|                                 |_        | j                            d           |                     d          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_importe  s{    |4#4#4#;<<<--//9%%%...>>C((u555r=   c                     t          j        t           j                  j                                                   _         j                            d           g _        dt          f fd}	 j        r j                            d            j        j
        j        dk    r |            rn                     d          }|j                            d	          r"                     d
|j        t                       j                            d          r=                     d          }j                            |j        |j        f           nj                            |j                    |            s j        j
        j        dk    rnn j                            d           Gt'          d          sd_        S )Nrd   zname:importr,   c                      j         j        j        dv rij                                                             d          r=t          j                   j        dk     _        j                                          dS dS )N>   r   withoutr   r   TF)r/   rB   ro   r   r   r   r   r   )r   r8   s   r;   parse_contextz(Parser.parse_from.<locals>.parse_contextr  s}    {"( -   +""$$)).99 %)$5$5$;v$E!  """t5r=   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_froml  s   tDK'8'8'?@@@--//=)))
	t 	 	 	 	 	 	 		+z ,""7+++{"'611 =?? 11D1AA;))#.. IIN2    
 ;&&y11 3 44t4DDEJ%%v{EJ&?@@@@J%%fk222 =?? dk&9&>'&I&I 'J ""6***+	+, t^,, 	& %Dr=   c                 P   g x}|_         g x}|_        | j                            d           | j        j        j        dk    r|r| j                            d           |                     d          }|                    d           | j                            d          r(|	                    | 
                                           n|r|                     d           |	                    |           | j        j        j        dk    | j                            d           d S )	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$$$k!&(22 ,""7+++**T*::CKK   {""8,, K 5 5 7 78888 K		IJJJKK k!&(22 	8$$$$$r=   c                    t          j        t          | j                  j                  }| j        j        j        dk    r|                     |           ng |_        g |_	        | 
                                }t          |t           j                  s|                     d|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&7&>???;#x//  &&&&DIDM))++	)UZ00 	4IIot{333	))*;)NN	r=   c                     t          j        t          | j                  j                  }|                     d d          |_        |                     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  s\     T[(9(9(@AAA''4'@@))*=4)PP	r=   c                     t          j        t          | j                  j                  }|                     d          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  sp    {$t{"3"3":;;;,,t,<<A	T"""))*<$)OO	r=   c                 Z   t          j        t          | j                  j                  }g |_         | j        j        j        dk    rb|j         r| j                            d           |j                             | 	                                           | j        j        j        dk    b|S )Nrd   r]   r   )
r   r   r   r/   r?   rB   r_   r   rM   r   r   s     r;   parse_printzParser.parse_print  s    |4#4#4#;<<<
k!&+55z ,""7+++Jd3355666 k!&+55 r=   
with_tupler   zte.Literal[True]c                     d S r    )r8   r   r   s      r;   r   zParser.parse_assign_target  s	     Sr=   Tr   c                     d S r   r  )r8   r   r   rZ   r   s        r;   r   zParser.parse_assign_target  s	     9<r=   c                    |r| j                                         j        dk    ro| j                             d          }t	          | j                    | j                             d          }t          j        |j        |j        |j                  }n|r<| j                             d          }t          j	        |j        d|j                  }nC|r| 
                    d|          }n|                                 }|                    d           |                                sB|                     dt          |          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[   "  	$dk..005>>K&&v..E;%%f--D[djNNNFF 	$K&&v..EZWU\JJJFF .))#_ *   ++--NN7###  "" 	IID4<<#8#>#>#@#@DDfm   r=   r   c                 V    |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_condexprparse_or)r8   r   s     r;   r   zParser.parse_expression  s,    
  	)&&(((}}r=   c                    | j         j        j        }|                                 }| j                             d          r|                                 }| j                             d          r|                                 }nd }t          j        ||||          }| j         j        j        }| j                             d          |S )Nr   r   rd   )r/   rB   r?   r  r   r  r   CondExpr)r8   r?   expr1expr2expr3s        r;   r  zParser.parse_condexpr  s    $+ k!!),, 	0MMOOE{"";// ++--N5%vFFFE[(/F k!!),, 	0 r=   c                 0   | j         j        j        }|                                 }| j                             d          rV|                                 }t          j        |||          }| j         j        j        }| j                             d          V|S )Nname:orrd   )r/   rB   r?   	parse_andr   r   Orr8   r?   leftrights       r;   r  zParser.parse_or  s    $+~~k!!),, 	0NN$$E8D%777D[(/F k!!),, 	0 r=   c                 0   | j         j        j        }|                                 }| j                             d          rV|                                 }t          j        |||          }| j         j        j        }| j                             d          V|S )Nname:andrd   )r/   rB   r?   	parse_notr   r   Andr  s       r;   r  zParser.parse_and$  s    $+~~k!!*-- 	0NN$$E9T5888D[(/F k!!*-- 	0 r=   c                     | j         j                            d          rAt          | j                   j        }t          j        |                                 |          S |                                 S )Nname:notrd   )	r/   rB   r   r   r?   r   Notr  parse_compare)r8   r?   s     r;   r  zParser.parse_not-  s`    ;##J// 	>$+&&-F9T^^--f====!!###r=   c                 l   | j         j        j        }|                                 }g }	 | j         j        j        }|t
          v rOt          | j                    |                    t          j	        ||                                                      n| j         
                    d          r;|                    t          j	        d|                                                      n| j         j                            d          r| j                                                             d          rU| j                             d           |                    t          j	        d|                                                      nn| j         j        j        }r|s|S t          j        |||          S )NTr   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_compare3  s   $+!!	0,1J///T[!!!

5=T5E5E5G5GHHIIII$$Y// 

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

5=$2B2B2D2DEEFFFF[(/F	0  	K}T3v6666r=   c                 b   | j         j        j        }|                                 }| j         j        j        dv rvt
          | j         j        j                 }t          | j                    |                                 } ||||          }| j         j        j        }| j         j        j        dv v|S )N)r   r   rd   )r/   rB   r?   parse_concatr_   r$   r   r8   r?   r  clsr  s        r;   r(  zParser.parse_math1J  s    $+  ""k!&.88dk167C%%''E3tU6222D[(/F k!&.88 r=   c                 z   | j         j        j        }|                                 g}| j         j        j        dk    rPt          | j                    |                    |                                            | j         j        j        dk    Pt          |          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_concatU  s    $+  ""#k!&'11KK((**+++ k!&'11 t99>>7N|D0000r=   c                 b   | j         j        j        }|                                 }| j         j        j        dv rvt
          | j         j        j                 }t          | j                    |                                 } ||||          }| j         j        j        }| j         j        j        dv v|S )N)r    r!   r"   r#   rd   )r/   rB   r?   	parse_powr_   r$   r   r0  s        r;   r4  zParser.parse_math2_  s    $+~~k!&*KKKdk167CNN$$E3tU6222D[(/F k!&*KKK r=   c                 D   | j         j        j        }|                                 }| j         j        j        dk    ret          | j                    |                                 }t          j        |||          }| j         j        j        }| j         j        j        dk    e|S )Npowrd   )r/   rB   r?   parse_unaryr_   r   r   Powr  s       r;   r8  zParser.parse_powj  s    $+!!k!&%//$$&&E9T5888D[(/F	 k!&%//
 r=   with_filterc                    | j         j        j        }| j         j        j        }|dk    r>t	          | j                    t          j        |                     d          |          }nX|dk    r>t	          | j                    t          j        |                     d          |          }n| 	                                }| 
                    |          }|r|                     |          }|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_unaryt  s    [(-
$+ 9T--e44VDDDDD5  9T--e44VDDDDD%%''D!!$'' 	0))$//Dr=   c                    | j         j        }|j        dk    r|j        dv r#t	          j        |j        dv |j                  }nF|j        dv rt	          j        d |j                  }n!t	          j        |j        d|j                  }t          | j                    n|j        dk    rt          | j                    |j        g}|j        }| j         j        j        dk    rM|	                    | j         j        j                   t          | j                    | j         j        j        dk    Mt	          j        d
                    |          |          }n|j        d	v r5t          | j                    t	          j        |j        |j                  }n|j        d
k    rEt          | j                    |                     d          }| j                             d           nk|j        dk    r|                                 }nK|j        dk    r|                                 }n+|                     dt!          |          |j                   |S )Nr)   )truefalseTrueFalse)rD  rF  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XX 000{4===z%+velKKKZ8##;-C\F+%*h66

4;.4555T[!!! +%*h66 ;rwws||F;;;DDZ///;u{5<@@@DDZ8#####>>DKx((((Z:%%??$$DDZ8##??$$DDII=N5$9$9==u|LLLr=   r  rO  c                      j         j        j        }|r j        }n|r j        }ndt
          j        f fd}g }d}	 |r j                             d                                |          rnH|	                     |                        j         j        j
        dk    rd}nn j         j        j        }z|s;|r|d         S |s/                     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                  0                          d          S )NFr   )r   )r8   s   r;   r4   z!Parser.parse_tuple.<locals>.parse  s    ,,5,AAAr=   FTr   r   zExpected an expression, got rJ  rd   )r/   rB   r?   r	  r   r   Exprr   ra   rM   r_   rC   r   Tuple)	r8   r  r   rZ   rO  r?   r4   r   is_tuples	   `        r;   r   zParser.parse_tuple  sk   2 $+ 	B&EE 	B)EEB5: B B B B B B $&
	0 ,""7+++  11 KK   {"'722[(/F
	0  	 Aw ( 		D*4;+>??D D  
 {47777r=   c                    | j                             d          }g }| j         j        j        dk    rn|r| j                             d           | j         j        j        dk    rn<|                    |                                            | j         j        j        dk    n| j                             d           t          j        ||j                  S )NrP  rbracketr   rd   )	r/   r   rB   r_   rM   r   r   Listr?   )r8   rv   itemss      r;   rS  zParser.parse_list  s    "":..$&k!&*44 ,""7+++{"':55LL..00111 k!&*44 	:&&&z%5555r=   c                 >   | j                             d          }g }| j         j        j        dk    r|r| j                             d           | j         j        j        dk    rn|                                 }| j                             d           |                                 }|                    t          j        |||j                             | j         j        j        dk    | j                             d           t          j	        ||j                  S )NrQ  rbracer   r}   rd   )
r/   r   rB   r_   r   rM   r   Pairr?   Dict)r8   rv   r^  keyro   s        r;   rT  zParser.parse_dict  s   ""8,,$&k!&(22 ,""7+++{"'833''))CKw'''))++ELLCszBBBCCC k!&(22 	8$$$z%5555r=   c                     	 | j         j        j        }|dk    s|dk    r|                     |          }n|dk    r|                     |          }nnQ|S )NTr  rP  r   )r/   rB   r_   parse_subscript
parse_callr8   r   r-  s      r;   rA  zParser.parse_postfix  sm    		,1JU""jJ&>&>++D11 x''t,,		 r=   c                     	 | j         j        j        }|dk    r|                     |          }nN|dk    r+| j         j        j        dk    r|                     |          }n|dk    r|                     |          }nn||S )NTpiper)   isr   )r/   rB   r_   r   ro   
parse_testrf  rg  s      r;   rB  zParser.parse_filter_expr  s    	,1JV##((..v%%$+*=*Ct*K*Kt,, x''t,,	 r=   c                    t          | j                  }|j        dk    r| j        j        }t          | j                   |j        dk    r"t	          j        ||j        d|j                  S |j        dk    r|                     d|j                   t	          j	        |j        |j                  }t	          j
        ||d|j                  S |j        dk    rg }| j        j        j        dk    rX|r| j                            d	           |                    |                                            | j        j        j        dk    X| j                            d           t          |          d
k    r	|d         }nt	          j        |d|j                  }t	          j
        ||d|j                  S |                     d|j                   d S )Nr  r)   rJ  rd   rM  zexpected name or numberrP  r\  r   r   r   zexpected subscript expression)r   r/   r_   rB   r   Getattrro   r?   rC   rR  Getitemr   rM   parse_subscribedr5  rY  )r8   r   rv   
attr_tokenr   r   s         r;   re  zParser.parse_subscript!  s    T[!! :,J&((}**F5<    I--		3Z5FGGG+j.z7HIIIC=sF5<HHHH:##')D+%*j88 0K&&w///D1133444 +%*j88 Kz***4yyA~~1gk$u|DDD=sF5<HHHH		15<@@@@@r=   c                 8   | j         j        j        }| j         j        j        dk    rt	          | j                    d g}nB|                                 }| j         j        j        dk    r|S t	          | j                    |g}| j         j        j        dk    r|                    d            nP| j         j        j        dvr(|                    |                                            n|                    d            | j         j        j        dk    ret	          | j                    | j         j        j        dvr(|                    |                                            n+|                    d            n|                    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;   ro  zParser.parse_subscribed@  s   $+ ;#w..6DD((**D{"'7226D;#w..KK[ %-BBBKK--//0000KK;#w..{"'/DDDD11334444D!!!!KK{40&000r=   c                    	  j                             d          	g }g }d }d }d}dt          dd f 	fd} j         j        j        dk    r|r1 j                             d            j         j        j        dk    rn j         j        j        dk    r; ||d u o|d u            t           j                                                     }n9 j         j        j        d	k    r6 ||d u            t           j                                                     }n j         j        j        d
k    r j                                         j        dk    r| ||d u             j         j        j        } j         	                    d                                            }|
                    t          j        |||j                             n; ||d u o|d u o|            |
                                                                d} j         j        j        dk    ԉ j                             d           ||||fS )Nr   Fr   r,   c                 F    | s                     dj                   d S d S )Nz+invalid syntax for function call expression)rC   r?   )r   r8   rv   s    r;   ensurez&Parser.parse_call_args.<locals>.ensureo  s5     W		GVVVVVW Wr=   r^   r   r    r:  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_commaru  rc  ro   rv   s
   `        @r;   parse_call_argszParser.parse_call_args`  s    ""8,,
	W 	W$ 	W 	W 	W 	W 	W 	W 	W k!&(22 ""7+++ ;&+x77{"'500x4'>J$,>???T[!!!0022$)U22zT)***T[!!!!2244

 K',66((**/8;; F:-...+-3CK$$Q''' 1133EMM%-U5<"P"P"PQQQQ F8t+Q
d0BQ6zRRRKK 5 5 7 7888 MA k!&(22D 	8$$$VXz11r=   c                     | j         j        }|                                 \  }}}}t          j        ||||||j                  S r   )r/   rB   rz  r   r   r?   )r8   r   rv   r   rv  rw  rx  s          r;   rf  zParser.parse_call  sG     #-1-A-A-C-C*fh
z$fh
5<XXXXr=   r   c           	      N   | j         j        j        dk    s|r|st          | j                    | j                             d          }|j        }| j         j        j        dk    rNt          | j                    |d| j                             d          j        z   z  }| j         j        j        dk    N| j         j        j        dk    r|                                 \  }}}}ng }g }d x}}t          j        |||||||j	                  }d}| j         j        j        dk    	||S )Nri  r)   r  rG   r   rd   F)
r/   rB   r_   r   r   ro   rz  r   Filterr?   )	r8   r   r   rv   r)   r   rv  rw  rx  s	            r;   r   zParser.parse_filter  s>    k!&&00L0 "T[!!!K&&v..E;D+%*e33T[!!!dk0088>>> +%*e33 {"'833595I5I5K5K2fh

(,,:<dD&(Ju|  D !L# k!&&00L0$ r=   c           	         t          | j                  }| j        j                            d          rt          | j                   d}nd}| j                            d          j        }| j        j        j        dk    rNt          | j                   |d| j                            d          j        z   z  }| j        j        j        dk    Nd x}}g }| j        j        j        dk    r|                                 \  }}}}n| j        j        j        dv r| j        j                            d	d
d          sa| j        j                            d          r| 	                    d           | 
                                }	|                     |	          }	|	g}ng }t          j        |||||||j                  }|rt          j        ||j                  }|S )Nr"  TFr)   r  rG   r   >   r)   rN  rQ  r   rK  rM  rP  r   r  r  zname:isz'You cannot chain multiple tests with isrd   )r   r/   rB   r   r   ro   r_   rz  r`   rC   r	  rA  r   Testr?   r#  )
r8   r   rv   negatedr)   rw  rx  rv  r   arg_nodes
             r;   rk  zParser.parse_test  s   T[!!;##J// 	GGG{!!&))/k!&%//C$+,,V44:::D k!&%// !%$:(*;#x//151E1E1G1G.D&(JJ[ % *
 
 
 +%..{IzRR
 {"''	22 E		CDDD))++H))(33H:DDDz$fh
5<
 
 
  	89T%,777Dr=   c                 8   g g j         }|| j                             |           dfd}	 | j        r| j        j        }|j        dk    rF|j        r) |t          j        |j        |j                             t          | j                   n4|j        dk    rNt          | j                    || 
                    d                     | j                            d           n|j        d	k    r |             t          | j                   |2 | j        j        j        | r|| j                                         S S |                                 }t          |t                     r                    |           n                     |           | j                            d
           nt%          d          | j         |             || j                                         n!# || j                                         w w xY wS )Nr,   c                      rEd         j         }                     t          j        d d          |                      d d = d S d S )Nr   rd   )r?   rM   r   r   )r?   r   data_buffers    r;   
flush_dataz#Parser.subparse.<locals>.flush_data  sY     #$Q.ELQQQGGGHHHNNN# #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  sZ    $&*,%!!((444	# 	# 	# 	# 	# 	# 	#	,+ C+:''{ W !3EK!U!U!UVVV%%%%Z#333%%%HT--D-AABBBK&&~6666Z=00JLLL%%%!-2N$+2E2N#3-  $ %%))++++ & --//B!"d++ (BBK&&{3333()ABBB1 + C4 JLLL%%))+++ %%))++++ &s   C>G9 BG9 9Hc                     t          j        |                                 d          }|                    | j                   |S )z0Parse the whole template into a `Template` node.r   rd   )r   Templater   set_environmentr'   )r8   r   s     r;   r4   zParser.parse  s:    :::t/000r=   )NNNr   )NN)F)..)TFNF)T)FTNF)`r  
__module____qualname____doc__strtOptionalr<   r   intTyperC   r]  rY  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  rX  r   r  r  r  r  r$  r(  r/  r4  r8  r;  r	  r   rS  rb  rT  rA  rB  rm  rn  re  ro  r   rz  r   rf  r   rk  r   r  r4   r  r=   r;   r&   r&   0   sA
         !%$(!%> >"> > jo	>
 *S/> z#> 
> > > >4 #'+>	9 99 
39 V'(	9
 
9 9 9 9&-jo&- S 12&- 
3	&-
 
&- &- &- &-R 48? ??!"C?	? ? ? ? 59"&	/ 	/JqwsCx01	/ 
3	/ 
		/ 	/ 	/ 	/ @D  z!'#s(*;<	    ajo AS    &QVEJ5G)G!H & & & &< BG '#s(+:>	

	   :	K175<1B#BC 	K 	K 	K 	KT59 T T T T&%(    $EJ    "#%+ # # # #U[    @u}    

"
-1
	
 
 
 

5u} 
5 
5 
5 
56el 6 6 6 6(E, ( ( ( (T%J %4 % % % % %/    E$5    U[    U\     _FI 1C	   _ _  9=$< << < AGCH$56	<
 < 
ej%+5	6< < < _<  9=$( (( ( AGCH$56	(
 ( 
ej%+5	6( ( ( (T d ej    
    %*    5:    $5: $ $ $ $7uz 7 7 7 7.	UZ 	 	 	 	1ej 1 1 1 1	UZ 	 	 	 	5:     t uz    $ uz        H !"9=%*@8 @8@8 @8 AGCH$56	@8
 #@8 
ej(	)@8 @8 @8 @8D
6EJ 
6 
6 
6 
66EJ 6 6 6 6%*     ej UZ    AJA	
-	.A A A A>1%* 1 1 1 1@62	
	uz	u}	
5:	
5:	 
62 62 62 62pYuz Yej Y Y Y Y BG Juz*:>	
EJ	   .$uz $ej $ $ $ $N ;?/ /*QWS#X%67/	

	/ / / /bu~      r=   r&   )'r  r  r  rL  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$   rb  r  r  rX  __annotations__r&   r  r=   r;   <module>r     s   > > >            . . . . . . + + + + + + ! ! ! ! ! ! & & & & & &? )""""((((((+U\5=IIQY|U[%/BB
i      YGGGHH  999990 0QVC
++,   a a a a a a a a a ar=   