a
lj @ s\ d dl Z d dlZd dlZd dlmZ ddlmZ ddlmZ ddl m
Z
G dd deZdS ) N)HTTPAdapter )CacheController) DictCache)CallbackFileWrapperc sN e Zd ZddhZd fdd Zd fdd Zd fd
d Z fdd
Z ZS )CacheControlAdapterZPUTZDELETENTc
sX t t| j|i | |d u r$t n|| _|| _|p6d| _|p@t} | | j||d| _d S )N)ZGET)cache_etags
serializer) superr __init__r cache heuristiccacheable_methodsr
controller)
selfr r Zcontroller_classr r
r argskwZcontroller_factory __class__ D/usr/lib/python3.9/site-packages/pip/_vendor/cachecontrol/adapter.pyr s
zCacheControlAdapter.__init__c s |p| j }|j|v rfz| j|}W n tjy< d}Y n0 |rR| j||ddS |j| j | t
t| j|fi |}|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_requestzliberrorbuild_responseZheadersupdateZconditional_headersr
r send)r requestr r cacheablecached_responserespr r r r $ s
zCacheControlAdapter.sendFc
s |p| j }|s|j|v r| jr*| j|}|jdkrh| j||}||urNd}|jdd | |}n\|jdkr| j || nBt
|jt
| jj |||_|jr|j fdd}t|||_tt| ||}|j| jv r|jr| 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_closer Zsuper_update_chunk_lengthr r _update_chunk_lengthn s
z@CacheControlAdapter.build_response.