U
    /v¶hú  ã                   @  sð   d dl m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 „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r¦d}	|�rt	|ƒ\}}t
 t|¡}|
dk	rè|
jdk	rèt|
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-c3xdgso7/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_replacer   s    
r.   z#type[ds.MultiDict[str, str]] | Nonezds.MultiDict[str, str])ÚcookieÚclsr   c                 C  sº   |dkrt  dtj¡}| s |ƒ S | › d�} g }t | ¡D ]x\}}| ¡ }| ¡ }|sVq8t|ƒdkr¢|d |d   kr~dkr¢n n t 	t
|dd…  ¡ ¡jd	d
�}| ||f¡ q8||ƒS )a)  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:: 3.0
        Passing bytes, and the ``charset`` and ``errors`` parameters, were removed.

    .. versionadded:: 2.2
    Nztype[ds.MultiDict[str, str]]ú;r   r   éÿÿÿÿú"r&   r   )Úerrors)r   r   ÚdsZ	MultiDictÚ
_cookie_reÚfindallÚstripr*   Ú_cookie_unslash_reÚsubr.   ÚencodeÚdecodeÚappend)r/   r0   ÚoutZckZcvr    r    r!   Úparse_cookie{   s(    
, ÿþr?   )Údatastructures)	NNNNNNNNT)NN)Ú
__future__r   ÚreÚtypingr   r   Ú	_internalr   Úhttpr   r   r   r	   r
   ÚcompileZ_etag_rer"   ÚASCIIÚVERBOSEr6   r9   r.   r?   Ú r@   r5   r    r    r    r!   Ú<module>   s<   
         ÷"P
ô

  þ0