o b)@sRdZdddZddZddZdd d ZeZd d Zd dZddZdddZ dS)z' Miscellany of text-munging functions. c Csd}g}t|turQd}|D]?\}}t||d}t|r:t|r,|dtd }||d|d|q||d|d|t|d dqn?t|tus]t|t ur~t|turfd }nd }|D]}t||d}|| d qjnt |fd dt | d|dd<|s|||r||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: z: z()z[],cSs||SN)sirr5/usr/lib/python3/dist-packages/twisted/python/text.py/szstringyString..)typedictitems stringyString isMultiline endsInNewlinelenappendtuplelistrstripmapstrsplitjoin)object indentationbracesslkeyvalueelementrrrr r s<  , $ ( rcCs|ddkS)z= Returns C{True} if this string has a newline in it. rr)findrrrr r@srcCs|td ddkS)z; Returns C{True} if this string ends in a newline. rN)rr&rrr rGsrPc Csg}|ddkr |d}|D] }|t||dgq|S|}d}d}|rw|t||}|d}||kr]|dkr?n|d}|d|||d}}|d|d}d}nt||ksq|d||dd=n|d}|s*|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 rr Nr)r%rextend greedyWraprrr) inStringwidthoutLines paragraphsparainWordscolumnptr_linelrrr r)Ns4    r)cCs(g}|D] }|s |r||q|Sr)stripr)linesretlinerrr removeLeadingBlankss   r7cCs4t|d}|t|}|d|dS)Nr)r7rreverser)rr4rrr removeLeadingTrailingBlankss r9cCsg}d}d}|D]G}|dur$|r$|ddvr$|d}|dd}g}|dur.||q |rL|d|krL|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 )"'r rr)rrr)routquotphrasewordrrr splitQuoteds$       r@TcCst|}tt|d}|s|} ||t|}|s"|}t|}|dkr,dSt|||}|dkr=||}n||d|}||dkrNdSq)z[ Find whether string C{p} occurs in a read()able object C{f}. @rtype: C{bool} ir r FNrT)rmaxrlowerreadr%)pf caseSensitivebufbuf_lenr bytes_readr2rrr strFiles$  rKN)r)r')T) __doc__rrrr)wordWrapr7r9r@rKrrrr s 5 2#