o
    ­—ŽjÔ^  ã                   @  sV  d dl mZ d dlZd dlZd dlZd dl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m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 d dlmZmZm Z m!Z! d dl"m#Z#m$Z$ d dl%m&Z& ee'ƒZ(d0dd„Z)d1dd„Z*e*d2dd„ƒZ+d3d#d$„Z,d3d%d&„Z-d4d(d)„Z.G d*d+„ d+ƒZ/G d,d-„ d-ƒZ0G d.d/„ d/ƒZ1dS )5é    )ÚannotationsN)ÚCallableÚ	GeneratorÚIterable)Úcache_from_source)ÚAny)ÚLegacyDistutilsInstallÚUninstallMissingRecord)Úget_bin_prefixÚget_bin_user)ÚBaseDistribution)ÚWINDOWS)Úegg_link_path_from_location)Ú	getLoggerÚ
indent_log)ÚaskÚnormalize_pathÚrenamesÚrmtree)ÚAdjacentTempDirectoryÚTempDirectory)Úrunning_under_virtualenvÚbin_dirÚstrÚscript_nameÚis_guiÚboolÚreturnúGenerator[str, None, None]c                 c  sZ   � t j | |¡}|V  tsdS |› d�V  |› d�V  |r%|› d�V  dS |› d�V  dS )z‘Create the fully qualified name of the files created by
    {console,gui}_scripts for the given ``dist``.
    Returns the list of file names
    Nz.exez.exe.manifestz-script.pywz
-script.py)ÚosÚpathÚjoinr   )r   r   r   Úexe_name© r#   ú\/var/www/kodo/Anonymous/send/lib/python3.10/site-packages/pip/_internal/req/req_uninstall.pyÚ_script_names   s   €r%   Úfnú)Callable[..., Generator[Any, None, None]]c                   s   t  ˆ ¡d‡ fdd„ƒ}|S )	NÚargsr   Úkwr   úGenerator[Any, None, None]c                  ?  s8   � t ƒ }ˆ | i |¤ŽD ]}||vr| |¡ |V  qd S ©N)ÚsetÚadd)r(   r)   ÚseenÚitem©r&   r#   r$   Úunique.   s   €
€ýz_unique.<locals>.unique)r(   r   r)   r   r   r*   )Ú	functoolsÚwraps)r&   r1   r#   r0   r$   Ú_unique+   s   r4   Údistr   c                 c  sª   � | j }|dusJ dƒ‚|  ¡ }|du rt| d�‚|D ]7}tj ||¡}|V  | d¡rRtj |¡\}}|dd… }tj ||d ¡}|V  tj ||d ¡}|V  qdS )aÇ  
    Yield all the uninstallation paths for dist based on RECORD-without-.py[co]

    Yield paths to all the files in RECORD. For each .py file in RECORD, add
    the .pyc and .pyo in the same directory.

    UninstallPathSet.add() takes care of the __pycache__ .py[co].

    If RECORD is not found, raises an error,
    with possible information from the INSTALLER file.

    https://packaging.python.org/specifications/recording-installed-packages/
    Nznot installed©Údistributionú.pyéýÿÿÿú.pycú.pyo)ÚlocationÚiter_declared_entriesr	   r   r    r!   ÚendswithÚsplit)r5   r<   ÚentriesÚentryr    Údnr&   Úbaser#   r#   r$   Úuninstallation_paths9   s$   €

€÷rD   ÚpathsúIterable[str]úset[str]c                 C  s    t jj}tƒ }tƒ }t| td�D ]=}| |d ¡r|dd… n|}| |¡}|r@||v r-n t j |¡ |¡}||kr<dn|}|s(| 	|¡ | 	| |¡¡ q|S )zÈCompact a path set to contain the minimal number of paths
    necessary to contain all paths in the set. If /a/path/ and
    /a/path/to/a/file.txt are both in the set, leave only the
    shorter path.©ÚkeyÚ*NéÿÿÿÿÚ )
r   r    Úsepr,   ÚsortedÚlenr>   ÚrstripÚdirnamer-   )rE   rM   Úshort_pathsÚprefixesr    ÚcurrentÚparentÚnext_parentr#   r#   r$   Úcompact[   s    
ü
€rW   c           	        sò   dd„ | D ƒ}t |ƒ}tdd„ | ¡ D ƒtd�}t ƒ }dd	d
„‰|D ]L‰t‡fdd„|D ƒƒr0q"t ƒ }t ƒ }t ˆ¡D ]!\‰ }}| ‡ ‡‡fdd„|D ƒ¡ | ‡ ‡‡fdd„|D ƒ¡ q;|| sn| |¡ | 	ˆtj
 ¡ q"t t|j|ƒƒ|B S )z«Returns a set containing the paths that need to be renamed.

    This set may include directories when the original sequence of paths
    included every file on disk.
    c                 S  s   i | ]	}t j |¡|“qS r#   )r   r    Únormcase©Ú.0Úpr#   r#   r$   Ú
<dictcomp>y   ó    z'compress_for_rename.<locals>.<dictcomp>c                 S  s   h | ]
}t j |¡d  ’qS )r   )r   r    r?   rY   r#   r#   r$   Ú	<setcomp>{   s    z&compress_for_rename.<locals>.<setcomp>rH   Úar   r   c                  W  s   t j t jj| Ž ¡S r+   )r   r    rX   r!   )r_   r#   r#   r$   Ú	norm_join~   s   z&compress_for_rename.<locals>.norm_joinc                 3  s"   � | ]}t j ˆ ¡ |¡V  qd S r+   )r   r    rX   Ú
startswith)rZ   Úw)Úrootr#   r$   Ú	<genexpr>‚   s   €  z&compress_for_rename.<locals>.<genexpr>c                 3  ó   � | ]	}ˆˆˆ |ƒV  qd S r+   r#   )rZ   Úd©rQ   r`   rc   r#   r$   rd   ‰   ó   € c                 3  re   r+   r#   )rZ   Úfrg   r#   r$   rd   Š   rh   N)r_   r   r   r   )r,   rN   ÚvaluesrO   Úanyr   ÚwalkÚupdateÚdifference_updater-   rM   ÚmapÚ__getitem__)	rE   Úcase_mapÚ	remainingÚ	uncheckedÚ	wildcardsÚ	all_filesÚall_subdirsÚsubdirsÚfilesr#   rg   r$   Úcompress_for_renames   s$   

€ry   útuple[set[str], set[str]]c                 C  sü   t | ƒ}t ƒ }t ƒ }t ƒ }|D ]}| d¡rq| d¡s d|v r)| tj |¡¡ | |¡ qt ttjj|ƒƒ}t|ƒ}|D ]2}t 	|¡D ]*\}}	}
|
D ]"}| d¡rTqLtj 
||¡}tj |¡rntj |¡|vrn| |¡ qLqEq>|dd„ |D ƒB }||fS )as  Returns a tuple of 2 sets of which paths to display to user

    The first set contains paths that would be deleted. Files of a package
    are not added and the top-level directory of the package has a '*' added
    at the end - to signify that all it's contents are removed.

    The second set contains files that would have been skipped in the above
    folders.
    r:   z__init__.pyz
.dist-infoc                 S  s   h | ]	}t j |d ¡’qS )rJ   )r   r    r!   )rZ   Úfolderr#   r#   r$   r^   Á   r]   z.compress_for_output_listing.<locals>.<setcomp>)r,   r>   r-   r   r    rQ   ro   rX   rW   rl   r!   Úisfile)rE   Úwill_removeÚ	will_skipÚfoldersrx   r    Ú_normcased_filesr{   ÚdirpathÚ_ÚdirfilesÚfnameÚfile_r#   r#   r$   Úcompress_for_output_listing•   s6   


ÿ
€öÿr†   c                   @  sZ   e Zd Z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	e
ddd„ƒZdS )ÚStashedUninstallPathSetzWA set of file rename operations to stash files while
    tentatively uninstalling them.r   ÚNonec                 C  s   i | _ g | _d S r+   )Ú
_save_dirsÚ_moves©Úselfr#   r#   r$   Ú__init__Ê   s   
z StashedUninstallPathSet.__init__r    r   c                 C  sB   zt |ƒ}W n ty   tdd�}Y nw || jtj |¡< |jS )z�Stashes a directory.

        Directories are stashed adjacent to their original location if
        possible, or else moved/copied into the user's temp dir.Ú	uninstall©Úkind)r   ÚOSErrorr   r‰   r   r    rX   )rŒ   r    Úsave_dirr#   r#   r$   Ú_get_directory_stashÒ   s   ÿz,StashedUninstallPathSet._get_directory_stashc                 C  sº   t j |¡}t j |¡d}}d}||kr3z| j| }W n& ty%   Y nw t j |¡|}}||kst j |¡}tdd�}|| j|< t j ||¡}|rZ|t jjkrZt j 	|j|¡S |jS )z‚Stashes a file.

        If no root has been provided, one will be created for the directory
        in the user's temp directory.NrŽ   r�   )
r   r    rX   rQ   r‰   ÚKeyErrorr   ÚrelpathÚcurdirr!   )rŒ   r    ÚheadÚold_headr’   r•   r#   r#   r$   Ú_get_file_stashà   s&   
ÿú	

z'StashedUninstallPathSet._get_file_stashc                 C  sl   t j |¡ot j |¡ }|r|  |¡}n|  |¡}| j ||f¡ |r/t j |¡r/t  |¡ t	||ƒ |S )z�Stashes the directory or file and returns its new location.
        Handle symlinks as files to avoid modifying the symlink targets.
        )
r   r    ÚisdirÚislinkr“   r™   rŠ   ÚappendÚrmdirr   )rŒ   r    Úpath_is_dirÚnew_pathr#   r#   r$   Ústashû   s   


zStashedUninstallPathSet.stashc                 C  s(   | j  ¡ D ]}| ¡  qg | _i | _ dS )z0Commits the uninstall by removing stashed files.N)r‰   rj   ÚcleanuprŠ   )rŒ   r’   r#   r#   r$   Úcommit  s   

zStashedUninstallPathSet.commitc                 C  sÊ   | j D ]}tjdg|¢R Ž  q| j D ]L\}}z*t d||¡ tj |¡s*tj |¡r0t |¡ n
tj 	|¡r:t
|ƒ t||ƒ W q ty^ } zt d|¡ t d|¡ W Y d}~qd}~ww |  ¡  dS )z2Undoes the uninstall by moving stashed files back.zMoving to %s
 from %szReplacing %s from %szFailed to restore %szException: %sN)rŠ   ÚloggerÚinfoÚdebugr   r    r|   r›   Úunlinkrš   r   r   r‘   Úerrorr¢   )rŒ   r[   rŸ   r    Úexr#   r#   r$   Úrollback  s    
€þz StashedUninstallPathSet.rollbackr   c                 C  s
   t | jƒS r+   )r   rŠ   r‹   r#   r#   r$   Úcan_rollback*  s   
z$StashedUninstallPathSet.can_rollbackN©r   rˆ   )r    r   r   r   ©r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r�   r“   r™   r    r¢   r©   Úpropertyrª   r#   r#   r#   r$   r‡   Æ   s    





r‡   c                   @  sp   e Zd ZdZd!dd„Zd"dd„Zd#dd„Zd$dd„Zd%d&dd„Zd'dd„Z	d(dd„Z
d(dd„Zed)dd„ƒZd S )*ÚUninstallPathSetzMA set of file paths to be removed in the uninstallation of a
    requirement.r5   r   r   rˆ   c                 C  s4   t ƒ | _t ƒ | _i | _|| _tƒ | _t t	¡| _
d S r+   )r,   Ú_pathsÚ_refuseÚ_pthÚ_distr‡   Ú_moved_pathsr2   Ú	lru_cacher   Ú_normalize_path_cached)rŒ   r5   r#   r#   r$   r�   3  s   zUninstallPathSet.__init__r    r   r   c                 C  s   t ƒ sdS | |  tj¡¡S )zs
        Return True if the given path is one we are permitted to
        remove/modify, False otherwise.

        T)r   ra   r¹   ÚsysÚprefix)rŒ   r    r#   r#   r$   Ú
_permitted>  s   zUninstallPathSet._permittedc                 C  sŠ   t j |¡\}}t j |  |¡t j |¡¡}t j |¡sd S |  |¡r*| j 	|¡ n| j
 	|¡ t j |¡d dkrC|  	t|ƒ¡ d S d S )Né   r8   )r   r    r?   r!   r¹   rX   Úexistsr¼   r³   r-   r´   Úsplitextr   )rŒ   r    r—   Útailr#   r#   r$   r-   I  s   
ÿzUninstallPathSet.addÚpth_filerA   c                 C  sP   |   |¡}|  |¡r || jvrt|ƒ| j|< | j|  |¡ d S | j |¡ d S r+   )r¹   r¼   rµ   ÚUninstallPthEntriesr-   r´   )rŒ   rÁ   rA   r#   r#   r$   Úadd_pth\  s   


zUninstallPathSet.add_pthFÚauto_confirmÚverbosec                 C  sâ   | j st d| jj¡ dS | jj› d| jj› �}t d|¡ tƒ �F |s)|  |¡r_| j}t	| j ƒ}t
t|ƒƒD ]}| |¡ t d|¡ q7| j ¡ D ]}| ¡  qJt d|¡ W d  ƒ dS W d  ƒ dS 1 sjw   Y  dS )z\Remove paths in ``self._paths`` with confirmation (unless
        ``auto_confirm`` is True).z7Can't uninstall '%s'. No files were found to uninstall.Nú-zUninstalling %s:zRemoving file or directory %szSuccessfully uninstalled %s)r³   r£   r¤   r¶   Úraw_nameÚraw_versionr   Ú_allowed_to_proceedr·   ry   rN   rW   r    rÅ   rµ   rj   Úremove)rŒ   rÄ   rÅ   Údist_name_versionÚmovedÚ
for_renamer    Úpthr#   r#   r$   rÊ   e  s*   þ


ó"ÿzUninstallPathSet.removec                 C  sp   ddd„}|st | jƒ\}}nt| jƒ}tƒ }|d	|ƒ |d
|ƒ |d| jƒ |r1|dt| jƒƒ tddƒdkS )z@Display which files would be deleted and prompt for confirmationÚmsgr   rE   rF   r   rˆ   c                 S  sZ   |sd S t  | ¡ tƒ � tt|ƒƒD ]}t  |¡ qW d   ƒ d S 1 s&w   Y  d S r+   )r£   r¤   r   rN   rW   )rÏ   rE   r    r#   r#   r$   Ú_display…  s   
ÿ"ÿz6UninstallPathSet._allowed_to_proceed.<locals>._displayzWould remove:z+Would not remove (might be manually added):z%Would not remove (outside of prefix):zWill actually move:zProceed (Y/n)? )ÚyÚnrL   rÒ   N)rÏ   r   rE   rF   r   rˆ   )r†   r³   r,   r´   ry   r   )rŒ   rÅ   rÐ   r}   r~   r#   r#   r$   rÉ   ‚  s   
	


z$UninstallPathSet._allowed_to_proceedc                 C  sR   | j jst d| jj¡ dS t d| jj¡ | j  ¡  | j 	¡ D ]}| ¡  q dS )z1Rollback the changes previously made by remove().z'Can't roll back %s; was not uninstalledNzRolling back uninstall of %s)
r·   rª   r£   r§   r¶   rÇ   r¤   r©   rµ   rj   )rŒ   rÎ   r#   r#   r$   r©   ž  s   þ

ÿzUninstallPathSet.rollbackc                 C  s   | j  ¡  dS )z?Remove temporary save dir: rollback will no longer be possible.N)r·   r¢   r‹   r#   r#   r$   r¢   «  s   zUninstallPathSet.commitc              
     sš  |j }|j}|d u rt d|j¡ | |ƒS t|ƒ}|js*t d|j|tj¡ | |ƒS |dd„ t	 
d¡t	 
d¡hD ƒv rGt d|j|¡ | |ƒS | |ƒ}t|jƒ}|jof|d uoftj |¡of| |j› d�¡ }|rÞ|d urr| |¡ | ¡ }|d urŠ|D ]}	| tj ||	¡¡ q|nò| d	¡rÝz| d
¡}
W n ty¡   g ‰ Y nw |
jdd�‰ ‡ fdd„| d	¡ ¡ D ƒD ]&}tj ||¡}| |¡ | |› d�¡ | |› d�¡ | |› d�¡ q¶nž|jræt|d�‚|j�r| |¡ tj |¡d }tj tj |¡d¡}| |d| ¡ nq|j �rt!|ƒD ]}| |¡ �qn_|�rut"|ƒ�}tj #| $¡  %¡ ¡}| &|¡}W d   ƒ n	1 �s?w   Y  tj '||¡�s^J d|› d|› d|j› d|› d�	ƒ‚| |¡ tj tj |¡d¡}| ||¡ nt (d||¡ |j)�r„t*ƒ }nt+ƒ }z$| ,¡ D ]}| tj ||¡¡ t-�r¨| tj ||› d�¡¡ �qŒW n tt.f�y·   Y nw d%d#d$„}|||ƒD ]}| |¡ �qÂ|S )&Nz-Not uninstalling %s since it is not installedz1Not uninstalling %s at %s, outside environment %sc                 S  s   h | ]}|r|’qS r#   r#   rY   r#   r#   r$   r^   Ä  s    ýÿz-UninstallPathSet.from_dist.<locals>.<setcomp>ÚstdlibÚ
platstdlibz<Not uninstalling %s at %s, as it is in the standard library.z	.egg-infoztop_level.txtznamespace_packages.txtF)Úkeependsc                   s   g | ]
}|r|ˆ vr|‘qS r#   r#   rY   ©Ú
namespacesr#   r$   Ú
<listcomp>ò  s    ýþz.UninstallPathSet.from_dist.<locals>.<listcomp>r8   r:   r;   r6   r½   zeasy-install.pthz./z	Egg-link z (to z') does not match installed location of z (at ú)z)Not sure how to uninstall: %s - Check: %sz.batr5   r   r   r   r   r   c                 s  sR   � |   ¡ D ]!}|jdkrt||jdƒE d H  q|jdkr&t||jdƒE d H  qd S )NÚconsole_scriptsFÚgui_scriptsT)Úiter_entry_pointsÚgroupr%   Úname)r5   r   Úentry_pointr#   r#   r$   Úiter_scripts_to_remove=  s   €

€üz:UninstallPathSet.from_dist.<locals>.iter_scripts_to_remove)r5   r   r   r   r   r   )/r<   Úinfo_locationr£   r¤   Úcanonical_namer   Úlocalrº   r»   Ú	sysconfigÚget_pathr   rÇ   Ú"installed_with_setuptools_egg_infor   r    r¾   r>   Úsetuptools_filenamer-   r=   r!   Úis_fileÚ	read_textÚFileNotFoundErrorÚ
splitlinesÚinstalled_by_distutilsr   Úinstalled_as_eggr?   rQ   rÃ   Úinstalled_with_dist_inforD   ÚopenrX   ÚreadlineÚstripr¹   Úsamefiler¥   Úin_usersiter   r
   Úiter_distutils_script_namesr   ÚNotADirectoryError)Úclsr5   Údist_locationrá   Únormalized_dist_locationÚpaths_to_removeÚdevelop_egg_linkÚsetuptools_flat_installationÚinstalled_filesÚinstalled_fileÚnamespace_packagesÚtop_level_pkgr    Úeasy_install_eggÚeasy_install_pthÚfhÚlink_pointerÚnormalized_link_pointerr   Úscriptrà   Úsr#   rÖ   r$   Ú	from_dist¯  sè   þüþý
ÿ
þú
ÿ
ÿ

þ
€


þÿ
ÿþÿÿÿý
ÿý€ýÿ

zUninstallPathSet.from_distN)r5   r   r   rˆ   )r    r   r   r   )r    r   r   rˆ   )rÁ   r   rA   r   r   rˆ   )FF)rÄ   r   rÅ   r   r   rˆ   )rÅ   r   r   r   r«   )r5   r   r   r²   )r­   r®   r¯   r°   r�   r¼   r-   rÃ   rÊ   rÉ   r©   r¢   Úclassmethodr  r#   r#   r#   r$   r²   /  s    



	


r²   c                   @  s4   e Zd Zddd„Zddd	„Zdd
d„Zddd„ZdS )rÂ   rÁ   r   r   rˆ   c                 C  s   || _ tƒ | _d | _d S r+   )Úfiler,   r@   Ú_saved_lines)rŒ   rÁ   r#   r#   r$   r�   N  s   
zUninstallPthEntries.__init__rA   c                 C  s<   t j |¡}trt j |¡d s| dd¡}| j |¡ d S )Nr   ú\ú/)r   r    rX   r   Ú
splitdriveÚreplacer@   r-   )rŒ   rA   r#   r#   r$   r-   S  s   
zUninstallPthEntries.addc              	   C  s0  t  d| j¡ tj | j¡st  d| j¡ d S t| jdƒ�}| ¡ }|| _	W d   ƒ n1 s/w   Y  t
dd„ |D ƒƒr@d}nd}|rY|d  | d	¡¡sY|d | d	¡ |d< | jD ]}zt  d
|¡ | ||  d	¡¡ W q\ tyy   Y q\w t| jdƒ�}| |¡ W d   ƒ d S 1 s‘w   Y  d S )NzRemoving pth entries from %s:z.Cannot remove entries from nonexistent file %sÚrbc                 s  s   � | ]}d |v V  qdS )s   
Nr#   )rZ   Úliner#   r#   r$   rd   m  s   € z-UninstallPthEntries.remove.<locals>.<genexpr>z
Ú
rK   zutf-8zRemoving entry: %sÚwb)r£   rÅ   r	  r   r    r|   Úwarningrï   Ú	readlinesr
  rk   r>   Úencoder@   rÊ   Ú
ValueErrorÚ
writelines)rŒ   r  ÚlinesÚendlinerA   r#   r#   r$   rÊ   b  s.   ý
ÿ"ÿzUninstallPthEntries.remover   c                 C  sh   | j d u rt d| j¡ dS t d| j¡ t| jdƒ�}| | j ¡ W d   ƒ dS 1 s-w   Y  dS )Nz.Cannot roll back changes to %s, none were madeFz!Rolling %s back to previous stater  T)r
  r£   r§   r	  r¥   rï   r  )rŒ   r  r#   r#   r$   r©   }  s   

ÿþzUninstallPthEntries.rollbackN)rÁ   r   r   rˆ   )rA   r   r   rˆ   r«   r¬   )r­   r®   r¯   r�   r-   rÊ   r©   r#   r#   r#   r$   rÂ   M  s
    


rÂ   )r   r   r   r   r   r   r   r   )r&   r'   r   r'   )r5   r   r   r   )rE   rF   r   rG   )rE   rF   r   rz   )2Ú
__future__r   r2   r   rº   rä   Úcollections.abcr   r   r   Úimportlib.utilr   Útypingr   Úpip._internal.exceptionsr   r	   Úpip._internal.locationsr
   r   Úpip._internal.metadatar   Úpip._internal.utils.compatr   Úpip._internal.utils.egg_linkr   Úpip._internal.utils.loggingr   r   Úpip._internal.utils.miscr   r   r   r   Úpip._internal.utils.temp_dirr   r   Úpip._internal.utils.virtualenvr   r­   r£   r%   r4   rD   rW   ry   r†   r‡   r²   rÂ   r#   r#   r#   r$   Ú<module>   s<    


!

"1i   