Current File : //lib/python3.9/site-packages/pip/_vendor/cachecontrol/__pycache__/controller.cpython-39.pyc
a

[��fE7�@s�dZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZe�
e�Ze�d�Zd	d
�ZGdd�de�ZdS)
z7
The httplib2 algorithms ported for use with requests.
�N)�parsedate_tz)�CaseInsensitiveDict�)�	DictCache)�
Serializerz9^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?cCs0t�|���}|d|d|d|d|dfS)z�Parses a URI using the regex given in Appendix B of RFC 3986.

        (scheme, authority, path, query, fragment) = parse_uri(uri)
    r����)�URI�match�groups)�urir
�r�G/usr/lib/python3.9/site-packages/pip/_vendor/cachecontrol/controller.py�	parse_urisrc@s\eZdZdZddd�Zedd��Zedd	��Zd
d�Zdd
�Z	dd�Z
ddd�Zdd�ZdS)�CacheControllerz9An interface to see if request should cached or not.
    NTcCs4|durt�n||_||_|p"t�|_|p,d|_dS)N)����i,�-)r�cache�cache_etagsr�
serializer�cacheable_status_codes)�selfrrr�status_codesrrr�__init__"szCacheController.__init__c	Csht|�\}}}}}|r|s&td|��|��}|��}|s>d}|rPd�||g�pR|}|d||}|S)z4Normalize the URL to create a safe key for the cachez(Only absolute URIs are allowed. uri = %s�/�?z://)r�	Exception�lower�join)	�clsr�schemeZ	authority�path�query�fragmentZrequest_uriZ
defrag_urirrr�_urlnorm*szCacheController._urlnormcCs
|�|�S�N)r')r"rrrr�	cache_url>szCacheController.cache_urlc

Cs"tdftdftdfddddddddtdfd�}|�d|�dd��}i}|�d�D]�}|��s^qP|�d	d
�}|d��}z||\}}	Wn"ty�t�d|�YqPYn0|r�|	s�d||<|rPz||d
���||<WqPty�|	r�t�d
|�YqPt�yt�d||j	�YqP0qP|S)NTF)NF)�max-agez	max-stale�	min-fresh�no-cache�no-storezno-transformzonly-if-cachedzmust-revalidateZpublicZprivatezproxy-revalidatezs-maxagez
cache-controlz
Cache-Control��,�=rrz,Ignoring unknown cache-control directive: %sz-Missing value for cache-control directive: %sz8Invalid value for cache-control directive %s, must be %s)
�int�get�split�strip�KeyError�logger�debug�
IndexError�
ValueError�__name__)
r�headersZknown_directivesZ
cc_headersZretvalZcc_directive�partsZ	directive�typ�requiredrrr�parse_cache_controlBsV�
��z#CacheController.parse_cache_controlcCs0|�|j�}t�d|�|�|j�}d|vr:t�d�dSd|vr\|ddkr\t�d�dS|j�|�}|dur~t�d	�dS|j�	||�}|s�t�
d
�dS|jdkr�d}t�|�|St|j�}|r�d
|vr�d|vr�t�d�|j�
|�t�d�dSt��}t�t|d
��}	td||	�}
t�d|
�|�|�}d}d|v�r^|d}t�d|�nDd|v�r�t|d�}
|
du�r�t�|
�|	}td|�}t�d|�d|v�r�|d}t�d|�d|v�r�|d}|
|7}
t�d|
�||
k�rt�d�t�d||
�|Sd|v�r,t�d�|j�
|�dS)ze
        Return a cached response if it exists in the cache, otherwise
        return False.
        zLooking up "%s" in the cacher,z-Request header has "no-cache", cache bypassedFr*rz1Request header has "max_age" as 0, cache bypassedNzNo cache entry availablez1Cache entry deserialization failed, entry ignoredrzVReturning cached "301 Moved Permanently" response (ignoring date and etag information)�date�etagz(Purging cached response: no date or etagz!Ignoring cached response: no datezCurrent age based on date: %iz#Freshness lifetime from max-age: %i�expiresz#Freshness lifetime from expires: %iz+Freshness lifetime from request max-age: %ir+z'Adjusted current age from min-fresh: %iz2The response is "fresh", returning cached responsez%i > %iz4The cached response is "stale" with no etag, purging)r)�urlr6r7r?r;rr2r�loadsZwarning�statusr�delete�time�calendarZtimegmr�max)r�requestr)�ccZ
cache_data�resp�msgr;Znowr@Zcurrent_ageZresp_ccZfreshness_lifetimerBZexpire_timeZ	min_freshrrr�cached_requestxsz





�









�




zCacheController.cached_requestcCs`|�|j�}|j�||j�|��}i}|r\t|j�}d|vrH|d|d<d|vr\|d|d<|S)NrAZETagz
If-None-Matchz
last-modifiedz
Last-ModifiedzIf-Modified-Since)r)rCrrDrr2rr;)rrJr)rLZnew_headersr;rrr�conditional_headers�s
z#CacheController.conditional_headerscCs|p|j}|j|vr(t�d|j|�dSt|j�}|durfd|vrf|d��rft|d�t|�krfdS|�	|j�}|�	|�}|�
|j�}	t�d|	�d}
d|vr�d}
t�d�d|vr�d}
t�d	�|
r�|j�
|	�r�t�d
�|j�|	�|
r�dSd|�
dd
�v�rt�d�dS|j�rLd|v�rLt�d�|j�|	|jj|||d��n�|jdk�r|t�d�|j�|	|j�||��n�d|v�rd|v�r�|ddk�r�t�d�|j�|	|jj|||d��n:d|v�r|d�rt�d�|j�|	|jj|||d��dS)zc
        Algorithm for caching requests.

        This assumes a requests Response object.
        zStatus code %s not in %sN�content-lengthz&Updating cache with response from "%s"Fr-TzResponse header has "no-store"zRequest header has "no-store"z0Purging existing cache entry to honor "no-store"�*Zvaryr.zResponse header has "Vary: *"rAzCaching due to etag)�bodyrzCaching permanant redirectr@r*rz'Caching b/c date exists and max-age > 0rBzCaching b/c of expires header)rrEr6r7rr;�isdigitr1�lenr?r)rCrr2rFr�setr�dumps)rrJ�responserRrrZresponse_headersZcc_reqrKr)Zno_storerrr�cache_response�sn

�
��
��





�


�


�zCacheController.cache_responsecsv|�|j�}|j�||j�|��}|s*|Sdg�|j�t�fdd�|j�	�D���d|_
|j�||j�||��|S)z�On a 304 we will get a new set of headers that we want to
        update our cached value with, assuming we have one.

        This should only ever be called when we've sent an ETag and
        gotten a 304 as the response.
        rPc3s&|]\}}|���vr||fVqdSr()r )�.0�k�v�Zexcluded_headersrr�	<genexpr>ks�z9CacheController.update_cached_response.<locals>.<genexpr>r)
r)rCrrDrr2r;�update�dict�itemsrErUrV)rrJrWr)Zcached_responserr\r�update_cached_responseRs	��	z&CacheController.update_cached_response)NTNN)NN)
r:�
__module__�__qualname__�__doc__r�classmethodr'r)r?rNrOrXrarrrrrs�


6o
[r)rdZlogging�rerHrGZemail.utilsrZpip._vendor.requests.structuresrrrZ	serializerZ	getLoggerr:r6�compilerr�objectrrrrr�<module>s