
    VPi                    T   d dl mZ 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 d dlmZ d dlmZmZmZmZ d dlmZ d d	lmZ d d
lmZ d,dZe
d-d            Z  edd          ej                  Zd,dZd,dZd.dZd/dZ d0dZ!d/dZ"d0d Z#d1d%Z$d2d)Z%d3d*Z&d3d+Z'dS )4    )annotationsN)	Generator)contextmanager)Path)NamedTemporaryFile)AnyBinaryIOCallablecast)get_path_uid)format_size)retrypathstrreturnboolc                   t           j        dk    st          t          d          sdS t          j                            |           sJ d }| |k    rt          j                            |           r^t          j                    dk    r(	 t          |           }n# t          $ r Y dS w xY w|dk    S t          j
        | t          j                  S | t          j                            |           } }| |k    dS )Nwin32geteuidTr   F)sysplatformhasattrosr   isabslexistsr   r   OSErroraccessW_OKdirname)r   previouspath_uids      r/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/pip/_internal/utils/filesystem.pycheck_path_ownerr#      s     |wgb)&<&<t7==H
(

7??4   	9z||q  !+D11HH ! ! ! 55!1}$yrw///!27??4#8#8dH (

 5s   B 
B&%B&kwargsr   Generator[BinaryIO, None, None]c              +    K   t          ddt          j                            |           t          j                            |           dd|5 }t          t          |          }	 |V  |                                 t          j        |	                                           n?# |                                 t          j        |	                                           w xY w	 ddd           dS # 1 swxY w Y   dS )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_filer2   .   s0      
 
GOOD!!w%%	
 

 
 
 & 
h""	&LLLLLNNNHV]]__%%%% LLNNNHV]]__%%%%%& & & & & & & & & & & & & & & & & &s*   C1%B$);C1$<C  C11C58C5   g      ?)stop_after_delaywaitc                J   t           j                            |           sGt           j                            |           }|| k    rn!|} t           j                            |           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   s     gmmD!! &&T>>	 gmmD!!  
w'yrw'''!$'''    c                   d}dt          d          D ]}|d                    fdt          d          D                       z   }t          j                            | |          }	 t          j        |t          j        t          j        z  t          j        z            }t          j        |           t          j	        |            dS # t          $ r Y t          $ r Y  dS w xY wt          d	          )
N(accesstest_deleteme_fishfingers_custard_$abcdefghijklmnopqrstuvwxyz0123456789
    c              3  @   K   | ]}t          j                  V  d S N)randomchoice).0_alphabets     r"   	<genexpr>z)_test_writable_dir_win.<locals>.<genexpr>d   s-      !L!La&-"9"9!L!L!L!L!L!Lr=      TFz3Unexpected condition testing for writable directory)rangejoinr   r   openO_RDWRO_CREATO_EXCLcloseunlinkFileExistsErrorPermissionErrorr   )r   r,   rH   r9   filefdrI   s         @r"   r:   r:   ^   s    :H5H2YY  "''!L!L!L!L588!L!L!LLLLw||D$''	ry2:5	ABBB HRLLLIdOOO44  	 	 	D 	 	 	 555	 G
H
HHs   )9C
C'	C'&C'pattern	list[str]c                    g }t          j        |           D ]<\  }}t          j        ||          }|                    fd|D                        =|S )zReturns a list of absolute paths of files beneath path, recursively,
    with filenames which match the UNIX-style shell glob pattern.c              3  X   K   | ]$}t           j                            |          V  %d S rD   )r   r   rM   )rG   r0   roots     r"   rJ   zfind_files.<locals>.<genexpr>   s3      ==bgll4++======r=   )r   walkfnmatchfilterextend)r   rX   r1   rH   filesmatchesr\   s         @r"   
find_filesrc   z   sg     F'$-- > >a.00====W=======Mr=   int | floatc                    t           j                            |           rdS t           j                            |           S Nr   )r   r   islinkgetsizer   s    r"   	file_sizerj      s1    	w~~d q7??4   r=   c                :    t          t          |                     S rD   )r   rj   ri   s    r"   format_file_sizerl      s    y'''r=   c                    d}t          j        |           D ]=\  }}}|D ]4}t           j                            ||          }|t	          |          z  }5>|S )Ng        )r   r]   r   rM   rj   )r   sizer\   _dirsra   filename	file_paths          r"   directory_sizerr      si    D gdmm ) )eU 	) 	)HT844IIi(((DD	) Kr=   c                :    t          t          |                     S rD   )r   rr   ri   s    r"   format_directory_sizert      s    ~d++,,,r=   	directorytarget_filer	   Nonec                2   t          j        |           j        dz  dz  }t           j        t           j        v r)t          j        |                                |           d S t           j        t           j        v rt          j        |j        |d           d S d S )Ni  i  F)follow_symlinks)r   statst_modechmodsupports_fdr/   supports_follow_symlinksr9   )ru   rv   modes      r"   copy_directory_permissionsr      s    
	"U*
	 	
 
x2>!!
##%%t,,,,,	R0	0	0
!4?????? 
1	0r=   	predicate Callable[[str, list[str]], bool]Generator[Path]c              #    K   g }t                      }t          j        t          |                                                     D ]z\  }}}t          |          } |||          rD|                    t          |j                  dd                    |                    |           |	                    |           {t          |d          D ]
}||vr|V  dS )zZYields every subdirectory of +path+ that has no files matching the
    predicate under it.NT)reverse)setr   r]   r   resolveupdatelistparentsaddappendsorted)	r   r   directoriesexcludedroot_strrH   	filenamesr\   ds	            r"   _subdirs_without_genericr      s       KuuH"$'$t***<*<*>*>"?"? 
! 
!!YH~~9Xy)) 	 OOD..ss3444LL4    K...  HGGG r=   c                $    t          | d           S )z?Yields every subdirectory of +path+ that has no files under it.c                (    t          |          dk    S rf   )lenr\   r   s     r"   <lambda>z'subdirs_without_files.<locals>.<lambda>   s    #i..STBT r=   r   ri   s    r"   subdirs_without_filesr      s    #D*T*TUUUr=   c                $    t          | d           S )zDYields every subdirectory of +path+ that has no .whl files under it.c                4    t          d |D                       S )Nc              3  @   K   | ]}|                     d           V  dS )z.whlN)endswith)rG   xs     r"   rJ   z;subdirs_without_wheels.<locals>.<lambda>.<locals>.<genexpr>   s.      )P)P!**V*<*<)P)P)P)P)P)Pr=   )anyr   s     r"   r   z(subdirs_without_wheels.<locals>.<lambda>   s    c)P)Pi)P)P)P&P&P r=   r   ri   s    r"   subdirs_without_wheelsr      s    #PP  r=   )r   r   r   r   )r   r   r$   r   r   r%   )r   r   rX   r   r   rY   )r   r   r   rd   )r   r   r   r   )ru   r   rv   r	   r   rw   )r   r   r   r   r   r   )r   r   r   r   )(
__future__r   r^   r   os.pathrE   r   collections.abcr   
contextlibr   pathlibr   tempfiler   typingr   r	   r
   r   pip._internal.utils.compatr   pip._internal.utils.miscr   pip._internal.utils.retryr   r#   r2   replacer<   r:   rc   rj   rl   rr   rt   r   r   r   r   r+   r=   r"   <module>r      s.   " " " " " "  				   



 % % % % % % % % % % % %       ' ' ' ' ' ' 0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 3 3 3 0 0 0 0 0 0 + + + + + +   6 & & & &0 /%%
.
.
.rz
:
:
( ( ( ($I I I I8   ! ! ! !( ( ( (   - - - -	@ 	@ 	@ 	@   4V V V V
     r=   