%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17212/usr/lib/python3/dist-packages/jinja2/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17212/usr/lib/python3/dist-packages/jinja2/__pycache__/parser.cpython-35.pyc



�bUr��@s�dZddlmZddlmZmZddlmZmZddl	m
Z
edddd	d
ddd
ddg
�Zeddddddg�Z
Gdd�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)�imap�for�if�blockZextends�printZmacro�include�from�import�set�eq�ne�ltZlteq�gtZgteqc@s�eZdZdZddddd�Zdedd�Zdd�Zdd	d
�Zdddd�Z	dd
d�Z
ddd�Zdd�Zddd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2ddd3d4�Zd2d5d6�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*d2dQdR�Z+dSdT�Z,dd2dddUdV�Z-dWdX�Z.dYdZ�Z/d[d\�Z0d]d^�Z1d_d`�Z2dadb�Z3dcdd�Z4ddedf�Z5dgdh�Z6ddidj�Z7dkdl�Z8dS)m�Parserz�This is the central parsing class Jinja2 uses.  It's passed to
    extensions and can be used to parse expressions or statements.
    NcCs�||_|j||||�|_||_||_d|_i|_x8|j�D]*}x!|jD]}|j	|j|<qeWqUWd|_
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%�//usr/lib/python3/dist-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.failcCsg}x$|D]}|jtt|��q
W|rVdjdd�|dD��}nd}|dkrtdg}n
d|g}|r�|dk	r�||kr�|jd|�n|jd|�|jr�|jd	|jd�|jd
j|�|�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'.� ���r2)�extendrr�join�appendrr,)r rZend_token_stackr)ZexpectedZexprsZcurrently_looking�messager%r%r&�_fail_ut_eof4s*
	
				zParser._fail_ut_eofcCs|j||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.
        )r7r)r rr)r%r%r&�fail_unknown_tagSszParser.fail_unknown_tagcCs;t|j�}|dk	r(|j|�|jd||�S)z9Like fail_unknown_tag but for end of template situations.N)�listrr5r7)r �
end_tokensr)�stackr%r%r&�fail_eofZs
zParser.fail_eofcCs<|jjjdkrdS|dk	r8|jjj|�SdS)zAre we at the end of a tuple?�variable_end�	block_end�rparenTNF)r=r>r?)rr(�type�test_any)r �extra_end_rulesr%r%r&�is_tuple_endas
zParser.is_tuple_endcCsE|jd7_tjtj�}tjj|d|jd|�|S)zDReturn a new free identifier as :class:`~jinja2.nodes.InternalName`.r0zfi%dr))r�object�__new__rZInternalNameZNoder')r r)�rvr%r%r&�free_identifieris zParser.free_identifierc
Cs|jj}|jdkr.|jd|j�|jj|j�d}z�|jtkrvt	|d|jjj��S|jdkr�|j
�S|jdkr�|j�S|jj
|j�}|dk	r�||�S|jj�d}|j|j|j�Wd|r|jj�XdS)	zParse a single statement.rztag name expectedTZparse_�call�filterNF)rr(r@r,r)rr5�value�_statement_keywords�getattr�parse_call_block�parse_filter_blockr�get�popr8)r �tokenZpop_tagZextr%r%r&�parse_statementps(



zParser.parse_statementFcCsh|jjd�|jjd�|j|�}|jjjdkrQ|j|�|rdt|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<�next)r r:�drop_needle�resultr%r%r&�parse_statements�s

zParser.parse_statementscCs}t|j�j}|j�}|jjd�rR|j�}tj||d|�S|jddd�}tj	||d|�S)zParse an assign statement.�assignr)�name:endsetrYT)r])
rXrr)�parse_assign_targetrU�parse_tuplerZAssignr[ZAssignBlock)r r)�targetr.�bodyr%r%r&�	parse_set�s	zParser.parse_setc	Cs�|jjd�j}|jdd�}|jjd�|jdddd�}d}|jjd�rs|j�}|jjd�}|jd�}t|j�j	dkr�g}n|jddd
�}t
j||||||d|�S)zParse a for loop.zname:forrB�name:in�
with_condexprF�name:recursiveNzname:if�name:endfor�	name:elseZendforrYTr))rc)re)rfrg)rf)rrVr)r^r_rU�parse_expressionr[rXrJrZFor)r r)r`�iter�testZ	recursivera�else_r%r%r&�	parse_for�s		zParser.parse_forcCs�tjd|jjd�j�}}x�|jdd�|_|jd
�|_t	|j�}|jd�r�tjd|jj
j�}|g|_|}q(n3|jd�r�|jddd	�|_n	g|_Pq(W|S)zParse an if construct.r)zname:ifrdF�	name:elif�	name:else�
name:endifrYT)rmrnro)ro)rZIfrrVr)r_rjr[rarXr(rk)r �noderZrQZnew_noder%r%r&�parse_if�s"%	zParser.parse_ifcCs�tjdt|j�j�}|jjd�j|_|jjd�|_	|jj
jdkrm|jd�|j
d
dd�|_|jjd	|j�|S)Nr)rzname:scoped�subzpBlock names in Jinja have to be valid Python identifiers and may not contain hyphens, use an underscore instead.�
name:endblockrYTzname:)rs)rZBlockrXrr)rVrJrrUZscopedr(r@r,r[ra)r rpr%r%r&�parse_block�s
zParser.parse_blockcCs1tjdt|j�j�}|j�|_|S)Nr))rZExtendsrXrr)rh�template)r rpr%r%r&�
parse_extends�szParser.parse_extendscCsh|jjjdd�r[|jj�jd�r[t|j�jdk|_|jj�n	||_|S)Nz	name:withzname:withoutzname:context�with)	rr(rA�lookrjrXrJ�with_context�skip)r rp�defaultr%r%r&�parse_import_context�s	zParser.parse_import_contextcCs�tjdt|j�j�}|j�|_|jjjd�rv|jj	�jd�rvd|_
|jjd�n	d|_
|j|d�S)Nr)zname:ignorezname:missingT�F)
r�IncluderXrr)rhrur(rjrxZignore_missingrzr|)r rpr%r%r&�
parse_include�s		zParser.parse_includecCsetjdt|j�j�}|j�|_|jjd�|jdd�j	|_
|j|d�S)Nr)zname:as�	name_onlyTF)rZImportrXrr)rhrurVr^rr`r|)r rpr%r%r&�parse_imports
zParser.parse_importcs|tjdt�j�j���j��_�jjd�g�_��fdd�}x��jrw�jjd��jj	j
dkrK|�r�P�jdd�}|jj
d	�r��jd
|jdt��jjd�r�jdd�}�jj|j|jf�n�jj|j�|�sG�jj	j
dkrLPq^Pq^Wt�d
�sxd�_�jjd��S)Nr)zname:importcs]�jjjdkrY�jj�jd�rYt�j�jdk�_�jj�dSdS)Nrw�withoutzname:contextTF)zwithr�)rr(rJrxrjrXryrzr%)rpr r%r&�
parse_contexts
z(Parser.parse_from.<locals>.parse_context�commarr�T�_z4names starting with an underline can not be importedr+zname:asryF)rZ
FromImportrXrr)rhrurV�namesr(r@r^r�
startswithr,rrUr5�hasattrry)r r�r`�aliasr%)rpr r&�
parse_froms6						zParser.parse_fromcCs�g|_}g|_}|jjd�x�|jjjdkr�|rX|jjd�|jdd�}|jd�|jjd�r�|j	|j
��n|r�|jd�|j	|�q-W|jjd�dS)	N�lparenr?r�r�TZparamr\z-non-default argument follows default argument)�args�defaultsrrVr(r@r^�set_ctxrUr5rhr,)r rpr�r��argr%r%r&�parse_signature2s



zParser.parse_signaturecCs�tjdt|j�j�}|jjjdkrC|j|�ng|_g|_	|j
�|_t|jtj
�s�|jd|j�|jddd�|_|S)Nr)r�z
expected call�name:endcallrYT)r�)rZ	CallBlockrXrr)r(r@r�r�r�rhrH�
isinstance�Callr,r[ra)r rpr%r%r&rMBs		zParser.parse_call_blockcCsRtjdt|j�j�}|jddd�|_|jddd�|_|S)Nr)�start_inlineT�name:endfilterrY)r�)	rZFilterBlockrXrr)�parse_filterrIr[ra)r rpr%r%r&rNPs
zParser.parse_filter_blockcCs_tjdt|j�j�}|jdd�j|_|j|�|jddd�|_	|S)Nr)r�T�
name:endmacrorY)r�)
rZMacrorXrr)r^rr�r[ra)r rpr%r%r&�parse_macroWs
zParser.parse_macrocCsvtjdt|j�j�}g|_xH|jjjdkrq|jrX|jjd�|jj|j	��q*W|S)Nr)r>r�)
r�OutputrXrr)r(r@rVr5rh)r rpr%r%r&�parse_print_s		zParser.parse_printTcCs�|r9|jjd�}tj|jdd|j�}n:|rZ|jddd|�}n|j�}|jd�|j	�s�|j
d|jjj
�|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.
        rZstorer)�
simplifiedTrBzcan't assign to %r)rrVr�NamerJr)r_�
parse_primaryr�Z
can_assignr,�	__class__�__name__�lower)r Z
with_tupler�rBrQr`r%r%r&r^hs	!

zParser.parse_assign_targetcCs|r|j�S|j�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 rdr%r%r&rh�s
zParser.parse_expressioncCs�|jjj}|j�}xs|jjd�r�|j�}|jjd�r]|j�}nd}tj|||d|�}|jjj}qW|S)Nzname:ifz	name:elser))rr(r)r�rUr�rZCondExpr)r r)Zexpr1Zexpr2Zexpr3r%r%r&r��szParser.parse_condexprcCsk|jjj}|j�}xI|jjd�rf|j�}tj||d|�}|jjj}qW|S)Nzname:orr))rr(r)�	parse_andrUrZOr)r r)�left�rightr%r%r&r��szParser.parse_orcCsk|jjj}|j�}xI|jjd�rf|j�}tj||d|�}|jjj}qW|S)Nzname:andr))rr(r)�	parse_notrUrZAnd)r r)r�r�r%r%r&r��szParser.parse_andcCsJ|jjjd�r@t|j�j}tj|j�d|�S|j�S)Nzname:notr))	rr(rjrXr)r�Notr��
parse_compare)r r)r%r%r&r��szParser.parse_notcCs5|jjj}|j�}g}x�|jjj}|tkrnt|j�|jtj	||j���n�|jj
d�r�|jtj	d|j���n`|jjjd�r|jj�jd�r|jj
d�|jtj	d|j���nP|jjj}q$W|s|Stj||d|�S)Nzname:in�inzname:notr}Znotinr))rr(r)�	parse_addr@�_compare_operatorsrXr5rZOperandrUrjrxrzZCompare)r r)r.Zops�
token_typer%r%r&r��s&
"""zParser.parse_comparecCs{|jjj}|j�}xY|jjjdkrvt|j�|j�}tj||d|�}|jjj}qW|S)N�addr))rr(r)�	parse_subr@rXrZAdd)r r)r�r�r%r%r&r��s
zParser.parse_addcCs{|jjj}|j�}xY|jjjdkrvt|j�|j�}tj||d|�}|jjj}qW|S)Nrrr))rr(r)�parse_concatr@rXrZSub)r r)r�r�r%r%r&r��s
zParser.parse_subcCs�|jjj}|j�g}x9|jjjdkrYt|j�|j|j��q!Wt|�dkrt|dStj	|d|�S)N�tilder0rr))
rr(r)�	parse_mulr@rXr5�lenrZConcat)r r)r�r%r%r&r��s
zParser.parse_concatcCs{|jjj}|j�}xY|jjjdkrvt|j�|j�}tj||d|�}|jjj}qW|S)N�mulr))rr(r)�	parse_divr@rXrZMul)r r)r�r�r%r%r&r��s
zParser.parse_mulcCs{|jjj}|j�}xY|jjjdkrvt|j�|j�}tj||d|�}|jjj}qW|S)NZdivr))rr(r)�parse_floordivr@rXrZDiv)r r)r�r�r%r%r&r��s
zParser.parse_divcCs{|jjj}|j�}xY|jjjdkrvt|j�|j�}tj||d|�}|jjj}qW|S)N�floordivr))rr(r)�	parse_modr@rXrZFloorDiv)r r)r�r�r%r%r&r��s
zParser.parse_floordivcCs{|jjj}|j�}xY|jjjdkrvt|j�|j�}tj||d|�}|jjj}qW|S)N�modr))rr(r)�	parse_powr@rXrZMod)r r)r�r�r%r%r&r�s
zParser.parse_modcCs{|jjj}|j�}xY|jjjdkrvt|j�|j�}tj||d|�}|jjj}qW|S)N�powr))rr(r)�parse_unaryr@rXrZPow)r r)r�r�r%r%r&r�
s
zParser.parse_powcCs�|jjj}|jjj}|dkrXt|j�tj|jd�d|�}nF|dkr�t|j�tj|jd�d|�}n|j	�}|j
|�}|r�|j|�}|S)NrrFr)r�)rr(r@r)rXrZNegr�ZPosr��
parse_postfix�parse_filter_expr)r Zwith_filterr�r)rpr%r%r&r�s
!
!zParser.parse_unarycCs|jj}|jdkr�|jdkrNtj|jdkd|j�}nH|jdkrxtjdd|j�}ntj|jd	d|j�}t|j�ne|jd
kr7t|j�|jg}|j}x<|jjjd
kr|j	|jjj�t|j�q�Wtjdj
|�d|�}n�|jdkrqt|j�tj|jd|j�}n�|jdkr�t|j�|jdd�}|jjd�nY|jdkr�|j
�}n;|jdkr�|j�}n|jdt|�|j�|S)Nr�true�false�True�Falser)�none�None�load�string��integer�floatr��explicit_parenthesesTr?�lbracket�lbracezunexpected '%s')�truezfalse�TruezFalse)r�r�)r�zNone)r�zfloat)rr(r@rJr�Constr)r�rXr5r4r_rV�
parse_list�
parse_dictr,r)r rQrpZbufr)r%r%r&r�$s<
	!

zParser.parse_primaryc	s	�jjj}|r!�j}n$|r3�j}n�fdd�}g}d}xh|rj�jjd��j|�rzP|j|���jjjdkr�d}nP�jjj}qTW|s�|r�|dS|s��j	dt
�jj��tj|dd	|�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)NrdF)rhr%)r r%r&�<lambda>`sz$Parser.parse_tuple.<locals>.<lambda>Fr�Trz Expected an expression, got '%s'r�r))
rr(r)r�rhrVrCr5r@r,rr�Tuple)	r r�rdrBr�r)rr�Zis_tupler%)r r&r_Fs2		zParser.parse_tuplecCs�|jjd�}g}xX|jjjdkrr|rF|jjd�|jjjdkr\P|j|j��qW|jjd�tj|d|j�S)Nr��rbracketr�r))	rrVr(r@r5rhrZListr))r rQ�itemsr%r%r&r�}szParser.parse_listcCs�|jjd�}g}x�|jjjdkr�|rF|jjd�|jjjdkr\P|j�}|jjd�|j�}|jtj||d|j��qW|jjd�tj	|d|j�S)Nr�Zrbracer�rSr))
rrVr(r@rhr5rZPairr)ZDict)r rQr��keyrJr%r%r&r��s&zParser.parse_dictcCscx\|jjj}|dks*|dkr<|j|�}q|dkrZ|j|�}qPqW|S)N�dotr�r�)rr(r@�parse_subscript�
parse_call)r rpr�r%r%r&r��szParser.parse_postfixcCs�x�|jjj}|dkr0|j|�}q|dkrc|jjjdkrc|j|�}q|dkr�|j|�}qPqW|S)N�piper�isr�)rr(r@r�rJ�
parse_testr�)r rpr�r%r%r&r��s!zParser.parse_filter_exprcCs�t|j�}|jdkr�|jj}t|j�|jdkretj||jdd|j�S|jdkr�|jd|j�tj	|jd|j�}tj
||dd|j�S|jdkr~g}xB|jjjdkr|r|jjd	�|j|j
��q�W|jjd�t|�d
krG|d}ntj|dd|j�}tj
||dd|j�S|jd|j�dS)
Nr�rr�r)r�zexpected name or numberr�r�r�r0rzexpected subscript expression)rXrr@r(rZGetattrrJr)r,r�ZGetitemrVr5�parse_subscribedr�r�)r rprQZ
attr_tokenr�r�r%r%r&r��s.


zParser.parse_subscriptcCsR|jjj}|jjjdkr=t|j�dg}n;|j�}|jjjdkrb|St|j�|g}|jjjdkr�|jd�n8|jjjdkr�|j|j��n
|jd�|jjjdkr2t|j�|jjjdkr"|j|j��q?|jd�n
|jd�tj|d|�S)NrSr�r�r))�rbracket�comma)r�r�)	rr(r)r@rXrhr5rZSlice)r r)r�rpr%r%r&r��s*

	


zParser.parse_subscribedc
s$�jjd��g}g}d}}d}��fdd�}x��jjjdkr�|r��jjd��jjjdkr�P�jjjdkr�||dko�|dk�t�j��j�}n��jjjdkr||dk�t�j��j�}n�||dko-|dk��jjjd	kr��jj�jd
kr��jjj}�jjd��j�}	|j	t
j||	d|	j��n||�|j	�j��d
}qFW�jjd�|dkr||||fSt
j
|||||d�j�S)Nr�Fcs|s�jd�j�dS)Nz+invalid syntax for function call expression)r,r))r.)r rQr%r&�ensure�s	z!Parser.parse_call.<locals>.ensurer?r�r�r�rr\r}r)T)rrVr(r@rXrhrxrJrzr5rZKeywordr)r�)
r rpr��kwargs�dyn_args�
dyn_kwargsZ
require_commar�r�rJr%)r rQr&r��sF



zParser.parse_callc		Csx	|jjjdks|r|s1t|j�|jjd�}|j}xC|jjjdkr�t|j�|d|jjd�j7}qOW|jjjdkr�|jd�\}}}}ng}g}d}}tj||||||d|j	�}d}qW|S)Nr�rr��.r�r)F)
rr(r@rXrVrJr�rZFilterr))	r rpr�rQrr�r�r�r�r%r%r&r�s"
	
!

zParser.parse_filterc		Cs�t|j�}|jjjd�r:t|j�d}nd}|jjd�j}xC|jjjdkr�t|j�|d|jjd�j7}qXWd}}g}|jjjdkr�|jd�\}}}}nk|jjjdkrC|jjjd
dd�rC|jjjd�r1|j	d�|j
�g}ng}tj||||||d|j
�}|r�tj|d|j
�}|S)Nzname:notTFrr�r�r�r�r�r�r�r�z	name:elsezname:orzname:andzname:isz'You cannot chain multiple tests with isr))znamezstringzintegerzfloatzlparenzlbracketzlbrace)rXrr(rjrVrJr@r�rAr,rhrZTestr)r�)	r rprQZnegatedrr�r�r�r�r%r%r&r�0s6
	
!
	

zParser.parse_testcs�g�g��j}|dk	r1|jj|���fdd�}zRxD|jr�|jj}|jdkr�|jr�|tj|jd|j��t	|j�qL|jdkr�t	|j�||j
dd��|jjd�qL|jd	kr�|�t	|j�|dk	r5|jjj|�r5�S|j
�}t|t�r`�j|�n
�j|�|jjd
�qLtd��qLW|�Wd|dk	r�|jj�X�S)NcsJ�rF�dj}�jtj�dd�d|���dd�=dS)Nrr))r)r5rr�)r))ra�data_bufferr%r&�
flush_dataWs
&z#Parser.subparse.<locals>.flush_data�datar)Zvariable_beginrdTr=Zblock_beginr>zinternal parsing error)r5rrr(r@rJrZTemplateDatar)rXr_rVrArRr�r9r3�AssertionErrorrP)r r:Zadd_datar�rQrFr%)rar�r&rWOsD		



zParser.subparsecCs/tj|j�dd�}|j|j�|S)z0Parse the whole template into a `Template` node.r)r0)rZTemplaterWZset_environmentr)r rZr%r%r&rszParser.parse)9r��
__module__�__qualname__�__doc__r'rr,r7r8r<rCrGrRr[rbrlrqrtrvr|rr�r�r�rMrNr�r�r^rhr�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._compatr�	frozensetrKr�rDrr%r%r%r&�<module>
s

Zerion Mini Shell 1.0