
    Kui                    V   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j8                        ZddZddZddZddZ ddZ!ddZ"ddZ#d dZ$	 	 	 	 	 	 d!dZ%d"dZ&d"dZ'y)#    )annotationsN)	Generator)contextmanager)Path)NamedTemporaryFile)AnyBinaryIOCallablecast)get_path_uid)format_size)retryc                   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ospathisabslexistsr   r   OSErroraccessW_OKdirname)r   previouspath_uids      h/root/.openclaw/workspace/chatterbox_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,c              +    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   kwargsfresults       r   adjacent_tmp_filer.   .   s      
 
GGOOD!ww%	

 
 & 
h"	&LLLNHHV]]_%& & LLNHHV]]_%& &s6   AC$CB #3C	C$ 5CCC!C$   g      ?)stop_after_delay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_dirr8   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'   rD   r5   filefdrE   s         @r   r6   r6   ^   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c                    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r@   )r   r   rI   )rC   r,   roots     r   rF   zfind_files.<locals>.<genexpr>   s      =bggll4+=s   *-)r   walkfnmatchfilterextend)r   patternr-   rD   filesmatchesrV   s         @r   
find_filesr^   z   sP     F''$- >a..0=W==> Mr9   c                    t         j                  j                  |       ryt         j                  j                  |       S Nr   )r   r   islinkgetsizer   s    r   	file_sizerd      s(    	ww~~d77??4  r9   c                *    t        t        |             S r@   )r   rd   rc   s    r   format_file_sizerf      s    y''r9   c                    d}t        j                  |       D ];  \  }}}|D ]0  }t         j                  j                  ||      }|t	        |      z  }2 = |S )Ng        )r   rW   r   rI   rd   )r   sizerV   _dirsr\   filename	file_paths          r   directory_sizerl      s^    D ggdm )eU 	)HT84IIi((D	)) Kr9   c                *    t        t        |             S r@   )r   rl   rc   s    r   format_directory_sizern      s    ~d+,,r9   c                ^   t        j                  |       j                  dz  dz  }t         j                  t         j                  v r%t        j                  |j                         |       y t         j                  t         j                  v r#t        j                  |j                  |d       y y )Ni  i  F)follow_symlinks)r   statst_modechmodsupports_fdr*   supports_follow_symlinksr5   )	directorytarget_filemodes      r   copy_directory_permissionsry      s|    
	""U*
	 	
 
xx2>>!
##%t,	R00	0
!!4? 
1r9   c              #  ~  K   g }t               }t        j                  t        |       j	                               D ]c  \  }}}t        |      } |||      r8|j                  t        |j                        dd        |j                  |       |j                  |       e t        |d      D ]  }||vs|  yw)zZYields every subdirectory of +path+ that has no files matching the
    predicate under it.NT)reverse)setr   rW   r   resolveupdatelistparentsaddappendsorted)	r   	predicatedirectoriesexcludedroot_strrD   	filenamesrV   ds	            r   _subdirs_without_genericr      s      KuH"$''$t**<*<*>"? 
!!YH~Xy) OOD.s34LL4 
! K. HGs   B3B=6B=c                    t        | d       S )z?Yields every subdirectory of +path+ that has no files under it.c                    t        |      dkD  S r`   )lenrV   r   s     r   <lambda>z'subdirs_without_files.<locals>.<lambda>   s    #i.STBT r9   r   rc   s    r   subdirs_without_filesr      s    #D*TUUr9   c                    t        | d       S )zDYields every subdirectory of +path+ that has no .whl files under it.c                &    t        d |D              S )Nc              3  >   K   | ]  }|j                  d         yw)z.whlN)endswith)rC   xs     r   rF   z;subdirs_without_wheels.<locals>.<lambda>.<locals>.<genexpr>   s     )P!**V*<)Ps   )anyr   s     r   r   z(subdirs_without_wheels.<locals>.<lambda>   s    c)Pi)P&P r9   r   rc   s    r   subdirs_without_wheelsr      s    #P r9   )r   strreturnbool)r   r   r+   r   r   zGenerator[BinaryIO, None, None])r   r   r[   r   r   z	list[str])r   r   r   zint | float)r   r   r   r   )rv   r   rw   r	   r   None)r   r   r   z Callable[[str, list[str]], bool]r   Generator[Path])r   r   r   r   )(
__future__r   rX   r   os.pathrA   r   collections.abcr   
contextlibr   pathlibr   tempfiler   typingr   r	   r
   r   pip._internal.utils.compatr   pip._internal.utils.miscr   pip._internal.utils.retryr   r    r.   replacer8   r6   r^   rd   rf   rl   rn   ry   r   r   r   r&   r9   r   <module>r      s    "  	   
 % %  ' 0 0 3 0 +6 & &0 /%
.rzz
:
($I8!(-	@
:4V
r9   