
    (ph                        S SK Jr  S SKrS SKrS SKrS SKJr  S SKJrJ	r	  S SK
Jr  S SKJrJr  S SKJr  \	(       a  S SKJr  S S	KJr   " S
 S5      r " S S\\5      r " S S\\5      rSS jrg)    )annotationsN)dedent)IOTYPE_CHECKING)Path)	BaseCacheSeparateBodyBaseCache)CacheController)datetime)BaseFileLockc                      \ rS rSrSr    S           SS jjr\SS j5       rSS jrSS jr	 S       SS jjr
SS	 jrSS
 jrSrg)_FileCacheMixin   z2Shared implementation for both FileCache variants.Nc                     Uc  SSK Jn  UnXl        X l        X0l        X@l        XPl        g ! [         a    [        S5      n[        U5      ef = f)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           Q/var/www/html/venv/lib/python3.13/site-packages/cachecontrol/caches/file_cache.py__init___FileCacheMixin.__init__   s]    	&!-%
 # $  	&F f%%	&s	   , !Ac                f    [         R                  " U R                  5       5      R                  5       $ N)hashlibsha224encode	hexdigest)xs    r   r"   _FileCacheMixin.encode6   s     ~~ahhj)3355    c                    U R                  U5      n[        US S 5      U/-   n[        R                  R                  " U R
                  /UQ76 $ )N   )r"   listospathjoinr   )r   namehashedpartss       r   _fn_FileCacheMixin._fn:   sE     T"VBQZ F8+ww||DNN3U33r&   c                    U R                  U5      n [        US5       nUR                  5       sS S S 5        $ ! , (       d  f       g = f! [         a     g f = f)Nrb)r0   openreadFileNotFoundError)r   keyr-   fhs       r   get_FileCacheMixin.getA   sH    xx}	dD!Rwwy "!! ! 		s+   A
 9	A
 
AA
 A
 

AAc                H    U R                  U5      nU R                  XB5        g r   r0   _write)r   r7   valueexpiresr-   s        r   set_FileCacheMixin.setJ   s     xx}D r&   c                   [         R                  R                  U5      n[         R                  " X0R                  SS9  U R                  US-   5         [        R                  " US9u  pE [         R                  " XB5        [         R                  " U5        [         R                  " XPR                  5        [         R                  " XQ5        SSS5        g! [         R                  " U5        f = f! , (       d  f       g= f)z*
Safely write the data to the given path.
T)exist_okz.lock)dirN)r*   r+   dirnamemakedirsr   r   tempfilemkstempwriteclosechmodr   replace)r   r+   datarE   fdr-   s         r   r=   _FileCacheMixin._writeP   s    
 ''//$'
G\\D9__TG^,!))g6JR"HHT==)JJt" -,  -,s%   C1+CAC1C..C11
C?c                    U R                  U5      U-   nU R                  (       d   [        R                  " U5        g g ! [         a     g f = fr   )r0   r   r*   remover6   )r   r7   suffixr-   s       r   _delete_FileCacheMixin._deleteb   sD    xx}v%||		$  % s   ? 
AA)r   r   r   r   r   )Fi  i  N)r   z
str | Pathr   boolr   intr   rV   r   ztype[BaseFileLock] | NonereturnNone)r$   strrW   rY   )r-   rY   rW   rY   )r7   rY   rW   zbytes | Noner   )r7   rY   r>   bytesr?   zint | datetime | NonerW   rX   )r+   rY   rM   rZ   rW   rX   )r7   rY   rR   rY   rW   rX   )__name__
__module____qualname____firstlineno____doc__r   staticmethodr"   r0   r9   r@   r=   rS   __static_attributes__ r&   r   r   r      s    <
 04%% % 	%
 % .% 
%: 6 64 HL!!$!/D!	!#$r&   r   c                  "    \ rS rSrSrSS jrSrg)	FileCachek   zW
Traditional FileCache: body is stored in memory, so not suitable for large
downloads.
c                (    U R                  US5        g )N rS   r   r7   s     r   deleteFileCache.deleteq   s    S"r&   rb   Nr7   rY   rW   rX   )r[   r\   r]   r^   r_   rj   ra   rb   r&   r   rd   rd   k   s    
r&   rd   c                  6    \ rS rSrSrSS jrS	S jrS
S jrSrg)SeparateBodyFileCacheu   z\
Memory-efficient FileCache: body is stored in a separate file, reducing
peak memory usage.
c                d    U R                  U5      S-   n [        US5      $ ! [         a     g f = f)N.bodyr3   )r0   r4   r6   )r   r7   r-   s      r   get_bodySeparateBodyFileCache.get_body{   s8    xx}w&	d##  		s   " 
//c                N    U R                  U5      S-   nU R                  X25        g )Nrq   r<   )r   r7   bodyr-   s       r   set_bodySeparateBodyFileCache.set_body   s     xx}w&Dr&   c                L    U R                  US5        U R                  US5        g )Nrg   rq   rh   ri   s     r   rj   SeparateBodyFileCache.delete   s    S"S'"r&   rb   N)r7   rY   rW   zIO[bytes] | None)r7   rY   ru   rZ   rW   rX   rl   )	r[   r\   r]   r^   r_   rr   rv   rj   ra   rb   r&   r   rn   rn   u   s    
 #r&   rn   c                P    [         R                  " U 5      nUR                  U5      $ )zTReturn the file cache path based on the URL.

This does not ensure the file exists!
)r
   	cache_urlr0   )url	filecacher7   s      r   url_to_file_pathr~      s#    
 
#
#C
(C==r&   )r|   rY   r}   rd   rW   rY   )
__future__r   r    r*   rG   textwrapr   typingr   r   pathlibr   cachecontrol.cacher   r	   cachecontrol.controllerr
   r   r   r   r   rd   rn   r~   rb   r&   r   <module>r      sZ    #  	   $  ? 3!%R Rj #O-B #,r&   