o
    4³cB  ã                   @   s\   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ i Z	G dd„ de
ƒZdS )	zGprovides the Lexer class for parsing template strings into parse trees.é    N)Úcompat)Ú
exceptions)Ú	parsetree)Úadjust_whitespacec                   @   s¦   e Zd Z				d$dd„Zedd„ ƒZd%dd„Zd	d
„ Zdd„ Zdd„ Z	e
 d¡Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ ZdS )&ÚLexerNFc                 C   s–   || _ || _t | j¡| _d| _d| _d| _d| _g | _	g | _
g | _|| _|| _tjr2|r2t d¡‚|d u r;g | _d S t|dƒsF|g| _d S || _d S )Né   r   z4Mako for Python 3 does not support disabling UnicodeÚ__iter__)ÚtextÚfilenamer   ÚTemplateNodeÚtemplateÚmatched_linenoÚmatched_charposÚlinenoÚmatch_positionÚtagÚcontrol_lineÚternary_stackÚdisable_unicodeÚencodingr   Úpy3kr   ÚUnsupportedErrorÚpreprocessorÚhasattr)Úselfr	   r
   r   Úinput_encodingr   © r   ú@/var/www/html/gps/gps/lib/python3.10/site-packages/mako/lexer.pyÚ__init__   s*   
ÿ


zLexer.__init__c                 C   s   | j | j| j| jdœS )N)Úsourcer   Úposr
   )r	   r   r   r
   )r   r   r   r   Úexception_kwargs6   s
   üzLexer.exception_kwargsc                 C   sV   zt ||f }W n ty%   |rt ||¡}nt |¡}|t ||f< Y nw |  |¡S )z>compile the given regexp, cache the reg, and call match_reg().)Ú_regexp_cacheÚKeyErrorÚreÚcompileÚ	match_reg)r   ÚregexpÚflagsÚregr   r   r   Úmatch?   s   
û
zLexer.matchc                 C   sÐ   | j }| | j| j ¡}|rf| ¡ \}}||kr|d | _ n|| _ | j| _t d| j|| j … ¡}|d }|dkrX|| jk rX| j| dkrX|d8 }|dkrX|| jk rX| j| dksD|| | _	|  jt
|ƒ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.

        r   z\nr   Ú
)r   r*   r	   Úspanr   r   r$   ÚfindallÚ
textlengthr   Úlen)r   r)   Úmpr*   ÚstartÚendÚlinesÚcpr   r   r   r&   M   s      ÿ
zLexer.match_regc           	      G   sJ  | j }d |¡}d}d}d}	 |  d¡}|rq|  dtj¡}|r!q|  d| ¡}|rL|r8|dksL|dksL|dksL| j|| j t| d¡ƒ … | d¡fS |sW|  d| tj¡}|r–|| d¡ d	¡7 }|| d¡ d
¡8 }|| d¡ d¡7 }|| d¡ d¡8 }|| d¡ d¡7 }|| d¡ d¡8 }qt	j
dd |¡ fi | j¤Ž‚)Nú|r   Tz#.*\nz+(\"\"\"|\'\'\'|\"|\')[^\\]*?(\\.[^\\]*?)*\1z(%s)r   z(.*?)(?=\"|\'|#|%s)Ú{Ú}ú(ú)ú[ú]zExpected: %sú,)r   Újoinr*   r$   ÚSr	   r/   ÚgroupÚcountr   ÚSyntaxExceptionr!   )	r   Úwatch_nestingr	   ÚstartposÚtext_reÚbrace_levelÚparen_levelÚbracket_levelr*   r   r   r   Úparse_until_textk   sX   

ÿÿþþþÿüÿÿzLexer.parse_until_textc                 O   s¼  |  d| j¡ |  d| j¡ |  d| j¡ | j|d< ||i |¤Ž}t| jƒr0| jd j |¡ n| j	j |¡ | j
rd| j
d }|j |¡ t|tjƒrQ| |j¡sd| jrd| jd rd| jd d j |¡ t|tjƒr}t| jƒru| jd |_| j |¡ d S t|tjƒrØ|jr’| j
 ¡  | j ¡  d S |jr£| j
 |¡ | j g ¡ d S | j
r¹| j
d  |j¡r¹| jd  |¡ d S | j
rÚ| j
d  |j¡sÜtjd|j| j
d jf fi | j¤Ž‚d S d S d S )Nr   r   r    r
   éÿÿÿÿz1Keyword '%s' not a legal ternary for keyword '%s')Ú
setdefaultr	   r   r   r
   r/   r   ÚnodesÚappendr   r   Ú
isinstancer   ÚControlLineÚ
is_ternaryÚkeywordr   ÚTagÚparentÚisendÚpopÚ
is_primaryr   rA   r!   )r   ÚnodeclsÚargsÚkwargsÚnodeÚcontrol_framer   r   r   Úappend_node“   sX   



ÿ
þ

ÿÿÿÿýòzLexer.append_nodez #.*coding[:=]\s*([-\w.]+).*\r?\nc              
   C   s"  t |tjƒr| j |¡}|r| d¡p|pd}||fS | tj¡rT|t	tjƒd… }d}| j | 
dd¡¡}|durS| d¡dkrSt d| d¡ | 
dd¡dd|¡‚n| j | 
dd¡¡}|rf| d¡}n|pid}|rz
| 
|¡}W ||fS  tyŒ   t d| | 
dd¡dd|¡‚w ||fS )z§given string/unicode or bytes/string, determine encoding
           from magic encoding comment, return body as unicode
           or raw if decode_raw=False

        r   zutf-8NÚignorezHFound utf-8 BOM in file, with conflicting magic encoding comment of '%s'r   z0Unicode decode operation of encoding '%s' failed)rM   r   Ú	text_typeÚ
_coding_rer*   r?   Ú
startswithÚcodecsÚBOM_UTF8r/   Údecoder   ÚCompileExceptionÚUnicodeDecodeError)r   r	   Ú
decode_rawÚknown_encodingr
   Úmr   Úparsed_encodingr   r   r   Údecode_raw_streamÄ   sN   ÿ
ú€	öÿ
úÿ
zLexer.decode_raw_streamc                 C   s6  |   | j| j | j| j¡\| _| _| jD ]}|| jƒ| _q|  | j¡ t| jƒ| _		 | j
| j	kr1n4|  ¡ r6n/|  ¡ r;q)|  ¡ r@q)|  ¡ rEq)|  ¡ rJq)|  ¡ rOq)|  ¡ rTq)|  ¡ rYq)| j
| j	kr`nt d¡‚t| jƒrztjd| jd j fi | j¤Ž‚t| jƒr˜t d| jd j | j| jd j| jd j| j¡‚| jS )NTzassertion failedúUnclosed tag: <%%%s>rI   z"Unterminated control keyword: '%s')ri   r	   r   r   r
   r   r&   r^   r/   r.   r   Ú	match_endÚmatch_expressionÚmatch_control_lineÚmatch_commentÚmatch_tag_startÚmatch_tag_endÚmatch_python_blockÚ
match_textr   rc   r   rA   rP   r!   r   r   r    r   )r   Úpreprocr   r   r   Úparseò   s\   ÿ


ÿþ

ÿ

úzLexer.parsec                 C   sò   |   dtjtjB tjB ¡}|rw| ¡ \}}}|| _i }|r9t d|¡D ]}|\}}}	|p-|	}
|
 dd¡}
|
||< q#|  	t
j||¡ |rJ| j ¡  d
S |dkru|   dtj¡}|sgtjd| jd j fi | j¤Ž‚|  	t
j| d	¡¡ |  ¡ S d
S dS )Na+  
            \<%     # opening tag

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

            ((?:\s+\w+|\s*=\s*|".*?"|'.*?')*)  # attrname, = \
                                               #        sign, string expression

            \s*     # more whitespace

            (/)?>   # closing

            z)\s*(\w+)\s*=\s*(?:'([^']*)'|\"([^\"]*)\")ú
r+   r	   z(.*?)(?=\</%text>)rj   rI   r   TF)r*   r$   ÚIr>   ÚXÚgroupsrP   r-   Úreplacer[   r   rQ   r   rT   r   rA   r!   ÚTextr?   rp   )r   r*   rP   ÚattrrS   Ú
attributesÚattÚkeyÚval1Úval2r	   r   r   r   ro   )  s@   òÿ


÷ÿþzLexer.match_tag_startc                 C   sˆ   |   d¡}|rBt| jƒstjd| d¡ fi | j¤Ž‚| jd j| d¡kr;tjd| d¡| jd jf fi | j¤Ž‚| j ¡  dS dS )Nz\</%[\t ]*(.+?)[\t ]*>z(Closing tag without opening tag: </%%%s>r   rI   z.Closing tag </%%%s> does not match tag: <%%%s>TF)	r*   r/   r   r   rA   r?   r!   rP   rT   ©r   r*   r   r   r   rp   X  s*   

ÿÿýÿÿý
zLexer.match_tag_endc                 C   s*   |   dtj¡}|r| ¡ }|r|S dS dS )Nz\ZTF)r*   r$   r>   r?   )r   r*   Ústringr   r   r   rk   l  s   zLexer.match_endc                 C   s<   |   dtjtjB ¡}|r| d¡}|r|  tj|¡ dS dS )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
                )r   TF)r*   r$   rw   r>   r?   r[   r   rz   )r   r*   r	   r   r   r   rr   w  s   
ï
zLexer.match_textc                 C   s`   |   d¡}|r.| j| j}}|  dd¡\}}t|ƒd }| jtj|| d¡dk||d dS dS )	Nz<%(!)?Fz%>r+   r   ú!©r   r    T)	r*   r   r   rH   r   r[   r   ÚCoder?   )r   r*   Úliner    r	   r2   r   r   r   rq   ”  s   
ûzLexer.match_python_blockc                 C   sz   |   d¡}|r;| j| j}}|  ddd¡\}}|dkr$|  dd¡\}}nd}| dd¡}| jtj|| ¡ ||d	 dS d
S )Nz\${Tz\|r7   r5   Ú ru   r+   r„   F)	r*   r   r   rH   ry   r[   r   Ú
ExpressionÚstrip)r   r*   r†   r    r	   r2   Úescapesr   r   r   rl   §  s"   
ûzLexer.match_expressionc                 C   sø   |   dtj¡}|rz| d¡}| d¡}|dkrqt  d|¡}|s+tjd| fi | j¤Ž‚| dd¡\}}|d u}|rft| jƒsLtjd||f fi | j¤Ž‚| jd j	|krftjd	|| jd j	f fi | j¤Ž‚|  
tj|||¡ d
S |  
tj|¡ d
S dS )NzB(?<=^)[\t ]*(%(?!%)|##)[\t ]*((?:(?:\\r?\n)|[^\r\n])*)(?:\r?\n|\Z)r   é   ú%z(end)?(\w+)\s*(.*)zInvalid control line: '%s'z!No starting keyword '%s' for '%s'rI   z'Keyword '%s' doesn't match keyword '%s'TF)r*   r$   ÚMr?   r   rA   r!   r/   r   rP   r[   r   rN   ÚComment)r   r*   Úoperatorr	   Úm2rS   rP   r   r   r   rm   ¼  sN   ý

ÿþ
ÿÿýÿÿýÿzLexer.match_control_linec                 C   s.   |   dtj¡}|r|  tj| d¡¡ dS dS )z*matches the multiline version of a commentz<%doc>(.*?)</%doc>r   TF)r*   r$   r>   r[   r   rŽ   r?   r   r   r   r   rn   ã  s
   zLexer.match_comment)NFNN)N)Ú__name__Ú
__module__Ú__qualname__r   Úpropertyr!   r*   r&   rH   r[   r$   r%   r^   ri   rt   ro   rp   rk   rr   rq   rl   rm   rn   r   r   r   r   r      s.    
ú!

(
/.7/'r   )Ú__doc__r`   r$   Úmakor   r   r   Ú
mako.pygenr   r"   Úobjectr   r   r   r   r   Ú<module>   s   