3
š(ƒhß  ã               @   sÜ   d Z ddlZddlmZ ddlmZ ddlmZmZ G dd„ de	ƒZ
G dd	„ d	ee
ƒZG d
d„ deje
ƒZejrveZneZeZG dd„ de	ƒZG dd„ deeƒZG dd„ dejeƒZejrÀeZneZeZdd„ Zdd„ ZdS )a8  
Functions for working with "safe strings": strings that can be displayed safely
without further escaping in HTML. Marking something as a "safe string" means
that the producer of the string has already turned characters that should not
be interpreted by the HTML engine (e.g. '<') into the appropriate entities.
é    N)Úsix)ÚRemovedInDjango20Warning)ÚPromiseÚcurryc               @   s   e Zd ZdS )Ú
EscapeDataN)Ú__name__Ú
__module__Ú__qualname__© r
   r
   ú;/tmp/pip-install-q3hcpn_q/Django/django/utils/safestring.pyr      s   r   c               @   s   e Zd ZdZdS )ÚEscapeBytesz@
    A byte string that should be HTML-escaped when output.
    N)r   r   r	   Ú__doc__r
   r
   r
   r   r      s   r   c               @   s   e Zd ZdZdS )Ú
EscapeTextzJ
    A unicode string object that should be HTML-escaped when output.
    N)r   r   r	   r   r
   r
   r
   r   r      s   r   c               @   s   e Zd Zdd„ ZdS )ÚSafeDatac             C   s   | S )z 
        Returns the html representation of a string for interoperability.

        This allows other template engines to understand Django's SafeData.
        r
   )Úselfr
   r
   r   Ú__html__(   s    zSafeData.__html__N)r   r   r	   r   r
   r
   r
   r   r   '   s   r   c                   s6   e Zd ZdZ‡ fdd„Zdd„ ZeeejdZ‡  Z	S )Ú	SafeByteszƒ
    A bytes subclass that has been specifically marked as "safe" (requires no
    further escaping) for HTML output purposes.
    c                s8   t t| ƒj|ƒ}t|tƒr"t|ƒS t|tƒr4t|ƒS |S )z¡
        Concatenating a safe byte string with another safe byte string or safe
        unicode string is safe. Otherwise, the result is no longer safe.
        )Úsuperr   Ú__add__Ú
isinstanceÚSafeText)r   ÚrhsÚt)Ú	__class__r
   r   r   6   s    

zSafeBytes.__add__c             O   s8   |j dƒ}|| f|ž|Ž}t|tƒr,t|ƒS t|ƒS dS )z°
        Wrap a call to a normal unicode method up so that we return safe
        results. The method that is being wrapped is passed in the 'method'
        argument.
        ÚmethodN)Úpopr   Úbytesr   r   )r   ÚargsÚkwargsr   Údatar
   r
   r   Ú_proxy_methodB   s
    

zSafeBytes._proxy_method)r   )
r   r   r	   r   r   r    r   r   ÚdecodeÚ__classcell__r
   r
   )r   r   r   1   s   r   c                   s8   e Zd ZdZ‡ fdd„Zdd„ Zeeejj	dZ	‡  Z
S )r   z‚
    A unicode (Python 2) / str (Python 3) subclass that has been specifically
    marked as "safe" for HTML output purposes.
    c                s&   t t| ƒj|ƒ}t|tƒr"t|ƒS |S )z¤
        Concatenating a safe unicode string with another safe byte string or
        safe unicode string is safe. Otherwise, the result is no longer safe.
        )r   r   r   r   r   )r   r   r   )r   r
   r   r   W   s    
zSafeText.__add__c             O   s8   |j dƒ}|| f|ž|Ž}t|tƒr,t|ƒS t|ƒS dS )z°
        Wrap a call to a normal unicode method up so that we return safe
        results. The method that is being wrapped is passed in the 'method'
        argument.
        r   N)r   r   r   r   r   )r   r   r   r   r   r
   r
   r   r    a   s
    

zSafeText._proxy_method)r   )r   r   r	   r   r   r    r   r   Ú	text_typeÚencoder"   r
   r
   )r   r   r   R   s   
r   c             C   sT   t | dƒr| S t| tƒs(t| tƒr0| jr0t| ƒS t| tjtfƒrHt| ƒS t	t
| ƒƒS )zÖ
    Explicitly mark a string as safe for (HTML) output purposes. The returned
    object can be used everywhere a string or unicode object is appropriate.

    Can be called multiple times on a single string.
    r   )Úhasattrr   r   r   Ú_delegate_bytesr   r   r#   r   Ú
SafeStringÚstr)Úsr
   r
   r   Ú	mark_safex   s    
r*   c             C   sj   t jdtƒ t| dƒs t| tƒr$| S t| tƒs>t| tƒrF| jrFt	| ƒS t| t
jtfƒr^t| ƒS tt| ƒƒS )zÜ
    Explicitly mark a string as requiring HTML escaping upon output. Has no
    effect on SafeData subclasses.

    Can be called multiple times on a single string (the resulting escaping is
    only applied once).
    z"mark_for_escaping() is deprecated.r   )ÚwarningsÚwarnr   r%   r   r   r   r   r&   r   r   r#   r   ÚEscapeStringr(   )r)   r
   r
   r   Úmark_for_escapingˆ   s    r.   )r   r+   Zdjango.utilsr   Zdjango.utils.deprecationr   Zdjango.utils.functionalr   r   Úobjectr   r   r   r#   r   ÚPY3r-   ZEscapeUnicoder   r   r   r'   ZSafeUnicoder*   r.   r
   r
   r
   r   Ú<module>   s(   
!