
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
2kSb(                 @   s  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G dd deZG dd deZeedrG dd dejZdd ZG dd deZyddlmZmZmZ W n( ek
r   ddlmZmZmZ Y nX es
eZejd dS )z
    markupsafe
    ~~~~~~~~~~

    Implements a Markup string.

    :copyright: (c) 2010 by Armin Ronacher.
    :license: BSD, see LICENSE for more details.
    N)Mapping)	text_typestring_types	int_typesunichr	iteritemsPY2Markupsoft_unicodeescapeescape_silentz(<!--.*?-->|<[^>]*>)z	&([^;]+);c                   s2  e Zd ZdZf Zd>ddZdd Z fd	d
Zdd Zdd Z	e	Z
dd Zdd Zdd Zejje_dd Zejje_dd Zejje_dd Zejje_dd Zdd Zedd  Zd!d" Zxd?D ]Zeee e< qW eed3 rd4d5 Zd6d7 Zeed8rd9d: Zd;d< Zeed=r&ed=Z[[  ZS )@r	   a  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;')
     Nstrictc             C   s6   t |dr|j }|d kr&tj| |S tj| |||S )N__html__)hasattrr   r   __new__)clsbaseencodingerrors r    /usr/lib64/python3.6/__init__.pyr   F   s
    
zMarkup.__new__c             C   s   | S )Nr   )selfr   r   r   r   M   s    zMarkup.__html__c                s4   t |tst|dr0| jtt| j| j|S tS )Nr   )	
isinstancer   r   	__class__superr	   __add__r   NotImplemented)r   other)r   r   r   r   P   s    zMarkup.__add__c             C   s(   t |dst|tr$| j|j| S tS )Nr   )r   r   r   r   r   r   )r   r   r   r   r   __radd__U   s    zMarkup.__radd__c             C   s    t |tr| jtj| |S tS )N)r   r   r   r   __mul__r   )r   Znumr   r   r   r    Z   s    
zMarkup.__mul__c                s@   t |tr"t fdd|D }nt| j} jtj |S )Nc             3   s   | ]}t | jV  qd S )N)_MarkupEscapeHelperr   ).0x)r   r   r   	<genexpr>b   s    z!Markup.__mod__.<locals>.<genexpr>)r   tupler!   r   r   r   __mod__)r   argr   )r   r   r&   `   s    
zMarkup.__mod__c             C   s   d| j jtj| f S )Nz%s(%s))r   __name__r   __repr__)r   r   r   r   r)   g   s    zMarkup.__repr__c             C   s   | j tj| t| j|S )N)r   r   joinmapr   )r   seqr   r   r   r*   m   s    zMarkup.joinc             O   s   t t| jtj| f||S )N)listr+   r   r   split)r   argskwargsr   r   r   r.   q   s    zMarkup.splitc             O   s   t t| jtj| f||S )N)r-   r+   r   r   rsplit)r   r/   r0   r   r   r   r1   u   s    zMarkup.rsplitc             O   s   t t| jtj| f||S )N)r-   r+   r   r   
splitlines)r   r/   r0   r   r   r   r2   y   s    zMarkup.splitlinesc                s(   ddl m   fdd}tj|t| S )zUnescape 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>'
        r   )HTML_ENTITIESc                s   | j d}| krt | S yH|d d dkrFtt|dd  dS |jdrdtt|dd  S W n tk
rz   Y nX dS )	N      #x#X   #r   )r6   r7   )groupr   int
startswith
ValueError)mname)r3   r   r   handle_match   s    

z%Markup.unescape.<locals>.handle_match)Zmarkupsafe._constantsr3   
_entity_resubr   )r   r@   r   )r3   r   unescape~   s    zMarkup.unescapec             C   s"   dj tjd| j }t|j S )a  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'
         r   )r*   _striptags_rerB   r.   r	   rC   )r   strippedr   r   r   	striptags   s    zMarkup.striptagsc             C   s   t |}|j| k	r| |S |S )zEscape 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   srvr   r   r   r      s    
zMarkup.escapec                s*   t t|   fdd} j|_ j|_|S )Nc                s>   t t|t|| j}t |t|| j | j | f||S )N)_escape_argspecr-   	enumerater   r   r   )r   r/   r0   )origr   r   func   s    z1Markup.make_simple_escaping_wrapper.<locals>.func)getattrr   r(   __doc__)r?   rM   r   )rL   r   make_simple_escaping_wrapper   s
    
z#Markup.make_simple_escaping_wrapper__getitem__
capitalizetitlelowerupperreplaceljustrjustlstriprstripcenterstrip	translate
expandtabsswapcasezfill	partitionc             C   s   t t| jtj| | j|S )N)r%   r+   r   r   ra   r   )r   sepr   r   r   ra      s    zMarkup.partitionc             C   s   t t| jtj| | j|S )N)r%   r+   r   r   
rpartitionr   )r   rb   r   r   r   rc      s    zMarkup.rpartitionformatc              O   s>   | d | dd   }} t |j}t| |}|j|j|| |S )Nr   r4   )EscapeFormatterr   _MagicFormatMappingr   Zvformat)r/   r0   r   Z	formatterr   r   r   rd      s    

zMarkup.formatc             C   s   |rt d| S )Nz,Unsupported format specification for Markup.)r=   )r   format_specr   r   r   __html_format__   s    zMarkup.__html_format____getslice__)r   Nr   )rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ) r(   
__module____qualname__rO   	__slots__r   r   r   r   r    __rmul__r&   r)   r*   r   r.   r1   r2   rC   rG   classmethodr   rP   methodlocalsr   ra   rc   rd   rh   ri   __classcell__r   r   )r   r   r	      sH   *





  c               @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )rf   zThis 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 )Nr   )_args_kwargs_last_index)r   r/   r0   r   r   r   __init__   s    z_MagicFormatMapping.__init__c             C   sN   |dkrD| j }|  j d7  _ y
| j| S  tk
r:   Y nX t|}| j| S )Nr   r4   )rt   rr   LookupErrorstrrs   )r   keyidxr   r   r   rQ      s    
z_MagicFormatMapping.__getitem__c             C   s
   t | jS )N)iterrs   )r   r   r   r   __iter__   s    z_MagicFormatMapping.__iter__c             C   s
   t | jS )N)lenrs   )r   r   r   r   __len__   s    z_MagicFormatMapping.__len__N)r(   rj   rk   rO   ru   rQ   r{   r}   r   r   r   r   rf      s
   rf   rd   c               @   s   e Zd Zdd Zdd ZdS )re   c             C   s
   || _ d S )N)r   )r   r   r   r   r   ru      s    zEscapeFormatter.__init__c             C   sT   t |dr|j|}n0t |dr6|r,td|j }ntjj| ||}t| j|S )Nrh   r   zSNo format specification allowed when formatting an object with its __html__ method.)	r   rh   r=   r   string	Formatterformat_fieldr   r   )r   valuerg   rI   r   r   r   r      s    


zEscapeFormatter.format_fieldN)r(   rj   rk   ru   r   r   r   r   r   re      s   re   c             C   s6   x0|D ](\}}t |ds"t|tr||| |< qW | S )z,Helper for various string-wrapped functions.r   )r   r   r   )objiterabler   rx   r   r   r   r   rJ     s    rJ   c               @   sD   e Zd ZdZdd Zdd Zdd  ZZdd Zdd Z	d	d Z
d
S )r!   zHelper for Markup.__mod__c             C   s   || _ || _d S )N)r   r   )r   r   r   r   r   r   ru     s    z_MarkupEscapeHelper.__init__c             C   s   t | j| | jS )N)r!   r   r   )rH   r#   r   r   r   <lambda>  s    z_MarkupEscapeHelper.<lambda>c             C   s   t | j| jS )N)r   r   r   )rH   r   r   r   r     s    c             C   s   t | jt| jS )N)rw   r   reprr   )rH   r   r   r   r     s    c             C   s
   t | jS )N)r;   r   )rH   r   r   r   r     s    c             C   s
   t | jS )N)floatr   )rH   r   r   r   r     s    N)r(   rj   rk   rO   ru   rQ   Z__unicode____str__r)   __int__	__float__r   r   r   r   r!     s   r!   )r   r   r
   soft_str) rO   rer~   collectionsr   Zmarkupsafe._compatr   r   r   r   r   r   __all__compilerE   rA   r	   rf   r   r   re   rJ   objectr!   Zmarkupsafe._speedupsr   r   r
   ImportErrorZmarkupsafe._nativer   appendr   r   r   r   <module>
   s*    

 @
