관리-도구
편집 파일: cache.cpython-311.pyc
� �܋f_ � �� � d Z ddlZddlmZ ddlmZ ddlmZmZmZm Z ddl mZ ddlm Z ddlmZ dd lmZmZ dd lmZ dedefd �Zeded fd�� � Z G d� de� � ZdS )zHTTP cache implementation. � N)�contextmanager)�datetime)�BinaryIO� Generator�Optional�Union)�SeparateBodyBaseCache)�SeparateBodyFileCache)�Response)�adjacent_tmp_file�replace)� ensure_dir�response�returnc �$ � t | dd� � S )N� from_cacheF)�getattr)r s �R/opt/cloudlinux/venv/lib64/python3.11/site-packages/pip/_internal/network/cache.py� is_from_cacher s � ��8�\�5�1�1�1� )NNNc # �6 K � dV � dS # t $ r Y dS w xY w)zvIf we can't access the cache then we can just skip caching and process requests as if caching wasn't enabled. N)�OSError� r r �suppressed_cache_errorsr s: � � � � � �������� � � ���� ���s � � �c �� � � e Zd ZdZdeddf� fd�Zdedefd�Zdedee fd �Z d ededdfd�Z dded edeee df ddfd�Zdeddfd�Zdedee fd�Zdededdfd�Z� xZS )� 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. � directoryr Nc �n �� |� J d� � �t � � � � � || _ d S )Nz!Cache directory must not be None.)�super�__init__r )�selfr � __class__s �r r zSafeFileCache.__init__2 s9 �� ��$�$�&I�$�$�$� ��������"����r �namec � � t j |� � }t |d d� � � |gz }t j j | j g|�R � S )N� )r �encode�list�os�path�joinr )r! r# �hashed�partss r �_get_cache_pathzSafeFileCache._get_cache_path7 sL � � '�-�d�3�3���V�B�Q�B�Z� � �F�8�+���w�|�D�N�3�U�3�3�3�3r �keyc � � | � |� � }|dz }t j � |� � rt j � |� � sd S t � � 5 t |d� � 5 }|� � � cd d d � � cd d d � � S # 1 swxY w Y d d d � � d S # 1 swxY w Y d S �N�.body�rb)r- r( r) �existsr �open�read)r! r. � metadata_path� body_path�fs r �getzSafeFileCache.get? sY � ��,�,�S�1�1� �!�G�+� �����}�-�-� �"�'�.�.��2K�2K� ��4� $� &� &� � ��m�T�*�*� �a��v�v�x�x� � � � � � � � � � � � � � � � � � � ���� � � � � � � � � � � � � � � � � ���� � � � � � s6 �)C �:B'�C �'B+ �+C �.B+ �/C � C�Cr) �datac �N � t � � 5 t t j � |� � � � t |� � 5 }|� |� � d d d � � n# 1 swxY w Y t |j |� � d d d � � d S # 1 swxY w Y d S �N) r r r( r) �dirnamer �writer r# )r! r) r: r8 s r �_writezSafeFileCache._writeI s � � $� &� &� "� "��r�w���t�,�,�-�-�-�"�4�(�(� �A����� � � � � � � � � � � � � � ���� � � � � �A�F�D�!�!�!� "� "� "� "� "� "� "� "� "� "� "� "���� "� "� "� "� "� "s5 �<B�A-�!B�-A1 �1B�4A1 �5B�B�!B�value�expiresc �\ � | � |� � }| � ||� � d S r<