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|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.
    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#