
    q"h                         S r SSKrSSKJr  SSKJr  SSKJrJrJrJ	r	  SSK
Jr  SSKJr  SSKJr  SS	KJrJr  SS
KJr  S\S\4S jr\S\S   4S j5       r " S S\5      rg)zHTTP cache implementation.    N)contextmanager)datetime)BinaryIO	GeneratorOptionalUnion)SeparateBodyBaseCache)SeparateBodyFileCache)Response)adjacent_tmp_filereplace)
ensure_dirresponsereturnc                     [        U SS5      $ )N
from_cacheF)getattr)r   s    M/var/www/html/env/lib/python3.13/site-packages/pip/_internal/network/cache.pyis_from_cacher      s    8\511    )NNNc               #   6   #     Sv   g! [          a     gf = f7f)znIf 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            
          ^  \ rS rSrSrS\SS4U 4S jjrS\S\4S jrS	\S\\	   4S
 jr
S\S\	SS4S jr SS	\S\	S\\\S4   SS4S jjrS	\SS4S jrS	\S\\   4S jrS	\S\	SS4S jrSrU =r$ )SafeFileCache   a  
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                 B   > Uc   S5       e[         TU ]  5         Xl        g )Nz!Cache directory must not be None.)super__init__r   )selfr   	__class__s     r   r!   SafeFileCache.__init__1   s%    $I&II$"r   namec                     [         R                  " U5      n[        US S 5      U/-   n[        R                  R
                  " U R                  /UQ76 $ )N   )r
   encodelistospathjoinr   )r"   r%   hashedpartss       r   _get_cache_pathSafeFileCache._get_cache_path6   sG     '--d3VBQZ F8+ww||DNN3U33r   keyc                    U R                  U5      nUS-   n[        R                  R                  U5      (       a$  [        R                  R                  U5      (       d  g [	        5          [        US5       nUR                  5       sS S S 5        sS S S 5        $ ! , (       d  f       O= f S S S 5        g ! , (       d  f       g = fN.bodyrb)r/   r*   r+   existsr   openread)r"   r1   metadata_path	body_pathfs        r   getSafeFileCache.get>   s    ,,S1!G+	}--"''..2K2K$&mT*avvx +* '&*** '&&s$   *B57B	B5
B(	$B55
Cr+   datac                    [        5          [        [        R                  R	                  U5      5        [        U5       nUR                  U5        [        R                  " U R                  5      R                  S-  S-  n[        R                  [        R                  ;   a&  [        R                  " UR                  5       U5        OB[        R                  [        R                  ;   a   [        R                  " UR                  USS9  S S S 5        [        WR                  U5        S S S 5        g ! , (       d  f       N-= f! , (       d  f       g = f)Ni  i  F)follow_symlinks)r   r   r*   r+   dirnamer   writestatr   st_modechmodsupports_fdfilenosupports_follow_symlinksr%   r   )r"   r+   r>   r;   modes        r   _writeSafeFileCache._writeH   s    $&rwwt,-"4(A GGDNN+33  88r~~-HHQXXZ.XX!<!<<HHQVVT5A ) AFFD!% '& )( '&s#   4ECD2E2
E 	<E
Evalueexpiresc                 H    U R                  U5      nU R                  XB5        g Nr/   rJ   )r"   r1   rL   rM   r+   s        r   setSafeFileCache.set]   s      ##C(D r   c                    U R                  U5      n[        5          [        R                  " U5        S S S 5        [        5          [        R                  " US-   5        S S S 5        g ! , (       d  f       N;= f! , (       d  f       g = fNr4   )r/   r   r*   remove)r"   r1   r+   s      r   deleteSafeFileCache.deletec   sV    ##C($&IIdO '$&IIdWn% '& '&&&s   A(A9(
A69
Bc                 "   U R                  U5      nUS-   n[        R                  R                  U5      (       a$  [        R                  R                  U5      (       d  g [	        5          [        US5      sS S S 5        $ ! , (       d  f       g = fr3   )r/   r*   r+   r6   r   r7   )r"   r1   r9   r:   s       r   get_bodySafeFileCache.get_bodyj   s`    ,,S1!G+	}--"''..2K2K$&	4( '&&s   *B  
Bbodyc                 N    U R                  U5      S-   nU R                  X25        g rT   rP   )r"   r1   r[   r+   s       r   set_bodySafeFileCache.set_bodys   s#    ##C(72Dr   )r   rO   )__name__
__module____qualname____firstlineno____doc__strr!   r/   r   bytesr<   rJ   r   intr   rQ   rV   r   rY   r]   __static_attributes____classcell__)r#   s   @r   r   r      s    "## #$ #
4C 4C 4 s  x  "3 "e " ", MQ!!$!/4S(D5H/I!	!&# &$ &)C )HX$6 ) C  u      r   r   )rc   r*   
contextlibr   r   typingr   r   r   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   <module>rq      si      	 %  7 7 @ A 0 E /2H 2 2 +;!<  V ) V r   