ó
!`¾Tc           @   sr  d  Z  d d l Z d d l Z d d l m Z d d l m Z m Z m Z m	 Z	 m
 Z
 m Z d d d d g Z e j d	 ƒ Z e j d
 ƒ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ e e d ƒ rã d e j f d „  ƒ  YZ n  d „  Z d e f d „  ƒ  YZ y  d d l m Z m Z m Z Wn- e k
 rQd d l m Z m Z m Z n Xe sne Z e j d ƒ n  d S(   sž   
    markupsafe
    ~~~~~~~~~~

    Implements a Markup string.

    :copyright: (c) 2010 by Armin Ronacher.
    :license: BSD, see LICENSE for more details.
iÿÿÿÿN(   t   Mapping(   t	   text_typet   string_typest	   int_typest   unichrt	   iteritemst   PY2t   Markupt   soft_unicodet   escapet   escape_silents   (<!--.*?-->|<[^>]*>)s	   &([^;]+);c           B   s|  e  Z d  Z d) Z d d* d d „ Z d „  Z d „  Z d „  Z d „  Z	 e	 Z
 d „  Z d	 „  Z d
 „  Z e j j e _ d „  Z e j j e _ d „  Z e j j e _ d „  Z e j j e _ d „  Z d „  Z e d „  ƒ Z d „  Z x! d+ D] Z e e ƒ e ƒ  e <qñ We e d" ƒ r2d# „  Z d$ „  Z n  e e d% ƒ rVd& „  Z d' „  Z n  e e d( ƒ rte d( ƒ Z n  [ [ RS(,   s  Marks a string as being safe for inclusion in HTML/XML output without
    needing to be escaped.  This implements the `__html__` interface a couple
    of frameworks and web applications use.  :class:`Markup` is a direct
    subclass of `unicode` and provides all the methods of `unicode` just that
    it escapes arguments passed and always returns `Markup`.

    The `escape` function returns markup objects so that double escaping can't
    happen.

    The constructor of the :class:`Markup` class can be used for three
    different things:  When passed an unicode object it's assumed to be safe,
    when passed an object with an HTML representation (has an `__html__`
    method) that representation is used, otherwise the object passed is
    converted into a unicode string and then assumed to be safe:

    >>> Markup("Hello <em>World</em>!")
    Markup(u'Hello <em>World</em>!')
    >>> class Foo(object):
    ...  def __html__(self):
    ...   return '<a href="#">foo</a>'
    ...
    >>> Markup(Foo())
    Markup(u'<a href="#">foo</a>')

    If you want object passed being always treated as unsafe you can use the
    :meth:`escape` classmethod to create a :class:`Markup` object:

    >>> Markup.escape("Hello <em>World</em>!")
    Markup(u'Hello &lt;em&gt;World&lt;/em&gt;!')

    Operations on a markup string are markup aware which means that all
    arguments are passed through the :func:`escape` function:

    >>> em = Markup("<em>%s</em>")
    >>> em % "foo & bar"
    Markup(u'<em>foo &amp; bar</em>')
    >>> strong = Markup("<strong>%(text)s</strong>")
    >>> strong % {'text': '<blink>hacker here</blink>'}
    Markup(u'<strong>&lt;blink&gt;hacker here&lt;/blink&gt;</strong>')
    >>> Markup("<em>Hello</em> ") + "<foo>"
    Markup(u'<em>Hello</em> &lt;foo&gt;')
    u    t   strictc         C   sP   t  | d ƒ r | j ƒ  } n  | d  k r: t j |  | ƒ St j |  | | | ƒ S(   Nt   __html__(   t   hasattrR   t   NoneR   t   __new__(   t   clst   baset   encodingt   errors(    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR   F   s
    c         C   s   |  S(   N(    (   t   self(    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR   M   s    c         C   sJ   t  | t ƒ s t | d ƒ rF |  j t t |  ƒ j |  j | ƒ ƒ ƒ St S(   NR   (	   t
   isinstanceR   R   t	   __class__t   superR   t   __add__R	   t   NotImplemented(   R   t   other(    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR   P   s    (c         C   s8   t  | d ƒ s t | t ƒ r4 |  j | ƒ j |  ƒ St S(   NR   (   R   R   R   R	   R   R   (   R   R   (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyt   __radd__U   s    c         C   s,   t  | t ƒ r( |  j t j |  | ƒ ƒ St S(   N(   R   R   R   R   t   __mul__R   (   R   t   num(    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR   Z   s    c            sY   t  | t ƒ r. t ‡  f d †  | Dƒ ƒ } n t | ˆ  j ƒ } ˆ  j t j ˆ  | ƒ ƒ S(   Nc         3   s!   |  ] } t  | ˆ  j ƒ Vq d  S(   N(   t   _MarkupEscapeHelperR	   (   t   .0t   x(   R   (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pys	   <genexpr>b   s    (   R   t   tupleR   R	   R   R   t   __mod__(   R   t   arg(    (   R   sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR"   `   s    c         C   s   d |  j  j t j |  ƒ f S(   Ns   %s(%s)(   R   t   __name__R   t   __repr__(   R   (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR%   g   s    	c         C   s%   |  j  t j |  t |  j | ƒ ƒ ƒ S(   N(   R   R   t   joint   mapR	   (   R   t   seq(    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR&   m   s    c         O   s%   t  t |  j t j |  | | Ž ƒ ƒ S(   N(   t   listR'   R   R   t   split(   R   t   argst   kwargs(    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR*   q   s    c         O   s%   t  t |  j t j |  | | Ž ƒ ƒ S(   N(   R)   R'   R   R   t   rsplit(   R   R+   R,   (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR-   u   s    c         O   s%   t  t |  j t j |  | | Ž ƒ ƒ S(   N(   R)   R'   R   R   t
   splitlines(   R   R+   R,   (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR.   y   s    c            s5   d d l  m ‰  ‡  f d †  } t j | t |  ƒ ƒ S(   sÖ   Unescape markup again into an text_type string.  This also resolves
        known HTML4 and XHTML entities:

        >>> Markup("Main &raquo; <em>About</em>").unescape()
        u'Main \xbb <em>About</em>'
        iÿÿÿÿ(   t   HTML_ENTITIESc            s   |  j  d ƒ } | ˆ  k r) t ˆ  | ƒ SyN | d  d k rS t t | d d ƒ ƒ S| j d ƒ rv t t | d ƒ ƒ SWn t k
 rŠ n Xd S(	   Ni   i   s   #xs   #Xi   t   #u    (   s   #xs   #X(   t   groupR   t   intt
   startswitht
   ValueError(   t   mt   name(   R/   (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyt   handle_match†   s    (   t   markupsafe._constantsR/   t
   _entity_ret   subR   (   R   R7   (    (   R/   sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyt   unescape~   s    c         C   s1   d j  t j d |  ƒ j ƒ  ƒ } t | ƒ j ƒ  S(   s  Unescape markup into an text_type string and strip all tags.  This
        also resolves known HTML4 and XHTML entities.  Whitespace is
        normalized to one:

        >>> Markup("Main &raquo;  <em>About</em>").striptags()
        u'Main \xbb About'
        u    t    (   R&   t   _striptags_reR:   R*   R   R;   (   R   t   stripped(    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyt	   striptags”   s    !c         C   s)   t  | ƒ } | j |  k	 r% |  | ƒ S| S(   s²   Escape the string.  Works like :func:`escape` with the difference
        that for subclasses of :class:`Markup` this function would return the
        correct subclass.
        (   R	   R   (   R   t   st   rv(    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR	   Ÿ   s    
c            s:   t  t |  ƒ ‰  ‡  f d †  } ˆ  j | _ ˆ  j | _ | S(   Nc            sS   t  t | ƒ t | ƒ |  j ƒ } t  | t | ƒ |  j ƒ |  j ˆ  |  | | Ž ƒ S(   N(   t   _escape_argspecR)   t	   enumerateR	   R   R   (   R   R+   R,   (   t   orig(    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyt   func¬   s    !(   t   getattrR   R$   t   __doc__(   R6   RE   (    (   RD   sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyt   make_simple_escaping_wrapperª   s
    t   __getitem__t
   capitalizet   titlet   lowert   uppert   replacet   ljustt   rjustt   lstript   rstript   centert   stript	   translatet
   expandtabst   swapcaset   zfillt	   partitionc         C   s+   t  t |  j t j |  |  j | ƒ ƒ ƒ ƒ S(   N(   R!   R'   R   R   RY   R	   (   R   t   sep(    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyRY   ¼   s    c         C   s+   t  t |  j t j |  |  j | ƒ ƒ ƒ ƒ S(   N(   R!   R'   R   R   t
   rpartitionR	   (   R   RZ   (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR[   ¿   s    t   formatc          O   sO   |  d |  d } }  t  | j ƒ } t |  | ƒ } | j | j | |  | ƒ ƒ S(   Ni    i   (   t   EscapeFormatterR	   t   _MagicFormatMappingR   t   vformat(   R+   R,   R   t	   formatter(    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR\   Å   s    c         C   s   | r t  d ƒ ‚ n  |  S(   Ns,   Unsupported format specification for Markup.(   R4   (   R   t   format_spec(    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyt   __html_format__Ë   s    t   __getslice__(    N(   s   __getitem__s
   capitalizes   titles   lowers   uppers   replaces   ljusts   rjusts   lstrips   rstrips   centers   strips	   translates
   expandtabss   swapcases   zfill(   R$   t
   __module__RG   t	   __slots__R   R   R   R   R   R   t   __rmul__R"   R%   R&   R   R*   R-   R.   R;   R?   t   classmethodR	   RH   t   methodt   localsR   RY   R[   R\   Rb   Rc   (    (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR      sH   *													
  
		R^   c           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sÍ   This class implements a dummy wrapper to fix a bug in the Python
    standard library for string formatting.

    See http://bugs.python.org/issue13598 for information about why
    this is necessary.
    c         C   s   | |  _  | |  _ d |  _ d  S(   Ni    (   t   _argst   _kwargst   _last_index(   R   R+   R,   (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyt   __init__à   s    		c         C   sa   | d k rV |  j  } |  j  d 7_  y |  j | SWn t k
 rF n Xt | ƒ } n  |  j | S(   NR<   i   (   Rl   Rj   t   LookupErrort   strRk   (   R   t   keyt   idx(    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyRI   å   s    	c         C   s   t  |  j ƒ S(   N(   t   iterRk   (   R   (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyt   __iter__ð   s    c         C   s   t  |  j ƒ S(   N(   t   lenRk   (   R   (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyt   __len__ó   s    (   R$   Rd   RG   Rm   RI   Rs   Ru   (    (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR^   Ø   s
   			R\   R]   c           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   R	   (   R   R	   (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyRm   ú   s    c         C   s   t  | d ƒ r! | j | ƒ } nK t  | d ƒ rT | rE t d ƒ ‚ n  | j ƒ  } n t j j |  | | ƒ } t |  j | ƒ ƒ S(   NRb   R   sS   No format specification allowed when formatting an object with its __html__ method.(	   R   Rb   R4   R   t   stringt	   Formattert   format_fieldR   R	   (   R   t   valueRa   RA   (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyRx   ý   s    (   R$   Rd   Rm   Rx   (    (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR]   ø   s   	c         C   sL   xE | D]= \ } } t  | d ƒ s1 t | t ƒ r | | ƒ |  | <q q W|  S(   s,   Helper for various string-wrapped functions.R   (   R   R   R   (   t   objt   iterableR	   Rp   Ry   (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyRB     s    R   c           B   sH   e  Z d  Z d „  Z d „  Z d „  Z Z d „  Z d „  Z d „  Z	 RS(   s   Helper for Markup.__mod__c         C   s   | |  _  | |  _ d  S(   N(   Rz   R	   (   R   Rz   R	   (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyRm     s    	c         C   s   t  |  j | |  j ƒ S(   N(   R   Rz   R	   (   R@   R    (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyt   <lambda>  s    c         C   s   t  |  j |  j ƒ ƒ S(   N(   R   R	   Rz   (   R@   (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR|     s    c         C   s   t  |  j t |  j ƒ ƒ ƒ S(   N(   Ro   R	   t   reprRz   (   R@   (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR|     s    c         C   s   t  |  j ƒ S(   N(   R2   Rz   (   R@   (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR|     s    c         C   s   t  |  j ƒ S(   N(   t   floatRz   (   R@   (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR|     s    (
   R$   Rd   RG   Rm   RI   t   __unicode__t   __str__R%   t   __int__t	   __float__(    (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyR     s   				(   R	   R
   R   t   soft_str(    RG   t   reRv   t   collectionsR    t   markupsafe._compatR   R   R   R   R   R   t   __all__t   compileR=   R9   R   R^   R   Rw   R]   RB   t   objectR   t   markupsafe._speedupsR	   R
   R   t   ImportErrort   markupsafe._nativeRƒ   t   append(    (    (    sY   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/markupsafe/__init__.pyt   <module>
   s(   .¿	  