HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/mako/__pycache__/lexer.cpython-310.pyc
o

%wen>�@sNdZddlZddlZddlmZddlmZddlmZiZGdd�d�Z	dS)zGprovides the Lexer class for parsing template strings into parse trees.�N)�
exceptions)�	parsetree)�adjust_whitespacec@s�eZdZ	d#dd�Zedd��Zd$dd�Zdd	�Zd
d�Zdd
�Z	e
�d�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�ZdS)%�LexerNcCs|||_||_t�|j�|_d|_d|_d|_d|_g|_	g|_
g|_||_|dur.g|_
dSt|d�s9|g|_
dS||_
dS)N�r�__iter__)�text�filenamer�TemplateNode�template�matched_lineno�matched_charpos�lineno�match_position�tag�control_line�
ternary_stack�encoding�preprocessor�hasattr)�selfrr	�input_encodingr�r�C/home/arjun/projects/env/lib/python3.10/site-packages/mako/lexer.py�__init__s 


zLexer.__init__cCs|j|j|j|jd�S)N)�sourcer�posr	)rrr
r	)rrrr�exception_kwargs*s
�zLexer.exception_kwargscCsTzt||f}Wnty$|rt�||�nt�|�}|t||f<Ynw|�|�S)z>compile the given regexp, cache the reg, and call match_reg().)�
_regexp_cache�KeyError�re�compile�	match_reg)r�regexp�flags�regrrr�match3s�
zLexer.matchcCs�|j}|�|j|j�}|rP|��\}}||kr|dn||_|j|_|d}|dkr;||jkr;|jd|d��d�}|||_|j|j||j��	d�7_|S)z�match the given regular expression object to the current text
        position.

        if a match occurs, update the current text and line position.

        rrN�
)
rr&r�spanrr�
textlength�rfindr
�count)rr%�mpr&�start�end�cprrrr">s
 zLexer.match_regc	GsJ|j}d�|�}d}d}d}	|�d�}|rq|�dtj�}|r!q|�d|�}|rL|r8|dksL|dksL|dksL|j||jt|�d���|�d�fS|sW|�d|tj�}|r�||�d��d	�7}||�d��d
�8}||�d��d�7}||�d��d�8}||�d��d
�7}||�d��d�8}qt	j
dd�|�fi|j���)N�|rTz#.*\nz+(\"\"\"|\'\'\'|\"|\')[^\\]*?(\\.[^\\]*?)*\1z(%s)rz(.*?)(?=\"|\'|#|%s)�{�}�(�)�[�]zExpected: %s�,)r�joinr&r �Sr�len�groupr+r�SyntaxExceptionr)	r�
watch_nestingr�startpos�text_re�brace_level�paren_level�
bracket_levelr&rrr�parse_until_textTsN

������zLexer.parse_until_textcOs�|�d|j�|�d|j�|�d|j�|j|d<||i|��}t|j�r0|jdj�|�n|j	j�|�|j
rd|j
d}|j�|�t|tj
�rQ|�|j�sd|jrd|jdrd|jddj�|�t|tj�r}t|j�ru|jd|_|j�|�dSt|tj
�r�|jr�|j
��|j��dS|jr�|j
�|�|j�g�dS|j
r�|j
d�|j�r�|jd�|�dS|j
r�|j
d�|j�s�tjd|j|j
djffi|j���dSdSdS)Nrrrr	���z1Keyword '%s' not a legal ternary for keyword '%s')�
setdefaultrrr
r	r:r�nodes�appendrr�
isinstancer�ControlLine�
is_ternary�keywordr�Tag�parent�isend�pop�
is_primaryrr<r)r�nodecls�args�kwargs�node�
control_framerrr�append_node|s^



�
���

������zLexer.append_nodez #.*coding[:=]\s*([-\w.]+).*\r?\nc
Cst|t�r|j�|�}|r|�d�p|pd}||fS|�tj�rS|ttj�d�}d}|j�|�	dd��}|durR|�d�dkrRt
�d|�d�|�	dd�dd|��n|j�|�	dd��}|rd|�d�n|pgd}|r�z
|�	|�}W||fSty�t
�d||�	dd�dd|��w||fS)z�given string/unicode or bytes/string, determine encoding
        from magic encoding comment, return body as unicode
        or raw if decode_raw=False

        rzutf-8N�ignorezHFound utf-8 BOM in file, with conflicting magic encoding comment of '%s'rz0Unicode decode operation of encoding '%s' failed)
rH�str�
_coding_rer&r;�
startswith�codecs�BOM_UTF8r:�decoder�CompileException�UnicodeDecodeError)rr�
decode_raw�known_encodingr	�mr�parsed_encodingrrr�decode_raw_stream�sJ
�
��	��
��
zLexer.decode_raw_streamcCs2|�|jd|j|j�\|_|_|jD]}||j�|_q|�|j�t|j�|_	|j	|jkr/n4|�
�r4n/|��r9q'|��r>q'|�
�rCq'|��rHq'|��rMq'|��rRq'|��rWq'|j	|jkr^nt�d��t|j�rxtjd|jdjfi|j���t|j�r�t�d|jdj|j|jdj|jdj|j��|jS)NTzassertion failed�Unclosed tag: <%%%s>rDz"Unterminated control keyword: '%s')rdrrr	rr"rYr:r)r�	match_end�match_expression�match_control_line�
match_comment�match_tag_start�
match_tag_end�match_python_block�
match_textr�
MakoExceptionrr<rKrrrrr)r�preprocrrr�parse�s\�


��

�

�zLexer.parsecCs�d}|�|tjtjBtjB�}|sdS|��\}}}||_i}|r=t�d|�D]}|\}}	}
|	p1|
}|�dd�}|||<q'|�	t
j||�|rN|j�
�dS|dkry|�dtj�}|sktjd|jd	jfi|j���|�	t
j|�d
��|��SdS)Na�
            \<%     # opening tag

            ([\w\.\:]+)   # keyword

            ((?:\s+\w+|\s*=\s*|"[^"]*?"|'[^']*?'|\s*,\s*)*)  # attrname, = \
                                               #        sign, string expression
                                               # comma is for backwards compat
                                               # identified in #366

            \s*     # more whitespace

            (/)?>   # closing

        Fz)\s*(\w+)\s*=\s*(?:'([^']*)'|\"([^\"]*)\")�
r'rz(.*?)(?=\</%text>)rerDrT)r&r �Ir9�X�groupsrK�findall�replacerVrrLrrOrr<r�Textr;rk)rr%r&rK�attrrN�
attributes�att�key�val1�val2rrrrrjsB��



���zLexer.match_tag_startcCs�|�d�}|rBt|j�stjd|�d�fi|j���|jdj|�d�kr;tjd|�d�|jdjffi|j���|j��dSdS)Nz\</%[\t ]*([^\t ]+?)[\t ]*>z(Closing tag without opening tag: </%%%s>rrDz.Closing tag </%%%s> does not match tag: <%%%s>TF)	r&r:rrr<r;rrKrO�rr&rrrrkDs*

������
zLexer.match_tag_endcCs*|�dtj�}|sdS|��}|r|SdS)Nz\ZFT)r&r r9r;)rr&�stringrrrrfXszLexer.match_endcCs<|�dtjtjB�}|r|�d�}|r|�tj|�dSdS)Na�
                (.*?)         # anything, followed by:
                (
                 (?<=\n)(?=[ \t]*(?=%|\#\#)) # an eval or line-based
                                             # comment preceded by a
                                             # consumed newline and whitespace
                 |
                 (?=\${)      # an expression
                 |
                 (?=</?[%&])  # a substitution or block or call start or end
                              # - don't consume
                 |
                 (\\\r?\n)    # an escaped newline  - throw away
                 |
                 \Z           # end of string
                )rTF)r&r rsr9r;rVrrw)rr&rrrrrmcs
�
zLexer.match_textcCs`|�d�}|r.|j|j}}|�dd�\}}t|�d}|jtj||�d�dk||d�dSdS)	Nz<%(!)?Fz%>r'r�!�rrT)	r&rr
rCrrVr�Coder;)rr&�linerrr.rrrrl�s
�zLexer.match_python_blockcCsz|�d�}|s	dS|j|j}}|�ddd�\}}|dkr&|�dd�\}}nd}|�dd	�}|jtj||��||d
�dS)Nz\${FTz\|r2r0�rqr'r�)	r&rr
rCrvrVr�
Expression�strip)rr&r�rrr.�escapesrrrrg�s"
�zLexer.match_expressioncCs�|�dtj�}|sdS|�d�}|�d�}|dkrst�d|�}|s-tjd|fi|j���|�dd�\}}|du}|rht|j�sNtjd||ffi|j���|jd	j	|krhtjd
||jd	j	ffi|j���|�
tj|||�dS|�
tj
|�dS)NzC(?<=^)[\t ]*(%(?!%)|##)[\t ]*((?:(?:\\\r?\n)|[^\r\n])*)(?:\r?\n|\Z)Fr��%z(end)?(\w+)\s*(.*)zInvalid control line: '%s'z!No starting keyword '%s' for '%s'rDz'Keyword '%s' doesn't match keyword '%s'T)r&r �Mr;rr<rr:rrKrVrrI�Comment)rr&�operatorr�m2rNrKrrrrh�sJ�

��

������zLexer.match_control_linecCs.|�dtj�}|r|�tj|�d��dSdS)z*matches the multiline version of a commentz<%doc>(.*?)</%doc>rTF)r&r r9rVrr�r;r~rrrri�s
zLexer.match_comment)NNN)N)�__name__�
__module__�__qualname__r�propertyrr&r"rCrVr r!rYrdrprjrkrfrmrlrgrhrirrrrrs(
�

(
2*82&r)
�__doc__r[r �makorr�
mako.pygenrrrrrrr�<module>s