o
    µ!<fS  ã                   @   s¤   d Z ddlZddlmZ ddlmZ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
edefdd„Zeded fdd„ƒZG dd„ deƒZdS )zHTTP cache implementation.
é    N)Úcontextmanager)ÚIteratorÚOptional)Ú	BaseCache)Ú	FileCache)ÚResponse)Úadjacent_tmp_fileÚreplace)Ú
ensure_dirÚresponseÚreturnc                 C   s   t | ddƒS )NÚ
from_cacheF)Úgetattr)r   © r   úR/var/www/html/kck/venv/lib/python3.10/site-packages/pip/_internal/network/cache.pyÚis_from_cache   s   r   c                   c   s$    zdV  W dS  t y   Y dS w )zvIf we can't access the cache then we can just skip caching and process
    requests as if caching wasn't enabled.
    N)ÚOSErrorr   r   r   r   Úsuppressed_cache_errors   s   €ÿr   c                	       s„   e Zd ZdZdeddf‡ fdd„Zdedefdd	„Zd
edee fdd„Z	dd
ededee
 ddfdd„Zd
eddf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.
    Ú	directoryr   Nc                    s$   |d usJ dƒ‚t ƒ  ¡  || _d S )Nz!Cache directory must not be None.)ÚsuperÚ__init__r   )Úselfr   ©Ú	__class__r   r   r   %   s   

zSafeFileCache.__init__Únamec                 C   s6   t  |¡}t|d d… ƒ|g }tjj| jg|¢R Ž S )Né   )r   ÚencodeÚlistÚosÚpathÚjoinr   )r   r   ÚhashedÚpartsr   r   r   Ú_get_cache_path*   s   
zSafeFileCache._get_cache_pathÚkeyc              	   C   sv   |   |¡}tƒ ) t|dƒ}| ¡ W  d   ƒ W  d   ƒ S 1 s$w   Y  W d   ƒ d S 1 s4w   Y  d S )NÚrb)r$   r   ÚopenÚread)r   r%   r    Úfr   r   r   Úget2   s   
ÿÿ"ÿzSafeFileCache.getÚvalueÚexpiresc              	   C   s„   |   |¡}tƒ 0 ttj |¡ƒ t|ƒ}| |¡ W d   ƒ n1 s%w   Y  t|j	|ƒ W d   ƒ d S 1 s;w   Y  d S ©N)
r$   r   r
   r   r    Údirnamer   Úwriter	   r   )r   r%   r+   r,   r    r)   r   r   r   Úset8   s   

ÿ"úzSafeFileCache.setc                 C   s@   |   |¡}tƒ  t |¡ W d   ƒ d S 1 sw   Y  d S r-   )r$   r   r   Úremove)r   r%   r    r   r   r   ÚdeleteB   s   
"ÿzSafeFileCache.deleter-   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr   r$   r   Úbytesr*   Úintr0   r2   Ú__classcell__r   r   r   r   r      s     
r   )r6   r   Ú
contextlibr   Útypingr   r   Úpip._vendor.cachecontrol.cacher   Úpip._vendor.cachecontrol.cachesr   Úpip._vendor.requests.modelsr   Úpip._internal.utils.filesystemr   r	   Úpip._internal.utils.miscr
   Úboolr   r   r   r   r   r   r   Ú<module>   s    
