3
Pf @ sT d dl Z d dlZd dlmZ ddlmZ ddlmZ ddlm Z G dd deZ
dS ) N)HTTPAdapter )CacheController) DictCache)CallbackFileWrapperc sP e Zd ZeddgZd fdd Z fddZd fd
d Z fdd
Z Z S )CacheControlAdapterZPUTZDELETENTc sB t t| j|| |pt | _|| _|p*t}|| j||d| _d S )N)cache_etags
serializer)superr __init__r cache heuristicr
controller) selfr r Zcontroller_classr r
argskwZcontroller_factory) __class__ /usr/lib/python3.6/adapter.pyr s zCacheControlAdapter.__init__c sV |j dkr>| jj|}|r*| j||ddS |jj| jj| tt| 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.
GETT)
from_cache)
methodr Zcached_requestbuild_responseZheadersupdateZconditional_headersr
r send)r requestr cached_responseresp)r r r r s
zCacheControlAdapter.sendFc s | r|j dkr| jr"| jj|}|jdkr`| jj||}||k rFd}|jdd |j |}n\|jdkrz| jj|| nBt |j
tj| jj|||_
|j
r|j fdd}tj|||_tt| j||}|j | jkr|jr| jj|j}| jj| ||_|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
r i0 TF)Zdecode_contenti- c s | j dkr| jj d S )Nr )Z
chunk_left_fpZ_close)r )super_update_chunk_lengthr r _update_chunk_lengthg s
z@CacheControlAdapter.build_response.