
 X1                 @   s  d  d l  m Z d  d l Z d  d l Z d  d l 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 d  d l m Z d  d l m Z m Z m Z d  d	 l m Z d  d
 l m Z m Z m Z m Z m Z m  Z  e j! d  Z" d j#   Z$ d Z% d Z& d Z' d Z( d Z) d Z* e j! d e% e' e( e* f  Z+ e j! d e% e' e) e* f  Z, e j! d e' e& e* e( f  Z- e. d  Z/ e. d  Z0 e j! d  Z1 e d d d   Z2 e d d d   Z3 e d d     Z4 e d! d"    Z5 d  d# d$  Z d d% d&  Z6 d d' d(  Z7 d) d*   Z8 d+ d,   Z9 d- d.   Z: d/ d0   Z; d1 d2   Z< d3 d4   Z= d5 d6   Z> d7 d8   Z? d9 d:   Z@ d; d<   ZA d d= d>  ZB d? d@   ZC dA dB dC d dD dE  ZD d S)F    )unicode_literalsN)Error)
formatdate)TooManyFieldsSent)six)MultiValueDict)force_bytes	force_str
force_text)keep_lazy_text)quote
quote_plusunquoteunquote_plus	urlencodeurlparsez(?:W/)?"((?:\\.|[^"])*)"z/jan feb mar apr may jun jul aug sep oct nov decz(?P<day>\d{2})z(?P<day>[ \d]\d)z(?P<mon>\w{3})z(?P<year>\d{4})z(?P<year>\d{2})z-(?P<hour>\d{2}):(?P<min>\d{2}):(?P<sec>\d{2})z^\w{3}, %s %s %s %s GMT$z^\w{6,9}, %s-%s-%s %s GMT$z^\w{3} %s %s %s %s$z:/?#[]@z!$&'()*+,;=z[&;]/c             C   s   t  t t |   t |    S)a  
    A version of Python's urllib.quote() function that can operate on unicode
    strings. The url is first UTF-8 encoded before quoting. The returned string
    can safely be used as part of an argument to a subsequent iri_to_uri() call
    without double-quoting occurring.
    )r
   r   r	   )urlsafe r   ?/home/ubuntu/projects/ifolica/build/django/django/utils/http.pyurlquote)   s    r    c             C   s   t  t t |   t |    S)a  
    A version of Python's urllib.quote_plus() function that can operate on
    unicode strings. The url is first UTF-8 encoded before quoting. The
    returned string can safely be used as part of an argument to a subsequent
    iri_to_uri() call without double-quoting occurring.
    )r
   r   r	   )r   r   r   r   r   urlquote_plus4   s    r   c             C   s   t  t t |     S)z~
    A wrapper for Python's urllib.unquote() function that can operate on
    the result of django.utils.http.urlquote().
    )r
   r   r	   )
quoted_urlr   r   r   
urlunquote?   s    r   c             C   s   t  t t |     S)z
    A wrapper for Python's urllib.unquote_plus() function that can operate on
    the result of django.utils.http.urlquote_plus().
    )r
   r   r	   )r   r   r   r   urlunquote_plusH   s    r   c             C   sV   t  |  t  r |  j   }  n t |  d  r< |  j   }  n  t d d   |  D |  S)z
    A version of Python's urllib.urlencode() function that can operate on
    unicode strings. The parameters are first cast to UTF-8 encoded strings and
    then encoded as per normal.
    itemsc             S   sV   g  |  ]L \ } } t  |  t | t t f  rC d  d   | D n	 t  |  f  q S)c             S   s   g  |  ] } t  |   q Sr   )r	   ).0ir   r   r   
<listcomp>]   s   	 z(urlencode.<locals>.<listcomp>.<listcomp>)r	   
isinstancelisttuple)r   kvr   r   r   r    \   s   	zurlencode.<locals>.<listcomp>)r!   r   listshasattrr   original_urlencode)querydoseqr   r   r   r   Q   s    	r   c             C   s;   t  |   } d | d d  | d d  | d d  f S)aI  
    Formats the time to ensure compatibility with Netscape's cookie standard.

    Accepts a floating point number expressed in seconds since the epoch, in
    UTC - such as that outputted by time.time(). If set to None, defaults to
    the current time.

    Outputs a string in the format 'Wdy, DD-Mon-YYYY HH:MM:SS GMT'.
    z%s-%s-%s GMTN               )r   )epoch_secondsZrfcdater   r   r   cookie_dateb   s    
r1   c             C   s   t  |  d d S)ac  
    Formats the time to match the RFC1123 date format as specified by HTTP
    RFC7231 section 7.1.1.1.

    Accepts a floating point number expressed in seconds since the epoch, in
    UTC - such as that outputted by time.time(). If set to None, defaults to
    the current time.

    Outputs a string in the format 'Wdy, DD Mon YYYY HH:MM:SS GMT'.
    usegmtT)r   )r0   r   r   r   	http_datep   s    r3   c       
      C   s{  xF t  t t f D]% } | j |   } | d k	 r Pq q Wt d |    y t | j d   } | d k  r | d k  r | d 7} q | d 7} n  t j | j d  j	    d	 } t | j d
   } t | j d   } t | j d   } t | j d   } t
 j
 | | | | | |  }	 t j |	 j    SWn9 t k
 rvt j t t d |   t j   d  Yn Xd S)a  
    Parses a date format as specified by HTTP RFC7231 section 7.1.1.1.

    The three formats allowed by the RFC are accepted, even if only the first
    one is still in widespread use.

    Returns an integer expressed in seconds since the epoch, in UTC.
    Nz%%r is not in a valid HTTP date formatyeard   F   i  il  mon   dayhourminsecz%r is not a valid date   )RFC1123_DATERFC850_DATEASCTIME_DATEmatch
ValueErrorintgroupMONTHSindexlowerdatetimecalendartimegmutctimetuple	Exceptionr   reraisesysexc_info)
dateregexmr4   monthr9   r:   r;   r<   resultr   r   r   parse_http_date~   s(    "rU   c             C   s'   y t  |   SWn t k
 r" Yn Xd S)zL
    Same as parse_http_date, but returns None if the input is invalid.
    N)rU   rL   )rP   r   r   r   parse_http_date_safe   s    rV   c             C   s[   t  |   d k r! t d   n  t |  d  } t j rW | t j k rW t d   n  | S)zo
    Converts a base 36 string to an ``int``. Raises ``ValueError` if the
    input won't fit into an int.
       zBase36 input too large$   )lenrB   rC   r   PY2rN   maxint)svaluer   r   r   base36_to_int   s    r^   c             C   s   d } |  d k  r! t  d   n  t j rl t |  t j  sK t d   n  |  t j k rl t  d   ql n  |  d k  r | |  Sd } x3 |  d k r t |  d  \ }  } | | | } q W| S)z0
    Converts an integer to a base36 string
    Z$0123456789abcdefghijklmnopqrstuvwxyzr   z!Negative base36 conversion input.z$Non-integer base36 conversion input.z"Base36 conversion input too large.rX   r   )	rB   r   rZ   r!   integer_types	TypeErrorrN   r[   divmod)r   Zchar_setZb36nr   r   r   int_to_base36   s    	rc   c             C   s   t  j |   j d  S)za
    Encodes a bytestring in base64 for use in URLs, stripping any trailing
    equal signs.
    s   
=)base64urlsafe_b64encoderstrip)r\   r   r   r   urlsafe_base64_encode   s    rg   c             C   s{   t  |   }  y1 t j |  j t |   t |   d d   SWn7 t t f k
 rv } z t |   WYd d } ~ Xn Xd S)zr
    Decodes a base64 encoded string, adding back any trailing equal signs that
    might have been stripped.
          =N)r   rd   urlsafe_b64decodeljustrY   LookupErrorBinasciiErrorrB   )r\   er   r   r   urlsafe_base64_decode   s
    1ro   c             C   s3   t  j |   } | s |  g Sd d   | D } | S)z
    Parses a string with one or several etags passed in If-None-Match and
    If-Match headers by the rules in RFC 2616. Returns a list of etags
    without surrounding double quotes (") and unescaped from \<CHAR>.
    c             S   s(   g  |  ] } | j  d   j d   q S)asciiZunicode_escape)encodedecode)r   rn   r   r   r   r       s   	 zparse_etags.<locals>.<listcomp>)
ETAG_MATCHfindall)Zetag_strZetagsr   r   r   parse_etags   s
    ru   c             C   s    d |  j  d d  j  d d  S)zI
    Wraps a string in double quotes escaping contents as necessary.
    z"%s"\z\\"z\")replace)etagr   r   r   
quote_etag   s    rz   c             C   s/   |  r+ |  j  d  j d d  j d d  S|  S)z;
    Unquote an ETag string; i.e. revert quote_etag().
    rw   z\"z\\rv   )striprx   )ry   r   r   r   unquote_etag   s    r|   c             C   sU   | s
 d S| j    } | d d k rK |  j |  pT |  | d d  k pT | |  k S)a4  
    Return ``True`` if the host is either an exact match or a match
    to the wildcard pattern.

    Any pattern beginning with a period matches a domain and all of its
    subdomains. (e.g. ``.example.com`` matches ``example.com`` and
    ``foo.example.com``). Anything else is an exact string match.
    Fr   .r8   N)rG   endswith)hostpatternr   r   r   is_same_domain  s
    	5r   c             C   s   |  d k	 r |  j    }  n  |  s% d St j rZ y t |   }  WqZ t k
 rV d SYqZ Xn  t |  |  o t |  j d d  |  S)z
    Return ``True`` if the url is a safe redirection (i.e. it doesn't point to
    a different host and uses a safe scheme).

    Always returns ``False`` on an empty url.
    NFrv   r   )r{   r   rZ   r
   UnicodeDecodeError_is_safe_urlrx   )r   r   r   r   r   is_safe_url  s    	r   c             C   s   |  j  d  r d St |   } | j r6 | j r6 d St j |  d  d d k rW d S| j sp | j | k o | j p | j d k S)Nz///Fr   Chttphttps)zhttpzhttps)
startswithr   netlocschemeunicodedatacategory)r   r   Zurl_infor   r   r   r   -  s    r   Fzutf-8rx   c             C   s  | r< t  j |  |  } t |  | k rK t d   qK n t  j |   } g  } x,| D]$} | sj qX n  | j t d  d  } t |  d k r | rX | j d  q qX n  t | d  s | rX t j r.| d j d d  }	 t	 |	 d	 | d
 | }	 | d j d d  }
 t	 |
 d	 | d
 | }
 n8 t	 | d j d d   }	 t	 | d j d d   }
 | j |	 |
 f  qX qX W| S)a~  
    Return a list of key/value tuples parsed from query string.

    Copied from urlparse with an additional "fields_limit" argument.
    Copyright (C) 2013 Python Software Foundation (see LICENSE.python).

    Arguments:

    qs: percent-encoded query string to be parsed

    keep_blank_values: flag indicating whether blank values in
        percent-encoded queries should be treated as blank strings. A
        true value indicates that blanks should be retained as blank
        strings. The default false value indicates that blank values
        are to be ignored and treated as if they were  not included.

    encoding and errors: specify how to decode percent-encoded sequences
        into Unicode characters, as accepted by the bytes.decode() method.

    fields_limit: maximum number of fields parsed or an exception
        is raised. None means no limit and is the default.
    zRThe number of GET/POST parameters exceeded settings.DATA_UPLOAD_MAX_NUMBER_FIELDS.=r8   r=   r   r   + encodingerrors   +    )
FIELDS_MATCHsplitrY   r   strappendr   PY3rx   r   )qskeep_blank_valuesr   r   Zfields_limitpairsr
name_valuenvnamer]   r   r   r   limited_parse_qslB  s2    	r   )E
__future__r   rd   rI   rH   rerN   r   binasciir   rm   email.utilsr   Zdjango.core.exceptionsr   Zdjango.utilsr   Zdjango.utils.datastructuresr   Zdjango.utils.encodingr   r	   r
   Zdjango.utils.functionalr   Z#django.utils.six.moves.urllib.parser   r   r   r   r   r(   r   compilers   r   rE   Z__DZ__D2Z__MZ__YZ__Y2Z__Tr>   r?   r@   r   ZRFC3986_GENDELIMSZRFC3986_SUBDELIMSr   r   r   r   r   r1   r3   rU   rV   r^   rc   rg   ro   ru   rz   r|   r   r   r   r   r   r   r   r   <module>   sf   .

		$