]N)>dZddlZddlmZGddZdZdS)zs6 $*%%% C     rNcd|_ttjd|D]N\}}|j|||||z|dOdS)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 enumeratersplitr appendr#r!)rblockstarting_linenoils rwrite_indented_blockz"PythonPrinter.write_indented_blockBs %bhx7788 # #DAq   # #A & & &*!!/A"5666    " " " "  # #rc:|D]}||dS)z"print a series of lines of python.N) writeline)rlineslines r writelineszPythonPrinter.writelinesNs0 ! !D NN4  ! !rcD|js|d|_|4|j|s|j|rd}nd}|ot |o |ddk}|sw|r||r`|jdkrU|xjdzc_t |jdkrtj d|j |dS|j ||dz|t |d|j|r|j|}|rA|d}|xjdz c_|j|dSd}|j|}|r.|xjdz c_|j|dSdSdS) 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#rzToo many whitespace closuresr%)r_flush_adjusted_linesrmatchrlen_is_unindentorrr r MakoExceptionpopr r& _indent_liner!r+rsearchrgroupr,r)rr5hastext is_commentr:indentorm2s rr3zPythonPrinter.writelineSsI# (  & & ( ( (#'D  L%++D11 ~##D)) GGG:c$ii:DGsN  % % $ 3 3D 9 9 % a KK1 KK4%&&!++ ./MNNN   " " $ $ $ < F $++D11D8999 C 4 0 011222 ? ! !$ ' ' 8 %++D11E 8 ;;q>> q "))(33333,224888KK1$KK&--h77777' 8 8"88rc.|dS)z1close this printer, flushing any remaining lines.N)r9rs rclosezPythonPrinter.closes ""$$$$$rct|jdkrdS|jd}|dS|j|}t |S)zqreturn true if the given line is an 'unindentor', relative to the last 'indent' event received. rF)r;r rr:bool)rr5rDr:s rr<zPythonPrinter._is_unindentors_ t! " "a ' '5%b)  5#))$//E{{rc~|dkr|j|jz|zStjd|z|j|jz|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 rrsub)rr5 stripspaces rr?zPythonPrinter._indent_linesN   $t{2T9 9v Z !2T[!@$   rc$d\|_|_dS)z^reset the flags which would indicate we are in a backslashed or triple-quoted section.)FFN) backslashed triplequotedrGs rrz%PythonPrinter._reset_multi_line_flagss/;+$+++rc|jp|j}ttjd||_t tjd|}|dks |dzdkr |j |_|S)zcreturn true if the given line is part of a multi-line block, via backslash or triple-quote.\\$ \"\"\"|\'\'\'rr)rRrSrKrr@r;findall)rr5 current_statetripless r_in_multi_linezPythonPrinter._in_multi_linesu(=D,=  &$ 7 788bj!148899 a<<7Q;!++$($5 5D rcd}||jD]}||r|j|dz5|}|=t jd|r(t jd| d}|j| ||dzg|_|dS)Nr%^[ \t]*[^# \t] ^([ \t]*)r) rr r[r r& expandtabsrr@r:rAr?)rrPentrys rr9z#PythonPrinter._flush_adjusted_liness  $$&&&% O OE""5)) O !!%$,////((**%")4Eu*M*M%!#,!>!>!D!DQ!G!GJ !!$"3"3E:"F"F"MNNNN $$&&&&&rrrL)__name__ __module__ __qualname__rr!r#r'r1r6r3rHr<r?rr[r9rrrrs&P&P&PP222!!! # # # #!!! E8E8E8N%%%P     ;;; &'''''rrcddgd\fd}d d}g}d}tjd|D]}||r||#|}|=tjd|r(tjd |d }||||d |S) z.in_multi_line..match sJa  A !C OO--...Qwrz%sz .*?(?=%s|$)r8rVrz.*?(?=\"\"\"|\'\'\'|#|$))rr@rA)r5 start_stater:rkrRstaterSs r in_multi_linez(adjust_whitespace..in_multi_linesAK(?E,,? 9VT " " '!%E+  !&E+     C\" C%l(; ;TBB4P*/E,''#eNU<5H$H$OOGAtt%d++4'&&% 0$774*+''!**E,'% ;TBB4# C&rrLc4tjd|zd|S)NrNrL)rrO)r5rPs rr?z'adjust_whitespace.._indent_line'svfz)2t444rNr)r]r^rr%ra)rr+r,r_r@r:rAjoin) textrnr?r4rPr5rRrmrSs @@@radjust_whitespacerrsENE"([,"""""""H5555 EJ4((99 =   9 LL    ??$$D!bi0A4&H&H!XlD99??BB LLdJ77 8 8 8 8 99U  r)__doc__rmakorrrrrerrrussCB l'l'l'l'l'l'l'l'^88888r