
    +h(                     6    d Z ddlZddlmZ  G d d      Zd Zy)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y)PythonPrinterc                    d| _         g | _        d| _        || _        d| _        g | _        d| _        | j                          i | _        t        j                  d      | _        t        j                  d      | _        t        j                  d      | _        t        j                  d      | _        t        j                  d	      | _        t        j                  d
      | _        y )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     =/var/www/html/venv/lib/python3.12/site-packages/mako/pygen.py__init__zPythonPrinter.__init__   s    
   #   $$$& !#H!5H-**%89JJ'JK"$**7#
 !jj)NO    c                 .    | xj                   |z  c_         y N)r   r   nums     r   _update_linenozPythonPrinter._update_lineno7   s    sr   c                 h    | j                   | j                  vr|| j                  | j                   <   y y r   )r   r   )r   r   s     r   start_sourcezPythonPrinter.start_source:   s)    ;;doo-+1DOODKK( .r   c                 b    | j                   j                  d|z         | j                  |       y )N
)r   writer!   r   s     r   write_blankszPythonPrinter.write_blanks>   s&    $*%C r   Nc                     d| _         t        t        j                  d|            D ]G  \  }}| j                  j                  |       || j                  ||z          | j                  d       I y)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   sj    
  %bhhx78 	#DAq##A&*!!/A"56"		#r   c                 4    |D ]  }| j                  |        y)z"print a series of lines of python.N)	writeline)r   lineslines      r   
writelineszPythonPrinter.writelinesN   s     	!DNN4 	!r   c                 >   | j                   s| j                          d| _         |6| j                  j                  |      s| j                  j                  |      rd}nd}|xr t        |      xr |d   dk(  }|s~|r| j                  |      rk| j                  dkD  r\| xj                  dz  c_        t        | j                        dk(  rt        j                  d      | j                  j                          |y| j                  j                  | j                  |      dz          | j                  t        |j!                  d                   | j"                  j%                  |      r| j&                  j                  |      }|rB|j)                  d      }| xj                  dz  c_        | j                  j+                  |       yd}| j,                  j                  |      }|r1| xj                  dz  c_        | j                  j+                  |       yyy)	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   s    ##&&(#'D  L%%++D1~~##D)GG:c$i:DGsN
  3 3D 9aKK1K 4%%&!+ ../MNN""$< 	$++D1D89C

4 012 ??!!$'
 %%++D1E ;;q>q ""))(3 ,,2248KK1$K&&--h7 # (r   c                 $    | j                          y)z1close this printer, flushing any remaining lines.N)r9   r   s    r   closezPythonPrinter.close   s    ""$r   c                     t        | j                        dk(  ry| j                  d   }|y| j                  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   sY     t!!"a'%%b)  ##))$/ 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. ^%s)r
   r   r   sub)r   r5   
stripspaces      r   r?   zPythonPrinter._indent_line   sR    
 $$t{{2T99vvZ!2!2T[[!@$
 	
r   c                 "    d\  | _         | _        y)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                   xs | j                  }t        t        j                  d|            | _         t        t        j                  d|            }|dk(  s|dz  dk7  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   sq     ((=D,=,=		&$ 78bjj!1489a<7Q;!+$($5$5 5Dr   c                    d }| j                          | j                  D ]  }| j                  |      r| j                  j	                  |dz          3|j                         }|;t        j                  d|      r%t        j                  d|      j                  d      }| j                  j	                  | j                  ||      dz           g | _        | j                          y )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E""5)!!%$,/((*%"))4Eu*M!#,!>!D!DQ!GJ!!$"3"3E:"F"MN	O $$&r   r   rM   )__name__
__module____qualname__r   r!   r#   r'   r1   r6   r3   rH   r<   r?   r   r[   r9    r   r   r   r      sH    &PP2!
#!
E8N%P
;&'r   r   c                    ddgd\  fd}dd}g }d}t        j                  d|       D ]  } ||      r|j                  |       |j                         }|;t        j                  d|      r%t        j
                  d|      j                  d	      }|j                   |||              d
j                  |      S )z<remove the left-whitespace margin of a block of Python code.F)r   r   c                 T      xs    }t        j                  d|       rd<   nd<   d }| rt   r- |d   z  |       \  }} |rd<   nR |d   z  |       \  }} n? |d|       \  }} |r|S  |d|       \  }} |r|j                  d	      <   g |d
|       \  }} | rt|S )NrU   TFc                 x    t        j                  | |      }|r||t        |j                  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  s=    a A!C
O-...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  s    K(?E,,?99VT"!%E+!&E+	 \"l(; ;TB4*/E,'#NU<5H$H$OGAtd+4&& 0$74*+''!*E,' ;TB4# & r   c                 6    t        j                  d|z  d|       S )NrN   rM   )r   rO   )r5   rP   s     r   r?   z'adjust_whitespace.<locals>._indent_line'  s    vvfz)2t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 EJ4( 9LL??$D!bii0A4&HXXlD9??B
LLdJ789 99Ur   )__doc__r   makor   r   rr   re   r   r   <module>ru      s#    C 	 l' l'^8r   