HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/pip/_vendor/cachecontrol/__pycache__/controller.cpython-310.pyc
o

@%Ne	=�@s�dZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZe�
e�Ze�d�Zd	Zd
d�ZGdd
�d
e�ZdS)z7
The httplib2 algorithms ported for use with requests.
�N)�parsedate_tz)�CaseInsensitiveDict�)�	DictCache)�
Serializerz9^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?)�-�4cCs0t�|���}|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�E/usr/lib/python3/dist-packages/pip/_vendor/cachecontrol/controller.py�	parse_uris"rc@s^eZdZdZ	ddd�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||_||_|pt�|_|pd|_dS)N)����i,rr)r�cache�cache_etagsr�
serializer�cacheable_status_codes)�selfrrr�status_codesrrr�__init__(szCacheController.__init__c	Csht|�\}}}}}|r
|std|��|��}|��}|sd}|r(d�||g�p)|}|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�scheme�	authority�path�query�fragment�request_uri�
defrag_urirrr�_urlnorm0szCacheController._urlnormcCs
|�|�S�N)r+)r#rrrr�	cache_urlDs
zCacheController.cache_urlc

Cstdftdftdfddddddddtdfd�}|�d|�dd��}i}|�d�D]c}|��s/q(|�d	d
�}|d��}z||\}}	WntyRt�d|�Yq(w|rW|	s[d||<|r�z||d
���||<Wq(tyz|	rxt�d
|�Yq(ty�t�d||j	�Yq(wq(|S)NTF)NF)�max-agez	max-stale�	min-fresh�no-cache�no-storezno-transformzonly-if-cachedzmust-revalidate�public�privatezproxy-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�headers�known_directives�
cc_headers�retval�cc_directive�parts�	directive�typ�requiredrrr�parse_cache_controlHs^�������z#CacheController.parse_cache_controlcCs*|�|j�}t�d|�|�|j�}d|vrt�d�dSd|vr.|ddkr.t�d�dS|j�|�}|dur?t�d	�dS|j�	||�}|sOt�
d
�dSt|j�t
vr_d}t�|�|St|j�}|rjd|vr�d
|vryt�d�|j�|�t�d�dSt��}t�t|d��}	td||	�}
t�d|
�|�|�}d}d|vr�|d}t�d|�n d|vr�t|d�}
|
dur�t�|
�|	}td|�}t�d|�d|vr�|d}t�d|�d|vr�|d}|
|7}
t�d|
�||
k�rt�d�t�d||
�|Sd
|v�rt�d�|j�|�dS)ze
        Return a cached response if it exists in the cache, otherwise
        return False.
        zLooking up "%s" in the cacher0z-Request header has "no-cache", cache bypassedFr.rz1Request header has "max_age" as 0, cache bypassedNzNo cache entry availablez1Cache entry deserialization failed, entry ignoredzQReturning cached permanent redirect 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-�urlr<r=rJrArr8r�loads�warningr7�status�PERMANENT_REDIRECT_STATUSESr�delete�time�calendar�timegmr�max)r�requestr-�cc�
cache_data�resp�msgrA�nowrK�current_age�resp_cc�freshness_lifetimerM�expire_time�	min_freshrrr�cached_request~sz



�





�



zCacheController.cached_requestcCs`|�|j�}|j�||j�|��}i}|r.t|j�}d|vr$|d|d<d|vr.|d|d<|S)NrL�ETagz
If-None-Matchz
last-modifiedz
Last-ModifiedzIf-Modified-Since)r-rNrrOrr8rrA)rrXr-r[�new_headersrArrr�conditional_headers�s
z#CacheController.conditional_headerscCs�|p|j}|j|vrt�d|j|�dSt|j�}d|vr't�t|d��}nd}|durCd|vrC|d�	�rCt
|d�t|�krCdS|�|j�}|�|�}	|�
|j�}
t�d|
�d}d|	vrgd	}t�d
�d|vrrd	}t�d�|r�|j�|
�r�t�d�|j�|
�|r�dSd
|�dd�vr�t�d�dS|jr�d|vr�d}|�d�r�t|d�}
|
dur�t�|
�|}t|d�}t�d�|��t�d�|jj|
|j�|||�|d�dSt
|j�tvr�t�d�|j�|
|j�||d��dSd|v�rbt�t|d��}d|	v�r)|	ddk�r)t�d�|	d}|jj|
|j�|||�|d�dSd|v�rd|d�rft|d�}
|
du�rFt�|
�|}nd}t�d�|��|jj|
|jj|||d�|d�dSdSdSdS)zc
        Algorithm for caching requests.

        This assumes a requests Response object.
        zStatus code %s not in %sNrKr�content-lengthz&Updating cache with response from "%s"Fr1TzResponse header has "no-store"zRequest header has "no-store"z0Purging existing cache entry to honor "no-store"�*�varyr4zResponse header has "Vary: *"rLrMiuz"etag object cached for {0} secondszCaching due to etag)rMzCaching permanent redirect�r.z'Caching b/c date exists and max-age > 0z5Caching b/c of expires header. expires in {0} seconds)�body)rrQr<r=rrArUrVr�isdigitr7�lenrJr-rNrr8rSrrW�format�setr�dumpsrR)rrX�responserkrr�response_headersrK�cc_reqrYr-�no_store�expires_timerMrrr�cache_response�s�

�

�








�



�


��
��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.
        rgc3s(�|]\}}|���vr||fVqdSr,)r!)�.0�k�v��excluded_headersrr�	<genexpr>�s���z9CacheController.update_cached_response.<locals>.<genexpr>r)
r-rNrrOrr8rA�update�dict�itemsrQrorp)rrXrqr-�cached_responserrzr�update_cached_responseys	��	z&CacheController.update_cached_response)NTNN)NN)
r@�
__module__�__qualname__�__doc__r�classmethodr+r-rJrcrfrvr�rrrrr$s
�

6p
{r)r��logging�rerUrT�email.utilsr�pip._vendor.requests.structuresrrr�	serializer�	getLoggerr@r<�compiler
rRr�objectrrrrr�<module>s