U
    ;»{jÌ  ã                   @  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r´d 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__© úA/tmp/pip-install-zsn1f9xv/pip/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   Zpip._vendor.requests.adaptersr   Z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   