ó
"^†Lc           @   sÛ   d  Z  d d l Z d d l m Z d d d d g Z e j d ƒ Z e j d	 ƒ Z d e f d
 „  ƒ  YZ	 d „  Z
 d e f d „  ƒ  YZ y  d d l m Z m Z m Z Wn- e k
 rÖ d d l m Z m Z m Z n Xd S(   sž   
    markupsafe
    ~~~~~~~~~~

    Implements a Markup string.

    :copyright: (c) 2010 by Armin Ronacher.
    :license: BSD, see LICENSE for more details.
iÿÿÿÿN(   t   imapt   Markupt   soft_unicodet   escapet   escape_silents   (<!--.*?-->|<[^>]*>)s	   &([^;]+);c           B   sv  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% ƒ rPe d% ƒ Z n  e e d& ƒ rn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   Nonet   unicodet   __new__(   t   clst   baset   encodingt   errors(    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyR
   C   s
    c         C   s   |  S(   N(    (   t   self(    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyR   J   s    c         C   sE   t  | d ƒ s t | t ƒ rA |  j t |  ƒ t t | ƒ ƒ ƒ St S(   NR   (   R   t
   isinstancet
   basestringt	   __class__R	   R   t   NotImplemented(   R   t   other(    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyt   __add__M   s    #c         C   sE   t  | d ƒ s t | t ƒ rA |  j t t | ƒ ƒ t |  ƒ ƒ St S(   NR   (   R   R   R   R   R	   R   R   (   R   R   (    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyt   __radd__R   s    #c         C   s2   t  | t t f ƒ r. |  j t j |  | ƒ ƒ St S(   N(   R   t   intt   longR   R	   t   __mul__R   (   R   t   num(    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyR   W   s    c         C   sL   t  | t ƒ r' t t t | ƒ ƒ } n t | ƒ } |  j t j |  | ƒ ƒ S(   N(   R   t   tupleR    t   _MarkupEscapeHelperR   R	   t   __mod__(   R   t   arg(    (    s7   /usr/lib/python2.7/dist-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   (    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyR    d   s    	c         C   s"   |  j  t j |  t t | ƒ ƒ ƒ S(   N(   R   R	   t   joinR    R   (   R   t   seq(    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyR!   j   s    c         O   s   t  |  j t j |  | | Ž ƒ S(   N(   t   mapR   R	   t   split(   R   t   argst   kwargs(    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyR$   n   s    c         O   s   t  |  j t j |  | | Ž ƒ S(   N(   R#   R   R	   t   rsplit(   R   R%   R&   (    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyR'   r   s    c         O   s   t  |  j t j |  | | Ž ƒ S(   N(   R#   R   R	   t
   splitlines(   R   R%   R&   (    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyR(   v   s    c            s5   d d l  m ‰  ‡  f d †  } t j | t |  ƒ ƒ S(   sÔ   Unescape markup again into an unicode 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   groupt   unichrR   t
   startswitht
   ValueError(   t   mt   name(   R)   (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyt   handle_match‚   s    (   t   markupsafe._constantsR)   t
   _entity_ret   subR	   (   R   R1   (    (   R)   s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyt   unescapez   s    c         C   s1   d j  t j d |  ƒ j ƒ  ƒ } t | ƒ j ƒ  S(   s  Unescape markup into an unicode 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_reR4   R$   R   R5   (   R   t   stripped(    (    s7   /usr/lib/python2.7/dist-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(    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyR   ›   s    
c            s:   t  t |  ƒ ‰  ‡  f d †  } ˆ  j | _ ˆ  j | _ | S(   Nc            sG   t  t | ƒ t | ƒ ƒ } t  | | j ƒ  ƒ |  j ˆ  |  | | Ž ƒ S(   N(   t   _escape_argspect   listt	   enumeratet	   iteritemsR   (   R   R%   R&   (   t   orig(    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyt   func¨   s    (   t   getattrR	   R   t   __doc__(   R0   RA   (    (   R@   s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyt   make_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 |  t | ƒ ƒ ƒ ƒ S(   N(   R   R#   R   R	   RU   R   (   R   t   sep(    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyRU   ¸   s    c         C   s(   t  t |  j t j |  t | ƒ ƒ ƒ ƒ S(   N(   R   R#   R   R	   t
   rpartitionR   (   R   RV   (    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyRW   »   s    t   formatt   __getslice__(    N(   s   __getitem__s
   capitalizes   titles   lowers   uppers   replaces   ljusts   rjusts   lstrips   rstrips   centers   strips	   translates
   expandtabss   swapcases   zfill(   R   t
   __module__RC   t	   __slots__R   R
   R   R   R   R   t   __rmul__R   R    R!   R	   R$   R'   R(   R5   R9   t   classmethodR   RD   t   methodt   localsR   RU   RW   RX   RY   (    (    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyR      sF   *													
  
	c         C   sL   xE | D]= \ } } t  | d ƒ s1 t | t ƒ r t | ƒ |  | <q q W|  S(   s,   Helper for various string-wrapped functions.R   (   R   R   R   R   (   t   objt   iterablet   keyt   value(    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyR<   Ê   s    R   c           B   sM   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s   Helper for Markup.__mod__c         C   s   | |  _  d  S(   N(   R`   (   R   R`   (    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyt   __init__Õ   s    c         C   s   t  |  j | ƒ S(   N(   R   R`   (   R:   t   x(    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyt   <lambda>Ø   s    c         C   s   t  t |  j ƒ ƒ S(   N(   t   strR   R`   (   R:   (    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyRf   Ù   s    c         C   s   t  t |  j ƒ ƒ S(   N(   R	   R   R`   (   R:   (    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyRf   Ú   s    c         C   s   t  t t |  j ƒ ƒ ƒ S(   N(   Rg   R   t   reprR`   (   R:   (    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyRf   Û   s    c         C   s   t  |  j ƒ S(   N(   R   R`   (   R:   (    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyRf   Ü   s    c         C   s   t  |  j ƒ S(   N(   t   floatR`   (   R:   (    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyRf   Ý   s    (
   R   RZ   RC   Rd   RE   t   __str__t   __unicode__R    t   __int__t	   __float__(    (    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyR   Ò   s   						(   R   R   R   (   RC   t   ret	   itertoolsR    t   __all__t   compileR7   R3   R	   R   R<   t   objectR   t   markupsafe._speedupsR   R   R   t   ImportErrort   markupsafe._native(    (    (    s7   /usr/lib/python2.7/dist-packages/markupsafe/__init__.pyt   <module>
   s   ´	 