U
    EZh                     @  s   d dl mZ d dlZd dlZd dlZd dlmZmZmZm	Z	 d dl
mZ d dlmZ d dlmZmZ d dlmZ erd dlmZmZ d d	lmZ d d
lmZ d dlmZ d dlmZ G dd deZdS )    )annotationsN)TYPE_CHECKINGAny
CollectionMapping)HTTPAdapter)	DictCache)PERMANENT_REDIRECT_STATUSESCacheController)CallbackFileWrapper)PreparedRequestResponse)HTTPResponse)	BaseCache)BaseHeuristic)
Serializerc                      s   e Zd ZdddhZd"dddd	d
ddddd	 fddZd#ddddddddd fddZd$dddddd fddZdd fd d!Z  ZS )%CacheControlAdapterPUTPATCHDELETENTzBaseCache | Noneboolztype[CacheController] | NonezSerializer | NonezBaseHeuristic | NonezCollection[str] | Noner   None)	cachecache_etagscontroller_class
serializer	heuristiccacheable_methodsargskwreturnc           
        sP   t  j|| |d krt n|| _|| _|p.d| _|p8t}	|	| j||d| _d S )N)GET)r   r   )super__init__r   r   r   r   r
   
controller)
selfr   r   r   r   r   r   r   r   controller_factory	__class__ D/tmp/pip-unpacked-wheel-36xvkur8/pip/_vendor/cachecontrol/adapter.pyr#      s    
  zCacheControlAdapter.__init__Fr   z7None | float | tuple[float, float] | tuple[float, None]z
bool | strz4None | bytes | str | tuple[bytes | str, bytes | str]zMapping[str, str] | Noner   )requeststreamtimeoutverifycertproxiesr   r    c                   s   |p| j }|j|krhz| j|}	W n tjk
r>   d}	Y nX |	rT| j||	ddS |j| j	| t
 ||||||}
|
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"   send)r%   r+   r,   r-   r.   r/   r0   r   	cacheablecached_responserespr'   r)   r*   r:   2   s    


zCacheControlAdapter.sendr   )r+   responser1   r   r    c           
        s(  |p| j }|s|j|kr| jr*| j|}|jdkrh| j||}||k	rNd}|jdd |  |}nht	|jt
kr| j|| nJt|jt| jj|||_|jr|j ddd fdd	}t|||_t ||}|j| jkr|jr|jd
k	st| 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_contentr   r   )r%   r    c                   s      | j dkr| j  d S )Nr   )
chunk_left_fp_closer%   super_update_chunk_lengthr)   r*   _update_chunk_length   s    
z@CacheControlAdapter.build_response.<locals>._update_chunk_lengthN)r   r2   r   applystatusr$   update_cached_responsereadrelease_connintr	   cache_responser   rA   	functoolspartialchunkedrF   types
MethodTyper"   r6   invalidating_methodsokurlAssertionError	cache_urlr   deleter1   )
r%   r+   r>   r1   r   r;   r<   rF   r=   rW   r'   rD   r*   r6   P   sL    

    z"CacheControlAdapter.build_response)r    c                   s   | j   t   d S )N)r   closer"   rC   r'   r)   r*   rY      s    
zCacheControlAdapter.close)NTNNNN)FNTNNN)FN)	__name__
__module____qualname__rS   r#   r:   r6   rY   __classcell__r)   r)   r'   r*   r      s&   
      $      ""  Or   )
__future__r   rN   rQ   r4   typingr   r   r   r   pip._vendor.requests.adaptersr   pip._vendor.cachecontrol.cacher   Z#pip._vendor.cachecontrol.controllerr	   r
   Z$pip._vendor.cachecontrol.filewrapperr   Zpip._vendor.requestsr   r   Zpip._vendor.urllib3r   r   Z#pip._vendor.cachecontrol.heuristicsr   Z"pip._vendor.cachecontrol.serializer   r   r)   r)   r)   r*   <module>   s   