Ñò -!Lc@sadZddkZddkZddklZddklZdefd„ƒ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|_|iƒdS(Nis (tindentt indent_detailt indentstringtstreamt line_buffertFalsetin_indent_linest_reset_multi_line_flags(tselfR((s./usr/lib/python2.6/site-packages/mako/pygen.pyt__init__s      cCs|ii|ƒdS(N(Rtwrite(R ttext((s./usr/lib/python2.6/site-packages/mako/pygen.pyR &scCs:t|_x*tid|ƒD]}|ii|ƒ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((s./usr/lib/python2.6/site-packages/mako/pygen.pytwrite_indented_block)s cGs"x|D]}|i|ƒqWdS(s"print a series of lines of python.N(t writeline(R tlinestline((s./usr/lib/python2.6/site-packages/mako/pygen.pyt writelines2scCsê|ip|iƒt|_nt}|djp&tid|ƒptid|ƒo t}nt}|ot|ƒo|ddj}| o}| ou| p|i|ƒo]|i djoI|i d8_ t|i ƒdjot i dƒ‚n|i i ƒqn|djodS|ii|i|ƒdƒtid |ƒo‘tid |ƒ}|o2|idƒ}|i d7_ |i i|ƒqæd}tid |ƒ}|o#|i d7_ |i i|ƒ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((s./usr/lib/python2.6/site-packages/mako/pygen.pyR7s@     $ cCs|iƒdS(s1close this printer, flushing any remaining lines.N(R(R ((s./usr/lib/python2.6/site-packages/mako/pygen.pytclosezscCs\t|iƒdjotS|id}|djotStid|ƒ}|ptStS(s_return 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((s./usr/lib/python2.6/site-packages/mako/pygen.pyR~s  tcCs!tid||i|i|ƒ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((s./usr/lib/python2.6/site-packages/mako/pygen.pyR"¥scCstt|_|_dS(sVreset the flags which would indicate we are in a backslashed or triple-quoted section.N(Rt backslashedt triplequoted(R ((s./usr/lib/python2.6/site-packages/mako/pygen.pyR ¬scCs‡|ip|i}tid|ƒo t|_n t|_ttid|ƒƒ}|djp|ddjo|i |_n|S(s[return 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((s./usr/lib/python2.6/site-packages/mako/pygen.pyt_in_multi_line°s  cCsÎd}|iƒx¤|iD]™}|i|ƒo|ii|dƒq|iƒ}|djo2tid|ƒoti d|ƒi dƒ}n|ii|i ||ƒdƒqWg|_|iƒdS(Ns s^[ \t]*[^# \t]s ^([ \t]*)i( RR RR3RR t expandtabsRR#RR$R"(R R-tentry((s./usr/lib/python2.6/site-packages/mako/pygen.pyRÄs    $ ( t__name__t __module__R R RRRR*RR"R R3R(((s./usr/lib/python2.6/site-packages/mako/pygen.pyR s    C  '   csîttg‰d \‰‰‡‡‡fd†}dd„}g}d }x™tid|ƒD]…}||ƒo|i|ƒqX|iƒ}|d jo2tid|ƒotid|ƒidƒ}n|i|||ƒƒqXWd i |ƒS( s<remove the left-whitespace margin of a block of Python code.iics&ˆˆpˆˆ}tid|ƒotˆˆs È