
    f                        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dS )    )annotationsN)dedent)IOTYPE_CHECKINGUnion)Path)	BaseCacheSeparateBodyBaseCache)CacheController)datetime)BaseFileLockfilenamestrfmodeintreturn	IO[bytes]c                   t           j        }|t           j        t           j        z  z  }t	          t           d          r|t           j        z  }t	          t           d          r|t           j        z  }	 t          j        |            n# t          $ r Y nw xY wt          j	        | ||          }	 t          j
        |d          S #  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)r   r   flagsfds       X/var/www/html/Alfredo/env/lib/python3.11/site-packages/cachecontrol/caches/file_cache.py_secure_open_writer%      s    KE 
RZ")##E r<    r: 
	(    
5%	(	(ByT"""
s   2B 
BB.C Cc                  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filemoder   dirmode
lock_classtype[BaseFileLock] | Noner   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]
            )	filelockr4   ImportErrorr   r*   r,   r.   r/   r0   )selfr*   r,   r.   r/   r0   r4   notices           r$   __init__z_FileCacheMixin.__init__A   s    	&!------%
 	& 	& 	& F f%%%	& # $s   
 )6xr   c                r    t          j        |                                                                           S N)hashlibsha224encode	hexdigest)r:   s    r$   r?   z_FileCacheMixin.encode^   s&    ~ahhjj))33555    namec                    |                      |          }t          |d d                   |gz   }t          j        j        | j        g|R  S )N   )r?   listr   pathjoinr*   )r7   rB   hashedpartss       r$   _fnz_FileCacheMixin._fnb   sM     T""VBQBZ  F8+w|DN3U3333rA   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)rJ   r   readFileNotFoundError)r7   rK   rB   fhs       r$   getz_FileCacheMixin.geti   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<   rJ   _write)r7   rK   rS   rU   rB   s        r$   setz_FileCacheMixin.setr   s-     xx}}D%     rA   rF   datac                ~   	 t          j        t           j                            |          | j                   n# t
          $ r Y nw xY w|                     |dz             5  t          || j                  5 }|	                    |           ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )z:
        Safely write the data to the given path.
        z.lockN)
r   makedirsrF   dirnamer/   r   r0   r%   r.   write)r7   rF   r[   rQ   s       r$   rY   z_FileCacheMixin._writex   s;   
	K--t|<<<< 	 	 	D	 __TG^,, 	 	#D$-88 B              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sE   7: 
AA"B28BB2B	B2!B	"B22B69B6suffixc                    |                      |          |z   }| j        s(	 t          j        |           d S # t          $ r Y d S w xY wd S r<   )rJ   r,   r   r   rP   )r7   rK   r`   rB   s       r$   _deletez_FileCacheMixin._delete   sb    xx}}v%| 		$$   	 	s   7 
AA)Fr(   r)   N)r*   r+   r,   r-   r.   r   r/   r   r0   r1   r   r2   )r:   r   r   r   )rB   r   r   r   )rK   r   r   rL   r<   )rK   r   rS   rT   rU   rV   r   r2   )rF   r   r[   rT   r   r2   )rK   r   r`   r   r   r2   )__name__
__module____qualname____doc__r9   staticmethodr?   rJ   rR   rZ   rY   rb    rA   r$   r'   r'   >   s        <<
 04% % % % %: 6 6 6 \64 4 4 4    HL! ! ! ! !        rA   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.
    rK   r   r   r2   c                2    |                      |d           d S )N rb   r7   rK   s     r$   deletezFileCache.delete   s    S"rA   NrK   r   r   r2   )rc   rd   re   rf   ro   rh   rA   r$   rj   rj      s2         
     rA   rj   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.
    rK   r   r   IO[bytes] | Nonec                v    |                      |          dz   }	 t          |d          S # t          $ r Y d S w xY w)N.bodyrN   )rJ   r   rP   )r7   rK   rB   s      r$   get_bodyzSeparateBodyFileCache.get_body   sM    xx}}w&	d###  	 	 	44	s   * 
88bodyrT   r2   c                b    |                      |          dz   }|                     ||           d S )Nru   rX   )r7   rK   rw   rB   s       r$   set_bodyzSeparateBodyFileCache.set_body   s0    xx}}w&D$rA   c                ^    |                      |d           |                      |d           d S )Nrl   ru   rm   rn   s     r$   ro   zSeparateBodyFileCache.delete   s0    S"S'"""""rA   N)rK   r   r   rs   )rK   r   rw   rT   r   r2   rp   )rc   rd   re   rf   rv   ry   ro   rh   rA   r$   rr   rr      sZ         
          # # # # # #rA   rr   url	filecachec                T    t          j        |           }|                    |          S )z\Return the file cache path based on the URL.

    This does not ensure the file exists!
    )r   	cache_urlrJ   )r{   r|   rK   s      r$   url_to_file_pathr      s&    
 
#C
(
(C==rA   )r   r   r   r   r   r   )r{   r   r|   rj   r   r   )
__future__r   r=   r   textwrapr   typingr   r   r   pathlibr   cachecontrol.cacher	   r
   cachecontrol.controllerr   r   r5   r   r%   r'   rj   rr   r   rh   rA   r$   <module>r      s   # " " " " "  				       + + + + + + + + + +       ? ? ? ? ? ? ? ? 3 3 3 3 3 3 &!!!!!!%%%%%%& & & &RO O O O O O O Od       # # # # #O-B # # #,     rA   