
    h                        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m	Z	 d dl
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Union)Path)	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       SD:\EasyAligner\venv\Lib\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 cachecontrol[filecache]
            )	filelockr%   ImportErrorr   	directoryforeverfilemodedirmode
lock_class)selfr(   r)   r*   r+   r,   r%   notices           r    __init__z_FileCacheMixin.__init__A   sg    	&!-%
 # $  	&F f%%	&s	   
0  Ac                d    t        j                  | j                               j                         S N)hashlibsha224encode	hexdigest)xs    r    r4   z_FileCacheMixin.encode^   s     ~~ahhj)3355    c                    | j                  |      }t        |d d       |gz   }t        j                  j                  | j
                  g| S )N   )r4   listr   pathjoinr(   )r-   namehashedpartss       r    _fnz_FileCacheMixin._fnb   sE     T"VBQZ F8+ww||DNN3U33r7   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.geti   sM    xx}	dD!Rwwy! !!! ! 		s*   A 9	A AA A 	AAc                J    | j                  |      }| j                  ||       y r1   r@   _write)r-   rE   valueexpiresr=   s        r    setz_FileCacheMixin.setr   s     xx}D% r7   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   makedirsr;   dirnamer+   r   r,   r!   r*   write)r-   r;   datarF   s       r    rJ   z_FileCacheMixin._writex   s    
	KK-t||< __TG^,#D$--8B 9 -,  		
 98 -,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r1   )r@   r)   r   r   rD   )r-   rE   suffixr=   s       r    _deletez_FileCacheMixin._delete   sD    xx}v%||		$  % s   9 	AA)Fi  i  N)r(   z
str | Pathr)   boolr*   intr+   rW   r,   ztype[BaseFileLock] | NonereturnNone)r6   strrX   rZ   )r=   rZ   rX   rZ   )rE   rZ   rX   zbytes | Noner1   )rE   rZ   rK   bytesrL   zint | datetime | NonerX   rY   )r;   rZ   rR   r[   rX   rY   )rE   rZ   rT   rZ   rX   rY   )__name__
__module____qualname____doc__r/   staticmethodr4   r@   rG   rM   rJ   rU    r7   r    r#   r#   >   s    <
 04%% % 	%
 % .% 
%: 6 64 HL!!$!/D!	!r7   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 rU   r-   rE   s     r    deletezFileCache.delete   s    S"r7   NrE   rZ   rX   rY   )r\   r]   r^   r_   rh   ra   r7   r    rc   rc      s    
r7   rc   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.bodyrB   )r@   r   rD   )r-   rE   r=   s      r    get_bodyzSeparateBodyFileCache.get_body   s8    xx}w&	d##  		s   " 	..c                P    | j                  |      dz   }| j                  ||       y )Nrm   rI   )r-   rE   bodyr=   s       r    set_bodyzSeparateBodyFileCache.set_body   s"    xx}w&D$r7   c                L    | j                  |d       | j                  |d       y )Nre   rm   rf   rg   s     r    rh   zSeparateBodyFileCache.delete   s    S"S'"r7   N)rE   rZ   rX   zIO[bytes] | None)rE   rZ   rp   r[   rX   rY   ri   )r\   r]   r^   r_   rn   rq   rh   ra   r7   r    rk   rk      s    
 #r7   rk   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	filecacherE   s      r    url_to_file_pathrw      s#    
 
#
#C
(C==r7   )r   rZ   r   rW   rX   z	IO[bytes])ru   rZ   rv   rc   rX   rZ   )
__future__r   r2   r   textwrapr   typingr   r   r   pathlibr   pip._vendor.cachecontrol.cacher	   r
   #pip._vendor.cachecontrol.controllerr   r   r&   r   r!   r#   rc   rk   rw   ra   r7   r    <module>r~      s`    #  	  + +  K ?!%&RO Od #O-B #,r7   