Current File : //lib/python3.9/site-packages/pip/_internal/utils/__pycache__/filesystem.cpython-39.pyc
a

[��f�@s�ddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZm
Z
mZmZmZmZddlmZmZmZddlmZddlmZeed�d	d
�Zeedd�dd
�Zeed�dd�Zeeeee
d�dd��Zeded�ed�d�Z e ej!�Z!eed�dd�Z"eed�dd�Z#eeeed�dd�Z$eee%e&fd�dd�Z'eed�d d!�Z(eee%e&fd�d"d#�Z)eed�d$d%�Z*dS)&�N)�contextmanager)�NamedTemporaryFile)�Any�BinaryIO�Iterator�List�Union�cast)�retry�stop_after_delay�
wait_fixed)�get_path_uid)�format_size)�path�returncCs�tjdksttd�sdStj�|�s(J�d}||kr�tj�|�r�t��dkrvzt|�}Wnt	ylYdS0|dkSt�
|tj�Sq,|tj�|�}}q,dS)N�win32�geteuidTrF)
�sys�platform�hasattr�osr�isabs�lexistsrr
�OSError�access�W_OK�dirname)rZpreviousZpath_uid�r�B/usr/lib/python3.9/site-packages/pip/_internal/utils/filesystem.py�check_path_ownersr)�src�destrcCsnzt�||�WnXtyh||fD]:}zt|�}WntyHYq&0|r&t�d|�d���q&�Yn0dS)z�Wrap shutil.copy2() but map errors copying socket files to
    SpecialFileError as expected.

    See also https://bugs.python.org/issue37700.
    �`z
` is a socketN)�shutil�copy2r�	is_socket�SpecialFileError)r r!�fZis_socket_filerrr�copy2_fixed-sr(cCst�t�|�j�S�N)�stat�S_ISSOCKr�lstat�st_mode�rrrrr%Dsr%)r�kwargsrcks�tfdtj�|�tj�|�dd�|���T}tt|�}z |VW|��t�|�	��n|��t�|�	��0Wd�n1s�0YdS)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)
rrrr�basenamer	r�flush�fsync�fileno)rr/r'�resultrrr�adjacent_tmp_fileHs 


��
�r9T�g�?)Zreraise�stop�waitcCsHtj�|�s(tj�|�}||kr"q(|}qtjdkr@t�|tj�St|�S)zgCheck if a directory is writable.

    Uses os.access() on POSIX, tries creating files on Windows.
    �posix)rr�isdirr�namerr�_test_writable_dir_win)r�parentrrr�test_writable_diris
rBc	s�d}d�td�D]�}|d��fdd�td�D��}tj�||�}zt�|tjtjBtjB�}Wn&tyrYqt	y�YdS0t�
|�t�|�d	Sqtd
��dS)NZ(accesstest_deleteme_fishfingers_custard_Z$abcdefghijklmnopqrstuvwxyz0123456789�
�c3s|]}t���VqdSr))�random�choice)�.0�_�Zalphabetrr�	<genexpr>��z)_test_writable_dir_win.<locals>.<genexpr>�FTz3Unexpected condition testing for writable directory)
�range�joinrr�open�O_RDWR�O_CREAT�O_EXCL�FileExistsError�PermissionError�close�unlinkr)rr4rHr?�file�fdrrIrr@{s 


r@)r�patternrcsBg}t�|�D].\�}}t�||�}|��fdd�|D��q|S)z�Returns 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'��rootrrrJ�rKzfind_files.<locals>.<genexpr>)r�walk�fnmatch�filter�extend)rrYr8rH�files�matchesrrZr�
find_files�s
rbcCstj�|�rdStj�|�S)Nr)rr�islink�getsizer.rrr�	file_size�srecCstt|��Sr))rrer.rrr�format_file_size�srfcCsBd}t�|�D].\}}}|D]}tj�||�}|t|�7}qq|S)Ng)rr\rrNre)r�sizer[Z_dirsr`�filenameZ	file_pathrrr�directory_size�sricCstt|��Sr))rrir.rrr�format_directory_size�srj)+r]rZos.pathrEr#r*r�
contextlibrZtempfiler�typingrrrrrr	Zpip._vendor.tenacityr
rrZpip._internal.utils.compatr
Zpip._internal.utils.miscr�str�boolrr(r%r9Z_replace_retry�replacerBr@rb�int�floatrerfrirjrrrr�<module>s4