U  üe°(ã@s2dZddlZddlmZGdd„dƒZdd„ZdS)zszPythonPrinter.write_blanksNcCsPd|_tt d|¡ƒD]4\}}|j |¡|dk r@| ||¡| d¡qdS)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 Ú enumeraterÚsplitr Úappendrr)rÚblockZstarting_linenoÚiÚlrrrÚwrite_indented_blockBs  z"PythonPrinter.write_indented_blockcGs|D]}| |¡qdS)z"print a series of lines of python.N)Ú writeline)rÚlinesÚlinerrrÚ writelinesNszPythonPrinter.writelinescCsR|js| ¡d|_|dks4|j |¡s4|j |¡r:d}nd}|oTt|ƒoT|ddk}|s¢|rh| |¡r¢|jdkr¢|jd8_t|jƒdkr˜t   d¡‚|j  ¡|dkr®dS|j   | |¡d¡| t| d¡ƒ¡|j |¡rN|j |¡}|r| d¡}|jd7_|j |¡n0d}|j |¡}|rN|jd7_|j |¡dS) 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. TNFrú#rzToo many whitespace closuresr)r Ú_flush_adjusted_linesrÚmatchrÚlenÚ_is_unindentorrrrZ MakoExceptionÚpoprr Ú _indent_linerr$rÚsearchrÚgroupr%r)rr,ZhastextZ is_commentr0ÚindentorÚm2rrrr*SsN ÿ þ ýÿþþý     zPythonPrinter.writelinecCs | ¡dS)z1close this printer, flushing any remaining lines.N)r/©rrrrÚclosešszPythonPrinter.closecCs<t|jƒdkrdS|jd}|dkr(dS|j |¡}t|ƒS)zqreturn true if the given line is an 'unindentor', relative to the last 'indent' event received. rFéÿÿÿÿN)r1rrr0Úbool)rr,r7r0rrrr2žs  zPythonPrinter._is_unindentorÚcCs2|dkr|j|j|St 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.r=ú^%s)rrrÚsub)rr,Ú stripspacerrrr4Æs ÿzPythonPrinter._indent_linecCsd\|_|_dS)z^reset the flags which would indicate we are in a backslashed or triple-quoted section.)FFN)Ú backslashedÚ triplequotedr9rrrr Ósz%PythonPrinter._reset_multi_line_flagscCsP|jp |j}tt d|¡ƒ|_tt d|¡ƒ}|dksB|ddkrL|j |_|S)zcreturn true if the given line is part of a multi-line block, via backslash or triple-quote.ú\\$ú \"\"\"|\'\'\'rér)rArBr<rr5r1Úfindall)rr,Z current_stateZtriplesrrrÚ_in_multi_lineÙs  zPythonPrinter._in_multi_linecCsŒd}| ¡|jD]f}| |¡r2|j |d¡q| ¡}|dkr`t d|¡r`t d|¡  d¡}|j |  ||¡d¡qg|_| ¡dS)Nrú^[ \t]*[^# \t]ú ^([ \t]*)r) r r rGrr Ú expandtabsrr5r0r6r4)rr@Úentryrrrr/ìs  z#PythonPrinter._flush_adjusted_lines)N)r=)Ú__name__Ú __module__Ú __qualname__rrrr!r)r-r*r:r2r4r rGr/rrrrrs( G( rcs ddg‰d\‰‰‡‡‡fdd„}ddd„}g}d}t d |¡D]V}||ƒrV| |¡q>| ¡}|dkr„t d |¡r„t d |¡ d ¡}| |||ƒ¡q>d  |¡S)z.in_multi_line..matchz%sz .*?(?=%s|$)r.rDrz.*?(?=\"\"\"|\'\'\'|#|$))rr5r6)r,Z start_stater0rQ©rAÚstaterBrrÚ in_multi_lines(   z(adjust_whitespace..in_multi_liner=cSst d|d|¡S)Nr>r=)rr?)r,r@rrrr4'sz'adjust_whitespace.._indent_lineNr"rHrIrr)r=)rr$r%rJr5r0r6Újoin)ÚtextrTr4r+r@r,rrRrÚadjust_whitespaceýs$  rW)Ú__doc__rÚmakorrrWrrrrÚs  p