mò ŽO,Ac@s|dZdkZdkZdd„Zd„Zd„Zd„Zdd„ZeZd „Z d „Z d „Z e d „Z dS( s&Miscellany of text-munging functions. NtcCs d}g}t|ƒtijo¯d}xU|iƒD]”\}}t ||dƒ}t |ƒo@t |ƒo|t dƒ }n|id|||fƒq5|id|||t |ƒdfƒq5Wn°t|ƒtitifjoht|ƒtijo d}nd }xg|D]3}t ||d ƒ}|iti|ƒd ƒqWn)t|d „tit|ƒdƒƒ|(|p|i|ƒn|oB||d |d t |ƒd|d <|d|d|d0siiiÿÿÿÿN(tbracestslttypetobjectttypestDictTypetitemstkeytvaluet stringyStringt indentationt isMultilinet endsInNewlinetlentappendt TupleTypetListTypetelementtstringtrstriptmaptsplittstrtjoinR(R RRRRRRR((RR s@    0 " (cCsti|dƒdjS(s0Returns True if this string has a newline in it.s iÿÿÿÿN(RtfindR(R((RRAscCs|tdƒ djS(s.Returns True if this string ends in a newline.s N(RR(R((RREscCs|p|Snti|dddƒ}ti|dƒ}d}xotdt|ƒƒD]X}||}ti |ƒo,x)||djo|d}qyPqyWn|oPqVqVW|dd!}x2tdt|ƒƒD]}|i |||ƒqÕWti |dƒS(sGets rid of unsightly lefthand docstring whitespace residue. You'd think someone would have done this already, but apparently not in 1.5.2. BUT since we're all using Python 2.1 now, use L{inspect.getdoc} instead. I{This function should go away soon.} s Ris iiN(t docstringRtreplaceRtlinestleadingtxrangeRtltlinetstriptoutlinesRR(R R"R%R#R&R(((RtdocstringLStripIs,    iPc CsTg}|idƒdjoEti|dƒ}x(|D] }|it|ƒdgƒq5W|Snti|ƒ}d}d}xÑ|oÉ|t ||ƒ}|d}||jo\|djon |d}|d|!||}}|iti|dƒƒd}d}qt |ƒ|jp!|iti|dƒƒ|2q|d}qW|S(s Given a string and a column width, return a list of lines. Caveat: I'm use a stupid greedy word-wrapping algorythm. I won't put two spaces at the end of a sentence. I don't do full justification. And no, I've never even *heard* of hypenation. s iRiRN(toutLinestinStringRRRt paragraphstparatextendt greedyWraptinWordstcolumntptr_lineRtwidthR%RR( R+R3R-R2R1R0R%R,R*((RR/ks8     cCs@g}x3|D]+}|p |iƒo|i|ƒq q W|S(N(tretR"R&R'R(R"R&R4((RtremoveLeadingBlanksžs cCsFt|idƒƒ}|iƒt|ƒ}|iƒdi|ƒdS(Ns (R5RRR"treverseR(RR"((RtremoveLeadingTrailingBlanks¥s    cCsîg}d}d}xÕ|iƒD]Ç}|djo:|o/|ddjo|d}|d}g}qln|djo|i|ƒq|oH|d|jo7|d }|i|ƒ|idi|ƒƒd}q|i|ƒqW|S( s6Like string.split, but don't break substrings inside quotes. >>> splitQuoted('the "hairy monkey" likes pie') ['the', 'hairy monkey', 'likes', 'pie'] Another one of those "someone must have a better solution for this" things. This implementation is a VERY DUMB hack done too quickly. is"t'iiÿÿÿÿRN(s"R8( touttNonetquottphraseRRtwordRR(RR=R;R<R9((Rt splitQuoted¬s(         cCsöd}tt|ƒddddƒ}|p|iƒ}nx±|i|t|ƒƒ}|p|iƒ}nt|ƒ}|djot Snt|ƒ||}|djo||}n|||}|i |ƒdjotSqAqAWdS(sNFind whether string p occurs in a read()able object f @rtype: C{bool} RiiiiÿÿÿÿN(tbuftmaxRtptbuf_lent caseSensitivetlowertftreadtrt bytes_readtFalseR%RtTrue(RARERCR%RGRBRHR?((RtstrFileÍs&!   (t__doc__RR RRRR)R/twordWrapR5R7R>RJRK( RR)RKR/R7R5RMRR R>RR((Rt?s 5   " 1   !