o
    a+)h                     @   s`   d dl Z d dlZd dlZd dlmZ ddlmZmZ ddlm	Z	 ddl
mZ G dd deZdS )	    N)HTTPAdapter   )CacheControllerPERMANENT_REDIRECT_STATUSES)	DictCache)CallbackFileWrapperc                       s\   e Zd Zh dZ						d fdd	Zd fdd	Z	d fd	d
	Z fddZ  ZS )CacheControlAdapter>   DELETEPATCHPUTNTc           
         sX   t t| j|i | |d u rt n|| _|| _|pd| _|p t}	|	| j||d| _d S )N)GET)cache_etags
serializer)	superr   __init__r   cache	heuristiccacheable_methodsr   
controller)
selfr   r   controller_classr   r   r   argskwcontroller_factory	__class__ _C:\Users\User\Downloads\Proyecto_IoT\venv\Lib\site-packages\pip/_vendor/cachecontrol/adapter.pyr      s   
zCacheControlAdapter.__init__c                    s   |p| j }|j|v r3z| j|}W n tjy   d}Y nw |r)| j||ddS |j| j	| t
t| j|fi |}|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   methodr   cached_requestzliberrorbuild_responseheadersupdateconditional_headersr   r   send)r   requestr   r   	cacheablecached_responserespr   r   r   r'   (   s   

zCacheControlAdapter.sendFc           
         s  |p| j }|sd|j|v rd| jr| j|}|jdkr4| j||}||ur'd}|jdd |  |}n0t	|jt
v rC| j|| n!t|jt| jj|||_|jrd|j  fdd}t|||_tt| ||}|j| jv 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
        i0  TF)decode_contentc                    s"      | j dkr| j  d S d S )Nr   )
chunk_left_fp_closer   super_update_chunk_lengthr   r   _update_chunk_lengthr   s   
z@CacheControlAdapter.build_response.<locals>._update_chunk_length)r   r   r   applystatusr   update_cached_responsereadrelease_connintr   cache_responser   r.   	functoolspartialchunkedr3   types
MethodTyper   r   r#   invalidating_methodsok	cache_urlurlr   deleter   )
r   r(   responser   r   r)   r*   r3   r+   rB   r   r1   r   r#   =   sB   
	

z"CacheControlAdapter.build_responsec                    s   | j   tt|   d S N)r   closer   r   r0   r   r   r   rG      s   
zCacheControlAdapter.close)NTNNNNrF   )FN)	__name__
__module____qualname__r@   r   r'   r#   rG   __classcell__r   r   r   r   r      s    Jr   )r>   r;   r!   Zpip._vendor.requests.adaptersr   r   r   r   r   r   filewrapperr   r   r   r   r   r   <module>   s   