
    .Ph                        d dl mZ d dl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 d dlmZmZ d dlmZ e	rd dlmZ d d	lmZ  G d
 d          Z G d dee          Z G d dee          ZddZdS )    )annotationsN)dedent)IOTYPE_CHECKING)Path)	BaseCacheSeparateBodyBaseCache)CacheController)datetime)BaseFileLockc                  h    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dS )-_FileCacheMixinz2Shared implementation for both FileCache variants.F    N	directory
str | Pathforeverboolfilemodeintdirmode
lock_classtype[BaseFileLock] | NonereturnNonec                    	 |ddl m} |}n,# t          $ r t          d          }t          |          w xY w|| _        || _        || _        || _        || _        d S )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   r   r   r   r   r   )selfr   r   r   r   r   r   notices           ^/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/cachecontrol/caches/file_cache.py__init__z_FileCacheMixin.__init__   s    	&!------%
 	& 	& 	& F f%%%	& # $s   
 )6xstrc                r    t          j        |                                                                           S N)hashlibsha224encode	hexdigest)r$   s    r"   r*   z_FileCacheMixin.encode6   s&    ~ahhjj))33555    namec                    |                      |          }t          |d d                   |gz   }t          j        j        | j        g|R  S )N   )r*   listospathjoinr   )r    r-   hashedpartss       r"   _fnz_FileCacheMixin._fn:   sM     T""VBQBZ  F8+w|DN3U3333r,   keybytes | Nonec                    |                      |          }	 t          |d          5 }|                                cd d d            S # 1 swxY w Y   d S # t          $ r Y d S w xY w)Nrb)r6   openreadFileNotFoundError)r    r7   r-   fhs       r"   getz_FileCacheMixin.getA   s    xx}}	dD!! !Rwwyy! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! 	 	 	44	s3   A AA AA AA 
A#"A#valuebytesexpiresint | datetime | Nonec                \    |                      |          }|                     ||           d S r'   r6   _write)r    r7   r@   rB   r-   s        r"   setz_FileCacheMixin.setJ   s-     xx}}D%     r,   r2   datac                   t           j                            |          }t          j        || j        d           |                     |dz             5  t          j        |          \  }}	 t          j        ||           t          j	        |           n# t          j	        |           w xY wt          j
        || j                   t          j        ||           ddd           dS # 1 swxY w Y   dS )z:
        Safely write the data to the given path.
        T)exist_okz.lock)dirN)r1   r2   dirnamemakedirsr   r   tempfilemkstempwriteclosechmodr   replace)r    r2   rH   rL   fdr-   s         r"   rF   z_FileCacheMixin._writeP   s   
 '//$''
GT\D9999__TG^,, 	# 	#!)g666JRT"""HT4=)))JtT"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#s*   C-.BC-B..2C--C14C1suffixc                    |                      |          |z   }| j        s(	 t          j        |           d S # t          $ r Y d S w xY wd S r'   )r6   r   r1   remover=   )r    r7   rU   r-   s       r"   _deletez_FileCacheMixin._deleteb   sb    xx}}v%| 		$$   	 	s   7 
AA)Fr   r   N)r   r   r   r   r   r   r   r   r   r   r   r   )r$   r%   r   r%   )r-   r%   r   r%   )r7   r%   r   r8   r'   )r7   r%   r@   rA   rB   rC   r   r   )r2   r%   rH   rA   r   r   )r7   r%   rU   r%   r   r   )__name__
__module____qualname____doc__r#   staticmethodr*   r6   r?   rG   rF   rX    r,   r"   r   r      s        <<
 04% % % % %: 6 6 6 \64 4 4 4    HL! ! ! ! !# # # #$     r,   r   c                      e Zd ZdZddZdS )		FileCachezc
    Traditional FileCache: body is stored in memory, so not suitable for large
    downloads.
    r7   r%   r   r   c                2    |                      |d           d S )N rX   r    r7   s     r"   deletezFileCache.deleteq   s    S"r,   Nr7   r%   r   r   )rY   rZ   r[   r\   re   r^   r,   r"   r`   r`   k   s2         
     r,   r`   c                  *    e Zd ZdZddZdd
ZddZdS )SeparateBodyFileCachezh
    Memory-efficient FileCache: body is stored in a separate file, reducing
    peak memory usage.
    r7   r%   r   IO[bytes] | Nonec                v    |                      |          dz   }	 t          |d          S # t          $ r Y d S w xY w)N.bodyr:   )r6   r;   r=   )r    r7   r-   s      r"   get_bodyzSeparateBodyFileCache.get_body{   sM    xx}}w&	d###  	 	 	44	s   * 
88bodyrA   r   c                b    |                      |          dz   }|                     ||           d S )Nrk   rE   )r    r7   rm   r-   s       r"   set_bodyzSeparateBodyFileCache.set_body   s0    xx}}w&D$r,   c                ^    |                      |d           |                      |d           d S )Nrb   rk   rc   rd   s     r"   re   zSeparateBodyFileCache.delete   s0    S"S'"""""r,   N)r7   r%   r   ri   )r7   r%   rm   rA   r   r   rf   )rY   rZ   r[   r\   rl   ro   re   r^   r,   r"   rh   rh   u   sZ         
          # # # # # #r,   rh   urlr%   	filecacher   c                T    t          j        |           }|                    |          S )z\Return the file cache path based on the URL.

    This does not ensure the file exists!
    )r
   	cache_urlr6   )rq   rr   r7   s      r"   url_to_file_pathru      s&    
 
#C
(
(C==r,   )rq   r%   rr   r`   r   r%   )
__future__r   r(   r1   rN   textwrapr   typingr   r   pathlibr   cachecontrol.cacher   r	   cachecontrol.controllerr
   r   r   r   r   r`   rh   ru   r^   r,   r"   <module>r|      sn   # " " " " "  				        $ $ $ $ $ $ $ $       ? ? ? ? ? ? ? ? 3 3 3 3 3 3 &!!!!!!%%%%%%R R R R R R R Rj       # # # # #O-B # # #,     r,   