
^Vd                 @   sf   d  d l  Z  d  d l m Z d d l m Z d d l m Z d d l m Z Gd d   d e  Z	 d S)	    N)HTTPAdapter   )CacheController)	DictCache)CallbackFileWrapperc                   s|   e  Z d  Z e d d g  Z d d d d d   f d d  Z   f d d   Z d	   f d
 d  Z   f d d   Z   S)CacheControlAdapterPUTDELETENTc       	         sb   t  t |   j | |   | p% t   |  _ | |  _ | p= t } | |  j d | d | |  _ d  S)Ncache_etags
serializer)superr   __init__r   cache	heuristicr   
controller)	selfr   r
   controller_classr   r   argskwcontroller_factory)	__class__ ?/tmp/pip-build-9m6vxulb/pip/pip/_vendor/cachecontrol/adapter.pyr      s    		zCacheControlAdapter.__init__c                s{   | j  d k r\ |  j j |  } | r= |  j | | d d S| j j |  j j |   n  t t |   j	 | |  } | 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.
        GET
from_cacheT)
methodr   cached_requestbuild_responseheadersupdateconditional_headersr   r   send)r   requestr   cached_responseresp)r   r   r   r!      s    	zCacheControlAdapter.sendFc                sM  | r | j  d k r | j d k rr |  j j | |  } | | k	 rO d } n  | j d d  | j   | } q | j d k r |  j j | |  q |  j r |  j j |  } n  t	 | j
 t j |  j j | |   | _
 n  t t |   j | |  } | j  |  j k r@| j r@|  j j | j  } |  j j |  n  | | _ | 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  Tdecode_contentFi-  )r   statusr   update_cached_responsereadrelease_conncache_responser   applyr   _fp	functoolspartialr   r   r   invalidating_methodsok	cache_urlurlr   deleter   )r   r"   responser   r#   r$   r1   )r   r   r   r   2   s4    		
				z"CacheControlAdapter.build_responsec                s$   |  j  j   t t |   j   d  S)N)r   closer   r   )r   )r   r   r   r5   s   s    zCacheControlAdapter.close)	__name__
__module____qualname__setr/   r   r!   r   r5   r   r   )r   r   r   
   s   Ar   )
r-   Zpip._vendor.requests.adaptersr   r   r   r   r   filewrapperr   r   r   r   r   r   <module>   s
   