o Ec@sddlZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z m Z mZmZmZmZddlmZmZmZddlmZddlmZded efd d Zd ed ed dfddZded efddZedede d ee fddZedededdZ e ej!Z!ded efddZ"ded efddZ#deded eefddZ$ded ee%e&ffd d!Z'ded efd"d#Z(ded ee%e&ffd$d%Z)ded efd&d'Z*dS)(N)contextmanager)NamedTemporaryFile)AnyBinaryIOIteratorListUnioncast)retrystop_after_delay wait_fixed) get_path_uid) format_sizepathreturncCstjdks ttds dStj|sJd}||krNtj|rAtdkr:z t|}W|dkSt y9YdSwt |tj S|tj |}}||ksdS)NZwin32geteuidTrF) sysplatformhasattrosrisabslexistsrr OSErroraccessW_OKdirname)rZpreviousZpath_uidrQ/opt/alt/python310/lib/python3.10/site-packages/pip/_internal/utils/filesystem.pycheck_path_owners"    rsrcdestc Cshz t||WdSty3||fD]}zt|}Wn ty%Yqw|r1td|dqw)zWrap shutil.copy2() but map errors copying socket files to SpecialFileError as expected. See also https://bugs.python.org/issue37700. `z ` is a socketN)shutilZcopy2r is_socketZSpecialFileError)rr fZis_socket_filerrr copy2_fixed-s    r%cCstt|jSN)statS_ISSOCKrlstatst_moderrrrr#Dsr#kwargsc kstddtj|tj|dd|+}tt|}z|VW|t| n |t| wWddS1sCwYdS)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)deletedirprefixsuffixNr) rrrrbasenamer rflushfsyncfileno)rr,r$resultrrradjacent_tmp_fileHs$    "r6Tg?)ZreraisestopwaitcCsRtj|stj|}||krn|}tj|rtjdkr%t|tjSt|S)zgCheck if a directory is writable. Uses os.access() on POSIX, tries creating files on Windows. posix)rrisdirrnamerr_test_writable_dir_win)rparentrrrtest_writable_diris   r?c sd}dtdD]H}|dfddtdD}tj||}zt|tjtjBtjB}Wnty9Yqt yCYdSwt |t |d St d ) NZ(accesstest_deleteme_fishfingers_custard_Z$abcdefghijklmnopqrstuvwxyz0123456789 c3s|]}tVqdSr&)randomZchoice).0_Zalphabetrr sz)_test_writable_dir_win..FTz3Unexpected condition testing for writable directory) rangejoinrropenO_RDWRO_CREATO_EXCLFileExistsErrorPermissionErrorcloseunlinkr)rr1rDr<filefdrrErr={s       r=patterncsBg}t|D]\}}t||}|fdd|Dq|S)zReturns a list of absolute paths of files beneath path, recursively, with filenames which match the UNIX-style shell glob pattern.c3s|] }tj|VqdSr&)rrrI)rCr$rootrrrFszfind_files..)rwalkfnmatchfilterextend)rrTr5rDfilesZmatchesrrUr find_filess  r\cCstj|rdStj|S)Nr)rrislinkgetsizer+rrr file_sizes  r_cC tt|Sr&)rr_r+rrrformat_file_size racCsBd}t|D]\}}}|D]}tj||}|t|7}qq|S)Ng)rrWrrIr_)rsizerVZ_dirsr[filenameZ file_pathrrrdirectory_sizesrecCr`r&)rrer+rrrformat_directory_sizerbrf)+rXrZos.pathrBr"r'r contextlibrZtempfilertypingrrrrrr Zpip._vendor.tenacityr r r Zpip._internal.utils.compatr Zpip._internal.utils.miscrstrboolrr%r#r6Z_replace_retryreplacer?r=r\intfloatr_rarerfrrrrs6