%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python37/lib/python3.7/site-packages/jinja2/__pycache__/
Upload File :
Create Path :
Current File : //opt/alt/python37/lib/python3.7/site-packages/jinja2/__pycache__/parser.cpython-37.pyc

B

��Rr��@s�dZddlmZddlmZmZddlmZmZddl	m
Z
mZedddd	d
ddd
ddg
�Z
eddddddg�ZGdd�de�ZdS)z�
    jinja2.parser
    ~~~~~~~~~~~~~

    Implements the template parser.

    :copyright: (c) 2010 by the Jinja Team.
    :license: BSD, see LICENSE for more details.
�)�nodes)�TemplateSyntaxError�TemplateAssertionError)�describe_token�describe_token_expr)�next�imap�for�if�blockZextends�printZmacroZinclude�from�import�set�eq�ne�ltZlteq�gtZgteqc@s�eZdZdZdmdd�Zdefdd�Zdd�Zdnd	d
�Zdodd�Z	dpd
d�Z
dqdd�Zdd�Zdrdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zdsd3d4�Zdtd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dudQdR�Z+dSdT�Z,dvdUdV�Z-dWdX�Z.dYdZ�Z/d[d\�Z0d]d^�Z1d_d`�Z2dadb�Z3dcdd�Z4dwdedf�Z5dgdh�Z6dxdidj�Z7dkdl�Z8dS)y�Parserz�This is the central parsing class Jinja2 uses.  It's passed to
    extensions and can be used to parse expressions or statements.
    NcCst||_|�||||�|_||_||_d|_i|_x,|��D] }x|jD]}|j	|j|<qFWq:Wd|_
g|_g|_dS)NFr)
�environment�	_tokenize�stream�name�filename�closed�
extensionsZiter_extensionsZtags�parse�_last_identifier�
_tag_stack�_end_token_stack)�selfr�sourcerr�state�	extension�tag�r%�>/opt/alt/python37/lib/python3.7/site-packages/jinja2/parser.py�__init__szParser.__init__cCs(|dkr|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�linenorr)r �msgr)�excr%r%r&�fail,s
zParser.failcCs�g}x|D]}|�tt|��q
W|r@d�dd�|dD��}nd}|dkrTdg}n
d|g}|r�|dk	r�||kr�|�d|�n|�d|�|jr�|�d	|jd�|�d
�|�|�dS)Nz or css|]}dt|�VqdS)z'%s'N)r)�.0�exprr%r%r&�	<genexpr>;sz&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�appendrr,)r rZend_token_stackr)ZexpectedZexprsZcurrently_looking�messager%r%r&�_fail_ut_eof5s*


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.
        )r6r)r rr)r%r%r&�fail_unknown_tagTszParser.fail_unknown_tagcCs*t|j�}|dk	r|�|�|�d||�S)z9Like fail_unknown_tag but for end of template situations.N)�listrr4r6)r �
end_tokensr)�stackr%r%r&�fail_eof[s

zParser.fail_eofcCs,|jjjdkrdS|dk	r(|jj�|�SdS)zAre we at the end of a tuple?)�variable_end�	block_end�rparenTNF)rr(�type�test_any)r �extra_end_rulesr%r%r&�is_tuple_endbs
zParser.is_tuple_endcCs6|jd7_t�tj�}tjj|d|j|d�|S)zDReturn a new free identifier as :class:`~jinja2.nodes.InternalName`.�zfi%d)r))r�object�__new__rZInternalNameZNoder')r r)�rvr%r%r&�free_identifierjszParser.free_identifiercCs�|jj}|jdkr |�d|j�|j�|j�d}z�|jtkrTt	|d|jjj��S|jdkrf|�
�S|jdkrx|��S|j�
|j�}|dk	r�||�S|j��d}|�|j|j�Wd|r�|j��XdS)	zParse a single statement.rztag name expectedTZparse_�call�filterNF)rr(r?r,r)rr4�value�_statement_keywords�getattr�parse_call_block�parse_filter_blockr�get�popr7)r �tokenZpop_tagZextr%r%r&�parse_statementqs(




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.
        �colonr=�eof)r�skip_if�expect�subparser(r?r;r)r r9�drop_needle�resultr%r%r&�parse_statements�s


zParser.parse_statementscCs8t|j�j}|��}|j�d�|��}tj|||d�S)zParse an assign statement.�assign)r))rrr)�parse_assign_targetrV�parse_tuplerZAssign)r r)�targetr.r%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)zname:in)rAzname:inF)zname:recursive)�
with_condexprrANzname:ifzname:recursive)zname:endforz	name:elseZendfor)zname:endforT)rX)r))rrVr)r\r]rU�parse_expressionrZrrJrZFor)r r)r^�iter�test�	recursive�body�else_r%r%r&�	parse_for�s
zParser.parse_forcCs�tj|j�d�jd�}}xx|jdd�|_|�d�|_t	|j�}|�d�rltj|jj
jd�}|g|_|}qn"|�d�r�|jdd	d
�|_ng|_PqW|S)zParse an if construct.zname:if)r)F)r`)z	name:elifz	name:elsez
name:endifz	name:elifz	name:else)z
name:endifT)rX)rZIfrrVr)r]rcrZrerr(rf)r �noderYrQZnew_noder%r%r&�parse_if�s 


zParser.parse_ifcCsptjt|j�jd�}|j�d�j|_|j�d�|_	|jj
jdkrJ|�d�|j
ddd�|_|j�d	|j�|S)
N)r)rzname:scoped�subzpBlock names in Jinja have to be valid Python identifiers and may not contain hyphens, use an underscore instead.)z
name:endblockT)rXzname:)rZBlockrrr)rVrJrrUZscopedr(r?r,rZre)r rhr%r%r&�parse_block�s
zParser.parse_blockcCs"tjt|j�jd�}|��|_|S)N)r))rZExtendsrrr)ra�template)r rhr%r%r&�
parse_extends�s
zParser.parse_extendscCsH|jj�dd�r>|j���d�r>t|j�jdk|_|j��n||_|S)Nz	name:withzname:withoutzname:context�with)	rr(r@�lookrcrrJ�with_context�skip)r rh�defaultr%r%r&�parse_import_context�szParser.parse_import_contextcCsbtjt|j�jd�}|��|_|jj�d�rP|j�	��d�rPd|_
|j�d�nd|_
|�|d�S)N)r)zname:ignorezname:missingT�F)
rZIncluderrr)rarlr(rcroZignore_missingrqrs)r rhr%r%r&�
parse_include�s
zParser.parse_includecCsFtjt|j�jd�}|��|_|j�d�|jdd�j	|_
|�|d�S)N)r)zname:asT)�	name_onlyF)rZImportrrr)rarlrVr\rr^rs)r rhr%r%r&�parse_imports

zParser.parse_importcstjt�j�jd������_�j�d�g�_��fdd�}x��jrR�j�d��jj	j
dkr�|�rhP�jdd�}|j�
d	�r��jd
|jtd��j�d�r��jdd�}�j�|j|jf�n�j�|j�|�s�jj	j
dkr�Pq@Pq@Wt�d
��s
d�_�j�d��S)N)r)zname:importcsB�jjjdkr>�j���d�r>t�j�jdk�_�j��dSdS)N)rnZwithoutzname:contextrnTF)rr(rJrorcrrprqr%)rhr r%r&�
parse_contexts
z(Parser.parse_from.<locals>.parse_context�commarT)rv�_z4names starting with an underline can not be imported)r+zname:asrpF)rZ
FromImportrrr)rarlrV�namesr(r?r\r�
startswithr,rrUr4�hasattrrp)r rxr^�aliasr%)rhr r&�
parse_from	s6
zParser.parse_fromcCs�g|_}g|_}|j�d�x\|jjjdkr||r@|j�d�|jdd�}|�d�|j�d�rp|�	|�
��|�	|�q"W|j�d�dS)N�lparenr>ryT)rvZparamr[)�args�defaultsrrVr(r?r\�set_ctxrUr4ra)r rhr�r��argr%r%r&�parse_signature0s


zParser.parse_signaturecCsttjt|j�jd�}|jjjdkr.|�|�ng|_g|_	|�
�|_t|jtj
�s`|�d|j�|jddd�|_|S)N)r)r�z
expected call)zname:endcallT)rX)rZ	CallBlockrrr)r(r?r�r�r�rarH�
isinstance�Callr,rZre)r rhr%r%r&rM>s
zParser.parse_call_blockcCs8tjt|j�jd�}|jddd�|_|jddd�|_|S)N)r)T)�start_inline)zname:endfilter)rX)	rZFilterBlockrrr)�parse_filterrIrZre)r rhr%r%r&rNLs

zParser.parse_filter_blockcCsBtjt|j�jd�}|jdd�j|_|�|�|jddd�|_	|S)N)r)T)rv)z
name:endmacro)rX)
rZMacrorrr)r\rr�rZre)r rhr%r%r&�parse_macroSs

zParser.parse_macrocCsTtjt|j�jd�}g|_x4|jjjdkrN|jr<|j�d�|j�|�	��qW|S)N)r)r=ry)
r�Outputrrr)r(r?rVr4ra)r rhr%r%r&�parse_print[szParser.parse_printTcCsr|r&|j�d�}tj|jd|jd�}n&|r:|jd|d�}n|��}|�d�|�	�sn|�
d|jj�
�|j�|S)a�Parse an assignment target.  As Jinja2 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.
        rZstore)r)T)�
simplifiedrAzcan't assign to %r)rrVr�NamerJr)r]�
parse_primaryr�Z
can_assignr,�	__class__�__name__�lower)r Z
with_tuplervrArQr^r%r%r&r\ds	

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 r`r%r%r&ra|szParser.parse_expressioncCsf|jjj}|��}xN|j�d�r`|��}|j�d�r>|��}nd}tj||||d�}|jjj}qW|S)Nzname:ifz	name:else)r))rr(r)r�rUr�rZCondExpr)r r)Zexpr1Zexpr2Zexpr3r%r%r&r��s

zParser.parse_condexprcCsJ|jjj}|��}x2|j�d�rD|��}tj|||d�}|jjj}qW|S)Nzname:or)r))rr(r)�	parse_andrUrZOr)r r)�left�rightr%r%r&r��s
zParser.parse_orcCsJ|jjj}|��}x2|j�d�rD|��}tj|||d�}|jjj}qW|S)Nzname:and)r))rr(r)�	parse_notrUrZAnd)r r)r�r�r%r%r&r��s
zParser.parse_andcCs4|jj�d�r,t|j�j}tj|��|d�S|��S)Nzname:not)r))	rr(rcrr)r�Notr��
parse_compare)r r)r%r%r&r��szParser.parse_notcCs�|jjj}|��}g}x�|jjj}|tkrLt|j�|�t�	||����nh|j�
d�rp|�t�	d|����nD|jj�d�r�|j���d�r�|j�
d�|�t�	d|����nP|jjj}qW|s�|Stj|||d�S)Nzname:in�inzname:notrtZnotin)r))rr(r)�	parse_addr?�_compare_operatorsrr4rZOperandrUrcrorqZCompare)r r)r.Zops�
token_typer%r%r&r��s&


zParser.parse_comparecCsV|jjj}|��}x>|jjjdkrPt|j�|��}tj|||d�}|jjj}qW|S)N�add)r))rr(r)�	parse_subr?rrZAdd)r r)r�r�r%r%r&r��s

zParser.parse_addcCsV|jjj}|��}x>|jjjdkrPt|j�|��}tj|||d�}|jjj}qW|S)Nrj)r))rr(r)�parse_concatr?rrZSub)r r)r�r�r%r%r&r��s

zParser.parse_subcCsb|jjj}|��g}x*|jjjdkr>t|j�|�|���qWt|�dkrT|dStj	||d�S)N�tilderCr)r))
rr(r)�	parse_mulr?rr4�lenrZConcat)r r)r�r%r%r&r��s


zParser.parse_concatcCsV|jjj}|��}x>|jjjdkrPt|j�|��}tj|||d�}|jjj}qW|S)N�mul)r))rr(r)�	parse_divr?rrZMul)r r)r�r�r%r%r&r��s

zParser.parse_mulcCsV|jjj}|��}x>|jjjdkrPt|j�|��}tj|||d�}|jjj}qW|S)NZdiv)r))rr(r)�parse_floordivr?rrZDiv)r r)r�r�r%r%r&r��s

zParser.parse_divcCsV|jjj}|��}x>|jjjdkrPt|j�|��}tj|||d�}|jjj}qW|S)N�floordiv)r))rr(r)�	parse_modr?rrZFloorDiv)r r)r�r�r%r%r&r��s

zParser.parse_floordivcCsV|jjj}|��}x>|jjjdkrPt|j�|��}tj|||d�}|jjj}qW|S)N�mod)r))rr(r)�	parse_powr?rrZMod)r r)r�r�r%r%r&r��s

zParser.parse_modcCsV|jjj}|��}x>|jjjdkrPt|j�|��}tj|||d�}|jjj}qW|S)N�pow)r))rr(r)�parse_unaryr?rrZPow)r r)r�r�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)NrjF)r)r�)rr(r?r)rrZNegr�ZPosr��
parse_postfix�parse_filter_expr)r Zwith_filterr�r)rhr%r%r&r�s





zParser.parse_unarycCsx|jj}|jdkrr|jdkr4tj|jdk|jd�}n0|jdkrPtjd|jd�}ntj|jd|jd�}t|j��n|jdkr�t|j�|jg}|j}x,|jjjdkr�|�	|jjj�t|j�q�Wtjd�
|�|d�}n�|jd	k�rt|j�tj|j|jd�}nr|jd
k�r2t|j�|jdd�}|j�d
�nB|jdk�rH|�
�}n,|jdk�r^|��}n|�dt|�|j�|S)Nr)�trueZfalse�True�False)r�r�)r))Znone�None�load�string�)�integer�floatr�T)�explicit_parenthesesr>�lbracket�lbracezunexpected '%s')rr(r?rJr�Constr)r�rr4r3r]rV�
parse_list�
parse_dictr,r)r rQrhZbufr)r%r%r&r� s<








zParser.parse_primaryc	s��jjj}|r�j}n|r"�j}n�fdd�}g}d}xL|rH�j�d���|�rTP|�|���jjjdkrtd}nP�jjj}q8W|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)NF)r`)rar%)r r%r&�<lambda>\�z$Parser.parse_tuple.<locals>.<lambda>FryTrz Expected an expression, got '%s'r�)r))
rr(r)r�rarVrBr4r?r,rr�Tuple)	r r�r`rAr�r)rr�Zis_tupler%)r r&r]Bs2

zParser.parse_tuplecCsn|j�d�}g}x@|jjjdkrP|r0|j�d�|jjjdkr@P|�|���qW|j�d�tj||jd�S)Nr��rbracketry)r))	rrVr(r?r4rarZListr))r rQ�itemsr%r%r&r�yszParser.parse_listcCs�|j�d�}g}xf|jjjdkrv|r0|j�d�|jjjdkr@P|��}|j�d�|��}|�tj|||jd��qW|j�d�tj	||jd�S)Nr�ZrbraceryrS)r))
rrVr(r?rar4rZPairr)ZDict)r rQr��keyrJr%r%r&r��szParser.parse_dictcCsFx@|jjj}|dks|dkr(|�|�}q|dkr<|�|�}qPqW|S)N�dotr�r�)rr(r?�parse_subscript�
parse_call)r rhr�r%r%r&r��s
zParser.parse_postfixcCs`xZ|jjj}|dkr |�|�}q|dkrB|jjjdkrB|�|�}q|dkrV|�|�}qPqW|S)N�piper�isr�)rr(r?r�rJ�
parse_testr�)r rhr�r%r%r&r��s
zParser.parse_filter_exprcCs t|j�}|jdkr�|jj}t|j�|jdkrFtj||jd|jd�S|jdkr^|�d|j�tj	|j|jd�}tj
||d|jd�S|jdk�rg}x0|jjjdkr�|r�|j�d	�|�|�
��q�W|j�d�t|�d
kr�|d}ntj|d|jd�}tj
||d|jd�S|�d|j�dS)
Nr�rr�)r)r�zexpected name or numberr�r�ryrCrzexpected subscript expression)rrr?r(rZGetattrrJr)r,r�ZGetitemrVr4�parse_subscribedr�r�)r rhrQZ
attr_tokenr�r�r%r%r&r��s.






zParser.parse_subscriptcCs�|jjj}|jjjdkr*t|j�dg}n*|��}|jjjdkrD|St|j�|g}|jjjdkrn|�d�n(|jjjdkr�|�|���n
|�d�|jjjdkr�t|j�|jjjdkr�|�|���q�|�d�n
|�d�tj|d|i�S)NrS)r�ryr))	rr(r)r?rrar4rZSlice)r r)r�rhr%r%r&r��s*





zParser.parse_subscribedc
s��j�d��g}g}d}}d}��fdd�}�x"�jjjdk�rR|rb�j�d��jjjdkrbP�jjjdkr�||dko�|dk�t�j����}n��jjjdkr�||dk�t�j����}n�||dko�|dk��jjjd	k�r4�j��jd
k�r4�jjj}�j�d����}	|�	t
j||	|	jd��n||�|�	����d
}q2W�j�d�|dk�rv||||fSt
j
|||||�jd�S)Nr�Fcs|s��d�j�dS)Nz+invalid syntax for function call expression)r,r))r.)r rQr%r&�ensure�sz!Parser.parse_call.<locals>.ensurer>ryr�r�rr[rt)r)T)rrVr(r?rrarorJrqr4rZKeywordr)r�)
r rhr��kwargs�dyn_args�
dyn_kwargsZ
require_commar�r�rJr%)r rQr&r��sF






zParser.parse_callc		Cs�x�|jjjdks|r�|s"t|j�|j�d�}|j}x2|jjjdkrft|j�|d|j�d�j7}q6W|jjjdkr�|�d�\}}}}ng}g}d}}tj|||||||j	d�}d}qW|S)Nr�rr��.r�)r)F)
rr(r?rrVrJr�rZFilterr))	r rhr�rQrr�r�r�r�r%r%r&r�s"

zParser.parse_filterc		Cst|j�}|jj�d�r(t|j�d}nd}|j�d�j}x2|jjjdkrlt|j�|d|j�d�j7}q<Wd}}g}|jjjdkr�|�d�\}}}}nH|jjjdkr�|jj�d	d
d�s�|jj�d�r�|�	d
�|�
�g}ng}tj|||||||j
d�}|�rtj||j
d�}|S)Nzname:notTFrr�r�r�)rr�r�r�r�r�r�z	name:elsezname:orzname:andzname:isz'You cannot chain multiple tests with is)r))rrr(rcrVrJr?r�r@r,rarZTestr)r�)	r rhrQZnegatedrr�r�r�r�r%r%r&r�,s2



zParser.parse_testcsDg�g��j}|dk	r"|j�|���fdd�}z�x�|j�r|jj}|jdkrv|jrj|tj|j|jd��t	|j�q4|jdkr�t	|j�||j
dd��|j�d�q4|jd	k�r|�t	|j�|dk	r�|jjj|�rވS|�
�}t|t�r���|�n
��|�|j�d
�q4td��q4W|�Wd|dk	�r>|j��X�S)Ncs8�r4�dj}��tj�dd�|d���dd�=dS)Nr)r))r)r4rr�)r))re�data_bufferr%r&�
flush_dataSs
z#Parser.subparse.<locals>.flush_data�data)r)Zvariable_beginT)r`r<Zblock_beginr=zinternal parsing error)r4rrr(r?rJrZTemplateDatar)rr]rVr@rRr�r8r2�AssertionErrorrP)r r9Zadd_datar�rQrFr%)rer�r&rWKsD









zParser.subparsecCs"tj|��dd�}|�|j�|S)z0Parse the whole template into a `Template` node.rC)r))rZTemplaterWZset_environmentr)r rYr%r%r&r{szParser.parse)NNN)N)NN)N)N)F)TFN)T)T)FTNF)F)N)9r��
__module__�__qualname__�__doc__r'rr,r6r7r;rBrGrRrZr_rgrirkrmrsrurwrr�rMrNr�r�r\rar�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r]r�r�r�r�r�r�r�r�r�rWrr%r%r%r&rsp
	




	'	

	
		








"
6
/

0rN)r�Zjinja2rZjinja2.exceptionsrrZjinja2.lexerrrZjinja2._compatrr�	frozensetrKr�rDrr%r%r%r&�<module>
s

Zerion Mini Shell 1.0