
    eg              
          d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
mZmZmZmZmZ d dlmZmZmZ d dlmZ d dlmZ ded	efd
Zedede
d	eeddf   fd       Z ed ed       ed            Z eej:                        Zded	efdZded	efdZdeded	ee   fdZ ded	ee!e"f   fdZ#ded	efdZ$ded	ee!e"f   fdZ%ded	efdZ&y)    N)contextmanager)NamedTemporaryFile)AnyBinaryIO	GeneratorListUnioncast)retrystop_after_delay
wait_fixed)get_path_uid)format_sizepathreturnc                    t         j                  dk(  st        t        d      syt        j                  j                  |       sJ d }| |k7  rt        j                  j                  |       rLt        j                         dk(  r	 t        |       }|dk(  S t        j                  | t        j                        S | t        j                  j                  |       } }| |k7  ry# t        $ r Y yw xY w)Nwin32geteuidTr   F)sysplatformhasattrosr   isabslexistsr   r   OSErroraccessW_OKdirname)r   previouspath_uids      {/var/www/html/FastMealFinder_FlaskServer-InitialRelease/venv/lib/python3.12/site-packages/pip/_internal/utils/filesystem.pycheck_path_ownerr"      s     ||wgb)&<77==H
(
77??4 zz|q !+D1H  1}$yyrww//!277??4#8dH (
   ! !s   C   	C,+C,kwargsc              +     K   t        ddt        j                  j                  |       t        j                  j	                  |       dd|5 }t        t        |      }	 | |j                          t        j                  |j                                	 ddd       y# |j                          t        j                  |j                                w xY w# 1 sw Y   yxY ww)a%  Return a file-like object pointing to a tmp file next to path.

    The file is created securely and is ensured to be written to disk
    after the context reaches its end.

    kwargs will be passed to tempfile.NamedTemporaryFile to control
    the way the temporary file will be opened.
    Fz.tmp)deletedirprefixsuffixN )
r   r   r   r   basenamer
   r   flushfsyncfileno)r   r#   fresults       r!   adjacent_tmp_filer0   +   s      
 
GGOOD!ww%	

 
 & 
h"	&LLLNHHV]]_%& & LLNHHV]]_%& &s6   AC$CB #3C	C$ 5CCC!C$T   g      ?)reraisestopwaitc                 R   t         j                  j                  |       sGt         j                  j                  |       }|| k(  rn"|} t         j                  j                  |       sGt         j                  dk(  r$t        j
                  | t         j                        S t        |       S )zgCheck if a directory is writable.

    Uses os.access() on POSIX, tries creating files on Windows.
    posix)r   r   isdirr   namer   r   _test_writable_dir_win)r   parents     r!   test_writable_dirr;   L   su     ggmmD!&T>	 ggmmD! 
ww'yyrww''!$''    c                    d}dt        d      D ]  }|dj                  fdt        d      D              z   }t        j                  j                  | |      }	 t        j                  |t        j
                  t        j                  z  t        j                  z        }t        j                  |       t        j                  |        y t        d	      # t        $ r Y t        $ r Y  yw xY w)
N(accesstest_deleteme_fishfingers_custard_$abcdefghijklmnopqrstuvwxyz0123456789
    c              3   H   K   | ]  }t        j                          y wN)randomchoice).0_alphabets     r!   	<genexpr>z)_test_writable_dir_win.<locals>.<genexpr>d   s     !La&--"9!Ls   "   TFz3Unexpected condition testing for writable directory)rangejoinr   r   openO_RDWRO_CREATO_EXCLcloseunlinkFileExistsErrorPermissionErrorr   )r   r*   rG   r8   filefdrH   s         @r!   r9   r9   ^   s     :H5H2Y "''!L58!LLLww||D$'	ryy2::5		ABB HHRLIIdO#( G
HH  	 	 	s   AC	C0$C0/C0patternc                     g }t        j                  |       D ]6  \  }}t        j                  ||      }|j	                  fd|D               8 |S )zReturns a list of absolute paths of files beneath path, recursively,
    with filenames which match the UNIX-style shell glob pattern.c              3   ^   K   | ]$  }t         j                  j                  |       & y wrC   )r   r   rL   )rF   r.   roots     r!   rI   zfind_files.<locals>.<genexpr>   s      =bggll4+=s   *-)r   walkfnmatchfilterextend)r   rW   r/   rG   filesmatchesrZ   s         @r!   
find_filesra   z   sP     F''$- >a..0=W==> Mr<   c                     t         j                  j                  |       ryt         j                  j                  |       S )Nr   )r   r   islinkgetsizer   s    r!   	file_sizerf      s(    	ww~~d77??4  r<   c                 *    t        t        |             S rC   )r   rf   re   s    r!   format_file_sizerh      s    y''r<   c                     d}t        j                  |       D ];  \  }}}|D ]0  }t         j                  j                  ||      }|t	        |      z  }2 = |S )Ng        )r   r[   r   rL   rf   )r   sizerZ   _dirsr_   filename	file_paths          r!   directory_sizern      s^    D ggdm )eU 	)HT84IIi((D	)) Kr<   c                 *    t        t        |             S rC   )r   rn   re   s    r!   format_directory_sizerp      s    ~d+,,r<   )'r\   r   os.pathrD   r   
contextlibr   tempfiler   typingr   r   r   r   r	   r
   pip._vendor.tenacityr   r   r   pip._internal.utils.compatr   pip._internal.utils.miscr   strboolr"   r0   _replace_retryreplacer;   r9   ra   intfloatrf   rh   rn   rp   r)   r<   r!   <module>r~      sB    	   
 % ' > > D D 3 03 4 6 &C &3 &9XtT=Q3R & &2 t*:1*=JtDTU

$
(C (D ($I I I8S 3 49 !C !E#u*- !(3 (3 ( sEz!2 - - -r<   