Ñò
<· Mc           @   s  d  Z  d d k Z d d k Z d d k l Z l Z d d k l Z d d k l	 Z	 d d k
 l Z d d d	 g Z d
 d d d d d g Z d d d d d d g Z e i d ƒ Z e i d ƒ Z e i d d i g  Z e D] Z e e i e ƒ qÛ [ ƒ d i g  Z e D] Z e e i e ƒ q[ ƒ f ƒ Z e i d ƒ Z e i d ƒ Z e i d e i ƒ Z e i d d i g  Z e D] Z e e i e ƒ q[ ƒ e i ƒ Z e i d ƒ Z [ d „  Z e	 e e  ƒ Z d@ dA dB dC dD dE dF dG dH dI dJ f Z! e! e" g  Z# e$ d4 ƒ D] Z% e# d5 e% d6 e% f q[# ƒ Z& d7 „  Z' e	 e' e  ƒ Z' d8 „  Z( e) d9 „ Z* e	 e* e  ƒ Z* d: „  Z+ e	 e+ ƒ Z+ d; „  Z, e	 e, e  ƒ Z, d< „  Z- e	 e- e  ƒ Z- d= „  Z. e	 e. e  ƒ Z. d e) e) d> „ Z0 e	 e0 e  ƒ Z0 d? „  Z1 e	 e1 e  ƒ Z1 d S(K   s'   HTML utilities suitable for global use.iÿÿÿÿN(   t   SafeDatat	   mark_safe(   t   force_unicode(   t
   allow_lazy(   t   urlquotet   (t   <s   &lt;t   .t   ,t   )t   >s   
s   &gt;s   &middot;t   *s   â€¢s   &#149;s   &bull;s   &#8226;s   &(?!(\w+|#\d+);)s   (\s+)s4   ^(?P<lead>(?:%s)*)(?P<middle>.*?)(?P<trail>(?:%s)*)$t   |s&   ^\S+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+$s   (<a [^>]*?)target=[^\s>]+sb   (?:<br clear="all">|<i><\/i>|<b><\/b>|<em><\/em>|<strong><\/strong>|<\/?smallcaps>|<\/?uppercase>)s%   ((?:<p>(?:%s).*?[a-zA-Z].*?</p>\s*)+)s(   (?:<p>(?:&nbsp;|\s|<br \/>)*?</p>\s*)+\Zc         C   sL   t  t |  ƒ i d d ƒ i d d ƒ i d d ƒ i d d ƒ i d	 d
 ƒ ƒ S(   sT   
    Returns the given HTML with ampersands, quotes and angle brackets encoded.
    t   &s   &amp;R   s   &lt;R
   s   &gt;t   "s   &quot;t   's   &#39;(   R   R   t   replace(   t   html(    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/html.pyt   escape   s    s   \s   \u005Cs   's   \u0027R   s   \u0022s   \u003Es   \u003CR   s   \u0026t   =s   \u003Dt   -s   \u002Dt   ;s   \u003Bu   â€¨s   \u2028u   â€©s   \u2029i    s   %cs   \u%04Xc         C   s9   x2 t  D]* \ } } t t |  ƒ i | | ƒ ƒ }  q W|  S(   s5   Hex encodes characters for use in JavaScript strings.(   t   _js_escapesR   R   R   (   t   valuet   badt   good(    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/html.pyt   escapejs7   s     "c         C   s#   t  |  t ƒ o |  St |  ƒ Sd S(   sU   
    Similar to escape(), except that it doesn't operate on pre-escaped strings.
    N(   t
   isinstanceR    R   (   R   (    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/html.pyt   conditional_escape>   s    c         C   s­   t  i d d t |  ƒ ƒ }  t  i d |  ƒ } | o; g  } | D]# } | d t | ƒ i d d ƒ q? ~ } n2 g  } | D] } | d | i d d ƒ qz ~ } d i | ƒ S(   s'   Converts newlines into <p> and <br />s.s
   \r\n|\r|\ns   
s   
{2,}u	   <p>%s</p>s   <br />u   

(   t   ret   subR   t   splitR   R   t   join(   R   t
   autoescapet   parast   _[1]t   pt   _[2](    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/html.pyt
   linebreaksG   s    ;1c         C   s   t  i d d t |  ƒ ƒ S(   s.   Returns the given HTML with all tags stripped.s   <[^>]*?>t    (   R   R   R   (   R   (    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/html.pyt
   strip_tagsR   s    c         C   s   t  i d d t |  ƒ ƒ S(   s8   Returns the given HTML with spaces between tags removed.s   >\s+<s   ><(   R   R   R   (   R   (    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/html.pyt   strip_spaces_between_tagsW   s    c         C   s   t  i d d t |  ƒ ƒ S(   s@   Returns the given HTML with all entities (&something;) stripped.s   &(?:\w+|#\d+);R'   (   R   R   R   (   R   (    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/html.pyt   strip_entities\   s    c         C   s   t  i d t |  ƒ ƒ S(   sG   Returns the given HTML with all unencoded ampersands encoded correctly.s   &amp;(   t   unencoded_ampersands_reR   R   (   R   (    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/html.pyt   fix_ampersandsa   s    c         C   sÉ  | d „ } t  |  t ƒ } t i t |  ƒ ƒ } | o d p d } xut | ƒ D]g\ } }	 d }
 d |	 j p d |	 j p d |	 j o t i |	 ƒ }
 n |
 oÞ|
 i	 ƒ  \ } } } d } | i
 d ƒ p | i
 d ƒ o t | d	 d
 ƒ} nÈ | i
 d ƒ p_ d | j ol | oe | d t i t i j oJ | i d ƒ p  | i d ƒ p | i d ƒ o t d | d	 d
 ƒ} n? d | j o1 d | j o$ t i | ƒ o d | } d } n | o… | | ƒ } | o> | o6 t | ƒ t | ƒ } } t | ƒ t | ƒ } } n d | | | f } t d | | | f ƒ | | <q¸| o t |	 ƒ | | <q¸| o t |	 ƒ | | <q¸qQ | o t |	 ƒ | | <qQ | o t |	 ƒ | | <qQ qQ Wd i | ƒ S(   sm  
    Converts any URLs in text into clickable links.

    Works on http://, https://, www. links and links ending in .org, .net or
    .com. Links can have trailing punctuation (periods, commas, close-parens)
    and leading punctuation (opening parens) and it'll still do the right
    thing.

    If trim_url_limit is not None, the URLs in link text longer than this limit
    will truncated to trim_url_limit-3 characters and appended with an elipsis.

    If nofollow is True, the URLs in link text will get a rel="nofollow"
    attribute.

    If autoescape is True, the link text and URLs will get autoescaped.
    c         S   s@   | d j	 o/ t |  ƒ | j o d  |  t d | d ƒ  p |  S(   s   %s...i    i   N(   t   Nonet   lent   max(   t   xt   limit(    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/html.pyt   <lambda>w   s    s    rel="nofollow"R'   R   t   @t   :s   http://s   https://t   safes	   /&=:;#?+*s   www.i    s   .orgs   .nets   .coms	   http://%ss	   mailto:%ss   <a href="%s"%s>%s</a>s   %s%s%su    N(   R   R    t   word_split_reR   R   t	   enumerateR-   t   punctuation_ret   matcht   groupst
   startswithR   t   stringt   ascii_letterst   digitst   endswitht   simple_email_reR   R   R    (   t   textt   trim_url_limitt   nofollowR!   t   trim_urlt
   safe_inputt   wordst   nofollow_attrt   it   wordR9   t   leadt   middlet   trailt   urlt   trimmed(    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/html.pyt   urlizef   sJ     ' "0*

!c         C   s­   d d k  l } | t |  ƒ ƒ }  t i d d |  ƒ }  t i d d |  ƒ }  t |  ƒ }  t i d |  ƒ }  t i d |  ƒ }  d	 „  } t i | |  ƒ }  t	 i d |  ƒ }  |  S(
   sþ  
    Clean the given HTML.  Specifically, do the following:
        * Convert <b> and <i> to <strong> and <em>.
        * Encode all ampersands correctly.
        * Remove all "target" attributes from <a> tags.
        * Remove extraneous HTML, such as presentational tags that open and
          immediately close and <br clear="all">.
        * Convert hard-coded bullets into HTML unordered lists.
        * Remove stuff like "<p>&nbsp;&nbsp;</p>", but only if it's at the
          bottom of the text.
    iÿÿÿÿ(   t   normalize_newliness   <(/?)\s*b\s*>s
   <\1strong>s   <(/?)\s*i\s*>s   <\1em>s   \1R'   c         S   sG   |  i  ƒ  i d d ƒ } x$ t D] } | i d | d ƒ } q Wd | S(   Ns   </p>s   </li>s   <p>%ss   <li>u   <ul>
%s
</ul>(   t   groupR   t   DOTS(   R9   t   st   d(    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/html.pyt   replace_p_tags¶   s
     (
   t   django.utils.textRP   R   R   R   R,   t   link_target_attribute_ret   html_gunk_ret   hard_coded_bullets_ret   trailing_empty_content_re(   RA   RP   RU   (    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/html.pyt
   clean_html    s    	(   s   \s   \u005C(   s   's   \u0027(   R   s   \u0022(   R
   s   \u003E(   R   s   \u003C(   R   s   \u0026(   R   s   \u003D(   R   s   \u002D(   R   s   \u003B(   u   â€¨s   \u2028(   u   â€©s   \u2029(2   t   __doc__R   R<   t   django.utils.safestringR    R   t   django.utils.encodingR   t   django.utils.functionalR   t   django.utils.httpR   t   LEADING_PUNCTUATIONt   TRAILING_PUNCTUATIONRR   t   compileR+   R6   R    R#   R0   R   R%   R8   R@   RW   t
   IGNORECASERX   t   _[3]t   DOTALLRY   RZ   t   unicodet   _base_js_escapest   tuplet   _[4]t   ranget   zR   R   R   t   FalseR&   R(   R)   R*   R,   R-   RO   R[   (    (    (    s;   /usr/local/lib/python2.6/dist-packages/django/utils/html.pyt   <module>   sh   	0:F		<								8	 