File: //usr/local/lib/python3.7/site-packages/pip/_internal/network/__pycache__/cache.cpython-37.pyc
B
L��g_ � @ s� d Z ddlZddlmZ ddlmZ ddlmZmZmZm Z ddl
mZ ddlm
Z
ddlmZ dd lmZmZ dd
lmZ eed�dd
�Zeed d�dd��ZG dd� de�ZdS )zHTTP cache implementation.
� N)�contextmanager)�datetime)�BinaryIO� Generator�Optional�Union)�SeparateBodyBaseCache)�SeparateBodyFileCache)�Response)�adjacent_tmp_file�replace)�
ensure_dir)�response�returnc C s t | dd�S )N�
from_cacheF)�getattr)r � r �?/tmp/pip-unpacked-wheel-hv55ucu3/pip/_internal/network/cache.py�
is_from_cache s r )NNN)r c c s$ y
dV W n t k
r Y nX dS )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 Zd ZdZedd�� fdd�Zeed�dd�Zeee d �d
d�Z eedd�d
d�Z
deeeee
df dd�dd�Zedd �dd�Zeee d �dd�Zeedd�dd�Z� ZS )�
SafeFileCacheaG
A file based cache which is safe to use even when the target directory may
not be accessible or writable.
There is a race condition when two processes try to write and/or read the
same entry at the same time, since each entry consists of two separate
files (https://github.com/psf/cachecontrol/issues/324). We therefore have
additional logic that makes sure that both files to be present before
returning an entry; this fixes the read side of the race condition.
For the write side, we assume that the server will only ever return the
same data for the same URL, which ought to be the case for files pip is
downloading. PyPI does not have a mechanism to swap out a wheel for
another wheel, for example. If this assumption is not true, the
CacheControl issue will need to be fixed.
N)� directoryr c s$ |d k st d��t� �� || _d S )Nz!Cache directory must not be None.)�AssertionError�super�__init__r )�selfr )� __class__r r r 2 s
zSafeFileCache.__init__)�namer c C s4 t �|�}t|d d� �|g }tjj| jf|�� S )N� )r �encode�list�os�path�joinr )r r �hashed�partsr r r �_get_cache_path7 s
zSafeFileCache._get_cache_path)�keyr c
C s^ | � |�}|d }tj�|�r*tj�|�s.d S t� � t|d��
}|�� S Q R X W d Q R X d S )Nz.body�rb)r'