Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/site-packages/markupsafe/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/site-packages/markupsafe/__pycache__/__init__.cpython-35.pyc



2�kSb(�@spdZddlZddlZddlmZddlmZmZmZm	Z	m
Z
mZddddgZej
d	�Zej
d
�ZGdd�de�ZGdd
�d
e�Zeed�r�Gdd�dej�Zdd�ZGdd�de�Zy ddlmZmZmZWn.ek
rRddlmZmZmZYnXesleZejd�dS)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	&([^;]+);cs�eZdZdZfZddddd�Zdd�Z�fd	d
�Zdd�Zd
d�Z	e	Z
dd�Zdd�Zdd�Z
ej
je
_dd�Zejje_dd�Zejje_dd�Zejje_dd�Zdd�Zedd ��Zd!d"�Zx!d>D]Zee�e�e<q*Weed3�rnd4d5�Zd6d7�Zeed8�r�d9d:�Zd;d<�Zeed=�r�ed=�Z[[�S)?r	aMarks 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�strictcCsMt|d�r|j�}|dkr7tj||�Stj||||�S)N�__html__)�hasattrrr�__new__)�cls�base�encoding�errors�r�F/opt/alt/python35/lib64/python3.5/site-packages/markupsafe/__init__.pyrFs
zMarkup.__new__cCs|S)Nr)�selfrrrrMszMarkup.__html__csJt|t�st|d�rF|jtt|�j|j|���StS)Nr)	�
isinstancerr�	__class__�superr	�__add__r�NotImplemented)r�other)rrrrPs(zMarkup.__add__cCs8t|d�st|t�r4|j|�j|�StS)Nr)rrrrrr)rrrrr�__radd__UszMarkup.__radd__cCs,t|t�r(|jtj||��StS)N)rrrr�__mul__r)r�numrrrr ZszMarkup.__mul__cs\t|t�r1t�fdd�|D��}nt|�j�}�jtj�|��S)Nc3s!|]}t|�j�VqdS)N)�_MarkupEscapeHelperr)�.0�x)rrr�	<genexpr>bsz!Markup.__mod__.<locals>.<genexpr>)r�tupler"rrr�__mod__)r�argr)rrr'`s"zMarkup.__mod__cCsd|jjtj|�fS)Nz%s(%s))r�__name__r�__repr__)rrrrr*gs	zMarkup.__repr__cCs%|jtj|t|j|���S)N)rr�join�mapr)r�seqrrrr+mszMarkup.joincOs%tt|jtj|||���S)N)�listr,rr�split)r�args�kwargsrrrr/qszMarkup.splitcOs%tt|jtj|||���S)N)r.r,rr�rsplit)rr0r1rrrr2usz
Markup.rsplitcOs%tt|jtj|||���S)N)r.r,rr�
splitlines)rr0r1rrrr3yszMarkup.splitlinescs8ddlm��fdd�}tj|t|��S)z�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>'
        r)�
HTML_ENTITIEScs�|jd�}|�kr)t�|�Sy`|dd�dkr_tt|dd�d��S|jd�r�tt|dd���SWntk
r�YnXdS)	N���#x�#X��#r
)r7r8)�groupr�int�
startswith�
ValueError)�m�name)r4rr�handle_match�s
z%Markup.unescape.<locals>.handle_match)Zmarkupsafe._constantsr4�
_entity_re�subr)rrAr)r4r�unescape~szMarkup.unescapecCs1djtjd|�j��}t|�j�S)aUnescape 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_rerCr/r	rD)r�strippedrrr�	striptags�s!zMarkup.striptagscCs)t|�}|j|k	r%||�S|S)z�Escape the string.  Works like :func:`escape` with the difference
        that for subclasses of :class:`Markup` this function would return the
        correct subclass.
        )rr)r�s�rvrrrr�s
z
Markup.escapecs=tt|���fdd�}�j|_�j|_|S)NcsStt|�t|�|j�}t|t|�|j�|j�|||��S)N)�_escape_argspecr.�	enumeraterrr)rr0r1)�origrr�func�s!z1Markup.make_simple_escaping_wrapper.<locals>.func)�getattrrr)�__doc__)r@rNr)rMr�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�	partitioncCs+tt|jtj||j|����S)N)r&r,rrrbr)r�seprrrrb�szMarkup.partitioncCs+tt|jtj||j|����S)N)r&r,rr�
rpartitionr)rrcrrrrd�szMarkup.rpartition�formatcOsU|d|dd�}}t|j�}t||�}|j|j|||��S)Nrr5)�EscapeFormatterr�_MagicFormatMappingr�vformat)r0r1r�	formatterrrrre�sz
Markup.formatcCs|rtd��|S)Nz,Unsupported format specification for Markup.)r>)r�format_specrrr�__html_format__�szMarkup.__html_format__�__getslice__)rRrSrTrUrVrWrXrYrZr[r\r]r^r_r`ra)r)�
__module__�__qualname__rP�	__slots__rrrrr �__rmul__r'r*r+rr/r2r3rDrH�classmethodrrQ�method�localsrrbrdrerkrlrr)rrr	sH*

c@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)rgz�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.
    cCs||_||_d|_dS)Nr)�_args�_kwargs�_last_index)rr0r1rrr�__init__�s		z_MagicFormatMapping.__init__cCs_|dkrT|j}|jd7_y|j|SWntk
rGYnXt|�}|j|S)Nr
r5)rvrt�LookupError�strru)r�key�idxrrrrR�s	
z_MagicFormatMapping.__getitem__cCs
t|j�S)N)�iterru)rrrr�__iter__�sz_MagicFormatMapping.__iter__cCs
t|j�S)N)�lenru)rrrr�__len__�sz_MagicFormatMapping.__len__N)r)rmrnrPrwrRr}rrrrrrg�s
rgrec@s(eZdZdd�Zdd�ZdS)rfcCs
||_dS)N)r)rrrrrrw�szEscapeFormatter.__init__cCs|t|d�r!|j|�}nHt|d�rQ|rBtd��|j�}ntjj|||�}t|j|��S)NrkrzSNo format specification allowed when formatting an object with its __html__ method.)	rrkr>r�string�	Formatter�format_fieldrr)r�valuerjrJrrrr��szEscapeFormatter.format_fieldN)r)rmrnrwr�rrrrrf�srfcCsIxB|D]:\}}t|d�s1t|t�r||�||<qW|S)z,Helper for various string-wrapped functions.r)rrr)�obj�iterablerrzr�rrrrKsrKc@sbeZdZdZdd�Zdd�Zdd�ZZdd�Zdd�Z	d	d�Z
d
S)r"zHelper for Markup.__mod__cCs||_||_dS)N)r�r)rr�rrrrrws	z_MarkupEscapeHelper.__init__cCst|j||j�S)N)r"r�r)rIr$rrr�<lambda>sz_MarkupEscapeHelper.<lambda>cCst|j|j��S)N)rrr�)rIrrrr�scCst|jt|j���S)N)ryr�reprr�)rIrrrr�scCs
t|j�S)N)r<r�)rIrrrr�scCs
t|j�S)N)�floatr�)rIrrrr�sN)r)rmrnrPrwrR�__unicode__�__str__r*�__int__�	__float__rrrrr"sr")rrr
�soft_str) rP�rer��collectionsrZmarkupsafe._compatrrrrrr�__all__�compilerFrBr	rgrr�rfrK�objectr"Zmarkupsafe._speedupsrrr
�ImportErrorZmarkupsafe._nativer��appendrrrr�<module>
s(.� 
!