
    jVh                        d dl mZ d dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
mZ d dlmZ erd dlmZ d dlmZ dd	Z G d
 d      Z G d dee
      Z G d dee      ZddZy)    )annotationsN)dedent)IOTYPE_CHECKING)	BaseCacheSeparateBodyBaseCache)CacheController)datetime)BaseFileLockc                   t         j                  }|t         j                  t         j                  z  z  }t	        t         d      r|t         j
                  z  }t	        t         d      r|t         j                  z  }	 t        j                  |        t        j                  | ||      }	 t        j                  |d      S # t        $ r Y 9w xY w#  t        j                  |        xY w)N
O_NOFOLLOWO_BINARYwb)osO_WRONLYO_CREATO_EXCLhasattrr   r   removeOSErroropenfdopenclose)filenamefmodeflagsfds       Z/home/dcms/DCMS/lib/python3.12/site-packages/pip/_vendor/cachecontrol/caches/file_cache.py_secure_open_writer      s    KKE 
RZZ"))##E r<  r:
		( 
5%	(ByyT""  
s   <B? )C ?	C
CC&c                      e Zd ZdZ	 	 	 	 d
	 	 	 	 	 	 	 	 	 	 	 ddZedd       ZddZddZ	 d	 	 	 	 	 	 	 ddZ	ddZ
dd	Zy)_FileCacheMixinz2Shared implementation for both FileCache variants.Nc                    	 |ddl m} |}|| _        || _        || _        || _        || _        y # t        $ r t        d      }t        |      w xY w)Nr   )FileLockz
            NOTE: In order to use the FileCache you must have
            filelock installed. You can install it via pip:
              pip install filelock
            )	filelockr#   ImportErrorr   	directoryforeverfilemodedirmode
lock_class)selfr&   r'   r(   r)   r*   r#   notices           r   __init__z_FileCacheMixin.__init__@   sg    	&!-%
 # $  	&F f%%	&s	   
0  Ac                d    t        j                  | j                               j                         S N)hashlibsha224encode	hexdigest)xs    r   r2   z_FileCacheMixin.encode]   s     ~~ahhj)3355    c                    | j                  |      }t        |d d       |gz   }t        j                  j                  | j
                  g| S )N   )r2   listr   pathjoinr&   )r+   namehashedpartss       r   _fnz_FileCacheMixin._fna   sE     T"VBQZ F8+ww||DNN3U33r5   c                    | j                  |      }	 t        |d      5 }|j                         cd d d        S # 1 sw Y   y xY w# t        $ r Y y w xY w)Nrb)r>   r   readFileNotFoundError)r+   keyr;   fhs       r   getz_FileCacheMixin.geth   sQ    xx}	dD! !Rwwy! ! ! ! 		s*   A 9	A AA A 	AAc                J    | j                  |      }| j                  ||       y r/   r>   _write)r+   rC   valueexpiresr;   s        r   setz_FileCacheMixin.setq   s     xx}D% r5   c                h   	 t        j                  t         j                  j                  |      | j                         | j                  |dz         5  t        || j                        5 }|j                  |       ddd       ddd       y# t
        $ r Y Yw xY w# 1 sw Y   !xY w# 1 sw Y   yxY w)z:
        Safely write the data to the given path.
        z.lockN)
r   makedirsr9   dirnamer)   r   r*   r   r(   write)r+   r9   datarD   s       r   rH   z_FileCacheMixin._writew   s    
	KK-t||< __TG^, 	#D$--8 B	 	  		
 	 	s5   =B B(*B<B(	BBB%	!B((B1c                    | j                  |      |z   }| j                  s	 t        j                  |       y y # t        $ r Y y w xY wr/   )r>   r'   r   r   rB   )r+   rC   suffixr;   s       r   _deletez_FileCacheMixin._delete   sD    xx}v%||		$  % s   9 	AA)Fi  i  N)r&   strr'   boolr(   intr)   rV   r*   ztype[BaseFileLock] | NonereturnNone)r4   rT   rW   rT   )r;   rT   rW   rT   )rC   rT   rW   zbytes | Noner/   )rC   rT   rI   bytesrJ   zint | datetime | NonerW   rX   )r9   rT   rP   rY   rW   rX   )rC   rT   rR   rT   rW   rX   )__name__
__module____qualname____doc__r-   staticmethodr2   r>   rE   rK   rH   rS    r5   r   r!   r!   =   s    <
 04%% % 	%
 % .% 
%: 6 64 HL!!$!/D!	!r5   r!   c                      e Zd ZdZddZy)	FileCachezc
    Traditional FileCache: body is stored in memory, so not suitable for large
    downloads.
    c                (    | j                  |d       y )N rS   r+   rC   s     r   deletezFileCache.delete   s    S"r5   NrC   rT   rW   rX   )rZ   r[   r\   r]   rf   r_   r5   r   ra   ra      s    
r5   ra   c                  (    e Zd ZdZddZddZddZy)	SeparateBodyFileCachezh
    Memory-efficient FileCache: body is stored in a separate file, reducing
    peak memory usage.
    c                b    | j                  |      dz   }	 t        |d      S # t        $ r Y y w xY w)N.bodyr@   )r>   r   rB   )r+   rC   r;   s      r   get_bodyzSeparateBodyFileCache.get_body   s8    xx}w&	d##  		s   " 	..c                P    | j                  |      dz   }| j                  ||       y )Nrk   rG   )r+   rC   bodyr;   s       r   set_bodyzSeparateBodyFileCache.set_body   s"    xx}w&D$r5   c                L    | j                  |d       | j                  |d       y )Nrc   rk   rd   re   s     r   rf   zSeparateBodyFileCache.delete   s    S"S'"r5   N)rC   rT   rW   zIO[bytes] | None)rC   rT   rn   rY   rW   rX   rg   )rZ   r[   r\   r]   rl   ro   rf   r_   r5   r   ri   ri      s    
 #r5   ri   c                N    t        j                  |       }|j                  |      S )z\Return the file cache path based on the URL.

    This does not ensure the file exists!
    )r	   	cache_urlr>   )url	filecacherC   s      r   url_to_file_pathru      s#    
 
#
#C
(C==r5   )r   rT   r   rV   rW   z	IO[bytes])rs   rT   rt   ra   rW   rT   )
__future__r   r0   r   textwrapr   typingr   r   pip._vendor.cachecontrol.cacher   r   #pip._vendor.cachecontrol.controllerr	   r
   r$   r   r   r!   ra   ri   ru   r_   r5   r   <module>r{      sZ    #  	  $ K ?!%&RO Od #O-B #,r5   