
 X\'                 @   s  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m Z d  d l	 m
 Z
 d  d l m Z m Z e j r d  d l m Z n  Gd d	   d	 e  Z e j Z d
 d d d d  Z e j e d  e e e j e j e j f Z d d   Z d
 d d d d  Z d
 d d d d  Z d
 d d d d  Z e j r[e Z e Z  n e Z e Z  e Z! e Z" d e _# d e  _# d d   Z$ d d   Z% d d   Z& d d    Z' d! d"   Z( d# d$   Z) e)   Z* d S)%    )unicode_literalsN)Decimal)six)Promise)quoteunquote)unquote_to_bytesc               @   s(   e  Z d  Z d d   Z d d   Z d S)DjangoUnicodeDecodeErrorc             G   s   | |  _  t j |  |  d  S)N)objUnicodeDecodeError__init__)selfr
   args r   C/home/ubuntu/projects/ifolica/build/django/django/utils/encoding.pyr      s    	z!DjangoUnicodeDecodeError.__init__c             C   s,   t  j |   } d | |  j t |  j  f S)Nz%s. You passed in %r (%s))r   __str__r
   type)r   Zoriginalr   r   r   r      s    z DjangoUnicodeDecodeError.__str__N)__name__
__module____qualname__r   r   r   r   r   r   r	      s   r	   zutf-8Fstrictc             C   s&   t  |  t  r |  St |  | | |  S)z
    Returns a text object representing 's' -- unicode on Python 2 and str on
    Python 3. Treats bytestrings using the 'encoding' codec.

    If strings_only is True, don't convert (some) non-string-like objects.
    )
isinstancer   
force_text)sencodingstrings_onlyerrorsr   r   r   
smart_text   s    r   c             C   s   t  |  t  S)zDetermine if the object instance is of a protected type.

    Objects of protected types are preserved as-is when passed to
    force_text(strings_only=True).
    )r   _PROTECTED_TYPES)r
   r   r   r   is_protected_type1   s    r   c                sY  t  t |   t j  r |  S r2 t |   r2 |  Sy t  t |   t j  s t j r t |  t  r} t j |      }  q t j |   }  q t	 |  d  r t j |   }  q t j t |       }  n |  j
     }  Wnq t k
 rT} zQ t |  t  st |  | j   n( d j     f d d   |  D  }  WYd d } ~ Xn X|  S)z
    Similar to smart_text, except that lazy instances are resolved to
    strings, rather than kept as lazy objects.

    If strings_only is True, don't convert (some) non-string-like objects.
    Z__unicode__ c             3   s$   |  ] } t  |      Vq d  S)N)r   ).0arg)r   r   r   r   r   	<genexpr>_   s   zforce_text.<locals>.<genexpr>N)
issubclassr   r   	text_typer   string_typesPY3r   byteshasattrdecoder   	Exceptionr	   r   join)r   r   r   r   er   )r   r   r   r   r   :   s(    	 r   c             C   s&   t  |  t  r |  St |  | | |  S)z
    Returns a bytestring version of 's', encoded as specified in 'encoding'.

    If strings_only is True, don't convert (some) non-string-like objects.
    )r   r   force_bytes)r   r   r   r   r   r   r   smart_bytesd   s    r/   c                sQ  t  |  t  r>   d k r |  S|  j d   j     Sn   rT t |   rT |  St  |  t j  rp t |   St  |  t  r t j |   j     St  |  t j	  s=y- t j
 r t j |   j    St |   SWqMt k
 r9t  |  t  rd j     f d d   |  D  St j |   j     SYqMXn |  j     Sd S)z
    Similar to smart_bytes, except that lazy instances are resolved to
    strings, rather than kept as lazy objects.

    If strings_only is True, don't convert (some) non-string-like objects.
    zutf-8    c             3   s$   |  ] } t  |      Vq d  S)N)r.   )r!   r"   )r   r   r   r   r   r#      s   zforce_bytes.<locals>.<genexpr>N)r   r(   r*   encoder   r   
memoryviewr   r%   r&   r'   UnicodeEncodeErrorr+   r,   )r   r   r   r   r   )r   r   r   r   r.   p   s*    
	!r.   zw
Apply smart_text in Python 3 and smart_bytes in Python 2.

This is suitable for writing to sys.stdout (for instance).
z;
Apply force_text in Python 3 and force_bytes in Python 2.
c             C   s&   |  d k r |  St  t |   d d S)u  
    Convert an Internationalized Resource Identifier (IRI) portion to a URI
    portion that is suitable for inclusion in a URL.

    This is the algorithm from section 3.1 of RFC 3987.  However, since we are
    assuming input is either UTF-8 or unicode already, we can simplify things a
    little from the full method.

    Takes an IRI in UTF-8 bytes (e.g. '/I â¥ Django/') or unicode
    (e.g. '/I ♥ Django/') and returns ASCII bytes containing the encoded result
    (e.g. '/I%20%E2%99%A5%20Django/').
    Nsafes   /#%[]=:;$&()+,!?*@'~)r   r.   )irir   r   r   
iri_to_uri   s    r6   c             C   sP   |  d k r |  St  |   }  t j r1 t |   n	 t |   } t |  j d  S)u;  
    Converts a Uniform Resource Identifier(URI) into an Internationalized
    Resource Identifier(IRI).

    This is the algorithm from section 3.2 of RFC 3987.

    Takes an URI in ASCII bytes (e.g. '/I%20%E2%99%A5%20Django/') and returns
    unicode containing the encoded result (e.g. '/I â¥ Django/').
    Nzutf-8)r.   r   r'   r   r   repercent_broken_unicoder*   )urir5   r   r   r   
uri_to_iri   s
    
!r9   c             C   s   t  t |   d d S)zh
    Escape the unsafe characters from the path portion of a Uniform Resource
    Identifier (URI).
    r4   s   /:@&+$,-_.!~*'())r   r.   )pathr   r   r   escape_uri_path   s    r;   c             C   s   y |  j  d  Wn{ t k
 r } z[ t |  | j | j  d d } t |  d | j  t |  |  | j d   }  WYd d } ~ Xn X|  S)z
    As per section 3.2 of RFC 3987, step three of converting a URI into an IRI,
    we need to re-percent-encode any octet produced that is not part of a
    strictly legal UTF-8 octet sequence.
    zutf-8r4   s   /#%[]=:;$&()+,!?*@'~N)r*   r   r   startendr7   r.   )r:   r-   Z	repercentr   r   r   r7      s    "Dr7   c             C   s2   |  d k r |  St  t |   j d d  d d S)a  Convert a file system path to a URI portion that is suitable for
    inclusion in a URL.

    We are assuming input is either UTF-8 or unicode already.

    This method will encode certain chars that would normally be recognized as
    special chars for URIs.  Note that this method does not encode the '
    character, as it is a valid character within URIs.  See
    encodeURIComponent() JavaScript function for more details.

    Returns an ASCII string containing the encoded result.
    Ns   \   /r4   s   /~!*()')r   r.   replace)r:   r   r   r   filepath_to_uri   s    r@   c              C   sF   y' t  j   d p d }  t j |   Wn t k
 rA d }  Yn X|  S)z
    The encoding of the default system locale but falls back to the given
    fallback encoding if the encoding is unsupported by python or could
    not be determined.  See tickets #10335 and #5846
       ascii)localegetdefaultlocalecodecslookupr+   )r   r   r   r   get_system_encoding  s    rG   )+
__future__r   rE   datetimerC   decimalr   Zdjango.utilsr   Zdjango.utils.functionalr   Z#django.utils.six.moves.urllib.parser   r   r'   urllib.parser   r   r	   Zpython_2_unicode_compatibler   integer_typesr   floatdatetimer   r   r   r/   r.   Z	smart_strZ	force_strZsmart_unicodeZforce_unicode__doc__r6   r9   r;   r7   r@   rG   ZDEFAULT_LOCALE_ENCODINGr   r   r   r   <module>   sD   		(	*$				