관리-도구
편집 파일: lexer.cpython-39.opt-1.pyc
a �����`{v����������������������@���s���d�Z�ddlZddlmZ�ddlmZ�ddlmZ�ddlm Z �ddlm Z �dd lmZ�dd lmZ�ddl mZ�ddlmZ�ed �Ze�dej�Ze�d�Ze�dej�Ze�d�Ze�dejejB��Zzeddd��W�n �ey����e�d�ZdZY�n0�ddlm Z�dZe 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'�Z.e d(�Z/e d)�Z0e d*�Z1e d+�Z2e d,�Z3e d-�Z4e d.�Z5e d/�Z6e d0�Z7e d1�Z8e d2�Z9e d3�Z:e d4�Z;e d5�Z<e d6�Z=e d7�Z>e d8�Z?e d9�Z@e d:�ZAe d;�ZBe d<�ZCe d=�ZDe d>�ZEe d?�ZFe d@�ZGe dA�ZHe dB�ZIe dC�ZJe dD�ZKe dE�ZLe dF�ZMe dG�ZNe dH�ZOe dI�ZPe dJ�ZQe!e9e%e(e1e0e4e:e,e6e-e7e+e5e'e2e)e*e.e/e"e&e#e3e$e8dK�ZReSdLdM��eeR�D���ZTe�dNdO�UdPdQ��eVeRdRdS��dT�D�����ZWeXeGeIeHe;eLeMeNg�ZYeXe;eOeIeNg�ZZdUdV��Z[dWdX��Z\dYdZ��Z]d[d\��Z^d]d^��Z_G�d_d`��d`e`�ZaG�dadb��dbeb�Zce G�dcdd��dde`��Zde G�dedf��dfe`��Zedgdh��ZfG�didj��djeb�ZgG�dkdl��dle`�ZhdS�)mz�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)� itemgetter����)�implements_iterator)�intern)� iteritems)� text_type)�TemplateSyntaxError)�LRUCache�2���z\s+z(\r\n|\r|\n)z7('([^'\\]*(?:\\.[^'\\]*)*)'|"([^"\\]*(?:\\.[^"\\]*)*)")z (\d+_)*\d+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 ) u���fööz <unknown>�evalz[a-zA-Z_][a-zA-Z0-9_]*F)�patternT�addZassign�colonZcommaZdiv�dot�eq�floordiv�gtZgteqZlbraceZlbracketZlparen�ltZlteq�mod�mul�ne�pipe�pow�rbraceZrbracketZrparenZ semicolon�sub�tildeZ whitespace�floatZinteger�name�string�operatorZblock_beginZ block_endZvariable_beginZvariable_endZ raw_beginZraw_endZ comment_beginZcomment_end�commentZlinestatement_beginZlinestatement_endZlinecomment_beginZlinecomment_endZlinecomment�data�initial�eof)�+�-�/z//�*�%z**�~�[�]�(�)�{�}z==z!=�>z>=�<z<=�=�.�:�|�,�;c�����������������C���s���g�|�]\}}||f�qS���r:���)�.0�k�vr:���r:����0/usr/lib/python3.9/site-packages/jinja2/lexer.py� <listcomp>���������r?���z(%s)r7���c�����������������c���s���|�]}t��|�V��qd�S��N)�re�escape�r;����xr:���r:���r>���� <genexpr>����r@���rF���c�����������������C���s ���t�|���S�rA���)�len�rE���r:���r:���r>����<lambda>����r@���rI���)�keyc�����������������C���sL���|�t�v�rt�|��S�tdtdtdtdtdtdtdtdt dt d td tdi� |�|��S�)Nzbegin of commentzend of commentr"���zbegin 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)� token_typer:���r:���r>����_describe_token_type����s"����� �rZ���c�����������������C���s���|�j�tkr|�jS�t|�j��S�)z#Returns a description of the token.)�type� TOKEN_NAME�valuerZ���)�tokenr:���r:���r>����describe_token����s���� r_���c�����������������C���s2���d|�v�r&|���dd�\}}|tkr*|S�n|�}t|�S�)z0Like `describe_token` but for token expressions.r6���r���)�splitr\���rZ���)�exprr[���r]���r:���r:���r>����describe_token_expr����s����rb���c�����������������C���s���t�t�|���S�)zsCount the number of newline characters in the string. This is useful for extensions that filter a stream. )rG���� newline_re�findall)r]���r:���r:���r>����count_newlines����s����re���c�����������������C���s����t�j}t|�j�t||�j�ft|�j�t||�j�ft|�j�t||�j�fg}|�j durp|� t|�j �td||�j ��f��|�jdur�|� 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]*c�����������������S���s���g�|�]}|d�d���qS�)r���Nr:���rD���r:���r:���r>���r?�������r@���z!compile_rules.<locals>.<listcomp>T)�reverse)rB���rC���rG����comment_start_stringrL����block_start_stringrP����variable_start_stringrR����line_statement_prefix�appendrT����line_comment_prefix�TOKEN_LINECOMMENT_BEGIN�sorted)�environment�e�rulesr:���r:���r>���� compile_rules����s:�������� �� ��rr���c�������������������@���s$���e�Zd�ZdZefdd�Zdd��ZdS�)�FailurezjClass that raises a `TemplateSyntaxError` if called. Used by the `Lexer` to specify known errors. c�����������������C���s���||�_�||�_d�S�rA���)�message�error_class)�selfrt����clsr:���r:���r>����__init__����s����zFailure.__init__c�����������������C���s���|���|�j||��d�S�rA���)ru���rt���)rv����lineno�filenamer:���r:���r>����__call__����s����zFailure.__call__N)�__name__� __module__�__qualname__�__doc__r ���rx���r{���r:���r:���r:���r>���rs�������s���rs���c�������������������@���sT���e�Zd�ZdZdZdd��ed�D��\ZZZdd��Z dd ��Z d d��Zdd ��Zdd��Z dS�)�TokenzToken class.r:���c�����������������c���s���|�]}t�t|��V��qd�S�rA���)�propertyr���rD���r:���r:���r>���rF�����r@���zToken.<genexpr>����c�����������������C���s���t��|�|tt|��|f�S�rA���)�tuple�__new__r����str)rw���ry���r[���r]���r:���r:���r>���r���� ��s����z Token.__new__c�����������������C���s*���|�j�tv�rt|�j��S�|�j�dkr$|�jS�|�j�S�)Nr���)r[���rK���r]����rv���r:���r:���r>����__str__��s ���� z Token.__str__c�����������������C���s2���|�j�|krdS�d|v�r.|�dd�|�j�|�jgkS�dS�)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. Tr6���r���F)r[���r`���r]����rv���ra���r:���r:���r>����test��s ���� z Token.testc�����������������G���s���|D�]}|���|�r�dS�qdS�)z(Test against multiple token expressions.TF)r����)rv����iterablera���r:���r:���r>����test_any ��s���� zToken.test_anyc�����������������C���s���d|�j�|�j|�jf�S�)NzToken(%r, %r, %r))ry���r[���r]���r����r:���r:���r>����__repr__'��s����zToken.__repr__N)r|���r}���r~���r���� __slots__�rangery���r[���r]���r����r����r����r����r����r:���r:���r:���r>���r������s��� r����c�������������������@���s(���e�Zd�ZdZdd��Zdd��Zdd��ZdS�) �TokenStreamIteratorz`The iterator for tokenstreams. Iterate over the stream until the eof token is reached. c�����������������C���s ���||�_�d�S�rA���)�stream)rv���r����r:���r:���r>���rx���1��s����zTokenStreamIterator.__init__c�����������������C���s���|�S�rA���r:���r����r:���r:���r>����__iter__4��s����zTokenStreamIterator.__iter__c�����������������C���s0���|�j�j}|jtu�r"|�j�����t���t|�j���|S�rA���)r�����currentr[���rW����close� StopIteration�next�rv���r^���r:���r:���r>����__next__7��s���� zTokenStreamIterator.__next__N)r|���r}���r~���r���rx���r����r����r:���r:���r:���r>���r����+��s���r����c�������������������@���sz���e�Zd�ZdZdd��Zdd��Zdd��ZeZedd ���Z d d��Z dd ��Zddd�Zdd��Z dd��Zdd��Zdd��Zdd��ZdS�)�TokenStreamz�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`. c�����������������C���s>���t�|�|�_t��|�_||�_||�_d|�_tdtd�|�_ t |���d�S�)NFr�����)�iter�_iterr����_pushedr���rz����closedr����� TOKEN_INITIALr����r����)rv���� generatorr���rz���r:���r:���r>���rx���G��s���� zTokenStream.__init__c�����������������C���s���t�|��S�rA���)r����r����r:���r:���r>���r����P��s����zTokenStream.__iter__c�����������������C���s���t�|�j�p|�jjtuS�rA���)�boolr����r����r[���rW���r����r:���r:���r>����__bool__S��s����zTokenStream.__bool__c�����������������C���s���|��S�)z Are we at the end of the stream?r:���r����r:���r:���r>����eosX��s����zTokenStream.eosc�����������������C���s���|�j��|��dS�)z Push a token back to the stream.N)r����rk���r����r:���r:���r>����push]��s����zTokenStream.pushc�����������������C���s"���t�|��}|�j}|��|��||�_|S�)zLook at the next token.)r����r����r����)rv���Z old_token�resultr:���r:���r>����looka��s ���� zTokenStream.lookr���c�����������������C���s���t�|�D�]}t|���qdS�)zGot n tokens ahead.N)r����r����)rv����n�_r:���r:���r>����skipi��s����zTokenStream.skipc�����������������C���s���|�j��|�rt|��S�dS�)zqPerform the token test and return the token if it matched. Otherwise the return value is `None`. N)r����r����r����r����r:���r:���r>����next_ifn��s����zTokenStream.next_ifc�����������������C���s���|���|�duS�)z8Like :meth:`next_if` but only returns `True` or `False`.N)r����r����r:���r:���r>����skip_ifu��s����zTokenStream.skip_ifc�����������������C���sV���|�j�}|�jr|�j���|�_�n8|�j�jturRzt|�j�|�_�W�n�tyP���|�����Y�n0�|S�)z|Go one token ahead and return the old one. Use the built-in :func:`next` instead of calling this directly. ) r����r�����popleftr[���rW���r����r����r����r����)rv����rvr:���r:���r>���r����y��s����zTokenStream.__next__c�����������������C���s"���t�|�jjtd�|�_d|�_d|�_dS�)zClose the stream.r����NT)r����r����ry���rW���r����r����r����r:���r:���r>���r�������s����zTokenStream.closec�����������������C���s~���|�j��|�s^t|�}|�j�jtu�r:td|�|�j�j|�j|�j��td|t |�j��f�|�j�j|�j|�j��z|�j�W�t |���S�t |���0�dS�)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 %r.zexpected token %r, got %rN)r����r����rb���r[���rW���r ���ry���r���rz���r_���r����r����r:���r:���r>����expect���s(�������zTokenStream.expectN)r���)r|���r}���r~���r���rx���r����r����Z__nonzero__r����r����r����r����r����r����r����r����r����r����r:���r:���r:���r>���r����@��s��� r����c�����������������C���sZ���|�j�|�j|�j|�j|�j|�j|�j|�j|�j|�j |�j |�jf}t� |�}|du�rVt|��}|t|<�|S�)z(Return a lexer which is probably cached.N)rh����block_end_stringri����variable_end_stringrg����comment_end_stringrj���rl����trim_blocks� lstrip_blocks�newline_sequence�keep_trailing_newline�_lexer_cacherX����Lexer)ro���rJ���Zlexerr:���r:���r>���� get_lexer���s$����� r����c�����������������������s$���e�Zd�ZdZdZ��fdd�Z���ZS�)�OptionalLStripzWA special tuple for marking a point in the state that can have lstrip applied. r:���c��������������������s���t�t|���|�|�S�rA���)�superr����r����)rw����members�kwargs�� __class__r:���r>���r�������s����zOptionalLStrip.__new__)r|���r}���r~���r���r����r����� __classcell__r:���r:���r����r>���r�������s���r����c�������������������@���s>���e�Zd�ZdZdd��Zdd��Zd dd�Zdd d �Zddd�ZdS�)r����a ��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. c�����������������C���s���t�j}dd��}ttd�fttd�fttd�ftt d�ft td�ftt d�fg}t|�}|jrTdpVd}|jrf|d�nd�|�_|j|�_|j|�_d|dd�d ||j�||j�||j�f�gd d��|D������ttd�df|d �td�fgt|d||j�||j�|f��ttfdf|d�td�fd�fgt|d||j�||j�|f��tdfg|�t |d||j!�||j!�f��t"dfg|�t#|d||j�||j�||j�|f��ttt$�df|d�td�fd�fgt%|d�t&dfg|�t'|d�t(t)fdfgi|�_*d�S�)Nc�����������������S���s���t��|�t�jt�jB��S�rA���)rB����compile�M�SrH���r:���r:���r>����c���s����zLexer.__init__.<locals>.cz\n?r����z[^ \t]�rootz(.*?)(?:%s)r7���z0(?P<raw_begin>%s(\-|\+|)\s*raw\s*(?:\-%s\s*|%s))c�����������������S���s���g�|�]\}}d�||f��qS�)z(?P<%s>%s(\-|\+|))r:���)r;���r�����rr:���r:���r>���r?�����s����z"Lexer.__init__.<locals>.<listcomp>�#bygroupz.+z(.*?)((?:\-%s\s*|%s)%s)�#popz(.)zMissing end of comment tagz(?:\-%s\s*|%s)%sz \-%s\s*|%sz1(.*?)((?:%s(\-|\+|))\s*endraw\s*(?:\-%s\s*|%s%s))zMissing end of raw directivez \s*(\n|$)z(.*?)()(?=\n|$))+rB���rC���� whitespace_re�TOKEN_WHITESPACE�float_re�TOKEN_FLOAT� integer_re� TOKEN_INTEGER�name_rer\���� string_re�TOKEN_STRING�operator_re�TOKEN_OPERATORrr���r����r�����lstrip_unless_rer����r�����joinrh���r����r����rV���rL���r����rN���rM���rs���rP���rQ���rR���r����rS����TOKEN_RAW_BEGIN� TOKEN_RAW_ENDrT���rU���rm���rO����TOKEN_LINECOMMENT_ENDrq���)rv���ro���rp���r����Z tag_rulesZroot_tag_rulesZblock_suffix_rer:���r:���r>���rx������s�������������������������������� ���� � ������zLexer.__init__c�����������������C���s���t��|�j|�S�)z@Called for strings and template data to normalize it to unicode.)rc���r���r����)rv���r]���r:���r:���r>����_normalize_newlinesa��s����zLexer._normalize_newlinesNc�����������������C���s&���|���||||�}t|��|||�||�S�)z:Calls tokeniter + tokenize and wraps it in a token stream.)� tokeniterr�����wrap)rv����sourcer���rz����stater����r:���r:���r>����tokenizee��s����zLexer.tokenizec����������� ������c���sz��|D��]n\}}}|t�v�rq�nH|tkr.t}�n8|tkr>t}�n(|ttfv�rPq�n|tkrf|��|�}�n�|dkrt|}n�|t kr�t |�}tr�|���s�t d|||��n�|tk�rz$|��|dd����dd��d�}W�nJ�t�y�}�z0t |��d�d����}t ||||��W�Y�d }~n d }~0�0�nJ|tk�r8t|�d d��}n.|tk�rTt|�d d��}n|tk�rft|�}t|||�V��qd 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-escaper6���Nr����r����)�ignored_tokensrT���rP���rU���rQ���r����r����rV���r����r\���r�����check_ident�isidentifierr ���r�����encode�decode� Exceptionr`����stripr�����int�replacer����r���r����� operatorsr����) rv���r����r���rz���ry���r^���r]���rp����msgr:���r:���r>���r����j��sJ����� ���& z Lexer.wrapc����������� ������c���s4��t�|�}|���}|�jr<|r<dD�]}|�|�r|�d���q<qd�|�}d}d}dg} |durr|dkrr| �|d���|�j| d ��} t|�}g�}|�j} d}d }| D��]d\}}}|� ||�}|du�r�q�|r�|t ttfv�r�q�t |t��r�|���}t |t��r�|d�}tdd��|d dd ��D���}|dk�rT|���}|t|�d���d�}|f|dd���}nj|dk�r�| du�r�|����t��s�|�d�d�}|dk�s�|�r�| �||��s�|d|��f|dd���}t|�D�]�\}}|jtu��r�|||��n�|dk�r@t|����D�]4\}}|du�r�|||fV��||�d�7�}��qz�q�td|���n:||�}|�sX|tv�rd|||fV��||�d�|�7�}d}�q�n�|���}|t k�r|dk�r�|�d��nv|dk�r�|�d��n`|dk�r�|�d��nJ|dv��r|�s�t!d|�|||��|�"��}||k�rt!d||f�|||��|�s.|tv�r:|||fV��||�d�7�}|���d d��dk}|�#��}|du�r�|dk�r�| �"���nT|dk�r�t|����D�]$\}}|du�r�| �|����qq�td|���n | �|��|�j| d ��} n||k�r�td|���|}�q�q�||k�rdS�t!d||�|f�|||��q�dS�)z�This method tokenizes the text and returns the tokens in a generator. Use this method if you just want to tokenize a template. )z � � r����r����r���r���r����NZ_beginr����Tc�����������������s���s���|�]}|d�ur|V��qd�S�rA���r:���)r;����gr:���r:���r>���rF������r@���z"Lexer.tokeniter.<locals>.<genexpr>����r'���r&���r����z?%r wanted to resolve the token dynamically but no group matchedr0���r1���r.���r/���r,���r-���)r1���r/���r-���zunexpected '%s'zunexpected '%s', expected '%s'r����zC%r wanted to resolve the new state dynamically but no group matchedz,%r yielded empty string without stack changezunexpected char %r at %d)$r ���� splitlinesr�����endswithrk���r����rq���rG���r�����matchrS���rQ���rU���� isinstancer�����groupsr����r�����rstrip�count� groupdictrX���rR����rfind�search� enumerater����rs���r����RuntimeError�ignore_if_empty�groupr����r ����pop�end) rv���r����r���rz���r�����lines�newline�posry����stackZstatetokensZ source_lengthZbalancing_stackr����Znewlines_strippedZ line_startingZregex�tokensZ new_state�mr�����textZ strip_sign�strippedZl_pos�idxr^���rJ���r]���r#���Zexpected_opZpos2r:���r:���r>���r�������s����� � ��� �� � �� �� � �zLexer.tokeniter)NNN)NN)NN) r|���r}���r~���r���rx���r����r����r����r����r:���r:���r:���r>���r�������s���� ,r����)ir���rB����astr����collectionsr���r!���r���Z_compatr���r���r���r ���� exceptionsr ���Zutilsr���r����r�����Ur����rc���r����r����r����� IGNORECASE�VERBOSEr�����SyntaxErrorr����r����Z_identifierr���Z TOKEN_ADDZTOKEN_ASSIGNZTOKEN_COLONZTOKEN_COMMAZ TOKEN_DIVZ TOKEN_DOTZTOKEN_EQZTOKEN_FLOORDIVZTOKEN_GTZ TOKEN_GTEQZTOKEN_LBRACEZTOKEN_LBRACKETZTOKEN_LPARENZTOKEN_LTZ TOKEN_LTEQZ TOKEN_MODZ TOKEN_MULZTOKEN_NEZ TOKEN_PIPEZ TOKEN_POWZTOKEN_RBRACEZTOKEN_RBRACKETZTOKEN_RPARENZTOKEN_SEMICOLONZ TOKEN_SUBZTOKEN_TILDEr����r����r����r\���r����r����rP���rQ���rR���rS���r����r����rL���rM���rN���rT���rU���rm���r����rO���rV���r����rW���r�����dictrK���r����rn���r����� frozensetr����r����rZ���r_���rb���re���rr����objectrs���r����r����r����r����r����r����r����r:���r:���r:���r>����<module>���s�� � � �"��� �) (f