î

_ÝV>  ã               @   s  d  Z  d d l m Z d d l m Z m Z Gd d „  d e ƒ Z Gd d „  d e e ƒ Z	 Gd d	 „  d	 e j
 e ƒ Z e j r‰ e Z n e	 Z e Z Gd
 d „  d e ƒ Z Gd d „  d e e ƒ Z Gd 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.
é    )Úsix)ÚPromiseÚcurryc               @   s   e  Z d  Z d S)Ú
EscapeDataN)Ú__name__Ú
__module__Ú__qualname__© r	   r	   ú9/tmp/pip-build-ghmbqnp_/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                   sI   e  Z d  Z d Z ‡  f d d †  Z d d „  Z e e d e j ƒZ ‡  S)Ú	SafeByteszƒ
    A bytes subclass that has been specifically marked as "safe" (requires no
    further escaping) for HTML output purposes.
    c                sN   t  t |  ƒ j | ƒ } t | t ƒ r1 t | ƒ St | t ƒ rJ t | ƒ 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   3   s    

zSafeBytes.__add__c             O   sH   | j  d ƒ } | |  | | Ž } t | t ƒ r: t | ƒ St | ƒ Sd 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_method?   s
    
zSafeBytes._proxy_methodr   )	r   r   r   r   r   r   r   r   Údecoder	   r	   )r   r
   r   .   s   r   c                   sL   e  Z d  Z d Z ‡  f d d †  Z d d „  Z e e d e j j	 ƒZ	 ‡  S)r   z‚
    A unicode (Python 2) / str (Python 3) subclass that has been specifically
    marked as "safe" for HTML output purposes.
    c                s5   t  t |  ƒ j | ƒ } t | t ƒ r1 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   T   s    
zSafeText.__add__c             O   sH   | j  d ƒ } | |  | | Ž } t | t ƒ r: t | ƒ St | ƒ Sd 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   ^   s
    
zSafeText._proxy_methodr   )
r   r   r   r   r   r   r   r   Ú	text_typeÚencoder	   r	   )r   r
   r   O   s   
r   c             C   sv   t  |  d ƒ r |  St |  t ƒ s: t |  t ƒ rD |  j rD t |  ƒ St |  t j t f ƒ rf t |  ƒ St	 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_safeu   s    '

r(   c             C   s…   t  |  d ƒ s t |  t ƒ r" |  St |  t ƒ sI t |  t ƒ rS |  j rS t |  ƒ St |  t j t f ƒ ru t	 |  ƒ St
 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).
    r   )r#   r   r   r   r   r$   r   r   r!   r   ÚEscapeStringr&   )r'   r	   r	   r
   Úmark_for_escaping…   s    '

r*   N)r   Zdjango.utilsr   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$   		
!		