a
    [f                     @   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	yV   e
efZY n0 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yb   Y n0 t 
| ||}zt |dW S    t |  Y n0 d S )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   |C:\Users\91910\OneDrive\Desktop\vts_admin_rebuild-master\vts\Lib\site-packages\pip/_vendor/cachecontrol/caches/file_cache.py_secure_open_write   s     




r   c                   @   sD   e 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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yV   td}	t|	Y n0 |rb|}n|d u rn|}|| _|| _|| _	|| _
|| _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   e   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   _fni   s    
zFileCache._fnc                 C   s\   |  |}z8t|d}| W  d    W S 1 s60    Y  W n tyV   Y d S 0 d S )Nrb)r:   r   readFileNotFoundError)r)   keyr7   fhr   r   r   getp   s    
,zFileCache.getc              	   C   s   |  |}zttj|| j W n ttfy:   Y n0 | |H}t	|j| j
}|| W d    n1 sv0    Y  W d    n1 s0    Y  d S r-   )r:   r	   makedirsr5   dirnamer'   r   r   r(   r   r&   write)r)   r>   valueexpiresr7   lockr?   r   r   r   sety   s    
zFileCache.setc                 C   s6   |  |}| js2zt| W n ty0   Y n0 d S r-   )r:   r%   r	   r   r=   )r)   r>   r7   r   r   r   delete   s    
zFileCache.delete)Fr   r   NN)N)
__name__
__module____qualname__r,   staticmethodr0   r:   r@   rG   rH   r   r   r   r   r   <   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    
rP   )r.   r	   textwrapr   cacher   
controllerr   r=   	NameErrorr   r   r   r   rP   r   r   r   r   <module>   s   )T