a
    e0h	                     @   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rxdd
lmZmZ dd Zedd ZG dd deZdS )zHTTP cache implementation.
    N)contextmanager)	BaseCache)	FileCache)Response)adjacent_tmp_filereplace)
ensure_dir)MYPY_CHECK_RUNNING)IteratorOptionalc                 C   s   t | ddS )N
from_cacheF)getattr)response r   I/var/www/auris/lib/python3.9/site-packages/pip/_internal/network/cache.pyis_from_cache   s    r   c                	   c   s&   z
dV  W n t tfy    Y n0 dS )zvIf we can't access the cache then we can just skip caching and process
    requests as if caching wasn't enabled.
    N)OSErrorIOErrorr   r   r   r   suppressed_cache_errors   s    
r   c                       s@   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Z  Z	S )SafeFileCachezw
    A file based cache which is safe to use even when the target directory may
    not be accessible or writable.
    c                    s(   |d usJ dt t|   || _d S )Nz!Cache directory must not be None.)superr   __init__	directory)selfr   	__class__r   r   r   *   s    zSafeFileCache.__init__c                 C   s6   t |}t|d d |g }tjj| jg|R  S )N   )r   encodelistospathjoinr   )r   namehashedpartsr   r   r   _get_cache_path0   s    
zSafeFileCache._get_cache_pathc              	   C   st   |  |}t P t|d&}| W  d    W  d    S 1 sH0    Y  W d    n1 sf0    Y  d S )Nrb)r%   r   openread)r   keyr    fr   r   r   get9   s    
zSafeFileCache.getc              	   C   s   |  |}t ^ ttj| t|}|| W d    n1 sJ0    Y  t|j	| W d    n1 st0    Y  d S N)
r%   r   r   r   r    dirnamer   writer   r"   )r   r)   valuer    r*   r   r   r   set@   s    

(zSafeFileCache.setc                 C   s>   |  |}t  t| W d    n1 s00    Y  d S r,   )r%   r   r   remove)r   r)   r    r   r   r   deleteK   s    
zSafeFileCache.delete)
__name__
__module____qualname____doc__r   r%   r+   r0   r2   __classcell__r   r   r   r   r   $   s   	r   )r6   r   
contextlibr   pip._vendor.cachecontrol.cacher   pip._vendor.cachecontrol.cachesr   pip._vendor.requests.modelsr   pip._internal.utils.filesystemr   r   pip._internal.utils.miscr   pip._internal.utils.typingr	   typingr
   r   r   r   r   r   r   r   r   <module>   s   
