
     d                         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 	 e	 n# e
$ r eefZ	Y nw xY wd Z G d d          Z G d	 d
ee          Z G d dee          Zd ZdS )    N)dedent   )	BaseCacheSeparateBodyBaseCache)CacheControllerc                    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          t          f$ 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IOErrorOSErroropenfdopenclose)filenamefmodeflagsfds       sC:\Users\ChattiNader\Documents\MyHotelMatch\api\dev\Lib\site-packages\pip/_vendor/cachecontrol/caches/file_cache.py_secure_open_writer      s    KE 
RZ")##E r<    r: 
	(W    
5%	(	(ByT"""
s   2B BB5C
 
C!c                   `    e Zd ZdZ	 	 	 	 	 ddZed             Zd Zd	 Zdd
Z	de
fdZd ZdS )_FileCacheMixinz2Shared implementation for both FileCache variants.F    Nc                     ||t          d          	 ddlm} ddlm} |r|}n1||}n,# t
          $ r t          d          }	t          |	          w xY w|| _        || _        || _	        || _
        || _        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#   notices
             r   __init__z_FileCacheMixin.__init__?   s     #
(>NOOO	&))))))<<<<<<  &*

#%
  	& 	& 	& F f%%%	&" # $s	   + )Ac                 r    t          j        |                                                                           S N)hashlibsha224encode	hexdigest)xs    r   r5   z_FileCacheMixin.encodef   s&    ~ahhjj))33555    c                     |                      |          }t          |d d                   |gz   }t          j        j        | j        g|R  S )N   )r5   listr   pathjoinr(   )r-   namehashedpartss       r   _fnz_FileCacheMixin._fnj   sM     T""VBQBZ  F8+w|DN3U3333r8   c                     |                      |          }	 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)rA   r   readFileNotFoundError)r-   keyr>   fhs       r   getz_FileCacheMixin.getq   s    xx}}	dD!! !Rwwyy! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! 	 	 	44	s3   A AA AA AA 
A#"A#c                 \    |                      |          }|                     ||           d S r2   rA   _write)r-   rF   valueexpiresr>   s        r   setz_FileCacheMixin.setz   s+    xx}}D%     r8   datac                    	 t          j        t           j                            |          | j                   n# t
          t          f$ r Y nw xY w|                     |          5 }t          |j        | 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.
        N)r   makedirsr<   dirnamer+   r   r   r,   r   r*   write)r-   r<   rO   lockrG   s        r   rK   z_FileCacheMixin._write~   s;   
	K--t|<<<<! 	 	 	D	 __T"" 	d#DIt}==               	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sE   7: AA&B;B#B;#B'	'B;*B'	+B;;B?B?c                     |                      |          |z   }| j        s(	 t          j        |           d S # t          $ r Y d S w xY wd S r2   )rA   r)   r   r   rE   )r-   rF   suffixr>   s       r   _deletez_FileCacheMixin._delete   sb    xx}}v%| 		$$   	 	s   7 
AA)Fr   r    NNr2   )__name__
__module____qualname____doc__r0   staticmethodr5   rA   rH   rN   bytesrK   rW    r8   r   r   r   <   s        <<
 %% %% %% %%N 6 6 \64 4 4  ! ! ! !        r8   r   c                       e Zd ZdZd ZdS )	FileCachezc
    Traditional FileCache: body is stored in memory, so not suitable for large
    downloads.
    c                 2    |                      |d           d S )N rW   r-   rF   s     r   deletezFileCache.delete   s    S"r8   N)rX   rY   rZ   r[   re   r^   r8   r   r`   r`      s-         
    r8   r`   c                   $    e Zd ZdZd Zd Zd ZdS )SeparateBodyFileCachezh
    Memory-efficient FileCache: body is stored in a separate file, reducing
    peak memory usage.
    c                 v    |                      |          dz   }	 t          |d          S # t          $ r Y d S w xY w)N.bodyrC   )rA   r   rE   )r-   rF   r>   s      r   get_bodyzSeparateBodyFileCache.get_body   sM    xx}}w&	d###  	 	 	44	s   * 
88c                 b    |                      |          dz   }|                     ||           d S )Nri   rJ   )r-   rF   bodyr>   s       r   set_bodyzSeparateBodyFileCache.set_body   s0    xx}}w&D$r8   c                 ^    |                      |d           |                      |d           d S )Nrb   ri   rc   rd   s     r   re   zSeparateBodyFileCache.delete   s0    S"S'"""""r8   N)rX   rY   rZ   r[   rj   rm   re   r^   r8   r   rg   rg      sK         
       # # # # #r8   rg   c                 T    t          j        |           }|                    |          S )z\Return the file cache path based on the URL.

    This does not ensure the file exists!
    )r   	cache_urlrA   )url	filecacherF   s      r   url_to_file_pathrs      s&    
 
#C
(
(C==r8   )r3   r   textwrapr   cacher   r   
controllerr   rE   	NameErrorr   r   r   r   r`   rg   rs   r^   r8   r   <module>rx      sB  
  				       4 4 4 4 4 4 4 4 ( ( ( ( ( (+ + + + '*+
& & &RW W W W W W W Wt       # # # # #O-B # # #,    s   ! 	--