Ńň
}RMc           @   sÜ  d  d k  Z  d  d k l Z d  d k l Z d  d k l Z l Z d  d k	 l
 Z
 d   Z e e e  Z d   Z e e e  Z d d	  Z e e e  Z d d
  Z e e e  Z d   Z e e e  Z e d  d  Z e e e  Z d   Z e e e  Z d   Z e e  Z d   Z e e  Z d   Z e  i d  Z e d  Z e e e  Z e  i d e  i  Z d   Z e e e  Z d   Z e  i d  Z d   Z e e e  Z d   Z  e e   Z  d S(   i˙˙˙˙N(   t   force_unicode(   t
   allow_lazy(   t   ugettext_lazyt   ugettext(   t   name2codepointc         C   s)   |  o" t  |   d  i   t  |   d S(   i    i   (   R    t   upper(   t   x(    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyt   <lambda>   s    c            s.   t          f d   } d i |    S(   s   
    A word-wrap function that preserves existing line breaks and most spaces in
    the text. Expects that existing line breaks are posix newlines.
    c          3   sđ   t    i d   }  |  i   } | Vt |  | i d  d } xŚ |  D] } d | j o | i d  } n
 | f } | t | d  d 7} |  j o d Vt | d  } n- d Vt |  d j o t | d  } n | VqJ Wd  S(   Nt    s   
i   i    i˙˙˙˙(   t   itert   splitt   nextt   lent   rfind(   t   itt   wordt   post   lines(   t   textt   width(    s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyt
   _generator   s"     	u    (   R    t   join(   R   R   R   (    (   R   R   s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyt   wrap   s    s   ...c         C   sw   t  |   }  t |  } |  i   } t |  | j o3 | |  } | d i |  p | i |  qj n d i |  S(   së   Truncates a string after a certain number of words. Takes an optional
    argument of what should be used to notify that the string has been
    truncated, defaulting to ellipsis (...)

    Newlines in the string will be stripped.
    i˙˙˙˙u    (   R    t   intR
   R   t   endswitht   appendR   (   t   st   numt   end_textt   lengtht   words(    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyt   truncate_words'   s    
c      	   C   s÷  t  |   }  t |  } | d j o d Sd } t i d t i  } t i d  } d } d } d }	 g  }
 x0|	 | j o"| i |  |  } | p Pn | i d  } | i d  o( |	 d 7}	 |	 | j o
 | } qo qo n | i | i d   } | p | o qo n | i	   \ } } } | i
   } | p | | j o qo | o; y |
 i |  } Wn t j
 o qX|
 | d }
 qo |
 i d |  qo W|	 | j o |  S|  |  } | o | d | 7} n x |
 D] } | d | 7} qŰW| S(   sI  Truncates HTML to a certain number of words (not counting tags and
    comments). Closes opened tags if they were correctly closed in the given
    html. Takes an optional argument of what should be used to notify that the
    string has been truncated, defaulting to ellipsis (...).

    Newlines in the HTML are preserved.
    i    u    t   brt   colt   linkt   baset   imgt   paramt   areat   hrt   inputs   &.*?;|<.*?>|(\w[\w-]*)s   <(/)?([^ ]+?)(?: (/)| .*?)?>i   R   s   </%s>(	   R    R!   s   links   baseR$   R%   R&   R'   s   input(   R    R   t   ret   compilet   Ut   searcht   endt   groupt   matcht   groupst   lowert   indext
   ValueErrort   insert(   R   R   R   R   t   html4_singletst   re_wordst   re_tagR   t   end_text_posR   t	   open_tagst   mt   tagt   closing_tagt   tagnamet   self_closingt   it   out(    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyt   truncate_html_words8   sZ     


 c         C   s1   t  |   i   i d d  }  t i d d |   S(   s  
    Returns the given string converted to a string that can be used for a clean
    filename. Specifically, leading and trailing spaces are removed; other
    spaces are converted to underscores; and anything that is not a unicode
    alphanumeric, dash, underscore, or dot, is removed.
    >>> get_valid_filename("john's portrait in 2004.jpg")
    u'johns_portrait_in_2004.jpg'
    R   t   _s   (?u)[^-\w.]t    (   R    t   stript   replaceR)   t   sub(   R   (    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyt   get_valid_filename{   s    	u   orc      	   C   s   t  |   d j o d St  |   d j o t |  d  Sd t d  i g  } |  D] } | t |  qT ~ d   t |  t |  d  f S(   s  
    >>> get_text_list(['a', 'b', 'c', 'd'])
    u'a, b, c or d'
    >>> get_text_list(['a', 'b', 'c'], 'and')
    u'a, b and c'
    >>> get_text_list(['a', 'b'], 'and')
    u'a and b'
    >>> get_text_list(['a'])
    u'a'
    >>> get_text_list([])
    u''
    i    u    i   u   %s %s %ss   , i˙˙˙˙(   R   R    RB   R   (   t   list_t	   last_wordt   _[1]R?   (    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyt   get_text_list   s      7c         C   s   t  t i d d |    S(   Ns
   \r\n|\r|\ns   
(   R    R)   RF   (   R   (    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyt   normalize_newlines   s    c         C   s:   t  |   i   }  t i d  } | i d   |   }  |  S(   sC   Recapitalizes text, placing caps after end-of-sentence punctuation.s   (?:^|(?<=[\.\?\!] ))([a-z])c         S   s   |  i  d   i   S(   i   (   R.   R   (   R   (    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyR   Ľ   s    (   R    R1   R)   R*   RF   (   R   t   capsRE(    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyt   recapitalizeĄ   s    c         C   s.   t  i d t  i  } d   } | i | |   S(   sA   Converts a phone number with letters into its numeric equivalent.s   [A-Z]c         S   sŇ   h d  d 6d  d 6d  d 6d d 6d d 6d d 6d d	 6d d
 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d  6d d! 6i  |  i d"  i    S(#   t   2t   at   bt   ct   3t   dt   et   ft   4t   gt   hR?   t   5t   jt   kt   lt   6R:   t   nt   ot   7t   pt   qt   rR   t   8t   tt   ut   vt   9t   wR   t   yt   zi    (   t   getR.   R1   (   R:   (    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyR   Ź   s   &114(   R)   R*   t   IRF   (   t   phonet   letterst   char2number(    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyt   phone2numericŠ   s    	c      	   C   sc   d d  k  } d d  k } | i   } | i d d d d d |  } | i |   | i   | i   S(   Ni˙˙˙˙t   modet   wbt   compressleveli   t   fileobj(   t	   cStringIOt   gzipt   StringIOt   GzipFilet   writet   closet   getvalue(   R   Rw   Rx   t   zbuft   zfile(    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyt   compress_stringś   s    
u
   ([Â-ďżż])c         C   sß   d   } t  |   t j o |  i d  }  n$ t  |   t j o t |    n |  i d d  }  |  i d d  }  |  i d d  }  |  i d	 d
  }  |  i d d  }  | o |  i d d  }  n t t i | |    S(   Nc         S   s   d t  |  i d   S(   Ns   \u%04xi   (   t   ordR.   (   R/   (    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyt   fixÂ   s    s   utf-8s   \s   \\s   s   \rs   
s   \ns   	s   \tt   's   \'t   "s   &quot;(   t   typet   strt   decodet   unicodet	   TypeErrorRE   t
   ustring_reRF   (   R   t   quote_double_quotesR   (    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyt   javascript_quoteŔ   s    	s   
    ((?:
        [^\s'"]*
        (?:
            (?:"(?:[^"\\]|\\.)*" | '(?:[^'\\]|\\.)*')
            [^\s'"]*
        )+
    ) | \S+)
c         c   s8   t  |   }  x% t i |   D] } | i d  Vq Wd S(   s­  
    Generator that splits a string by spaces, leaving quoted phrases together.
    Supports both single and double quotes, and supports escaping quotes with
    backslashes. In the output, strings will keep their initial and trailing
    quote marks and escaped quotes will remain escaped (the results can then
    be further processed with unescape_string_literal()).

    >>> list(smart_split(r'This is "a person\'s" test.'))
    [u'This', u'is', u'"a person\\\'s"', u'test.']
    >>> list(smart_split(r"Another 'person\'s' test."))
    [u'Another', u"'person\\'s'", u'test.']
    >>> list(smart_split(r'A "\"funky\" style" test.'))
    [u'A', u'"\\"funky\\" style"', u'test.']
    i    N(   R    t   smart_split_ret   finditerR.   (   R   t   bit(    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyt   smart_splitß   s     c         C   sĚ   |  i  d  } | d d j op | d } yB | d d j o t | d d  } n t |  } t |  SWqČ t j
 o |  i  d  SXn9 y t t |  SWn# t t f j
 o |  i  d  SXd  S(   Ni   i    u   #u   xXi   (   R.   R   t   unichrR3   R   t   KeyError(   R/   R   RR   (    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyt   _replace_entityó   s    
s#   &(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));c         C   s   t  i t |   S(   N(   t
   _entity_reRF   R   (   R   (    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyt   unescape_entities  s    c         C   sk   |  d d j p |  d |  d j o t  d |    n |  d } |  d d !i d | |  i d d  S(	   sl  
    Convert quoted string literals to unquoted strings with escaped quotes and
    backslashes unquoted::

        >>> unescape_string_literal('"abc"')
        'abc'
        >>> unescape_string_literal("'abc'")
        'abc'
        >>> unescape_string_literal('"a \"bc\""')
        'a "bc"'
        >>> unescape_string_literal("'\'ab\' c'")
        "'ab' c"
    i    s   "'i˙˙˙˙s   Not a string literal: %ri   s   \%ss   \\s   \(   R3   RE   (   R   t   quote(    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyt   unescape_string_literal  s    &
(!   R)   t   django.utils.encodingR    t   django.utils.functionalR   t   django.utils.translationR   R   RB   t   htmlentitydefsR   t   capfirstR   R   R   RA   RG   RK   RL   RN   Rr   R   R*   R   t   FalseR   t   VERBOSER   R   R   R   R   R   (    (    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/text.pyt   <module>   sH   		A										