HEX
Server: Apache/2.4.65 (Debian)
System: Linux kubikelcreative 5.10.0-35-amd64 #1 SMP Debian 5.10.237-1 (2025-05-19) x86_64
User: www-data (33)
PHP: 8.4.13
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/jinja2/__pycache__/parser.cpython-39.pyc
a

�`L��@s�dZddlmZddlmZddlmZddlmZddlm	Z	ddlm
Z
egd��Zegd	��Z
ejejejejejejd
�ZGdd�de�Zd
S)z8Parse tokens from the lexer into nodes for the compiler.�)�nodes)�imap)�TemplateAssertionError)�TemplateSyntaxError)�describe_token��describe_token_expr)�for�if�blockZextends�printZmacroZinclude�from�import�set�with�
autoescape)�eq�ne�ltZlteq�gtZgteq)�add�sub�mul�div�floordiv�modc@s�eZdZdZdidd�Zdefdd�Zdd�Zdjd	d
�Zdkdd�Z	dld
d�Z
dmdd�Zdd�Zdndd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zdod7d8�Zdpd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dqdMdN�Z)dOdP�Z*drdQdR�Z+dSdT�Z,dUdV�Z-dWdX�Z.dYdZ�Z/d[d\�Z0d]d^�Z1d_d`�Z2dsdadb�Z3dcdd�Z4dtdedf�Z5dgdh�Z6dS)u�Parserz�This is the central parsing class Jinja uses.  It's passed to
    extensions and can be used to parse expressions or statements.
    NcCsl||_|�||||�|_||_||_d|_i|_|��D]}|jD]}|j	|j|<qBq8d|_
g|_g|_dS)NF�)
�environment�	_tokenize�stream�name�filename�closed�
extensionsZiter_extensionsZtags�parse�_last_identifier�
_tag_stack�_end_token_stack)�selfr�sourcer!r"�state�	extension�tag�r.�//usr/lib/python3/dist-packages/jinja2/parser.py�__init__+s
zParser.__init__cCs(|dur|jjj}||||j|j��dS)z�Convenience method that raises `exc` with the message, passed
        line number or last line number as well as the current name and
        filename.
        N)r �current�linenor!r")r)�msgr2�excr.r.r/�fail9s
zParser.failcCs�g}|D]}|�tt|��q|r<d�dd�|dD��}nd}|durPdg}n
d|g}|r�|dur~||vr~|�d|�n|�d|�|jr�|�d	|jd�|�d
�|�|�dS)Nz or css|]}dt|�VqdS)z'%s'Nr)�.0�exprr.r.r/�	<genexpr>Gsz&Parser._fail_ut_eof.<locals>.<genexpr>���zUnexpected end of template.zEncountered unknown tag '%s'.z_You probably made a nesting mistake. Jinja is expecting this tag, but currently looking for %s.z-Jinja was looking for the following tags: %s.z4The innermost block that needs to be closed is '%s'.� )�extendrr�join�appendr'r5)r)r!Zend_token_stackr2ZexpectedZexprsZcurrently_looking�messager.r.r/�_fail_ut_eofBs<
�

������zParser._fail_ut_eofcCs|�||j|�S)z�Called if the parser encounters an unknown tag.  Tries to fail
        with a human readable error message that could help to identify
        the problem.
        )r?r()r)r!r2r.r.r/�fail_unknown_taggszParser.fail_unknown_tagcCs*t|j�}|dur|�|�|�d||�S)z9Like fail_unknown_tag but for end of template situations.N)�listr(r=r?)r)�
end_tokensr2�stackr.r.r/�fail_eofns

zParser.fail_eofcCs,|jjjdvrdS|dur(|jj�|�SdS)zAre we at the end of a tuple?)�variable_end�	block_end�rparenTNF)r r1�type�test_any)r)�extra_end_rulesr.r.r/�is_tuple_endus
zParser.is_tuple_endcCs6|jd7_t�tj�}tjj|d|j|d�|S)zDReturn a new free identifier as :class:`~jinja2.nodes.InternalName`.rzfi%d�r2)r&�object�__new__rZInternalNameZNoder0)r)r2�rvr.r.r/�free_identifier}szParser.free_identifiercCs|jj}|jdkr |�d|j�|j�|j�d}z�|jtvrdt	|d|jjj��W|rb|j�
�S|jdkr�|��W|r�|j�
�S|jdkr�|��W|r�|j�
�S|j
�|j�}|dur�||�W|r�|j�
�S|j�
�d}|�|j|j�W|�r|j�
�n|�r|j�
�0dS)	zParse a single statement.r!ztag name expectedTZparse_�call�filterNF)r r1rHr5r2r'r=�value�_statement_keywords�getattr�pop�parse_call_block�parse_filter_blockr$�getr@)r)�tokenZpop_tagZextr.r.r/�parse_statement�sD


�

�

�	
�
�zParser.parse_statementFcCsL|j�d�|j�d�|�|�}|jjjdkr:|�|�|rHt|j�|S)aRParse multiple statements into a list until one of the end tokens
        is reached.  This is used to parse the body of statements as it also
        parses template data if appropriate.  The parser checks first if the
        current token is a colon and skips it if there is one.  Then it checks
        for the block end and parses until if one of the `end_tokens` is
        reached.  Per default the active token in the stream at the end of
        the call is the matched end token.  If this is not wanted `drop_needle`
        can be set to `True` and the end token is removed.
        �colonrF�eof)r �skip_if�expect�subparser1rHrD�next)r)rB�drop_needle�resultr.r.r/�parse_statements�s


zParser.parse_statementscCsft|j�j}|jdd�}|j�d�r<|��}tj|||d�S|�d�}|j	ddd�}tj
||||d�S)zParse an assign statement.T)�with_namespace�assignrLN)zname:endset�rb)rar r2�parse_assign_targetr^�parse_tuplerZAssign�parse_filterrdZAssignBlock)r)r2�targetr7Zfilter_node�bodyr.r.r/�	parse_set�s
zParser.parse_setc	Cs�|j�d�j}|jdd�}|j�d�|jddd�}d}|j�d	�rL|��}|j�d
�}|�d�}t|j�j	dkrxg}n|jd
dd�}t
j|||||||d�S)zParse a for loop.zname:for)�name:in)rJrnF)�name:recursive)�
with_condexprrJN�name:ifro)�name:endfor�	name:elseZendfor)rrTrgrL)r r_r2rhrir^�parse_expressionrdrarSrZFor)r)r2rk�iter�test�	recursiverl�else_r.r.r/�	parse_for�s�
zParser.parse_forcCs�tj|j�d�jd�}}|jdd�|_|�d�|_g|_	g|_
t|j�}|�d�rvtj|jjjd�}|j	�
|�qq�|�d�r�|jdd	d
�|_
q�q|S)zParse an if construct.rqrLF�rp)�	name:elifrs�
name:endifr{rs)r|Trg)rZIfr r_r2rirvrdrlZelif_rxrar1r=)r)�nodercrZr.r.r/�parse_if�s


zParser.parse_ifcCs�tjt|j�jd�}g}g}|jjjdkrr|r:|j�d�|��}|�	d�|�
|�|j�d�|�
|���q||_||_
|jddd�|_|S)	NrLrF�comma�paramrf)zname:endwithTrg)rZWithrar r2r1rHr_rh�set_ctxr=rt�targets�valuesrdrl)r)r}r�r�rkr.r.r/�
parse_with�s

zParser.parse_withcCsDtjt|j�jd�}t�d|���g|_|jddd�|_	t�
|g�S)NrLr)zname:endautoescapeTrg)rZScopedEvalContextModifierrar r2�KeywordrtZoptionsrdrlZScope�r)r}r.r.r/�parse_autoescape�szParser.parse_autoescapecCsptjt|j�jd�}|j�d�j|_|j�d�|_	|jj
jdkrJ|�d�|j
ddd�|_|j�d	|j�|S)
NrLr!zname:scopedrzpBlock names in Jinja have to be valid Python identifiers and may not contain hyphens, use an underscore instead.)z
name:endblockTrgzname:)rZBlockrar r2r_rSr!r^Zscopedr1rHr5rdrlr�r.r.r/�parse_blocks�zParser.parse_blockcCs"tjt|j�jd�}|��|_|S)NrL)rZExtendsrar r2rt�templater�r.r.r/�
parse_extendss
zParser.parse_extendscCsH|jj�dd�r>|j���d�r>t|j�jdk|_|j��n||_|S)Nz	name:withzname:without�name:contextr)	r r1rI�lookrvrarS�with_context�skip)r)r}�defaultr.r.r/�parse_import_contexts��zParser.parse_import_contextcCsbtjt|j�jd�}|��|_|jj�d�rP|j�	��d�rPd|_
|j�d�nd|_
|�|d�S)NrLzname:ignorezname:missingT�F)
rZIncluderar r2rtr�r1rvr�Zignore_missingr�r�r�r.r.r/�
parse_include$s
�zParser.parse_includecCsFtjt|j�jd�}|��|_|j�d�|jdd�j	|_
|�|d�S)NrL�name:asT��	name_onlyF)rZImportrar r2rtr�r_rhr!rkr�r�r.r.r/�parse_import0s

zParser.parse_importcstjt�j�jd������_�j�d�g�_��fdd�}�jrP�j�d��jj	j
dkr�|�rfq�jdd�}|j�
d	�r��jd
|jtd��j�d�r��jdd�}�j�|j|jf�n�j�|j�|�s�jj	j
dkr�q�q>�j�d�q>t�d
��sd�_�S)NrLzname:importcsB�jjjdvr>�j���d�r>t�j�jdk�_�j��dSdS)N)rZwithoutr�rTF)r r1rSr�rvrar�r�r.�r}r)r.r/�
parse_context=s�
z(Parser.parse_from.<locals>.parse_contextrr!Tr��_z4names starting with an underline can not be imported)r4r�r�F)rZ
FromImportrar r2rtr�r_�namesr1rHrhr!�
startswithr5rr^r=�hasattrr�)r)r�rk�aliasr.r�r/�
parse_from7s6
�zParser.parse_fromcCs�g|_}g|_}|j�d�|jjjdkr�|r>|j�d�|jdd�}|�d�|j�d�rp|�	|�
��n|r~|�d�|�	|�q |j�d�dS)	N�lparenrGrTr�r�rfz-non-default argument follows default argument)�args�defaultsr r_r1rHrhr�r^r=rtr5)r)r}r�r��argr.r.r/�parse_signatureas



zParser.parse_signaturecCsttjt|j�jd�}|jjjdkr.|�|�ng|_g|_	|�
�|_t|jtj
�s`|�d|j�|jddd�|_|S)NrLr�z
expected call)zname:endcallTrg)rZ	CallBlockrar r2r1rHr�r�r�rtrQ�
isinstance�Callr5rdrlr�r.r.r/rWqs
zParser.parse_call_blockcCs8tjt|j�jd�}|jddd�|_|jddd�|_|S)NrLT)�start_inline)zname:endfilterrg)	rZFilterBlockrar r2rjrRrdrlr�r.r.r/rXszParser.parse_filter_blockcCsBtjt|j�jd�}|jdd�j|_|�|�|jddd�|_	|S)NrLTr�)z
name:endmacrorg)
rZMacrorar r2rhr!r�rdrlr�r.r.r/�parse_macro�s

zParser.parse_macrocCsPtjt|j�jd�}g|_|jjjdkrL|jr:|j�d�|j�|�	��q|S)NrLrFr)
r�Outputrar r2r1rHr_r=rtr�r.r.r/�parse_print�szParser.parse_printTcCs�|rN|j��jdkrN|j�d�}t|j�|j�d�}tj|j|j|jd�}nL|rt|j�d�}tj	|jd|jd�}n&|r�|j
d|d�}n|��}|�d�|�
�s�|�d|jj��|j�|S)aParse an assignment target.  As Jinja allows assignments to
        tuples, this function can parse all allowed assignment targets.  Per
        default assignments to tuples are parsed, that can be disable however
        by setting `with_tuple` to `False`.  If only assignments to names are
        wanted `name_only` can be set to `True`.  The `extra_end_rules`
        parameter is forwarded to the tuple parsing function.  If
        `with_namespace` is enabled, a namespace assignment may be parsed.
        �dotr!rLZstoreT)�
simplifiedrJzcan't assign to %r)r r�rHr_rarZNSRefrSr2�Nameri�
parse_primaryr�Z
can_assignr5�	__class__�__name__�lower)r)Z
with_tupler�rJrerZ�attrrkr.r.r/rh�s&
�
�zParser.parse_assign_targetcCs|r|��S|��S)z�Parse 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)r)rpr.r.r/rt�szParser.parse_expressioncCsb|jjj}|��}|j�d�r^|��}|j�d�r<|��}nd}tj||||d�}|jjj}q|S)NrqrsrL)r r1r2r�r^r�rZCondExpr)r)r2Zexpr1Zexpr2Zexpr3r.r.r/r��s

zParser.parse_condexprcCsF|jjj}|��}|j�d�rB|��}tj|||d�}|jjj}q|S)N�name:orrL)r r1r2�	parse_andr^rZOr�r)r2�left�rightr.r.r/r��s
zParser.parse_orcCsF|jjj}|��}|j�d�rB|��}tj|||d�}|jjj}q|S)N�name:andrL)r r1r2�	parse_notr^rZAndr�r.r.r/r��s
zParser.parse_andcCs4|jj�d�r,t|j�j}tj|��|d�S|��S)N�name:notrL)	r r1rvrar2r�Notr��
parse_compare)r)r2r.r.r/r��szParser.parse_notcCs�|jjj}|��}g}|jjj}|tvrJt|j�|�t�	||����nh|j�
d�rn|�t�	d|����nD|jj�d�r�|j���d�r�|j�
d�|�t�	d|����nq�|jjj}q|s�|Stj|||d�S)Nrn�inr�r�ZnotinrL)r r1r2�parse_math1rH�_compare_operatorsrar=rZOperandr^rvr�r�ZCompare)r)r2r7�ops�
token_typer.r.r/r��s&


�zParser.parse_comparecCs^|jjj}|��}|jjjdvrZt|jjj}t|j�|��}||||d�}|jjj}q|S)N)rrrL)r r1r2�parse_concatrH�_math_nodesra�r)r2r��clsr�r.r.r/r��s

zParser.parse_math1cCs^|jjj}|��g}|jjjdkr<t|j�|�|���qt|�dkrP|dStj	||d�S)N�tilderrrL)
r r1r2�parse_math2rHrar=�lenrZConcat)r)r2r�r.r.r/r�
s


zParser.parse_concatcCs^|jjj}|��}|jjjdvrZt|jjj}t|j�|��}||||d�}|jjj}q|S)N)rrrrrL)r r1r2�	parse_powrHr�rar�r.r.r/r�s

zParser.parse_math2cCsR|jjj}|��}|jjjdkrNt|j�|��}tj|||d�}|jjj}q|S)N�powrL)r r1r2�parse_unaryrHrarZPowr�r.r.r/r�s

zParser.parse_powcCs�|jjj}|jjj}|dkr<t|j�tj|�d�|d�}n0|dkrdt|j�tj|�d�|d�}n|�	�}|�
|�}|r�|�|�}|S)NrFrLr)r r1rHr2rarZNegr�ZPosr��
parse_postfix�parse_filter_expr)r)Zwith_filterr�r2r}r.r.r/r�)s





zParser.parse_unarycCsp|jj}|jdkrp|jdvr4tj|jdv|jd�}n0|jdvrPtjd|jd�}ntj|jd|jd�}t|j�n�|jdkr�t|j�|jg}|j}|jjjdkr�|�	|jjj�t|j�q�tjd�
|�|d�}n�|jd	vr�t|j�tj|j|jd�}nr|jd
k�r*t|j�|jdd�}|j�d
�nB|jdk�r@|�
�}n,|jdk�rV|��}n|�dt|�|j�|S)Nr!)�trueZfalse�True�False)r�r�rL)Znone�None�load�string�)�integer�floatr�T)�explicit_parenthesesrG�lbracket�lbracezunexpected '%s')r r1rHrSr�Constr2r�rar=r<rir_�
parse_list�
parse_dictr5r)r)rZr}Zbufr2r.r.r/r�9s:









zParser.parse_primaryc	s��jjj}|r�j}n|r"�j}n�fdd�}g}d}|rF�j�d���|�rRq�|�|���jjjdkr�d}nq��jjj}q6|s�|r�|dS|s���	dt
�jj��tj|d|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.
        cs�jdd�S)NFrz)rtr.�r)r.r/r%zsz!Parser.parse_tuple.<locals>.parseFrTrz Expected an expression, got '%s'r�rL)
r r1r2r�rtr_rKr=rHr5rr�Tuple)	r)r�rprJr�r2r%r�Zis_tupler.r�r/riZs6


��zParser.parse_tuplecCsj|j�d�}g}|jjjdkrN|r.|j�d�|jjjdkr>qN|�|���q|j�d�tj||jd�S)Nr��rbracketrrL)	r r_r1rHr=rtr�Listr2)r)rZ�itemsr.r.r/r��szParser.parse_listcCs�|j�d�}g}|jjjdkrt|r.|j�d�|jjjdkr>qt|��}|j�d�|��}|�tj|||jd��q|j�d�tj	||jd�S)Nr�Zrbracerr\rL)
r r_r1rHrtr=rZPairr2�Dict)r)rZr��keyrSr.r.r/r��szParser.parse_dictcCsB|jjj}|dks|dkr&|�|�}q|dkr>|�|�}qq>q|S)Nr�r�r�)r r1rH�parse_subscript�
parse_call�r)r}r�r.r.r/r��s
zParser.parse_postfixcCs\|jjj}|dkr|�|�}q|dkr@|jjjdkr@|�|�}q|dkrX|�|�}qqXq|S)N�piper!�isr�)r r1rHrjrS�
parse_testr�r�r.r.r/r��s
zParser.parse_filter_exprcCst|j�}|jdkr�|jj}t|j�|jdkrFtj||jd|jd�S|jdkr^|�d|j�tj	|j|jd�}tj
||d|jd�S|jdk�r
g}|jjjdkr�|r�|j�d	�|�|�
��q�|j�d�t|�d
kr�|d}ntj|d|jd�}tj
||d|jd�S|�d|j�dS)
Nr�r!r�rLr�zexpected name or numberr�r�rrrzexpected subscript expression)rar rHr1rZGetattrrSr2r5r�ZGetitemr_r=�parse_subscribedr�r�)r)r}rZZ
attr_tokenr�r�r.r.r/r��s0



�

zParser.parse_subscriptcCs�|jjj}|jjjdkr*t|j�dg}n*|��}|jjjdkrD|St|j�|g}|jjjdkrn|�d�n(|jjjdvr�|�|���n
|�d�|jjjdkr�t|j�|jjjdvr�|�|���q�|�d�n
|�d�tj|d|i�S)Nr\)r�rr2)	r r1r2rHrartr=rZSlice)r)r2r�r}r.r.r/r��s*





zParser.parse_subscribedc
s��j�d��g}g}d}}d}��fdd�}�jjjdk�r\|r`�j�d��jjjdkr`�q\�jjjdkr�||duo~|du�t�j����}n��jjjdkr�||du�t�j����}n��jjjd	k�r*�j��jd
k�r*||du��jjj}�j�d����}	|�	t
j||	|	jd��n,||du�oD|du�oD|�|�	����d
}q.�j�d�|du�r~||||fSt
j
|||||�jd�S)Nr�Fcs|s��d�j�dS)Nz+invalid syntax for function call expression)r5r2)r7�r)rZr.r/�ensuresz!Parser.parse_call.<locals>.ensurerGrrr�r!rfr�rLT)r r_r1rHrartr�rSr�r=rr�r2r�)
r)r}r��kwargs�dyn_args�
dyn_kwargsZ
require_commar�r�rSr.r�r/r�sF



��

zParser.parse_callc		Cs�|jjjdks|r�|s t|j�|j�d�}|j}|jjjdkrbt|j�|d|j�d�j7}q2|jjjdkr�|�d�\}}}}ng}g}d}}tj|||||||j	d�}d}q|S)Nr�r!r��.r�rLF)
r r1rHrar_rSr�rZFilterr2)	r)r}r�rZr!r�r�r�r�r.r.r/rj<s$

�zParser.parse_filterc
	Cs"t|j�}|jj�d�r(t|j�d}nd}|j�d�j}|jjjdkrjt|j�|d|j�d�j7}q:d}}g}|jjjdkr�|�d�\}}}}nV|jjjdvr�|jj�d	d
d�s�|jj�d�r�|�	d
�|�
�}	|�|	�}	|	g}ng}tj
|||||||jd�}|�rtj||jd�}|S)Nr�TFr!r�r�r�)r!r�r�r�r�r�r�rsr�r�zname:isz'You cannot chain multiple tests with isrL)rar r1rvr_rSrHr�rIr5r�r�rZTestr2r�)
r)r}rZZnegatedr!r�r�r�r�Zarg_noder.r.r/r�Qs8


�	

�zParser.parse_testcslg�g��j}|dur"|j�|���fdd�}�z|j�r4|jj}|jdkrv|jrj|tj|j|jd��t	|j�q4|jdkr�t	|j�||j
dd��|j�d�q4|jd	k�r*|�t	|j�|dur�|jjj|�r�W|dur�|j�
�S|��}t|t��r��|�n
��|�|j�d
�q4td��q4|�W|du�rh|j�
�n|du�rf|j�
�0�S)Ncs8�r4�dj}��tj�dd�|d���dd�=dS)NrrL)r2r=rr�rL�rlZdata_bufferr.r/�
flush_datas
z#Parser.subparse.<locals>.flush_data�datarLZvariable_beginTrzrEZblock_beginrFzinternal parsing error)r=r(r r1rHrSrZTemplateDatar2rarir_rIrVr[r�rAr;�AssertionError)r)rBZadd_datar�rZrOr.r�r/r`wsN



�
�


�
zParser.subparsecCs"tj|��dd�}|�|j�|S)z0Parse the whole template into a `Template` node.rrL)rZTemplater`Zset_environmentr)r)rcr.r.r/r%�szParser.parse)NNN)N)NN)N)N)F)TFNF)T)T)FTNF)F)N)7r��
__module__�__qualname__�__doc__r0rr5r?r@rDrKrPr[rdrmryr~r�r�r�r�r�r�r�r�r�rWrXr�r�rhrtr�r�r�r�r�r�r�r�r�r�r�rir�r�r�r�r�r�r�rjr�r`r%r.r.r.r/r&sv
	%





*�
%
	
		


#�
A
0
&
0rN)r�r�rZ_compatr�
exceptionsrrZlexerrr�	frozensetrTr�ZAddZSubZMulZDivZFloorDivZModr�rMrr.r.r.r/�<module>s$��