ó
Ð²Ebc           @   sÙ   d  Z  d d l Z d d l m Z d d l m Z d d l m Z d d l m	 Z	 d d l
 m Z m Z d d l m Z d d	 l m Z e r§ d d
 l m Z m Z n  d „  Z e d „  ƒ Z d e f d „  ƒ  YZ d S(   s   HTTP cache implementation.
iÿÿÿÿN(   t   contextmanager(   t	   BaseCache(   t	   FileCache(   t   Response(   t   adjacent_tmp_filet   replace(   t
   ensure_dir(   t   MYPY_CHECK_RUNNING(   t   Iteratort   Optionalc         C   s   t  |  d t ƒ S(   Nt
   from_cache(   t   getattrt   False(   t   response(    (    s8   /tmp/pip-build-UPPWic/pip/pip/_internal/network/cache.pyt   is_from_cache   s    c           c   s'   y	 d VWn t  t f k
 r" n Xd S(   sv   If we can't access the cache then we can just skip caching and process
    requests as if caching wasn't enabled.
    N(   t   OSErrort   IOError(    (    (    s8   /tmp/pip-build-UPPWic/pip/pip/_internal/network/cache.pyt   suppressed_cache_errors   s    	t   SafeFileCachec           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sw   
    A file based cache which is safe to use even when the target directory may
    not be accessible or writable.
    c         C   s8   | d  k	 s t d ƒ ‚ t t |  ƒ j ƒ  | |  _ d  S(   Ns!   Cache directory must not be None.(   t   Nonet   AssertionErrort   superR   t   __init__t	   directory(   t   selfR   (    (    s8   /tmp/pip-build-UPPWic/pip/pip/_internal/network/cache.pyR   *   s    c         C   s<   t  j | ƒ } t | d  ƒ | g } t j j |  j | Œ S(   Ni   (   R   t   encodet   listt   ost   patht   joinR   (   R   t   namet   hashedt   parts(    (    s8   /tmp/pip-build-UPPWic/pip/pip/_internal/network/cache.pyt   _get_cache_path0   s    c      	   C   sE   |  j  | ƒ } t ƒ  ' t | d ƒ  } | j ƒ  SWd  QXWd  QXd  S(   Nt   rb(   R!   R   t   opent   read(   R   t   keyR   t   f(    (    s8   /tmp/pip-build-UPPWic/pip/pip/_internal/network/cache.pyt   get9   s    
c      
   C   sk   |  j  | ƒ } t ƒ  M t t j j | ƒ ƒ t | ƒ  } | j | ƒ Wd  QXt | j	 | ƒ Wd  QXd  S(   N(
   R!   R   R   R   R   t   dirnameR   t   writeR   R   (   R   R%   t   valueR   R&   (    (    s8   /tmp/pip-build-UPPWic/pip/pip/_internal/network/cache.pyt   set@   s    
c         C   s0   |  j  | ƒ } t ƒ   t j | ƒ Wd  QXd  S(   N(   R!   R   R   t   remove(   R   R%   R   (    (    s8   /tmp/pip-build-UPPWic/pip/pip/_internal/network/cache.pyt   deleteK   s    
(   t   __name__t
   __module__t   __doc__R   R!   R'   R+   R-   (    (    (    s8   /tmp/pip-build-UPPWic/pip/pip/_internal/network/cache.pyR   $   s   					(   R0   R   t
   contextlibR    t   pip._vendor.cachecontrol.cacheR   t   pip._vendor.cachecontrol.cachesR   t   pip._vendor.requests.modelsR   t   pip._internal.utils.filesystemR   R   t   pip._internal.utils.miscR   t   pip._internal.utils.typingR   t   typingR   R	   R   R   R   (    (    (    s8   /tmp/pip-build-UPPWic/pip/pip/_internal/network/cache.pyt   <module>   s   	