U
    
W[j                     @   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krd}|  D ]r\}}t||d }t|rnt|rX|dtd  }|d|||f  q |d|||t|d d f  q n~t | tkst | t	krt | tkrd	}nd
}| D ]$}t||d }||
 d  qn$t|fddt| d|dd< |s$|| |rf||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	%s %s:
%sz	%s %s: %s   z()z[] ,c                 S   s   ||  S N )sir   r   5/usr/lib/python3/dist-packages/twisted/python/text.py<lambda>0       zstringyString.<locals>.<lambda>       )typedictitemsstringyStringisMultilineendsInNewlinelenappendtuplelistrstripmapstrsplitjoin)objectZindentationZbracesZ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   B   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   I   s    r   P   c           	      C   s   g }|  ddkr@| d}|D ]}|t||dg  q |S |  }d}d}|r|t||  }|d }||kr|dkr~n|d }|d| ||d  }}|d| d}d}qPt||ks|d| |dd= 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   r   r   Nr   )r#   r   extend
greedyWrapr   r   r   )	ZinStringwidthZoutLinesZ
paragraphsZparaZinWordscolumnZptr_linelr   r   r
   r'   P   s2    


r'   c                 C   s(   g }| D ]}|s|  r|| q|S r   )stripr   )linesZretliner   r   r
   removeLeadingBlanks   s
    r.   c                 C   s4   t | d}|  t |}|  d|d S )Nr   )r.   r   reverser   )r   r,   r   r   r
   removeLeadingTrailingBlanks   s
    r0   c                 C   s   g }d}d}|   D ]}|dkrH|rH|d dkrH|d }|dd }g }|dkr\|| q|r|d |kr|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   outZquotphraseZwordr   r   r
   splitQuoted   s$    
r5   Tc                 C   s   t |  }tt| d}|s$|  } ||t|  }|sB| }t|}|dkrVdS t|| | }|dkrx|| }n||d | }|| dkr$dS q$dS )z[
    Find whether string C{p} occurs in a read()able object C{f}.

    @rtype: C{bool}
    i   r   FNr   T)r   maxr   lowerreadr#   )pfZcaseSensitiveZbufZbuf_lenrZ
bytes_readr*   r   r   r
   strFile   s     

r<   N)r   )r%   )T)
__doc__r   r   r   r'   ZwordWrapr.   r0   r5   r<   r   r   r   r
   <module>   s   
7
2#