
    YeIi(                     >    d Z ddlZddlmZ  G d d          Zd ZdS )z<utilities for generating and formatting literal Python code.    N)
exceptionsc                   `    e Zd Zd Zd Zd Zd ZddZd Zd Z	d	 Z
d
 ZddZd Zd Zd ZdS )PythonPrinterc                    d| _         g | _        d| _        || _        d| _        g | _        d| _        |                                  i | _        t          j
        d          | _        t          j
        d          | _        t          j
        d          | _        t          j
        d          | _        t          j
        d	          | _        t          j
        d
          | _        d S )Nr   z       Fz^\s*#z^\s*$z:[ \t]*(?:#.*)?$z ^\s*(if|try|elif|while|for|with)z(^\s*(def|class|else|elif|except|finally)z"^\s*(else|elif|except|finally).*\:)indentindent_detailindentstringstreamlinenoline_bufferin_indent_lines_reset_multi_line_flags
source_maprecompile_re_space_comment	_re_space
_re_indent_re_compound_re_indent_keyword_re_unindentor)selfr   s     O/var/www/html/MCyber-Diagnostic/venv/lib/python3.11/site-packages/mako/pygen.py__init__zPythonPrinter.__init__   s    
   #   $$$&&& !#H!5!5H--*%899J'JKK"$*7#
 #
 !j)NOO    c                 &    | xj         |z  c_         d S N)r   r   nums     r   _update_linenozPythonPrinter._update_lineno7   s    sr   c                 D    | j         | j        vr|| j        | j         <   d S d S r   )r   r   )r   r   s     r   start_sourcezPythonPrinter.start_source:   s-    ;do--+1DODK((( .-r   c                 j    | j                             d|z             |                     |           d S )N
)r   writer!   r   s     r   write_blankszPythonPrinter.write_blanks>   s6    $*%%%C     r   Nc                     d| _         t          t          j        d|                    D ]N\  }}| j                            |           ||                     ||z              |                     d           OdS )zprint 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   	enumerater   splitr   appendr#   r!   )r   blockstarting_linenoils        r   write_indented_blockz"PythonPrinter.write_indented_blockB   s    
  %bhx7788 	# 	#DAq##A&&&*!!/A"5666""""		# 	#r   c                 :    |D ]}|                      |           dS )z"print a series of lines of python.N)	writeline)r   lineslines      r   
writelineszPythonPrinter.writelinesN   s0     	! 	!DNN4    	! 	!r   c                 D   | j         s|                                  d| _         |4| j                            |          s| j                            |          rd}nd}|ot          |          o|d         dk    }|sw|r|                     |          r`| j        dk    rU| xj        dz  c_        t          | j                  dk    rt          j
        d          | j                                         |dS | j                            |                     |          dz              |                     t          |                    d                               | j                            |          r| j                            |          }|rA|                    d          }| xj        dz  c_        | j                            |           dS d}| j                            |          }|r.| xj        dz  c_        | j                            |           dS dS dS )	zprint 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.

        TNFr   #r   zToo many whitespace closuresr%   )r   _flush_adjusted_linesr   matchr   len_is_unindentorr   r	   r   MakoExceptionpopr   r&   _indent_liner!   r+   r   searchr   groupr,   r   )r   r5   hastext
is_commentr:   indentorm2s          r   r3   zPythonPrinter.writelineS   sI    # 	(&&(((#'D  L%++D11 ~##D))  GGG:c$ii:DGsN
 	%	% $ 3 3D 9 9	% aKK1KK 4%&&!++ ./MNNN""$$$<F 	$++D11D8999C

4 0 011222 ?!!$'' 	8
 %++D11E 8 ;;q>>q "))(33333 ,22488 8KK1$KK&--h77777'	8 	8"8 8r   c                 .    |                                   dS )z1close this printer, flushing any remaining lines.N)r9   r   s    r   closezPythonPrinter.close   s    ""$$$$$r   c                     t          | j                  dk    rdS | j        d         }|dS | j                            |          }t	          |          S )zqreturn true if the given line is an 'unindentor',
        relative to the last 'indent' event received.

        r   F)r;   r	   r   r:   bool)r   r5   rD   r:   s       r   r<   zPythonPrinter._is_unindentor   s_     t!""a''5%b) 5 #))$// E{{r    c                 ~    |dk    r| j         | j        z  |z   S t          j        d|z  | j         | j        z  |          S )zindent 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.rL   ^%s)r
   r   r   sub)r   r5   
stripspaces      r   r?   zPythonPrinter._indent_line   sN    
 $t{2T99vZ!2T[!@$
 
 	
r   c                 $    d\  | _         | _        dS )z^reset the flags which would indicate we are in a backslashed
        or triple-quoted section.)FFN)backslashedtriplequotedrG   s    r   r   z%PythonPrinter._reset_multi_line_flags   s     /;+$+++r   c                     | j         p| j        }t          t          j        d|                    | _         t          t          j        d|                    }|dk    s	|dz  dk    r| j         | _        |S )zcreturn true if the given line is part of a multi-line block,
        via backslash or triple-quote.\\$\"\"\"|\'\'\'r      r   )rR   rS   rK   r   r@   r;   findall)r   r5   current_statetripless       r   _in_multi_linezPythonPrinter._in_multi_line   su     (=D,=	&$ 7 788bj!148899a<<7Q;!++$($5 5Dr   c                    d }|                                   | j        D ]}|                     |          r| j                            |dz              5|                                }|=t          j        d|          r(t          j        d|          	                    d          }| j                            | 
                    ||          dz              g | _        |                                   d S )Nr%   ^[ \t]*[^# \t]	^([ \t]*)r   )r   r   r[   r   r&   
expandtabsr   r@   r:   rA   r?   )r   rP   entrys      r   r9   z#PythonPrinter._flush_adjusted_lines   s    
$$&&&% 	O 	OE""5)) O!!%$,////((**%")4Eu*M*M%!#,!>!>!D!DQ!G!GJ!!$"3"3E:"F"F"MNNNN$$&&&&&r   r   rL   )__name__
__module____qualname__r   r!   r#   r'   r1   r6   r3   rH   r<   r?   r   r[   r9    r   r   r   r      s        &P &P &PP  2 2 2! ! !
# 
# 
# 
#! ! !
E8 E8 E8N% % %  P
 
 
 
; ; ;  &' ' ' ' 'r   r   c                    ddgd\  fd}dd}g }d}t          j        d|           D ]} ||          r|                    |           #|                                }|=t          j        d|          r(t          j        d	|                              d
          }|                     |||                     d                    |          S )z<remove the left-whitespace margin of a block of Python code.F)r   r   c                             p         }t          j        d|           rd<   nd<   d }| r         r9 |d         z  |           \  }} |rd<   ne |d         z  |           \  }} nL |d|           \  }} |r|S  |d|           \  }} |r|                    d	          <    |d
|           \  }} | |S )NrU   TFc                     t          j        | |          }|r,||t          |                    d                    d          fS d |fS )Nr   )r   r:   r;   rA   )regtms      r   r:   z7adjust_whitespace.<locals>.in_multi_line.<locals>.match  sJ    a  A !C

OO--...Qwr   z%sz.*?(?=%s|$)r8   rV   r   z.*?(?=\"\"\"|\'\'\'|#|$))r   r@   rA   )r5   start_stater:   rk   rR   staterS   s       r   in_multi_linez(adjust_whitespace.<locals>.in_multi_line  sA   K(?E,,?9VT"" 	'!%E+!&E+	 	 	  	C\" C%l(; ;TBB4 P*/E,''#eNU<5H$H$OOGAtt%d++4 '&&% 0$774 *+''!**E,'% ;TBB4#  	C& r   rL   c                 4    t          j        d|z  d|           S )NrN   rL   )r   rO   )r5   rP   s     r   r?   z'adjust_whitespace.<locals>._indent_line'  s    vfz)2t444r   Nr)   r]   r^   r   r%   ra   )r   r+   r,   r_   r@   r:   rA   join)	textrn   r?   r4   rP   r5   rR   rm   rS   s	         @@@r   adjust_whitespacerr      s    ENE"([," " " " " " "H5 5 5 5 EJ4(( 9 9= 	9LL??$$D!bi0A4&H&H!XlD99??BB
LLdJ77888899Ur   )__doc__r   makor   r   rr   re   r   r   <module>ru      ss    C B 				      l' l' l' l' l' l' l' l'^8 8 8 8 8r   