U  W[j@sRdZdddZddZddZdd d ZeZd d Zd dZddZdddZ dS)z' Miscellany of text-munging functions. c Csd}g}t|tkrd}|D]r\}}t||d}t|rnt|rX|dtd }|d|||fq |d|||t|ddfq n~t|tkst|t krt|tkrd }nd }|D]$}t||d }|| d qn$t |fd dt | d|dd<|s$|||rf||d|dt|dd|d<|d|d|d<d|}t|rt|s|d}|S)al Expansive string formatting for sequence types. C{list.__str__} and C{dict.__str__} use C{repr()} to display their elements. This function also turns these sequence types into strings, but uses C{str()} on their elements instead. Sequence elements are also displayed on separate lines, and nested sequences have nested indentation. rz{}z N z %s %s: %sz %s %s: %sz()z[] ,cSs||SN)sirr5/usr/lib/python3/dist-packages/twisted/python/text.py0zstringyString..)typedictitems stringyString isMultiline endsInNewlinelenappendtuplelistrstripmapstrsplitjoin)objectZ indentationZbracesZslkeyvalueelementrrrr r s@        ( rcCs|ddkS)z= Returns C{True} if this string has a newline in it. rr)findrrrr rBsrcCs|td ddkS)z; Returns C{True} if this string ends in a newline. rN)rr$rrr rIsrPc Csg}|ddkr@|d}|D]}|t||dgq |S|}d}d}|r|t||}|d}||kr|dkr~n|d}|d|||d}}|d|d}d}qPt||ks|d||dd=qP|d}qP|S)a 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. z r rrNr)r#rextend greedyWraprrr) ZinStringwidthZoutLinesZ paragraphsZparaZinWordscolumnZptr_linelrrr r'Ps2     r'cCs(g}|D]}|s|r||q|Sr)stripr)linesZretlinerrr removeLeadingBlankss   r.cCs4t|d}|t|}|d|dS)Nr)r.rreverser)rr,rrr removeLeadingTrailingBlankss r0cCsg}d}d}|D]}|dkrH|rH|ddkrH|d}|dd}g}|dkr\||q|r|d|kr|dd}|||d|d}q||q|S)a= Like a 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. Nr )"'rrr)rrr)routZquotphraseZwordrrr splitQuoteds$       r5TcCst|}tt|d}|s$|}||t|}|sB|}t|}|dkrVdSt|||}|dkrx||}n||d|}||dkr$dSq$dS)z[ Find whether string C{p} occurs in a read()able object C{f}. @rtype: C{bool} ir FNrT)rmaxrlowerreadr#)pfZ caseSensitiveZbufZbuf_lenrZ bytes_readr*rrr strFiles   r<N)r)r%)T) __doc__rrrr'ZwordWrapr.r0r5r<rrrr s 7 2#