o
    a+)h                     @   s   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 ze	 W n e
y-   eefZ	Y nw dd ZG dd	 d	ZG d
d deeZG dd deeZdd ZdS )    N)dedent   )	BaseCacheSeparateBodyBaseCache)CacheControllerc              	   C   s   t j}|t jt jB O }tt dr|t jO }tt dr|t jO }zt |  W n tt	fy1   Y nw t 
| ||}zt |dW S    t |  )N
O_NOFOLLOWO_BINARYwb)osO_WRONLYO_CREATO_EXCLhasattrr   r   removeIOErrorOSErroropenfdopenclose)filenamefmodeflagsfd r   iC:\Users\User\Downloads\Proyecto_IoT\venv\Lib\site-packages\pip/_vendor/cachecontrol/caches/file_cache.py_secure_open_write   s"   




r   c                   @   s`   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e
fddZdd ZdS )_FileCacheMixinz2Shared implementation for both FileCache variants.F    Nc           
      C   s   |d ur|d urt dzddlm} ddlm} W n ty)   td}	t|	w |r/|}n|d u r5|}|| _|| _|| _	|| _
|| _d S )Nz/Cannot use use_dir_lock and lock_class togetherr   )LockFile)MkdirLockFilez
            NOTE: In order to use the FileCache you must have
            lockfile installed. You can install it via pip:
              pip install lockfile
            )
ValueErrorlockfiler   lockfile.mkdirlockfiler    ImportErrorr   	directoryforeverfilemodedirmode
lock_class)
selfr%   r&   r'   r(   use_dir_lockr)   r   r    noticer   r   r   __init__?   s(   

z_FileCacheMixin.__init__c                 C   s   t |   S N)hashlibsha224encode	hexdigest)xr   r   r   r1   f   s   z_FileCacheMixin.encodec                 C   s6   |  |}t|d d |g }tjj| jg|R  S )N   )r1   listr
   pathjoinr%   )r*   namehashedpartsr   r   r   _fnj   s   
z_FileCacheMixin._fnc                 C   sZ   |  |}zt|d}| W  d    W S 1 sw   Y  W d S  ty,   Y d S w )Nrb)r;   r   readFileNotFoundError)r*   keyr8   fhr   r   r   getq   s   
(z_FileCacheMixin.getc                 C   s   |  |}| || d S r.   r;   _write)r*   r?   valueexpiresr8   r   r   r   setz   s   
z_FileCacheMixin.setdatac              	   C   s   zt t j|| j W n ttfy   Y nw | |-}t|j| j	}|
| W d   n1 s6w   Y  W d   dS W d   dS 1 sNw   Y  dS )z:
        Safely write the data to the given path.
        N)r
   makedirsr6   dirnamer(   r   r   r)   r   r'   write)r*   r6   rG   lockr@   r   r   r   rC   ~   s   "z_FileCacheMixin._writec                 C   s>   |  || }| jszt| W d S  ty   Y d S w d S r.   )r;   r&   r
   r   r>   )r*   r?   suffixr8   r   r   r   _delete   s   z_FileCacheMixin._delete)Fr   r   NNr.   )__name__
__module____qualname____doc__r-   staticmethodr1   r;   rA   rF   bytesrC   rM   r   r   r   r   r   <   s    
'

	r   c                   @   s   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.
    c                 C   s   |  |d d S )N rM   r*   r?   r   r   r   delete   s   zFileCache.deleteN)rN   rO   rP   rQ   rX   r   r   r   r   rT      s    rT   c                   @   s(   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.
    c                 C   s0   |  |d }zt|dW S  ty   Y d S w )N.bodyr<   )r;   r   r>   )r*   r?   r8   r   r   r   get_body   s   zSeparateBodyFileCache.get_bodyc                 C   s   |  |d }| || d S )NrZ   rB   )r*   r?   bodyr8   r   r   r   set_body   s   zSeparateBodyFileCache.set_bodyc                 C   s   |  |d |  |d d S )NrU   rZ   rV   rW   r   r   r   rX      s   zSeparateBodyFileCache.deleteN)rN   rO   rP   rQ   r[   r]   rX   r   r   r   r   rY      s
    rY   c                 C   s   t | }||S )z\Return the file cache path based on the URL.

    This does not ensure the file exists!
    )r   	cache_urlr;   )url	filecacher?   r   r   r   url_to_file_path   s   

ra   )r/   r
   textwrapr   cacher   r   
controllerr   r>   	NameErrorr   r   r   r   rT   rY   ra   r   r   r   r   <module>   s   )Z
