
[XMc           @   s   d  Z  d d l Z d d l Z d d l m Z m Z d d  Z d   Z d   Z e j	 e j
 d d	 d
 d  d e d  d   Z d d  Z e Z d   Z d   Z d   Z e d  Z d S(   s'   
Miscellany of text-munging functions.
iN(   t	   deprecatet   versionst    c         C   s  d } g  } t  |   t j k r d } xL|  j   D] \ } } t | | d  } t |  r t |  r | t d   } n  | j d | | | f  q4 | j d | | | t |  d f  q4 Wn t  |   t j	 t j
 f k rNt  |   t j	 k rd } n d	 } xf |  D]3 } t | | d
  } | j t j |  d  qWn( t | d  t j t |   d   | (| s| j |  n  | r| | d | d t |  d | d <| d | d | d <n  t j | d  } t |  rt |  r| d } n  | S(   s`  
    Expansive string formatting for sequence types.

    list.__str__ and dict.__str__ use repr() to display their
    elements.  This function also turns these sequence types
    into strings, but uses str() on their elements instead.

    Sequence elements are also displayed on seperate lines,
    and nested sequences have nested indentation.
    R   s   {}s      s   
s	   %s %s:
%ss	   %s %s: %si   s   ()s   []t    t   ,c         S   s   | |  S(   N(    (   t   st   i(    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/text.pyt   <lambda>5   s    i    i   i(   t   typet   typest   DictTypet   itemst   stringyStringt   isMultilinet   endsInNewlinet   lent   appendt	   TupleTypet   ListTypet   stringt   rstript   mapt   splitt   strt   join(   t   objectt   indentationt   bracest   slt   keyt   valuet   elementR   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/text.pyR      s<     	!(c         C   s   t  j |  d  d k S(   s0   Returns True if this string has a newline in it.s   
i(   R   t   find(   R   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/text.pyR   F   s    c         C   s   |  t  d  d k S(   s.   Returns True if this string ends in a newline.s   
(   R   (   R   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/text.pyR   J   s    t   Twistedi
   i   i    s"   Please use inspect.getdoc instead.t   docstringLStripc         C   s   |  s
 |  St  j |  d d  }  t  j |  d  } d } xg t d t |   D]P } | | } t  j |  r x$ | | d k r | d } qo Pqo n  | rM PqM qM W| d d !} x2 t d t |   D] } | j | | |  q Wt  j | d  S(   s  
    Gets rid of unsightly lefthand docstring whitespace residue.

    You'd think someone would have done this already, but apparently
    not in 1.5.2.

    BUT since we're all using Python 2.1 now, use L{inspect.getdoc}
    instead.  I{This function should go away soon.}
    s   	R   i   s   
i    i   s           (   R   t   replaceR   t   xrangeR   t   stripR   R   (   t	   docstringt   linest   leadingt   lt   linet   outlines(    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/text.pyR"   W   s$    
iP   c   	      C   sG  g  } |  j  d  d k r\ t j |  d  } x( | D]  } | j t |  d g  q4 W| St j |   } d } d } x | rB| t | |  } | d } | | k r| d k r n
 | d } | d | !| | } } | j t j | d   d } d } qz t |  | k s5| j t j | d   | 2qz | d } qz W| S(   s
  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.
    s   

i    R   i   R   (   R    R   R   t   extendt
   greedyWrapR   R   R   (	   t   inStringt   widtht   outLinest
   paragraphst   parat   inWordst   columnt   ptr_lineR)   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/text.pyR-   z   s2    		

	c         C   s=   g  } x0 |  D]( } | s% | j    r | j |  q q W| S(   N(   R%   R   (   R'   t   retR*   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/text.pyt   removeLeadingBlanks   s
    c         C   sF   t  |  j d   } | j   t  |  } | j   d j |  d S(   Ns   
(   R7   R   t   reverseR   (   R   R'   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/text.pyt   removeLeadingTrailingBlanks   s
    

c         C   s   g  } d } d } x |  j   D] } | d k rg | rg | d d k rg | d } | d } g  } qg n  | d k r | j |  q | r | d | k r | d  } | j |  | j d j |   d } q | j |  q W| S(	   s6  Like 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.
    i    s   "t   'i   iR   N(   s   "R:   (   t   NoneR   R   R   (   R   t   outt   quott   phraset   word(    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/text.pyt   splitQuoted   s$    



	c         C   s   d } t  t |   d d d  } | s8 |  j   }  n  x | j | t |    } | si | j   } n  t |  } | d k r t St |  | | } | d k r | | } n | | | } | j |   d k r; t Sq; d S(   sN   Find whether string p occurs in a read()able object f
    @rtype: C{bool}
    R   i   i    iNi   (   t   maxR   t   lowert   readt   FalseR    t   True(   t   pt   ft   caseSensitivet   buft   buf_lent   rt
   bytes_readR)   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/text.pyt   strFile   s"    (   t   __doc__R   R	   t   twisted.pythonR    R   R   R   R   t   deprecatedModuleAttributet   Versiont   __name__R"   R-   t   wordWrapR7   R9   R@   RE   RM   (    (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/text.pyt   <module>	   s    6		
	#1			!