o
    4³cY'  ã                   @   s4   d Z ddlZddlmZ G dd„ deƒZdd„ ZdS )z<utilities for generating and formatting literal Python code.é    N)Ú
exceptionsc                   @   sx   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zdd
d„Zdd„ Zdd„ Z	dd„ Z
dd„ Zddd„Zdd„ Zdd„ Zdd„ Zd	S )ÚPythonPrinterc                 C   s<   d| _ g | _d| _|| _d| _g | _d| _|  ¡  i | _d S )Nr   z    é   F)	ÚindentÚindent_detailÚindentstringÚstreamÚlinenoÚline_bufferÚin_indent_linesÚ_reset_multi_line_flagsÚ
source_map)Úselfr   © r   ú@/var/www/html/gps/gps/lib/python3.10/site-packages/mako/pygen.pyÚ__init__   s   
zPythonPrinter.__init__c                 C   s   |  j |7  _ d S ©N)r	   ©r   Únumr   r   r   Ú_update_lineno.   ó   zPythonPrinter._update_linenoc                 C   s    | j | jvr|| j| j < d S d S r   )r	   r   )r   r	   r   r   r   Ústart_source1   s   ÿzPythonPrinter.start_sourcec                 C   s   | j  d| ¡ |  |¡ d S )NÚ
)r   Úwriter   r   r   r   r   Úwrite_blanks5   s   zPythonPrinter.write_blanksNc                 C   sP   d| _ tt d|¡ƒD ]\}}| j |¡ |dur |  || ¡ |  d¡ qdS )zµprint a line or lines of python which already contain indentation.

        The indentation of the total block of lines will be adjusted to that of
        the current indent level.Fú\r?\nNr   )r   Ú	enumerateÚreÚsplitr
   Úappendr   r   )r   ÚblockÚstarting_linenoÚiÚlr   r   r   Úwrite_indented_block9   s   üz"PythonPrinter.write_indented_blockc                 G   s   |D ]}|   |¡ qdS )z"print a series of lines of python.N)Ú	writeline)r   ÚlinesÚliner   r   r   Ú
writelinesE   s   ÿzPythonPrinter.writelinesc                 C   sV  | j s
|  ¡  d| _ |du st d|¡st d|¡rd}nd}|o*t|ƒo*|d dk}|sQ|r4|  |¡rQ| jdkrQ|  jd8  _t| jƒdkrLt 	d	¡‚| j 
¡  |du rWdS | j |  |¡d
 ¡ |  t| d
¡ƒ¡ t d|¡r§t d|¡}|rŽ| d¡}|  jd7  _| j |¡ dS d}t d|¡}|r©|  jd7  _| j |¡ dS dS dS )z¾print a line of python, indenting it according to the current
        indent level.

        this also adjusts the indentation counter according to the
        content of the line.

        TNz^\s*#z^\s*$Fr   ú#r   zToo many whitespace closuresr   z:[ \t]*(?:#.*)?$z ^\s*(if|try|elif|while|for|with)z(^\s*(def|class|else|elif|except|finally))r   Ú_flush_adjusted_linesr   ÚmatchÚlenÚ_is_unindentorr   r   r   ÚSyntaxExceptionÚpopr   r   Ú_indent_liner   r   ÚsearchÚgroupr   )r   r'   ÚhastextÚ
is_commentr+   ÚindentorÚm2r   r   r   r%   J   sN   	ÿ
þ
ý
ÿ

ÿëzPythonPrinter.writelinec                 C   s   |   ¡  dS )z1close this printer, flushing any remaining lines.N)r*   ©r   r   r   r   Úclose’   s   zPythonPrinter.closec                 C   s@   t | jƒdkr	dS | jd }|du rdS t d|¡}|sdS dS )zqreturn true if the given line is an 'unindentor',
        relative to the last 'indent' event received.

        r   FéÿÿÿÿNz"^\s*(else|elif|except|finally).*\:T)r,   r   r   r+   )r   r'   r5   r+   r   r   r   r-   –   s   
zPythonPrinter._is_unindentorÚ c                 C   s   t  d| | j| j |¡S )z±indent the given line according to the current indent level.

        stripspace is a string of space that will be truncated from the
        start of the line before indenting.ú^%s)r   Úsubr   r   )r   r'   Ú
stripspacer   r   r   r0   Á   s   ÿzPythonPrinter._indent_linec                 C   s   d\| _ | _dS )z^reset the flags which would indicate we are in a backslashed
        or triple-quoted section.)FFN)ÚbackslashedÚtriplequotedr7   r   r   r   r   Ë   s   z%PythonPrinter._reset_multi_line_flagsc                 C   sX   | j p| j}t d|¡rd| _ nd| _ tt d|¡ƒ}|dks%|d dkr*| j | _|S )zcreturn true if the given line is part of a multi-line block,
        via backslash or triple-quote.ú\\$TFú\"\"\"|\'\'\'r   é   r   )r>   r?   r   r1   r,   Úfindall)r   r'   Úcurrent_stateÚtriplesr   r   r   Ú_in_multi_lineÑ   s   

zPythonPrinter._in_multi_linec                 C   sŒ   d }|   ¡  | jD ]3}|  |¡r| j |d ¡ q	| ¡ }|d u r0t d|¡r0t d|¡ 	d¡}| j |  
||¡d ¡ q	g | _|   ¡  d S )Nr   ú^[ \t]*[^# \t]ú	^([ \t]*)r   )r   r
   rF   r   r   Ú
expandtabsr   r1   r+   r2   r0   )r   r=   Úentryr   r   r   r*   è   s   

z#PythonPrinter._flush_adjusted_linesr   ©r:   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r$   r(   r%   r8   r-   r0   r   rF   r*   r   r   r   r   r      s    
H
+
r   c                    s    ddg‰d\‰ ‰‡ ‡‡fdd„}ddd„}g }d}t  d	| ¡D ]+}||ƒr+| |¡ q| ¡ }|du rBt  d
|¡rBt  d|¡ d¡}| |||ƒ¡ qd |¡S )z<remove the left-whitespace margin of a block of Python code.F)r   r   c                    sÌ   ˆˆ  pˆˆ }t  d| ¡rdˆˆ < ndˆˆ < dd„ }| rdˆˆ r?|dˆˆ  | ƒ\}} |r3dˆˆ< n/|dˆˆ  | ƒ\}} n#|d| ƒ\}} |rJ|S |d	| ƒ\}} |r[| d
¡ˆˆ< q|d| ƒ\}} | s|S )Nr@   TFc                 S   s2   t  | |¡}|r||t| d¡ƒd … fS d |fS )Nr   )r   r+   r,   r2   )ÚregÚtÚmr   r   r   r+     s   z7adjust_whitespace.<locals>.in_multi_line.<locals>.matchz%sz.*?(?=%s|$)r)   rA   r   z.*?(?=\"\"\"|\'\'\'|#|$))r   r1   r2   )r'   Ústart_stater+   rQ   ©r>   Ústater?   r   r   Úin_multi_lineÿ   s*   

ïz(adjust_whitespace.<locals>.in_multi_liner:   c                 S   s   t  d| d| ¡S )Nr;   r:   )r   r<   )r'   r=   r   r   r   r0   #  r   z'adjust_whitespace.<locals>._indent_lineNr   rG   rH   r   r   rK   )r   r   r   rI   r1   r+   r2   Újoin)ÚtextrU   r0   r&   r=   r'   r   rS   r   Úadjust_whitespaceù   s   
$
rX   )Ú__doc__r   Úmakor   Úobjectr   rX   r   r   r   r   Ú<module>   s    l