Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.12/site-packages/pip/_internal/network/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.12/site-packages/pip/_internal/network/__pycache__/cache.cpython-312.pyc

�

4Μg_����dZddlZddlmZddlmZddlmZmZmZm	Z	ddl
mZddlm
Z
ddlmZdd	lmZmZdd
lmZdedefd
�Zededfd��ZGd�de�Zy)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)rs �F/usr/local/lib/python3.12/site-packages/pip/_internal/network/cache.py�
is_from_cachers���8�\�5�1�1�)NNNc#�4K�	d��y#t$rYywxYw�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�rr�suppressed_cache_errorsrs����

�
���
��
�s��	��	���c
����eZdZdZdeddf�fd�Zdedefd�Zdedeefd	�Z	d
ededdfd�Z
	dded
edeee
dfddfd�Zdeddfd�Zdedeefd�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.
    �	directoryrNc�B��|�Jd��t�|��||_y)Nz!Cache directory must not be None.)�super�__init__r)�selfr�	__class__s  �rr zSafeFileCache.__init__2s'����$�I�&I�I�$�
����"��r�namec��tj|�}t|dd�|gz}tjj
|jg|���S)N�)r
�encode�list�os�path�joinr)r!r#�hashed�partss    r�_get_cache_pathzSafeFileCache._get_cache_path7sG��'�-�-�d�3���V�B�Q�Z� �F�8�+���w�w�|�|�D�N�N�3�U�3�3r�keyc�d�|j|�}|dz}tjj|�rtjj|�syt	�5t|d�5}|j
�cddd�cddd�S#1swYnxYw	ddd�y#1swYyxYw�N�.body�rb)r-r(r)�existsr�open�read)r!r.�
metadata_path�	body_path�fs     r�getzSafeFileCache.get?s���,�,�S�1�
�!�G�+�	������}�-�"�'�'�.�.��2K��
$�
&��m�T�*�a��v�v�x�+�*�'�
&�*�*��*�'�
&�
&�s$� 
B&�-B�=	B&�B	�B&�&B/r)�datac� �t�5ttjj	|��t|�5}|j
|�ddd�tj|�ddd�y#1swY�(xYw#1swYyxYw�N)	rrr(r)�dirnamer�writer
r#)r!r)r:r8s    r�_writezSafeFileCache._writeIsa��
$�
&��r�w�w���t�,�-�"�4�(�A�����
�)�
�A�F�F�D�!�
'�
&�)�(��'�
&�s"�4B�A8�B�8B	�=B�B
�value�expiresc�J�|j|�}|j||�yr<�r-r?)r!r.r@rAr)s     r�setzSafeFileCache.setRs"���#�#�C�(�����D�%� rc��|j|�}t�5tj|�ddd�t�5tj|dz�ddd�y#1swY�5xYw#1swYyxYw�Nr1)r-rr(�remove)r!r.r)s   r�deletezSafeFileCache.deleteXsV���#�#�C�(��
$�
&��I�I�d�O�'�
$�
&��I�I�d�W�n�%�'�
&�'�
&��
&�
&�s�A&�A2�&A/�2A;c��|j|�}|dz}tjj|�rtjj|�syt	�5t|d�cddd�S#1swYyxYwr0)r-r(r)r3rr4)r!r.r6r7s    r�get_bodyzSafeFileCache.get_body_sZ���,�,�S�1�
�!�G�+�	������}�-�"�'�'�.�.��2K��
$�
&��	�4�(�'�
&�
&�s� A6�6A?�bodyc�P�|j|�dz}|j||�yrFrC)r!r.rKr)s    r�set_bodyzSafeFileCache.set_bodyhs%���#�#�C�(�7�2�����D�$�rr<)�__name__�
__module__�__qualname__�__doc__�strr r-r�bytesr9r?r�intrrDrHrrJrM�
__classcell__)r"s@rrr s�����"#�#�#�$�#�
4�C�4�C�4� �s� �x��� �"�3�"�e�"��"�MQ�!��!�$�!�/4�S�(�D�5H�/I�!�	
�!�&�#�&�$�&�)�C�)�H�X�$6�)� �C� �u� �� rr)rQr(�
contextlibrr�typingrrrr�pip._vendor.cachecontrol.cacher	�pip._vendor.cachecontrol.cachesr
�pip._vendor.requests.modelsr�pip._internal.utils.filesystemrr
�pip._internal.utils.miscr�boolrrrrrr�<module>r^sm���
�%��7�7�@�A�0�E�/�2�H�2��2��
��+;�!<�
��
�J �)�J r

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists