U
    aA                     @   s
  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mZmZmZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlm Z  e!d	ej"Z#d
$ Z%dZ&dZ'dZ(dZ)dZ*dZ+e!de&e(e)e+f Z,e!de&e(e*e+f Z-e!de(e'e+e)f Z.dZ/dZ0e!dZ1e dIddZ2e dJddZ3e dd Z4e dd  Z5dKd"d#ZdLd$d%Z6d&d' Z7d(d) Z8d*d+ Z9d,d- Z:d.d/ Z;d0d1 Z<d2d3 Z=d4d5 Z>d6d7 Z?dMd8d9Z@dNd:d;ZAdOd=d>ZBdPd?d@ZCdQdAdBZDdRdEdFZEdGdH ZFdS )S    N)Error
formatdate)ParseResultSplitResult_coerce_args_splitnetloc_splitparamsquote
quote_plusscheme_charsunquoteunquote_plus	urlencodeuses_params)TooManyFieldsSent)MultiValueDict)RemovedInDjango40Warning)keep_lazy_textz
    \A(      # start of string and capture group
    (?:W/)?  # optional weak indicator
    "        # opening quote
    [^"]*    # any sequence of non-quote characters
    "        # end quote
    )\Z      # end of string and capture group
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 jdtdd t| |S )z
    A legacy compatibility wrapper to Python's urllib.parse.quote() function.
    (was used for unicode handling on Python 2)
    zLdjango.utils.http.urlquote() is deprecated in favor of urllib.parse.quote().   
stacklevel)warningswarnr   r
   urlsafe r   /home/adriano.carvalho/ftp/files/BrinquedotecaVirtual/brinquedotecavirtual/venv/lib/python3.8/site-packages/django/utils/http.pyurlquote/   s     r     c                 C   s   t jdtdd t| |S )z
    A legacy compatibility wrapper to Python's urllib.parse.quote_plus()
    function. (was used for unicode handling on Python 2)
    zVdjango.utils.http.urlquote_plus() is deprecated in favor of urllib.parse.quote_plus(),r   r   )r   r   r   r   r   r   r   r   urlquote_plus=   s     r"   c                 C   s   t jdtdd t| S )z
    A legacy compatibility wrapper to Python's urllib.parse.unquote() function.
    (was used for unicode handling on Python 2)
    zPdjango.utils.http.urlunquote() is deprecated in favor of urllib.parse.unquote().r   r   )r   r   r   r   Z
quoted_urlr   r   r   
urlunquoteK   s     r$   c                 C   s   t jdtdd t| S )z
    A legacy compatibility wrapper to Python's urllib.parse.unquote_plus()
    function. (was used for unicode handling on Python 2)
    zZdjango.utils.http.urlunquote_plus() is deprecated in favor of urllib.parse.unquote_plus().r   r   )r   r   r   r   r#   r   r   r   urlunquote_plusY   s     r%   Fc              	   C   s   t | tr|  } nt| dr&|  } g }| D ]\}}|dkrLtd| n~|r^t |ttfrd|}nfzt|}W n tk
r   |}Y nBX g }|D ]6}|dkrtd| nt |tst|}|	| q|	||f q.t
||S )z
    A version of Python's urllib.parse.urlencode() function that can operate on
    MultiValueDict and non-string values.
    itemsNzjCannot encode None for key '%s' in a query string. Did you mean to pass an empty string or omit the value?)
isinstancer   listshasattrr&   	TypeErrorstrbytesiterappendoriginal_urlencode)querydoseqZquery_paramskeyvalueZ	query_valitritemr   r   r   r   g   s>    




r   c                 C   s   t | ddS )ao  
    Format the time to match the RFC1123 date format as specified by HTTP
    RFC7231 section 7.1.1.1.

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

    Output a string in the format 'Wdy, DD Mon YYYY HH:MM:SS GMT'.
    T)usegmtr   )Zepoch_secondsr   r   r   	http_date   s    r7   c              
   C   s2  t ttfD ]}|| }|dk	r
 q2q
td|  zt|d}|dk rtj j	}||d  }||d  dkr||d 7 }n||7 }t
|d d }t|d}t|d	}t|d
}	t|d}
t|||||	|
}t| W S  tk
r, } ztd|  |W 5 d}~X Y nX dS )a  
    Parse 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.

    Return an integer expressed in seconds since the epoch, in UTC.
    Nz%%r is not in a valid HTTP date formatyeard   2   mon   dayhourminsecz%r is not a valid date)RFC1123_DATERFC850_DATEASCTIME_DATEmatch
ValueErrorintgroupdatetimeutcnowr8   MONTHSindexlowercalendartimegmutctimetuple	Exception)dateregexmr8   Zcurrent_yearZcurrent_centurymonthr=   r>   r?   r@   resultexcr   r   r   parse_http_date   s,    
rW   c                 C   s$   z
t | W S  tk
r   Y nX dS )zK
    Same as parse_http_date, but return None if the input is invalid.
    N)rW   rP   )rQ   r   r   r   parse_http_date_safe   s    
rX   c                 C   s   t | dkrtdt| dS )zf
    Convert a base 36 string to an int. Raise ValueError if the input won't fit
    into an int.
       zBase36 input too large$   )lenrE   rF   sr   r   r   base36_to_int   s    r^   c                 C   sP   d}| dk rt d| dk r$||  S d}| dkrLt| d\} }|| | }q(|S )z&Convert an integer to a base36 string.Z$0123456789abcdefghijklmnopqrstuvwxyzr   z!Negative base36 conversion input.rZ   r!   )rE   divmod)iZchar_setZb36nr   r   r   int_to_base36   s    rb   c                 C   s   t | ddS )ze
    Encode a bytestring to a base64 string for use in URLs. Strip any trailing
    equal signs.
    s   
=ascii)base64urlsafe_b64encoderstripdecoder\   r   r   r   urlsafe_base64_encode   s    rh   c              
   C   s`   |   } z$t| t| t| d  dW S  ttfk
rZ } zt|W 5 d}~X Y nX dS )zn
    Decode a base64 encoded string. Add back any trailing equal signs that
    might have been stripped.
          =N)encoderd   urlsafe_b64decodeljustr[   LookupErrorBinasciiErrorrE   )r]   er   r   r   urlsafe_base64_decode   s
    $rq   c                 C   s8   |   dkrdgS dd | dD }dd |D S dS )z
    Parse a string of ETags given in an If-None-Match or If-Match header as
    defined by RFC 7232. Return a list of quoted ETags, or ['*'] if all ETags
    should be matched.
    *c                 s   s   | ]}t | V  qd S )N)
ETAG_MATCHrD   strip).0etagr   r   r   	<genexpr>  s     zparse_etags.<locals>.<genexpr>,c                 S   s   g | ]}|r| d qS )r<   )rG   )ru   rD   r   r   r   
<listcomp>  s      zparse_etags.<locals>.<listcomp>N)rt   split)etag_strZetag_matchesr   r   r   parse_etags  s    r|   c                 C   s   t | r| S d|  S dS )z
    If the provided string is already a quoted ETag, return it. Otherwise, wrap
    the string in quotes, making it a strong ETag.
    z"%s"N)rs   rD   )r{   r   r   r   
quote_etag  s    
r}   c                 C   s>   |sdS |  }|d dkr6| |p<| |dd kp<|| 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   .r<   N)rL   endswith)hostpatternr   r   r   is_same_domain  s    	&r   c                 C   s\   | dk	r|   } | sdS |dkr(t }nt|tr8|h}t| ||doZt| dd||dS )a  
    Return ``True`` if the url uses an allowed host and a safe scheme.

    Always return ``False`` on an empty url.

    If ``require_https`` is ``True``, only 'https' will be considered a valid
    scheme, as opposed to 'http' and 'https' with the default, ``False``.

    Note: "True" doesn't entail that a URL is "safe". It may still be e.g.
    quoted incorrectly. Ensure to also use django.utils.encoding.iri_to_uri()
    on the path component of untrusted URLs.
    NF)require_https\r   )rt   setr'   r+    _url_has_allowed_host_and_schemereplacer   allowed_hostsr   r   r   r   url_has_allowed_host_and_scheme-  s    
r   c                 C   s   t jdtdd t| ||S )Nz\django.utils.http.is_safe_url() is deprecated in favor of url_has_allowed_host_and_scheme().r   r   )r   r   r   r   r   r   r   r   is_safe_urlJ  s     r   Tc           
      C   sf   t | |\} }}t| ||}|\}}} }}|tkrHd| krHt| \} }nd}t||| |||}	||	S )a#  Parse a URL into 6 components:
    <scheme>://<netloc>/<path>;<params>?<query>#<fragment>
    Return a 6-tuple: (scheme, netloc, path, params, query, fragment).
    Note that we don't break the components up in smaller bits
    (e.g. netloc is a single string) and we don't expand % escapes.;r!   )r   	_urlsplitr   r	   r   )
r   schemeallow_fragments_coerce_resultsplitresultnetlocr0   fragmentparamsrU   r   r   r   	_urlparseT  s    r   c           
      C   s   t | |\} }}d } }}| d}|dkrn| d| D ]}|tkr: qnq:| d|  | |d d  }} | dd dkrt| d\}} d|krd	|ksd	|krd|krtd
|rd| kr| dd\} }d| kr| dd\} }t||| ||}	||	S )a  Parse a URL into 5 components:
    <scheme>://<netloc>/<path>?<query>#<fragment>
    Return a 5-tuple: (scheme, netloc, path, query, fragment).
    Note that we don't break the components up in smaller bits
    (e.g. netloc is a single string) and we don't expand % escapes.r!   :r   Nr<   r   //[]zInvalid IPv6 URL#?)r   findr   rL   r   rE   rz   r   )
r   r   r   r   r   r0   r   r`   cvr   r   r   r   g  s,    
"r   c                 C   s   |  drdS zt| }W n tk
r0   Y dS X |jsB|jrBdS t| d d dkr\dS |j}|jsr|jrrd}|r|dgnddg}|j s|j|ko| p||kS )Nz///Fr   Chttphttps)
startswithr   rE   r   r   unicodedatacategory)r   r   r   Zurl_infor   Zvalid_schemesr   r   r   r     s"    
r   utf-8r   c                 C   s   |r&t | |}t||kr0tdn
t | }g }|D ]}|sBq8|dd}t|dkrl|r8|d nq8|d sx|r8|d dd}	t|	||d	}	|d dd}
t|
||d	}
||	|
f q8|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.=r<   r   r!   r   + )encodingerrors)FIELDS_MATCHrz   r[   r   r.   r   r   )qskeep_blank_valuesr   r   Zfields_limitpairsr
name_valuenvnamer3   r   r   r   limited_parse_qsl  s.    
r   c                 C   s    |  drd| dd } | S )z
    If redirecting to an absolute path (two leading slashes), a slash must be
    escaped to prevent browsers from handling the path as schemaless and
    redirecting to another host.
    r   z/%2F{}r   N)r   format)r   r   r   r   escape_leading_slashes  s    
r   )r   )r!   )F)N)F)F)r!   T)r!   T)F)Fr   r   N)Grd   rM   rH   rer   r   binasciir   ro   email.utilsr   urllib.parser   r   r   r   r	   r
   r   r   r   r   r   r/   r   Zdjango.core.exceptionsr   Zdjango.utils.datastructuresr   Zdjango.utils.deprecationr   Zdjango.utils.functionalr   compileXrs   rz   rJ   Z__DZ__D2Z__MZ__YZ__Y2Z__TrA   rB   rC   ZRFC3986_GENDELIMSZRFC3986_SUBDELIMSr   r    r"   r$   r%   r7   rW   rX   r^   rb   rh   rq   r|   r}   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sr   8	



)
(





    
5