U
ÀÒ.eÿ ã @ s\ d dl Z d dlZd dlZd dlmZ ddlmZ ddlmZ ddl m
Z
G dd„ deƒZdS ) é N)ÚHTTPAdapteré )ÚCacheController)Ú DictCache)ÚCallbackFileWrapperc sN e Zd ZddhZd‡ fdd„ Zd‡ fdd„ Zd‡ fd
d„ Z‡ fdd
„Z‡ ZS )ÚCacheControlAdapterZPUTZDELETENTc
sL t t| ƒj||Ž |ptƒ | _|| _|p*d| _|p4t} | | j||d�| _d S )N)ZGET)Úcache_etagsÚ
serializer) Úsuperr Ú__init__r ÚcacheÚ heuristicÚcacheable_methodsr Ú
controller)
Úselfr r Zcontroller_classr r
r ÚargsÚkwZcontroller_factory©Ú __class__© úD/usr/lib/python3.8/site-packages/pip/_vendor/cachecontrol/adapter.pyr s
ÿzCacheControlAdapter.__init__c s€ |p| j }|j|krhz| j |¡}W n tjk
r> d}Y nX |rT| j||dd�S |j | j |¡¡ t
t| ƒj|f|Ž}|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 Zcached_requestÚzlibÚerrorÚbuild_responseZheadersÚupdateZconditional_headersr
r Úsend)r Úrequestr r Ú cacheableÚcached_responseÚrespr r r r $ s
zCacheControlAdapter.sendFc
s |p| j }|sÄ|j|krÄ| jr*| j |¡}|jdkrh| j ||¡}||k rNd}|jdd� | ¡ |}n\|jdkr‚| j ||¡ nBt
|jt
| jj ||¡ƒ|_|jrÄ|j‰ ‡ fdd„}t ||¡|_tt| ƒ ||¡}|j| jk�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)Zdecode_contenti- c s ˆ ƒ | j dkr| j ¡ d S )Nr )Z
chunk_leftÚ_fpZ_close©r ©Zsuper_update_chunk_lengthr r Ú_update_chunk_lengthn s
z@CacheControlAdapter.build_response.