łň
Je|Mc           @   sL  d  Z  d d k Z d d k Z d d k Z d d k l Z y d d k l Z Wn e j
 o d Z n Xd d d d d	 d
 d d d d d d d d d g Z	 d d e
 d  Z d d d  Z e d  Z e
 d  Z d   Z d   Z d   Z d d  Z d  e d!  Z d"   Z d#   Z d$   Z d%   Z d& d'  Z d& d(  Z d S()   se   Functions that output text (not HTML).

Helpers for filtering, formatting, and transforming strings.
i˙˙˙˙N(   t
   strip_tags(   t	   unidecodet   chop_att   collapset   convert_accented_entitiest   convert_misc_entitiest   excerptt   lchopt   pluralt   rchopt   remove_formattingt   replace_whitespacet   seriest   strip_leading_whitespacet   truncatet   urlifyt   wrap_paragraphsi   s   ...c         C   sĺ   |  p d Sn t  |   | j o |  Sn | t  |  } | p |  |  | Sn | } x. | d j o  |  | i   o | d 8} qZ Wx- | d j o |  | i   o | d 8} q W| d j o |  |  | Sn |  | d  | S(   sy  Truncate ``text`` with replacement characters.
    
    ``length``
        The maximum length of ``text`` before replacement
    ``indicator``
        If ``text`` exceeds the ``length``, this string will replace
        the end of the string
    ``whole_word``
        If true, shorten the string further to avoid breaking a word in the
        middle.  A word is defined as any string not containing whitespace.
        If the entire text before the break is a single word, it will have to
        be broken.

    Example::

        >>> truncate('Once upon a time in a world far far away', 14)
        'Once upon a...'
        
    t    i    i   (   t   lent   isspace(   t   textt   lengtht	   indicatort
   whole_wordt   short_lengtht   i(    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/text.pyR   %   s"      id   c         C   sä   |  p | o |  Sn t  i d | t  i |  | f t  i  } | i |   } | p d Sn | i d  } | i d  d j o | | } n | i d  t |   j  o | | } n t	 |  d  o t
 t  Sn | Sd S(   so  Extract an excerpt from the ``text``, or '' if the phrase isn't
    found.

    ``phrase``
        Phrase to excerpt from ``text``
    ``radius``
        How many surrounding characters to include
    ``excerpt_string``
        Characters surrounding entire excerpt
    
    Example::
    
        >>> excerpt("hello my world", "my", 3)
        '...lo my wo...'

    s   (.{0,%s}%s.{0,%s})R   s   \1i   i    t   __html__N(   t   ret   compilet   escapet   It   searcht   expandt   startt   endR   t   hasattrt   literalt   excertp(   R   t   phraset   radiust   excerpt_stringt   patt   matchR   (    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/text.pyR   N   s    c         C   s>   |  d j o
 | } n | } | o d |  | f Sn | Sd S(   sK  Return the singular or plural form of a word, according to the number.

    If ``with_number`` is true (default), the return value will be the number
    followed by the word. Otherwise the word alone will be returned.

    Usage:

    >>> plural(2, "ox", "oxen")
    '2 oxen'
    >>> plural(2, "ox", "oxen", False)
    'oxen'
    i   s   %s %sN(    (   t   nt   singularR   t   with_numbert   form(    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/text.pyR   r   s    
c         C   sI   |  i  |  } | d j o |  Sn | o |  | t |   Sn |  |  S(   s  Truncate string ``s`` at the first occurence of ``sub``.

    If ``inclusive`` is true, truncate just after ``sub`` rather than at it.

    >>> chop_at("plutocratic brats", "rat")
    'plutoc'
    >>> chop_at("plutocratic brats", "rat", True)
    'plutocrat'
    i˙˙˙˙(   t   findR   (   t   st   subt	   inclusivet   pos(    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/text.pyR      s    
c         C   s(   |  i  |  o |  t |  }  n |  S(   sR  Chop ``sub`` off the front of ``s`` if present.

    >>> lchop("##This is a comment.##", "##")
    'This is a comment.##'

    The difference between ``lchop`` and ``s.lstrip`` is that ``lchop`` strips
    only the exact prefix, while ``s.lstrip`` treats the argument as a set of
    leading characters to delete regardless of order.
    (   t
   startswithR   (   R0   R1   (    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/text.pyR      s    
c         C   s)   |  i  |  o |  t |   }  n |  S(   sU  Chop ``sub`` off the end of ``s`` if present.
    
    >>> rchop("##This is a comment.##", "##")
    '##This is a comment.'

    The difference between ``rchop`` and ``s.rstrip`` is that ``rchop`` strips
    only the exact suffix, while ``s.rstrip`` treats the argument as a set of
    trailing characters to delete regardless of order.
    (   t   endswithR   (   R0   R1   (    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/text.pyR	   §   s    
c         C   s=   g  } |  i  t  D] } | | i   q ~ } d i |  S(   s˛   Strip the leading whitespace in all lines in ``s``.
    
    This deletes *all* leading whitespace.  ``textwrap.dedent`` deletes only
    the whitespace common to all lines.
    R   (   t
   splitlinest   Truet   lstript   join(   R0   t   _[1]t   xt   ret(    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/text.pyR   ľ   s    0iH   c   	      C   s4  t  | t i  o
 | } n t i d |  } g  } |  i t  } t |  } d } d } xČ | | j  oş t | |  | j o" | i | |  | d 7} q_ n | d } x. | | j  o  | | i   o | d 7} q˛ Wd i	 | | | ! } | i
 |  d } | i |  | } d } q_ Wd i	 |  S(   s   Wrap all paragraphs in a text string to the specified width.

    ``width`` may be an int or a ``textwrap.TextWrapper`` instance.  
    The latter allows you to set other options besides the width, and is more
    efficient when wrapping many texts.  
    t   widthi    i   R   s   
N(   t
   isinstancet   textwrapt   TextWrapperR6   R7   R   t   Nonet   appendR   R9   t   fill(	   R   R=   t   wrappert   resultt   linest	   lines_lenR!   R"   t	   paragraph(    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/text.pyR   ž   s0    
 

 t   andc         C   s˘   t  |   }  t |   } | d j o d Sn | d j o |  d Sn | d j o
 t } n d i |  d   } |  d } | o d p d } d | | | | f S(	   sg  Join strings using commas and a conjunction such as "and" or "or".

    Examples:

    >>> series(["A", "B", "C"])
    'A, B, and C'
    >>> series(["A", "B", "C"], "or")
    'A, B, or C'
    >>> series(["A", "B", "C"], strict_commas=False)
    'A, B and C'
    >>> series(["A", "B"])
    'A and B'
    >>> series(["A"])
    'A'
    >>> series([])
    ''
    i    R   i   i   s   , i˙˙˙˙t   ,s
   %s%s %s %s(   t   listR   t   FalseR9   (   t   itemst   conjunctiont   strict_commasR   t   nonlastt   lastt   comma(    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/text.pyR   ŕ   s    

c         C   s=   t  |   i   } t | d  } t | d  } t i |  S(   s^  Create a URI-friendly representation of the string
    
    Can be called manually in order to generate an URI-friendly version
    of any string.

    If the ``unidecode`` package is installed, it will also transliterate 
    non-ASCII Unicode characters to their nearest pronounciation equivalent in
    ASCII.

    Examples::
        >>> urlify("Mighty Mighty Bosstones")
        'mighty-mighty-bosstones'

    Based on Ruby's stringex package
    (http://github.com/rsl/stringex/tree/master)

    Changed in WebHelpers 1.2: urlecode the result in case it contains special
    characters like "?". 
    t   -(   R
   t   lowerR   R   t   urllibt   quote(   t   stringR0   (    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/text.pyR   ˙   s    c         C   sE   t  |   } t |  } t |  } t o t |  } n t |  S(   sJ  Simplify HTML text by removing tags and several kinds of formatting.
    
    If the ``unidecode`` package is installed, it will also transliterate 
    non-ASCII Unicode characters to their nearest pronounciation equivalent in
    ASCII.

    Based on Ruby's stringex package
    (http://github.com/rsl/stringex/tree/master)
    (   R    R   R   R   R   (   RW   R0   (    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/text.pyR
     s    
c         C   s   t  i d d |   S(   s  Converts HTML entities into the respective non-accented letters.
    
    Examples::
    
      >>> convert_accented_entities("&aacute;")
      'a'
      >>> convert_accented_entities("&ccedil;")
      'c'
      >>> convert_accented_entities("&egrave;")
      'e'
      >>> convert_accented_entities("&icirc;")
      'i'
      >>> convert_accented_entities("&oslash;")
      'o'
      >>> convert_accented_entities("&uuml;")
      'u'
    
    Note: This does not do any conversion of Unicode/ASCII
    accented-characters. For that functionality please use unidecode.
    
    Based on Ruby's stringex package
    (http://github.com/rsl/stringex/tree/master)
    s:   \&([A-Za-z])(grave|acute|circ|tilde|uml|ring|cedil|slash);s   \1(   R   R1   (   RW   (    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/text.pyR   ,  s    	c         C   sú   h  d d <d d <d d <d d <d	 d
 <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d  <d! d" <d# d$ <d% d& <} x3 | i    D]% \ } } t i d' | | |   }  qž Wt i d( d) |   S(*   s@  Converts HTML entities (taken from common Textile formattings) 
    into plain text formats
    
    Note: This isn't an attempt at complete conversion of HTML
    entities, just those most likely to be generated by Textile.
    
    Based on Ruby's stringex package
    (http://github.com/rsl/stringex/tree/master)
    s   "s   #822[01]t   's   #821[67]s   ...s   #8230RS   s   #8211s   --s   #8212R;   s   #215t   >t   gtt   <t   lts   (tm)s   (#8482|trade)s   (r)s
   (#174|reg)s   (c)s   (#169|copy)RI   s	   (#38|amp)t    t   nbsps    cents   (#162|cent)s    pounds   (#163|pound)s
   one fourths   (#188|frac14)t   halfs   (#189|frac12)s   three fourthss   (#190|frac34)s    degreess
   (#176|deg)s   \&%s;s   \&[^;]+;R   (   RM   R   R1   (   RW   t   replace_dictt   textiledt   normal(    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/text.pyR   H  s0    
																		 R]   c         C   s   t  i d | |   S(   s}  Replace runs of whitespace in string
    
    Defaults to a single space but any replacement string may be
    specified as an argument. Examples::

        >>> replace_whitespace("Foo       bar")
        'Foo bar'
        >>> replace_whitespace("Foo       bar", "-")
        'Foo-bar'
    
    Based on Ruby's stringex package
    (http://github.com/rsl/stringex/tree/master)
    s   \s+(   R   R1   (   RW   t   replace(    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/text.pyR   Ź  s    c         C   s/   t  i d |  } t  i | | |  i |   S(   sç   Removes specified character from the beginning and/or end of the
    string and then condenses runs of the character within the string.
    
    Based on Ruby's stringex package
    (http://github.com/rsl/stringex/tree/master)
    s   (%s){2,}(   R   R   R1   t   strip(   RW   t	   charactert   reg(    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/text.pyR   ź  s    (   t   __doc__R   R?   RU   t   webhelpers.html.toolsR    R   t   ImportErrorRA   t   __all__RL   R   R   R7   R   R   R   R	   R   R   R   R   R
   R   R   R   R   (    (    (    s_   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/text.pys   <module>   sL   	)$				"				d