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

[��f�@s\ddlZddlZddlZddlmZddlmZddlmZddl	m
Z
Gdd�de�ZdS)	�N)�HTTPAdapter�)�CacheController)�	DictCache)�CallbackFileWrappercsNeZdZddhZd�fdd�	Zd�fdd�	Zd�fd
d�	Z�fdd
�Z�ZS)�CacheControlAdapterZPUTZDELETENTc
sXtt|�j|i|��|dur$t�n||_||_|p6d|_|p@t}	|	|j||d�|_dS)N)ZGET)�cache_etags�
serializer)	�superr�__init__r�cache�	heuristic�cacheable_methodsr�
controller)
�selfrrZcontroller_classr	r
r�args�kwZcontroller_factory��	__class__��D/usr/lib/python3.9/site-packages/pip/_vendor/cachecontrol/adapter.pyrs
�zCacheControlAdapter.__init__cs�|p|j}|j|vrfz|j�|�}Wntjy<d}Yn0|rR|j||dd�S|j�|j�	|��t
t|�j|fi|��}|S)z�
        Send a request. Use the request information to see if it
        exists in the cache and cache the response if we need to and can.
        NT)�
from_cache)
r�methodrZcached_request�zlib�error�build_responseZheaders�updateZconditional_headersr
r�send)r�requestrr�	cacheable�cached_response�resprrrr$s


zCacheControlAdapter.sendFc
s|p|j}|s�|j|vr�|jr*|j�|�}|jdkrh|j�||�}||urNd}|jdd�|��|}n\|jdkr�|j�	||�nBt
|jt�
|jj	||��|_|jr�|j��fdd�}t�||�|_tt|��||�}|j|jv�r|j�r|j�|j�}	|j�|	�||_|S)z�
        Build a response by making a request or using the cache.

        This will end up calling send and returning a potentially
        cached response
        i0TF)Zdecode_contenti-cs��|jdkr|j��dS)Nr)Z
chunk_left�_fpZ_close�r�Zsuper_update_chunk_lengthrr�_update_chunk_lengthns
z@CacheControlAdapter.build_response.<locals>._update_chunk_length)rrr
Zapply�statusrZupdate_cached_response�readZrelease_connZcache_responserr"�	functools�partialZchunkedr%�types�
MethodTyper
rr�invalidating_methods�ok�	cache_url�urlr�deleter)
rrZresponserrrr r%r!r.rr$rr9sB	

�

���z"CacheControlAdapter.build_responsecs|j��tt|���dS)N)r�closer
rr#rrrr1�s
zCacheControlAdapter.close)NTNNNN)N)FN)	�__name__�
__module__�__qualname__r,rrrr1�
__classcell__rrrrrs��Jr)r*r(rZpip._vendor.requests.adaptersrrrrrZfilewrapperrrrrrr�<module>s