a [f@sddlZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z m Z mZmZmZmZddlmZmZmZddlmZddlmZeedd d Zeedd d d ZeedddZeee ee dddZedededdZ e ej!Z!eedddZ"eedddZ#eeeedddZ$eee%e&fdddZ'eedd d!Z(eee%e&fdd"d#Z)eedd$d%Z*dS)&N)contextmanager)NamedTemporaryFile)AnyBinaryIOIteratorListUnioncast)retrystop_after_delay wait_fixed) get_path_uid) format_size)pathreturncCstjdksttdsdStj|s(Jd}||krtj|rtdkrvz t|}Wnt ylYdS0|dkSt |tj Sq,|tj |}}q,dS)Nwin32geteuidTrF) sysplatformhasattrosrisabslexistsrr OSErroraccessW_OKdirname)rZpreviousZpath_uidrB/usr/lib/python3.9/site-packages/pip/_internal/utils/filesystem.pycheck_path_owners    r)srcdestrc Csnzt||WnXtyh||fD]:}z t|}WntyHYq&0|r&td|dq&Yn0dS)zWrap shutil.copy2() but map errors copying socket files to SpecialFileError as expected. See also https://bugs.python.org/issue37700. `z ` is a socketN)shutilcopy2r is_socketSpecialFileError)r r!fZis_socket_filerrr copy2_fixed-s    r(cCstt|jSN)statS_ISSOCKrlstatst_moderrrrr%Dsr%)rkwargsrc kstfdtj|tj|dd|T}tt|}z |VW|t| n|t| 0Wdn1s0YdS)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)deletedirprefixsuffixN) rrrrbasenamer rflushfsyncfileno)rr/r'resultrrradjacent_tmp_fileHs    r9Tg?)ZreraisestopwaitcCsHtj|s(tj|}||kr"q(|}qtjdkr@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   rBc sd}dtdD]}|dfddtdD}tj||}zt|tjtjBtjB}Wn&tyrYqt yYdS0t |t |d Sqt d dS) NZ(accesstest_deleteme_fishfingers_custard_Z$abcdefghijklmnopqrstuvwxyz0123456789 c3s|]}tVqdSr))randomchoice).0_Zalphabetrr z)_test_writable_dir_win..FTz3Unexpected condition testing for writable directory) rangejoinrropenO_RDWRO_CREATO_EXCLFileExistsErrorPermissionErrorcloseunlinkr)rr4rHr?filefdrrIrr@{s       r@)rpatternrcsBg}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))rrrN)rGr'rootrrrJrKzfind_files..)rwalkfnmatchfilterextend)rrYr8rHfilesmatchesrrZr find_filess  rbcCstj|rdStj|S)Nr)rrislinkgetsizer.rrr file_sizes recCs tt|Sr))rrer.rrrformat_file_sizesrfcCsBd}t|D].\}}}|D]}tj||}|t|7}qq|S)Ng)rr\rrNre)rsizer[Z_dirsr`filenameZ file_pathrrrdirectory_sizes ricCs tt|Sr))rrir.rrrformat_directory_sizesrj)+r]rZos.pathrEr#r*r contextlibrZtempfilertypingrrrrrr Zpip._vendor.tenacityr r r Zpip._internal.utils.compatr Zpip._internal.utils.miscrstrboolrr(r%r9Z_replace_retryreplacerBr@rbintfloatrerfrirjrrrrs4