o
    ©„jœ  ã                   @  s<  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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 d dlmZ d d	lmZ d d
lmZ d9dd„Zed:dd„ƒZeddd�ejƒZd9dd„Zd9dd„Zd;dd „Zd<d"d#„Z d=d$d%„Z!d<d&d'„Z"d=d(d)„Z#d>d.d/„Z$d?d3d4„Z%d@d5d6„Z&d@d7d8„Z'dS )Aé    )ÚannotationsN)ÚCallableÚ	Generator)Úcontextmanager)ÚPath)ÚNamedTemporaryFile)ÚAnyÚBinaryIOÚcast)Úget_path_uid)Úformat_size)ÚretryÚpathÚstrÚreturnÚboolc                 C  s    t jdks
ttdƒsdS tj | ¡sJ ‚d }| |krNtj | ¡rAt ¡ dkr:z	t| ƒ}W |dkS  t	y9   Y dS w t 
| tj¡S | tj | ¡}} | |ksdS )NÚwin32ÚgeteuidTr   F)ÚsysÚplatformÚhasattrÚosr   ÚisabsÚlexistsr   r   ÚOSErrorÚaccessÚW_OKÚdirname)r   ÚpreviousÚpath_uid© r    ú\/var/www/html/django_cbt/venv/lib/python3.10/site-packages/pip/_internal/utils/filesystem.pyÚcheck_path_owner   s"   
þÿòr"   Úkwargsr   úGenerator[BinaryIO, None, None]c                 k  s”   � t ddtj | ¡tj | ¡ddœ|¤Ž�+}tt|ƒ}z|V  W | ¡  t | 	¡ ¡ n| ¡  t | 	¡ ¡ w W d  ƒ dS 1 sCw   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ÚsuffixNr    )
r   r   r   r   Úbasenamer
   r	   ÚflushÚfsyncÚfileno)r   r#   ÚfÚresultr    r    r!   Úadjacent_tmp_file.   s$   €


üû
ÿ"ôr/   é   g      Ð?)Ústop_after_delayÚwaitc                 C  sR   t j | ¡st j | ¡}|| krn|} t j | ¡rt jdkr%t  | 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   Úparentr    r    r!   Útest_writable_dirL   s   ü
r8   c              	     sª   d}d‰ t dƒD ]H}|d ‡ fdd„t dƒD ƒ¡ }tj | |¡}zt |tjtjB tjB ¡}W n ty9   Y q t	yC   Y  dS w t 
|¡ t |¡  d	S td
ƒ‚)NÚ(accesstest_deleteme_fishfingers_custard_Ú$abcdefghijklmnopqrstuvwxyz0123456789é
   Ú c                 3  s   � | ]}t  ˆ ¡V  qd S ©N)ÚrandomÚchoice)Ú.0Ú_©Úalphabetr    r!   Ú	<genexpr>d   ó   € z)_test_writable_dir_win.<locals>.<genexpr>é   FTz3Unexpected condition testing for writable directory)ÚrangeÚjoinr   r   ÚopenÚO_RDWRÚO_CREATÚO_EXCLÚFileExistsErrorÚPermissionErrorÚcloseÚunlinkr   )r   r)   rA   r5   ÚfileÚfdr    rB   r!   r6   ^   s     ú

r6   Úpatternú	list[str]c                   sB   g }t  | ¡D ]\‰ }}t ||¡}| ‡ fdd„|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.c                 3  s   � | ]
}t j ˆ |¡V  qd S r=   )r   r   rH   )r@   r-   ©Úrootr    r!   rD   €   s   € zfind_files.<locals>.<genexpr>)r   ÚwalkÚfnmatchÚfilterÚextend)r   rS   r.   rA   ÚfilesÚmatchesr    rU   r!   Ú
find_filesz   s
   r]   úint | floatc                 C  s   t j | ¡rdS t j | ¡S ©Nr   )r   r   ÚislinkÚgetsize©r   r    r    r!   Ú	file_size„   s   rc   c                 C  ó   t t| ƒƒS r=   )r   rc   rb   r    r    r!   Úformat_file_size‹   ó   re   c                 C  sB   d}t  | ¡D ]\}}}|D ]}t j ||¡}|t|ƒ7 }qq|S )Ng        )r   rW   r   rH   rc   )r   ÚsizerV   Ú_dirsr[   ÚfilenameÚ	file_pathr    r    r!   Údirectory_size�   s   þrk   c                 C  rd   r=   )r   rk   rb   r    r    r!   Úformat_directory_size˜   rf   rl   Ú	directoryÚtarget_filer	   ÚNonec                 C  sZ   t  | ¡jd@ dB }t jt jv rt  | ¡ |¡ d S t jt jv r+t j|j|dd� d S d S )Ni¶  i€  F)Úfollow_symlinks)r   ÚstatÚst_modeÚchmodÚsupports_fdr,   Úsupports_follow_symlinksr5   )rm   rn   Úmoder    r    r!   Úcopy_directory_permissionsœ   s   ÿÿÿrw   Ú	predicateú Callable[[str, list[str]], bool]úGenerator[Path]c           	      c  sˆ   � g }t ƒ }t t| ƒ ¡ ¡D ]"\}}}t|ƒ}|||ƒr,| |jdd… ¡ | |¡ | |¡ qt	|dd�D ]	}||vrA|V  q8dS )zZYields every subdirectory of +path+ that has no files matching the
    predicate under it.NéÿÿÿÿT)Úreverse)
Úsetr   rW   r   ÚresolveÚupdateÚparentsÚaddÚappendÚsorted)	r   rx   ÚdirectoriesÚexcludedÚroot_strrA   Ú	filenamesrV   Údr    r    r!   Ú_subdirs_without_generic¨   s   €

€þr‰   c                 C  ó   t | dd„ ƒS )z?Yields every subdirectory of +path+ that has no files under it.c                 S  s   t |ƒdkS r_   )Úlen©rV   r‡   r    r    r!   Ú<lambda>Â   s    z'subdirs_without_files.<locals>.<lambda>©r‰   rb   r    r    r!   Úsubdirs_without_filesÀ   s   r�   c                 C  rŠ   )zDYields every subdirectory of +path+ that has no .whl files under it.c                 S  s   t dd„ |D ƒƒS )Nc                 s  s   � | ]}|  d ¡V  qdS )z.whlN)Úendswith)r@   Úxr    r    r!   rD   È   rE   z;subdirs_without_wheels.<locals>.<lambda>.<locals>.<genexpr>)ÚanyrŒ   r    r    r!   r�   È   s    z(subdirs_without_wheels.<locals>.<lambda>rŽ   rb   r    r    r!   Úsubdirs_without_wheelsÅ   s   ÿr“   )r   r   r   r   )r   r   r#   r   r   r$   )r   r   rS   r   r   rT   )r   r   r   r^   )r   r   r   r   )rm   r   rn   r	   r   ro   )r   r   rx   ry   r   rz   )r   r   r   rz   )(Ú
__future__r   rX   r   Úos.pathr>   r   Úcollections.abcr   r   Ú
contextlibr   Úpathlibr   Útempfiler   Útypingr   r	   r
   Úpip._internal.utils.compatr   Úpip._internal.utils.miscr   Úpip._internal.utils.retryr   r"   r/   Úreplacer8   r6   r]   rc   re   rk   rl   rw   r‰   r�   r“   r    r    r    r!   Ú<module>   s:    








	


