ó
ú2ec           @   s  d  d l  Z  d  d l Z d  d l m Z d  d l m Z m Z d  d l m Z d d d d d	 g Z	 d
 Z
 d d „ Z e j d ƒ Z e j d „ Z d d „ Z d „  Z d „  Z e j d ƒ Z e j d ƒ Z d „  Z e Z e Z e d k r	d  d l Z e j ƒ  n  d S(   iÿÿÿÿN(   t   html_entities(   t   quotet   unquote(   t   htmlt
   html_quotet   html_unquotet	   url_quotet   url_unquotet
   strip_htmls   UTF-8c         C   sû   | p	 t  } |  d k r d St |  t j ƒ rl t j rY t j |  j | ƒ d ƒ j	 | ƒ St j |  d ƒ Sn‹ t |  t j
 ƒ r³ t j r— t j |  d ƒ St j |  j	 | ƒ d ƒ SnD t j rÕ t j t j
 |  ƒ d ƒ St j t j
 |  ƒ j	 | ƒ d ƒ Sd S(   sZ   
    Quote the value (turned to a string) as HTML.  This quotes <, >,
    and quotes:
    t    i   N(   t   default_encodingt   Nonet
   isinstancet   sixt   binary_typet   PY3R   t   escapet   decodet   encodet	   text_type(   t   vt   encoding(    (    s<   /usr/local/lib/python2.7/dist-packages/paste/util/quoting.pyR      s    	"		s   &([a-zA-Z]+);c         C   s<   | j  |  j d ƒ ƒ } | r+ t j | ƒ S|  j d ƒ Sd  S(   Ni   i    (   t   gett   groupR   t   unichr(   t   matcht   name2ct   code(    (    s<   /usr/local/lib/python2.7/dist-packages/paste/util/quoting.pyt   _entity_subber*   s    c         C   s:   t  |  t j ƒ r* |  j | p! t ƒ }  n  t j t |  ƒ S(   s   
    Decode the value.

    (   R   R   R   R   R
   t   _unquote_ret   subR   (   t   sR   (    (    s<   /usr/local/lib/python2.7/dist-packages/paste/util/quoting.pyR   1   s    c         C   s%   t  j d d |  ƒ }  t |  ƒ }  |  S(   Ns   <.*?>R	   (   t   reR   R   (   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/paste/util/quoting.pyR   :   s    c         C   s   |  S(   s*   
    Quoting that doesn't do anything
    (    (   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/paste/util/quoting.pyt   no_quote@   s    s   \-\s*\>s   [ ---]c         C   s"   t  |  ƒ } t j d | ƒ } | S(   s;   
    Quote that makes sure text can't escape a comment
    s   -&gt;(   t   strt   _comment_quote_reR   (   R   t   comment(    (    s<   /usr/local/lib/python2.7/dist-packages/paste/util/quoting.pyt   comment_quoteI   s    t   __main__(   R   R    t	   six.movesR    t   six.moves.urllib.parseR   R   t
   paste.utilR   t   __all__R
   R   R   t   compileR   t   name2codepointR   R   R   R!   R#   t   _bad_chars_reR%   R   R   t   __name__t   doctestt   testmod(    (    (    s<   /usr/local/lib/python2.7/dist-packages/paste/util/quoting.pyt   <module>   s*   					