o
    ¯b)  ã                   @   sR   d Z ddd„Zdd„ Zdd„ Zdd	d
„ZeZdd„ Zdd„ Zdd„ Zddd„Z	dS )z'
Miscellany of text-munging functions.
Ú c              
   C   s”  d}g }t | ƒtu rQd}|  ¡ D ]?\}}t||d ƒ}t|ƒr:t|ƒr,|dtdƒ … }| |› d|› d|› �¡ q| |› d|› d|t|ƒd	 d… › �¡ qn?t | ƒtu s]t | ƒt	u r~t | ƒtu rfd
}nd}| D ]}t||d ƒ}| | 
¡ d ¡ qjnt|fdd„t| ƒ d¡ƒ|dd…< |s—| |¡ |r·||d  |d t|ƒd d…  |d< |d |d  |d< d |¡}t|ƒrÈt|ƒ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.
    r   z{}z   NÚ
ú z:
z: é   z()z[]ú,c                 S   s   ||  S ©N© )ÚsÚir   r   ú5/usr/lib/python3/dist-packages/twisted/python/text.pyÚ<lambda>/   s    zstringyString.<locals>.<lambda>é    é   éÿÿÿÿ)ÚtypeÚdictÚitemsÚstringyStringÚisMultilineÚendsInNewlineÚlenÚappendÚtupleÚlistÚrstripÚmapÚstrÚsplitÚjoin)ÚobjectÚindentationÚbracesÚslÚkeyÚvalueÚelementr   r   r   r
   r      s<   ,ø
þ$
(
r   c                 C   s   |   d¡dkS )z=
    Returns C{True} if this string has a newline in it.
    r   r   )Úfind©r   r   r   r
   r   @   s   r   c                 C   s   | t dƒ d… dkS )z;
    Returns C{True} if this string ends in a newline.
    r   N)r   r&   r   r   r
   r   G   s   r   éP   c           	      C   sò   g }|   d¡dkr |  d¡}|D ]}| t||ƒdg ¡ q|S |  ¡ }d}d}|rw|t|| ƒ }|d }||kr]|dkr?n|d }|d|… ||d… }}| d |¡¡ d}d}nt|ƒ|ksq| d |¡¡ |dd…= 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   r   r   Nr   )r%   r   ÚextendÚ
greedyWrapr   r   r   )	ÚinStringÚwidthÚoutLinesÚ
paragraphsÚparaÚinWordsÚcolumnÚptr_lineÚlr   r   r
   r)   N   s4   

êr)   c                 C   s(   g }| D ]}|s|  ¡ r| |¡ q|S r   )Ústripr   )ÚlinesÚretÚliner   r   r
   ÚremoveLeadingBlanksƒ   s   
€r7   c                 C   s4   t |  d¡ƒ}| ¡  t |ƒ}| ¡  d |¡d S )Nr   )r7   r   Úreverser   )r   r4   r   r   r
   ÚremoveLeadingTrailingBlanks‹   s
   r9   c                 C   s¨   g }d}d}|   ¡ D ]G}|du r$|r$|d dv r$|d }|dd… }g }|du r.| |¡ q
|rL|d |krL|dd… }| |¡ | 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   r   r   )r   r   r   )r   ÚoutÚquotÚphraseÚwordr   r   r
   ÚsplitQuoted“   s$   
r@   Tc                 C   sž   t | ƒƒ }tt| ƒdƒ}|s|  ¡ } 	 | |t| ƒ ¡}|s"| ¡ }t|ƒ}|dkr,dS t|ƒ| | }|dkr=|| }n||d… | }| | ¡dkrNdS q)z[
    Find whether string C{p} occurs in a read()able object C{f}.

    @rtype: C{bool}
    i   r   r   FNr   T)r   Úmaxr   ÚlowerÚreadr%   )ÚpÚfÚcaseSensitiveÚbufÚbuf_lenÚrÚ
bytes_readr2   r   r   r
   ÚstrFile¶   s$   

órK   N)r   )r'   )T)
Ú__doc__r   r   r   r)   ÚwordWrapr7   r9   r@   rK   r   r   r   r
   Ú<module>   s   
5
2#