U
    dZ                     @  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 ddl	mZ dd	l	mZ dd
l	mZ edZd"ddddddddddd
ddZejdejejB dZedZdddddZd#dddddddd Zdd!lmZ dS )$    )annotationsN)datetime   )
_dt_as_utc)generate_etag)
parse_date)parse_etags)parse_if_range_header)unquote_etagz&([Ww]/)?(?:"(.*?)"|(.*?))(?:\s*,\s*|$)Tz
str | Nonezbytes | Nonezdatetime | str | Nonebool)

http_rangehttp_if_rangehttp_if_modified_sincehttp_if_none_matchhttp_if_matchetagdatalast_modifiedignore_if_rangereturnc	                 C  s  |dkr|dk	rt |}n|dk	r*tdd}	t|tr@t|}|dk	rXt|jdd}d}
|sp| dk	rpt|}
|
dk	r|
jdk	r|
j}nt|}|r|r||krd}	|rt	|\}}t
t|}|
dk	r|
jdk	rt|
j|}	n0t|}|r||}	t|}|r|| }	|	 S )a  Convenience method for conditional requests.
    :param http_range: Range HTTP header
    :param http_if_range: If-Range HTTP header
    :param http_if_modified_since: If-Modified-Since HTTP header
    :param http_if_none_match: If-None-Match HTTP header
    :param http_if_match: If-Match HTTP header
    :param etag: the etag for the response for comparison.
    :param data: or alternatively the data of the response to automatically
                 generate an etag using :func:`generate_etag`.
    :param last_modified: an optional date of the last modification.
    :param ignore_if_range: If `False`, `If-Range` header will be taken into
                            account.
    :return: `True` if the resource was modified, otherwise `False`.

    .. versionadded:: 2.2
    Nzboth data and etag givenFr   )microsecondT)r   	TypeError
isinstancestrr   r   replacer	   dater
   tcastr   r   containsZcontains_weakZ	is_strong)r   r   r   r   r   r   r   r   r   Z
unmodifiedZif_rangeZmodified_since_Zif_none_matchZif_match r    8/tmp/pip-unpacked-wheel-m99gisyz/werkzeug/sansio/http.pyis_resource_modified   s:    


r"   zr
    ([^=;]*)
    (?:\s*=\s*
      (
        "(?:[^\\"]|\\.)*"
      |
        .*?
      )
    )?
    \s*;\s*
    )flagss   \\([0-3][0-7]{2}|.)zt.Match[bytes]bytes)mr   c                 C  s,   |  d}t|dkr|S t|dddS )N      big)grouplenintto_bytes)r%   vr    r    r!   _cookie_unslash_replaces   s    
r.   ztype[ds.MultiDict] | Nonezds.MultiDict[str, str])cookiecharseterrorsclsr   c                 C  s  |dkrt j}t| tr0tjdtdd |  } |dk	rJtjdtdd nd}|dk	rhtjdtdd nd}| sv| S |  d	} g }t	| D ]x\}}|
 }|
 }|sqt|dkr|d
 |d   krdkrn n tt|dd  ||}|||f q||S )aW  Parse a cookie from a string.

    The same key can be provided multiple times, the values are stored
    in-order. The default :class:`MultiDict` will have the first value
    first, and all values can be retrieved with
    :meth:`MultiDict.getlist`.

    :param cookie: The cookie header as a string.
    :param cls: A dict-like class to store the parsed cookies in.
        Defaults to :class:`MultiDict`.

    .. versionchanged:: 2.3
        Passing bytes, and the ``charset`` and ``errors`` parameters, are deprecated and
        will be removed in Werkzeug 3.0.

    .. versionadded:: 2.2
    NzoThe 'cookie' parameter must be a string. Passing bytes is deprecated and will not be supported in Werkzeug 3.0.r   )
stacklevelzIThe 'charset' parameter is deprecated and will be removed in Werkzeug 3.0zutf-8zHThe 'errors' parameter is deprecated and will be removed in Werkzeug 3.0r   ;r   "r&   )dsZ	MultiDictr   r$   warningswarnDeprecationWarningdecode
_cookie_refindallstripr*   _cookie_unslash_resubr.   encodeappend)r/   r0   r1   r2   outZckZcvr    r    r!   parse_cookie|   sT    

,  rD   )datastructures)	NNNNNNNNT)NNNN)
__future__r   retypingr   r8   r   	_internalr   httpr   r   r   r	   r
   compileZ_etag_rer"   ASCIIVERBOSEr<   r?   r.   rD    rE   r7   r    r    r    r!   <module>   sB   
         "P


    N