ó žòœMc@sadZddlZddlZddlmZddlmZdefd„ƒYZd„ZdS(s<utilities for generating and formatting literal Python code.iÿÿÿÿN(tStringIO(t exceptionst PythonPrintercBsneZd„Zd„Zd„Zd„Zd„Zd„Zd„Zdd„Z d „Z d „Z d „Z RS( cCsDd|_g|_d|_||_g|_t|_|jƒdS(Nis (tindentt indent_detailt indentstringtstreamt line_buffertFalsetin_indent_linest_reset_multi_line_flags(tselfR((s0/usr/lib/python2.7/vendor-packages/mako/pygen.pyt__init__s      cCs|jj|ƒdS(N(Rtwrite(R ttext((s0/usr/lib/python2.7/vendor-packages/mako/pygen.pyR &scCs:t|_x*tjd|ƒD]}|jj|ƒqWdS(s¶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.s\r?\nN(RR tretsplitRtappend(R tblocktl((s0/usr/lib/python2.7/vendor-packages/mako/pygen.pytwrite_indented_block)s cGs"x|D]}|j|ƒqWdS(s"print a series of lines of python.N(t writeline(R tlinestline((s0/usr/lib/python2.7/vendor-packages/mako/pygen.pyt writelines2s cCsÑ|js|jƒt|_nt}|dksUtjd|ƒsUtjd|ƒr^t}nt}|oƒt|ƒoƒ|ddk}| r| r| sª|j|ƒr|j dkr|j d8_ t|j ƒdkrït j dƒ‚n|j j ƒqn|dkrdS|jj|j|ƒdƒtjd |ƒrÍtjd |ƒ}|rŠ|jdƒ}|j d7_ |j j|ƒqÍd}tjd |ƒ}|rÍ|j d7_ |j j|ƒqÍndS( s¿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. s^\s*#s^\s*$it#isToo many whitespace closuresNs s:[ \t]*(?:#.*)?$s^\s*(if|try|elif|while|for)s(^\s*(def|class|else|elif|except|finally)(R t_flush_adjusted_linestTrueRtNoneRtmatchtlent_is_unindentorRRRtSyntaxExceptiontpopRR t _indent_linetsearchtgroupR(R Rtdecreased_indentthastextt is_commentRtindentortm2((s0/usr/lib/python2.7/vendor-packages/mako/pygen.pyR7sB     "  cCs|jƒdS(s1close this printer, flushing any remaining lines.N(R(R ((s0/usr/lib/python2.7/vendor-packages/mako/pygen.pytclosescCsVt|jƒdkrtS|jd}|dkr6tStjd|ƒ}|sRtStS(ssreturn true if the given line is an 'unindentor', relative to the last 'indent' event received. iiÿÿÿÿs"^\s*(else|elif|except|finally).*\:N(RRRRRRR(R RR(R((s0/usr/lib/python2.7/vendor-packages/mako/pygen.pyRƒs  tcCs!tjd||j|j|ƒS(s²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.s^%s(RtsubRR(R Rt stripspace((s0/usr/lib/python2.7/vendor-packages/mako/pygen.pyR"®scCstt|_|_dS(s^reset the flags which would indicate we are in a backslashed or triple-quoted section.N(Rt backslashedt triplequoted(R ((s0/usr/lib/python2.7/vendor-packages/mako/pygen.pyR ·scCs|jp|j}tjd|ƒr0t|_n t|_ttjd|ƒƒ}|dksm|ddkr}|j |_n|S(screturn true if the given line is part of a multi-line block, via backslash or triple-quote.s\\$s \"\"\"|\'\'\'iii(R.R/RR#RRRtfindall(R Rt current_statettriples((s0/usr/lib/python2.7/vendor-packages/mako/pygen.pyt_in_multi_line½s   cCsÉd}|jƒxŸ|jD]”}|j|ƒrF|jj|dƒq|jƒ}|dkrŽtjd|ƒrŽtj d|ƒj dƒ}n|jj|j ||ƒdƒqWg|_|jƒdS(Ns s^[ \t]*[^# \t]s ^([ \t]*)i( RR RR3RR t expandtabsRR#RR$R"(R R-tentry((s0/usr/lib/python2.7/vendor-packages/mako/pygen.pyRÔs  $ ( t__name__t __module__R R RRRR*RR"R R3R(((s0/usr/lib/python2.7/vendor-packages/mako/pygen.pyR s    H  +  cséttg‰d \‰‰‡‡‡fd†}dd„}g}d }x”tjd|ƒD]€}||ƒrz|j|ƒqX|jƒ}|d krÂtjd|ƒrÂtjd|ƒjdƒ}n|j|||ƒƒqXWd j |ƒS( s<remove the left-whitespace margin of a block of Python code.iicsˆˆpˆˆ}tjd|ƒr3tˆˆs Ø