Your IP : 18.222.161.57


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

B

g[a�t�@sUdZddlZddlZddlmZddlmZddlm	Z	ddl
mZddl
mZdd	lmZejrxddlZdd
lmZed�Zejejdfed
<e�d�Ze�d�Ze�dej�Ze�dejej B�Z!e�dejej B�Z"e	d�Z#e	d�Z$e	d�Z%e	d�Z&e	d�Z'e	d�Z(e	d�Z)e	d�Z*e	d�Z+e	d�Z,e	d�Z-e	d�Z.e	d�Z/e	d �Z0e	d!�Z1e	d"�Z2e	d#�Z3e	d$�Z4e	d%�Z5e	d&�Z6e	d'�Z7e	d(�Z8e	d)�Z9e	d*�Z:e	d+�Z;e	d,�Z<e	d-�Z=e	d.�Z>e	d/�Z?e	d0�Z@e	d1�ZAe	d2�ZBe	d3�ZCe	d4�ZDe	d5�ZEe	d6�ZFe	d7�ZGe	d8�ZHe	d9�ZIe	d:�ZJe	d;�ZKe	d<�ZLe	d=�ZMe	d>�ZNe	d?�ZOe	d@�ZPe	dA�ZQe	dB�ZRe	dC�ZSe#e;e'e*e3e2e6e<e.e8e/e9e-e7e)e4e+e,e0e1e$e(e%e5e&e:dD�ZTdEdF�eT�U�D�ZVeWeT�eWeV�k�s�tXdG��e�dHdI�YdJdK�eZeTdLdM�dN�D���dO��Z[e\eIeKeJe=eNeOePg�Z]e\e=eQeKePg�Z^e_e_dP�dQdR�Z`dSe_dT�dUdV�Zae_e_dW�dXdY�Zbe_ecdZ�d[d\�Zdd]ejeeje_e_fd^�d_d`�ZfGdadb�db�ZgGdcdS�dSejh�ZiGddde�de�ZjGdfdg�dg�Zkd]dd^�dhdi�ZlGdjdk�dkem�ZnGdldm�dmejh�ZoGdnd�d�ZpdS)oz�Implements a Jinja / Python combination lexer. The ``Lexer`` class
is used to do some preprocessing. It filters out invalid operators like
the bitshift operators we don't allow in templates. It separates
template code and python code in expressions.
�N)�literal_eval)�deque)�intern�)�pattern)�TemplateSyntaxError)�LRUCache)�Environment�2�Lexer�_lexer_cachez\s+z(\r\n|\r|\n)z7('([^'\\]*(?:\\.[^'\\]*)*)'|"([^"\\]*(?:\\.[^"\\]*)*)")z�
    (
        0b(_?[0-1])+ # binary
    |
        0o(_?[0-7])+ # octal
    |
        0x(_?[\da-f])+ # hex
    |
        [1-9](_?\d)* # decimal
    |
        0(_?0)* # decimal zero
    )
    z�
    (?<!\.)  # doesn't start with a .
    (\d+_)*\d+  # digits, possibly _ separated
    (
        (\.(\d+_)*\d+)?  # optional fractional part
        e[+\-]?(\d+_)*\d+  # exponent part
    |
        \.(\d+_)*\d+  # required fractional part
    )
    �addZassignZcolonZcommaZdiv�dot�eq�floordiv�gtZgteqZlbraceZlbracketZlparen�ltZlteq�mod�mul�ne�pipe�powZrbraceZrbracketZrparenZ	semicolon�sub�tilde�
whitespace�floatZinteger�name�string�operatorZblock_beginZ	block_endZvariable_beginZvariable_endZ	raw_beginZraw_endZ
comment_beginZcomment_end�commentZlinestatement_beginZlinestatement_endZlinecomment_beginZlinecomment_endZlinecomment�data�initial�eof)�+�-�/z//�*�%z**�~�[�]�(�)�{�}z==z!=�>z>=�<z<=�=�.�:�|�,�;cCsi|]\}}||�qS�r7)�.0�k�vr7r7�=/opt/alt/python37/lib/python3.7/site-packages/jinja2/lexer.py�
<dictcomp>�sr<zoperators droppedr+r4ccs|]}t�|�VqdS)N)�re�escape)r8�xr7r7r;�	<genexpr>�sr@cCs
t|�S)N)�len)r?r7r7r;�<lambda>��rB)�keyr,)�
token_type�returncCsL|tkrt|Stdtdtdtdtdtdtdtdt	dt
d	td
tdi�
||�S)Nzbegin of commentzend of commentrzbegin of statement blockzend of statement blockzbegin of print statementzend of print statementzbegin of line statementzend of line statementztemplate data / textzend of template)�reverse_operators�TOKEN_COMMENT_BEGIN�TOKEN_COMMENT_END�
TOKEN_COMMENT�TOKEN_LINECOMMENT�TOKEN_BLOCK_BEGIN�TOKEN_BLOCK_END�TOKEN_VARIABLE_BEGIN�TOKEN_VARIABLE_END�TOKEN_LINESTATEMENT_BEGIN�TOKEN_LINESTATEMENT_END�
TOKEN_DATA�	TOKEN_EOF�get)rEr7r7r;�_describe_token_type�srU�Token)�tokenrFcCs|jtkr|jSt|j�S)z#Returns a description of the token.)�type�
TOKEN_NAME�valuerU)rWr7r7r;�describe_token�s
r[)�exprrFcCs2d|kr&|�dd�\}}|tkr*|Sn|}t|�S)z0Like `describe_token` but for token expressions.r3r)�splitrYrU)r\rXrZr7r7r;�describe_token_expr�sr^)rZrFcCstt�|��S)zsCount the number of newline characters in the string.  This is
    useful for extensions that filter a stream.
    )rA�
newline_re�findall)rZr7r7r;�count_newlines�srar	)�environmentrFcCs�tj}t|j�t||j�ft|j�t||j�ft|j�t||j�fg}|j	dk	rp|�
t|j	�td||j	�f�|jdk	r�|�
t|j�t
d||j�f�dd�t|dd�D�S)zACompiles all the rules from the environment into a list of rules.Nz	^[ \t\v]*z(?:^|(?<=\S))[^\S\r\n]*cSsg|]}|dd��qS)rNr7)r8r?r7r7r;�
<listcomp>�sz!compile_rules.<locals>.<listcomp>T)�reverse)r=r>rA�comment_start_stringrH�block_start_stringrL�variable_start_stringrN�line_statement_prefix�appendrP�line_comment_prefix�TOKEN_LINECOMMENT_BEGIN�sorted)rb�e�rulesr7r7r;�
compile_rules�s*



roc@s>eZdZdZefeejedd�dd�Ze	edd�dd	�Z
dS)
�FailurezjClass that raises a `TemplateSyntaxError` if called.
    Used by the `Lexer` to specify known errors.
    N)�message�clsrFcCs||_||_dS)N)rq�error_class)�selfrqrrr7r7r;�__init__szFailure.__init__zte.NoReturn)�lineno�filenamerFcCs|�|j||��dS)N)rsrq)rtrvrwr7r7r;�__call__szFailure.__call__)�__name__�
__module__�__qualname__�__doc__r�str�tZTyperu�intrxr7r7r7r;rp�srpc@sTeZdZUeed<eed<eed<ed�dd�Zeed�dd	�Zeed
�dd�Z	d
S)rVrvrXrZ)rFcCst|�S)N)r[)rtr7r7r;�__str__sz
Token.__str__)r\rFcCs2|j|krdSd|kr.|�dd�|j|jgkSdS)z�Test a token against a token expression.  This can either be a
        token type or ``'token_type:token_value'``.  This can only test
        against string values and types.
        Tr3rF)rXr]rZ)rtr\r7r7r;�tests

z
Token.test)�iterablerFcst�fdd�|D��S)z(Test against multiple token expressions.c3s|]}��|�VqdS)N)r�)r8r\)rtr7r;r@$sz!Token.test_any.<locals>.<genexpr>)�any)rtr�r7)rtr;�test_any"szToken.test_anyN)
ryrzr{r�__annotations__r}r��boolr�r�r7r7r7r;rVs
c@s<eZdZdZddd�dd�Zdd�dd	�Zed�d
d�ZdS)�TokenStreamIteratorz`The iterator for tokenstreams.  Iterate over the stream
    until the eof token is reached.
    �TokenStreamN)�streamrFcCs
||_dS)N)r�)rtr�r7r7r;ru,szTokenStreamIterator.__init__)rFcCs|S)Nr7)rtr7r7r;�__iter__/szTokenStreamIterator.__iter__cCs.|jj}|jtkr |j��t�t|j�|S)N)r��currentrXrS�close�
StopIteration�next)rtrWr7r7r;�__next__2s


zTokenStreamIterator.__next__)ryrzr{r|rur�rVr�r7r7r7r;r�'sr�c@s�eZdZdZejeejeejed�dd�Z	e
d�dd�Zed�dd	�Z
eed�d
d��Zedd
�dd�Zed�dd�Zd!edd�dd�Zeejed�dd�Zeed�dd�Zed�dd�Zdd�dd�Zeed�dd �ZdS)"r�z�A token stream is an iterable that yields :class:`Token`\s.  The
    parser however does not iterate over it but calls :meth:`next` to go
    one token ahead.  The current active token is stored as :attr:`current`.
    )�	generatorrrwcCs>t|�|_t�|_||_||_d|_tdtd�|_	t
|�dS)NFr�)�iter�_iterr�_pushedrrw�closedrV�
TOKEN_INITIALr�r�)rtr�rrwr7r7r;ruCs
zTokenStream.__init__)rFcCst|�S)N)r�)rtr7r7r;r�QszTokenStream.__iter__cCst|j�p|jjtk	S)N)r�r�r�rXrS)rtr7r7r;�__bool__TszTokenStream.__bool__cCs|S)z Are we at the end of the stream?r7)rtr7r7r;�eosWszTokenStream.eosN)rWrFcCs|j�|�dS)z Push a token back to the stream.N)r�ri)rtrWr7r7r;�push\szTokenStream.pushcCs"t|�}|j}|�|�||_|S)zLook at the next token.)r�r�r�)rtZ	old_token�resultr7r7r;�look`s

zTokenStream.lookr)�nrFcCsxt|�D]}t|�q
WdS)zGot n tokens ahead.N)�ranger�)rtr��_r7r7r;�skiphszTokenStream.skip)r\rFcCs|j�|�rt|�SdS)zqPerform the token test and return the token if it matched.
        Otherwise the return value is `None`.
        N)r�r�r�)rtr\r7r7r;�next_ifmszTokenStream.next_ifcCs|�|�dk	S)z8Like :meth:`next_if` but only returns `True` or `False`.N)r�)rtr\r7r7r;�skip_ifvszTokenStream.skip_ifcCsX|j}|jr|j��|_n:|jjtk	rTyt|j�|_Wntk
rR|��YnX|S)z|Go one token ahead and return the old one.

        Use the built-in :func:`next` instead of calling this directly.
        )	r�r��popleftrXrSr�r�r�r�)rt�rvr7r7r;r�zszTokenStream.__next__cCs&t|jjtd�|_td�|_d|_dS)zClose the stream.r�r7TN)rVr�rvrSr�r�r�)rtr7r7r;r��s
zTokenStream.closecCsn|j�|�sft|�}|jjtkr>td|�d�|jj|j|j��td|�dt	|j���|jj|j|j��t
|�S)z}Expect a given token type and return it.  This accepts the same
        argument as :meth:`jinja2.lexer.Token.test`.
        z%unexpected end of template, expected r2zexpected token z, got )r�r�r^rXrSrrvrrwr[r�)rtr\r7r7r;�expect�s
zTokenStream.expect)r)ryrzr{r|r~�IterablerV�Optionalr}rur�r�r�r��propertyr�r�r�rr�r�r�r�r�r�r7r7r7r;r�=s 
	r�cCsZ|j|j|j|j|j|j|j|j|j|j	|j
|jf}t�
|�}|dkrVt|�t|<}|S)z(Return a lexer which is probably cached.N)rf�block_end_stringrg�variable_end_stringre�comment_end_stringrhrj�trim_blocks�
lstrip_blocks�newline_sequence�keep_trailing_newlinerrTr)rbrDZlexerr7r7r;�	get_lexer�s 
r�cs$eZdZdZdZ�fdd�Z�ZS)�OptionalLStripzWA special tuple for marking a point in the state that can have
    lstrip applied.
    r7cst��||�S)N)�super�__new__)rr�members�kwargs)�	__class__r7r;r��szOptionalLStrip.__new__)ryrzr{r|�	__slots__r��
__classcell__r7r7)r�r;r��sr�c@sNeZdZUejeed<ejeejedfeje	fed<ej
eed<dS)�_Ruler.�tokensZcommandN)ryrzr{r~�Patternr}r�ZUnion�Tuplerpr�r7r7r7r;r��s
$r�c
@s�eZdZdZddd�dd�Zeed�dd	�Zdeejeejeejee	d
�dd�Z
dejeje
eefejeejeejed
�dd�Zdeejeejeejeejeje
eefd
�dd�ZdS)ra
Class that implements a lexer for a given environment. Automatically
    created by the environment class, usually you don't have to do that.

    Note that the lexer is not automatically bound to an environment.
    Multiple environments can share the same lexer.
    r	N)rbrFc
Cs0tj}ttjtd�dd�}tttd�ttt	d�tt
td�ttt
d�tttd�tttd�g}t|�}||j�}||j�}||j�}||j�}	|jr�dnd}
|jr�|d�nd|_|j|_|j|_d|�d|�d	|�d
�}d�|gdd
�|D��}dt|d|�d��ttd�d�t|d�td�gtt|d|�d|�d	|�|
�d
��t t!fd�t|d�t"d�fd�gt#t|d|�d|�d	|�|
�d��t$d�g|t%t|d|	�d	|	���t&d�g|t't|d|�d|�d|�d	|�|
�d
�
�ttt(�d�t|d�t"d�fd�gt)t|d�t*d�g|t+t|d�t,t-fd�gi|_.dS)N)r?rFcSst�|tjtjB�S)N)r=�compile�M�S)r?r7r7r;�c�szLexer.__init__.<locals>.cz\n?r�z[^ \t]z(?P<raw_begin>z(\-|\+|)\s*raw\s*(?:\-z\s*|z))r4cSs"g|]\}}d|�d|�d��qS)z(?P<r/z	(\-|\+|))r7)r8r��rr7r7r;rc
sz"Lexer.__init__.<locals>.<listcomp>�rootz(.*?)(?:r,z#bygroupz.+z(.*?)((?:\+z|\-z#popz(.)zMissing end of comment tagz(?:\+z\-z	(.*?)((?:z(\-|\+|))\s*endraw\s*(?:\+zMissing end of raw directivez	\s*(\n|$)z(.*?)()(?=\n|$))/r=r>r}r~r�r��
whitespace_re�TOKEN_WHITESPACE�float_re�TOKEN_FLOAT�
integer_re�
TOKEN_INTEGER�name_rerY�	string_re�TOKEN_STRING�operator_re�TOKEN_OPERATORrorfr�r�r�r�r��lstrip_unless_rer�r��joinr�rRrHrJrIrprLrMrNrO�TOKEN_RAW_BEGIN�
TOKEN_RAW_ENDrPrQrkrK�TOKEN_LINECOMMENT_ENDrn)
rtrbrmr�Z	tag_rulesZroot_tag_rulesZblock_start_reZblock_end_reZcomment_end_reZvariable_end_reZblock_suffix_reZroot_raw_reZ
root_parts_rer7r7r;ru�sz




	



"zLexer.__init__)rZrFcCst�|j|�S)z`Replace all newlines with the configured sequence in strings
        and template data.
        )r_rr�)rtrZr7r7r;�_normalize_newlinesVszLexer._normalize_newlines)�sourcerrw�staterFcCs&|�||||�}t|�|||�||�S)z:Calls tokeniter + tokenize and wraps it in a token stream.)�	tokeniterr��wrap)rtr�rrwr�r�r7r7r;�tokenize\szLexer.tokenize)r�rrwrFc
csx�xp|D�]f\}}}|tkrq|}|tkr2t}�n0|tkrBt}�n |ttfkrTq�n|tkrh|�|�}n�|dkrv|}n�|t	kr�|}|�
�s�td|||��n�|tk�ry$|�|dd���
dd��d�}WnJtk
�r}z*t|��d�d��}	t|	|||�|�Wd	d	}~XYnXnL|tk�r4t|�d
d�d�}n.|tk�rPt|�d
d��}n|tk�rbt|}t|||�VqWd	S)
z�This is called with the stream as returned by `tokenize` and wraps
        every token in a :class:`Token` and converts the value.
        �keywordzInvalid character in identifierr����ascii�backslashreplacezunicode-escaper3Nr�r�r)�ignored_tokensrPrLrQrMr�r�rRr�rY�isidentifierrr��encode�decode�	Exceptionr}r]�stripr�r�replacer�rr��	operatorsrV)
rtr�rrwrvrWZ	value_strrZrm�msgr7r7r;r�gsD	

$


z
Lexer.wrapccsVt�|�ddd�}|js,|ddkr,|d=d�|�}d}d}dg}|dk	rr|dkrr|d	ksdtd
��|�|d�|j|d}	t|�}
g}|j}d}
d}�x��x�|	D�]v\}}}|�	||�}|dkr�q�|r�|t
ttfkr�q�t
|t��r�|��}t
|t��r�|d}td
d�|ddd�D��}|dk�r\|��}|t|�d��d�}
|f|dd��}nj|dk�r�|dk	�r�|���t��s�|�d�d}|dk�s�|�r�|�||��s�|d|�f|dd��}x�t|�D]�\}}|jtk�r�|||��n�|dk�rLx�|����D]0\}}|dk	�r|||fV||�d�7}P�qWt|�d���n:||}|�sd|tk�rp|||fV||�d�|
7}d}
�q�Wn�|��}|t k�r6|dk�r�|�d�n�|dk�r�|�d�nj|dk�r�|�d�nT|dk�r6|�st!d|�d�|||��|�"�}||k�r6t!d|�d|�d�|||��|�sF|tk�rR|||fV||�d�7}|��dd�dk}|�#�}|dk	�r|dk�r�|�"�nV|dk�r�xJ|����D] \}}|dk	�r�|�|�P�q�Wt|�d���n
|�|�|j|d}	n||k�rt|�d���|}Pq�W||
k�r0dSt!d ||�d!|��|||��q�WdS)"aThis method tokenizes the text and returns the tokens in a
        generator. Use this method if you just want to tokenize a template.

        .. versionchanged:: 3.0
            Only ``\n``, ``\r\n`` and ``\r`` are treated as line
            breaks.
        N�r�r��
rrr�)Zvariable�blockz
invalid stateZ_beginTcss|]}|dk	r|VqdS)Nr7)r8�gr7r7r;r@�sz"Lexer.tokeniter.<locals>.<genexpr>r$r#z#bygroupz= wanted to resolve the token dynamically but no group matchedr-r.r+r,r)r*)r.r,r*zunexpected '�'z
', expected 'z#popzA wanted to resolve the new state dynamically but no group matchedz* yielded empty string without stack changezunexpected char z at )$r_r]r�r��AssertionErrorrirnrAr��matchrOrMrQ�
isinstance�tuple�groupsr�r��rstrip�count�	groupdictrTrN�rfind�search�	enumerater�rp�items�RuntimeError�ignore_if_empty�groupr�r�pop�end)rtr�rrwr��lines�posrv�stackZstatetokensZ
source_lengthZbalancing_stackr�Znewlines_strippedZ
line_startingZregexr�Z	new_state�mr��textZ
strip_sign�strippedZl_pos�idxrWrDrZr Zexpected_opZpos2r7r7r;r��s�




















zLexer.tokeniter)NNN)NN)NN)ryrzr{r|rur}r�r~r�r�r�r�r�r�IteratorrVr�r�r7r7r7r;r�sy	&5)qr|r=�typingr~Zastr�collectionsr�sysrZ_identifierrr��
exceptionsrZutilsrZ
TYPE_CHECKINGZtyping_extensionsZterbr	r�MutableMappingr�r�r�r�r_r�r��
IGNORECASE�VERBOSEr�r�Z	TOKEN_ADDZTOKEN_ASSIGNZTOKEN_COLONZTOKEN_COMMAZ	TOKEN_DIVZ	TOKEN_DOTZTOKEN_EQZTOKEN_FLOORDIVZTOKEN_GTZ
TOKEN_GTEQZTOKEN_LBRACEZTOKEN_LBRACKETZTOKEN_LPARENZTOKEN_LTZ
TOKEN_LTEQZ	TOKEN_MODZ	TOKEN_MULZTOKEN_NEZ
TOKEN_PIPEZ	TOKEN_POWZTOKEN_RBRACEZTOKEN_RBRACKETZTOKEN_RPARENZTOKEN_SEMICOLONZ	TOKEN_SUBZTOKEN_TILDEr�r�r�rYr�r�rLrMrNrOr�r�rHrIrJrPrQrkr�rKrRr�rSr�r�rGrAr�r�rlr��	frozensetr�r�r}rUr[r^rraZListrorpZ
NamedTuplerVr�r�r�r�r�r�rr7r7r7r;�<module>s�




*
 )m


?>