Sindbad~EG File Manager
3
�Pf � @ sT d dl Z d dlZd dlmZ ddlmZ ddlmZ ddlm Z G dd� de�Z
dS ) � N)�HTTPAdapter� )�CacheController)� DictCache)�CallbackFileWrapperc sP e Zd Zeddg�Zd� fdd� Z� fdd�Zd� 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
�args�kwZcontroller_factory)� __class__� �/usr/lib/python3.6/adapter.pyr s zCacheControlAdapter.__init__c sV |j dkr>| jj|�}|r*| j||dd�S |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_request�build_responseZheaders�updateZconditional_headersr
r �send)r �requestr �cached_response�resp)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.<locals>._update_chunk_length)r r
ZapplyZstatusr Zupdate_cached_response�readZrelease_connZcache_responser r � functools�partialZchunkedr �types�
MethodTyper
r r �invalidating_methods�ok� cache_urlZurlr �deleter )r r Zresponser r r r r( )r )r r r 3 s<