o
    tBh9                     @   s|   d dl Z d dlZd dlmZ ddl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	eZd
d ZdS )    N)dedent   )	BaseCache)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   u/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/cachecontrol/caches/file_cache.py_secure_open_write   s"   




r   c                   @   sL   e Zd Z					dddZedd Zd	d
 Zdd Zdd Zdd Z	dS )	FileCacheF    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FileCache.__init__c                 C   s   t |   S N)hashlibsha224encode	hexdigest)xr   r   r   r0   a   s   zFileCache.encodec                 C   s6   |  |}t|d d |g }tjj| jg|R  S )N   )r0   listr	   pathjoinr$   )r)   namehashedpartsr   r   r   _fne   s   
zFileCache._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)   keyr7   fhr   r   r   getl   s   
(zFileCache.getc              	   C   s   |  |}zttj|| j W n ttfy   Y nw | |-}t	|j| j
}|| W d    n1 s;w   Y  W d    d S W d    d S 1 sSw   Y  d S r-   )r:   r	   makedirsr5   dirnamer'   r   r   r(   r   r&   write)r)   r>   valuer7   lockr?   r   r   r   setu   s   
"zFileCache.setc                 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>   r7   r   r   r   delete   s   
zFileCache.delete)Fr   r   NN)
__name__
__module____qualname__r,   staticmethodr0   r:   r@   rF   rG   r   r   r   r   r   8   s    
'
	r   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   

rO   )r.   r	   textwrapr   cacher   
controllerr   r=   	NameErrorr   r   r   r   rO   r   r   r   r   <module>   s    )T