
    g(                     6    S r SSKrSSKJr   " S S5      rS rg)z<utilities for generating and formatting literal Python code.    N)
exceptionsc                   j    \ rS rSrS rS rS rS rSS jrS r	S	 r
S
 rS rSS jrS rS rS rSrg)PythonPrinter   c                    SU l         / U l        SU l        Xl        SU l        / U l        SU l        U R                  5         0 U l        [        R                  " S5      U l        [        R                  " S5      U l        [        R                  " S5      U l        [        R                  " S5      U l        [        R                  " S	5      U l        [        R                  " S
5      U l        g )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     R/Users/Alptekin/Desktop/izin_takip/venv/lib/python3.13/site-packages/mako/pygen.py__init__PythonPrinter.__init__   s    
   #   $$$& !#H!5H-**%89JJ'JK"$**7#
 !jj)NO    c                 .    U =R                   U-  sl         g N)r   r   nums     r   _update_linenoPythonPrinter._update_lineno7   s    sr   c                 j    U R                   U R                  ;  a  XR                  U R                   '   g g r    )r   r   )r   r   s     r   start_sourcePythonPrinter.start_source:   s'    ;;doo-+1OODKK( .r   c                 b    U R                   R                  SU-  5        U R                  U5        g )N
)r   writer#   r!   s     r   write_blanksPythonPrinter.write_blanks>   s&    $*%C r   Nc                     SU l         [        [        R                  " SU5      5       HG  u  p4U R                  R                  U5        Ub  U R                  X#-   5        U R                  S5        MI     g)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_block"PythonPrinter.write_indented_blockB   sa    
  %bhhx78DA##A&*!!/"56"	 9r   c                 8    U H  nU R                  U5        M     g)z"print a series of lines of python.N)	writeline)r   lineslines      r   
writelinesPythonPrinter.writelinesN   s    DNN4  r   c                    U R                   (       d  U R                  5         SU l         Ub@  U R                  R                  U5      (       d   U R                  R                  U5      (       a  SnOSnU=(       a    [        U5      =(       a    US   S:H  nU(       d  U(       a  U R                  U5      (       an  U R                  S:  a^  U =R                  S-  sl        [        U R                  5      S:X  a  [        R                  " S5      eU R                  R                  5         Uc  gU R                  R                  U R                  U5      S-   5        U R                  [        UR!                  S5      5      5        U R"                  R%                  U5      (       a  U R&                  R                  U5      nU(       aB  UR)                  S5      nU =R                  S-  sl        U R                  R+                  U5        gSnU R,                  R                  U5      nU(       a1  U =R                  S-  sl        U R                  R+                  U5        ggg)	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#   r0   r   searchr   groupr1   r   )r   r;   hastext
is_commentrA   indentorm2s          r   r9   PythonPrinter.writelineS   s    ##&&(#'D  L%%++D11~~##D))GG:c$i:DGsN
  3 3D 9 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                 $    U R                  5         g)z1close this printer, flushing any remaining lines.N)r@   r   s    r   closePythonPrinter.close   s    ""$r   c                     [        U R                  5      S:X  a  gU R                  S   nUc  gU R                  R                  U5      n[	        U5      $ )zareturn true if the given line is an 'unindentor',
relative to the last 'indent' event received.

r   F)rB   r
   r   rA   bool)r   r;   rK   rA   s       r   rC   PythonPrinter._is_unindentor   sY     t!!"a'%%b)  ##))$/ E{r   c                     US:X  a  U R                   U R                  -  U-   $ [        R                  " SU-  U R                   U R                  -  U5      $ )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   r;   
stripspaces      r   rF   PythonPrinter._indent_line   sR    
 $$t{{2T99vvZ!2!2T[[!@$
 	
r   c                 "    Su  U l         U l        g)zVreset the flags which would indicate we are in a backslashed
or triple-quoted section.)FFN)backslashedtriplequotedrO   s    r   r   %PythonPrinter._reset_multi_line_flags   s     /;+$+r   c                    U R                   =(       d    U R                  n[        [        R                  " SU5      5      U l         [        [        R                  " SU5      5      nUS:X  d	  US-  S:w  a  U R                  (       + U l        U$ )z[return true if the given line is part of a multi-line block,
via backslash or triple-quote.\\$\"\"\"|\'\'\'r      r   )r]   r^   rT   r   rG   rB   findall)r   r;   current_statetripless       r   _in_multi_linePythonPrinter._in_multi_line   sq     ((=D,=,=		&$ 78bjj!1489a<7Q;!+$($5$5 5Dr   c                    S nU R                  5         U R                   H  nU R                  U5      (       a   U R                  R	                  US-   5        M9  UR                  5       nUcB  [        R                  " SU5      (       a&  [        R                  " SU5      R                  S5      nU R                  R	                  U R                  X!5      S-   5        M     / U l        U R                  5         g )Nr)   ^[ \t]*[^# \t]	^([ \t]*)r   )r   r   rg   r   r*   
expandtabsr   rG   rA   rH   rF   )r   rZ   entrys      r   r@   #PythonPrinter._flush_adjusted_lines   s    
$$&%%E""5))!!%$,/((*%"))4Eu*M*M!#,!>!D!DQ!GJ!!$"3"3E"F"MN & $$&r   )r   r   r   r   r   r   r]   r   r	   r
   r   r   r   r   r   r^   r    rW   )__name__
__module____qualname____firstlineno__r   r#   r&   r+   r6   r<   r9   rP   rC   rF   r   rg   r@   __static_attributes__ r   r   r   r      sH    &PP2!
#!
E8N%P
;&'r   r   c                   ^^^ SS/mSu  mmUUU4S jnSS jn/ nSn[         R                  " SU 5       H  nU" U5      (       a  UR                  U5        M#  UR                  5       nUcB  [         R                  " SU5      (       a&  [         R
                  " SU5      R                  S	5      nUR                  U" XT5      5        M     S
R                  U5      $ )z<remove the left-whitespace margin of a block of Python code.F)r   r   c                   > TT   =(       d    TT   n[         R                  " SU 5      (       a  STT'   OSTT'   S nU (       a  TT   (       a0  U" STT   -  U 5      u  p0U(       a  STT'   OYU" STT   -  U 5      u  p0OGU" SU 5      u  p0U(       a  U$ U" SU 5      u  p0U(       a  UR                  S	5      TT'   M}  U" S
U 5      u  p0U (       a  M  U$ )Nra   TFc                     [         R                  " X5      nU(       a  X![        UR                  S5      5      S  4$ S U4$ )Nr   )r   rA   rB   rH   )regtms      r   rA   7adjust_whitespace.<locals>.in_multi_line.<locals>.match  s9     AC
O-...Qwr   z%sz.*?(?=%s|$)r?   rb   r   z.*?(?=\"\"\"|\'\'\'|#|$))r   rG   rH   )r;   start_staterA   r{   r]   stater^   s       r   in_multi_line(adjust_whitespace.<locals>.in_multi_line  s    K(?E,,?99VT""!%E+!&E+	 \"l(; ;TB*/E,'#NU<5H$H$OGAtd+&& 0$7*+''!*E,' ;TB# d& r   c                 8    [         R                  " SU-  SU 5      $ )NrX   rW   )r   rY   )r;   rZ   s     r   rF   'adjust_whitespace.<locals>._indent_line'  s    vvfz)2t44r   Nr.   rj   rk   r   r)   ro   )r   r0   r1   rl   rG   rA   rH   join)	textr   rF   r:   rZ   r;   r]   r~   r^   s	         @@@r   adjust_whitespacer      s     ENE"([,"H5 EJ4(LL??$D!bii0A4&H&HXXlD9??B
LLd78 ) 99Ur   )__doc__r   makor   r   r   ru   r   r   <module>r      s#    C 	 l' l'^8r   