o
    Vh[                     @  s   d dl mZ d dl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                      sr   e Zd Zh dZ						d-d. fddZ						d/d0 fd$d%Z		d1d2 fd)d*Zd3 fd+d,Z  ZS )4CacheControlAdapter>   PUTPATCHDELETENTcacheBaseCache | Nonecache_etagsboolcontroller_classtype[CacheController] | None
serializerSerializer | None	heuristicBaseHeuristic | Nonecacheable_methodsCollection[str] | Noneargsr   kwreturnNonec           
        sT   t  j|i | |d u rt n|| _|| _|pd| _|pt}	|	| 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__ h/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/cachecontrol/adapter.pyr(      s   
zCacheControlAdapter.__init__Frequestr   streamtimeout7None | float | tuple[float, float] | tuple[float, None]verify
bool | strcert4None | bytes | str | tuple[bytes | str, bytes | str]proxiesMapping[str, str] | Noner   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
 ||||||}
|
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*   r0   r1   r2   r4   r6   r8   r    	cacheablecached_responserespr,   r.   r/   rC   3   s   

zCacheControlAdapter.sendresponser   r:   c           
   	     s*  |p| j }|sl|j|v rl| jr| j|}|jdkr4| j||}||ur'd}|jdd |  |}n8t	|jt
v rC| j|| n)t|jt| jj|t||_|jrl|jj d fd	d
}t|t||_t ||}|j| jv r|jr|jdusJ | 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_content	weak_self#weakref.ReferenceType[HTTPResponse]r$   r%   c                   s6   |  }|d u r	d S  | |j dkr|j  d S d S )Nr   )
chunk_left_fp_close)rI   r*   super_update_chunk_lengthr.   r/   _update_chunk_length   s   
z@CacheControlAdapter.build_response.<locals>._update_chunk_lengthN)rI   rJ   r$   r%   )r    r;   r   applystatusr)   update_cached_responsereadrelease_connintr	   cache_responser   rL   	functoolspartialweakrefrefchunkedr-   rP   r'   r?   invalidating_methodsokurl	cache_urlr   deleter:   )
r*   r0   rG   r:   r    rD   rE   rP   rF   r`   r,   rN   r/   r?   Q   sD   


z"CacheControlAdapter.build_responsec                   s   | j   t   d S )N)r   closer'   )r*   r,   r.   r/   rb      s   
zCacheControlAdapter.close)NTNNNN)r   r   r   r   r   r   r   r   r   r   r    r!   r"   r   r#   r   r$   r%   )FNTNNN)r0   r   r1   r   r2   r3   r4   r5   r6   r7   r8   r9   r    r!   r$   r   )FN)
r0   r   rG   r   r:   r   r    r!   r$   r   )r$   r%   )	__name__
__module____qualname__r]   r(   rC   r?   rb   __classcell__r.   r.   r,   r/   r      s(    "Ur   )
__future__r   rX   typesrZ   r=   typingr   r   r   r   requests.adaptersr   cachecontrol.cacher   cachecontrol.controllerr	   r
   cachecontrol.filewrapperr   requestsr   r   urllib3r   r   cachecontrol.heuristicsr   cachecontrol.serializer   r   r.   r.   r.   r/   <module>   s"   