a
    eÖ0hÛ\  ã                   @   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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 d dlmZ d dlmZmZmZmZmZmZmZmZmZ d d	lm Z m!Z! d d
l"m#Z# e#r
d dl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- d dl.m/Z/ e 0e1¡Z2dd„ Z3dd„ Z4e4dd„ ƒZ5dd„ Z6dd„ Z7dd„ Z8G dd„ de9ƒZ:G dd„ de9ƒZ;G dd„ de9ƒZ<dS )é    )Úabsolute_importN)Úpkg_resources)ÚUninstallationError)Úbin_pyÚbin_user)ÚWINDOWSÚcache_from_sourceÚuses_pycache)Ú
indent_log)	ÚFakeFileÚaskÚdist_in_usersiteÚdist_is_localÚegg_link_pathÚis_localÚnormalize_pathÚrenamesÚrmtree)ÚAdjacentTempDirectoryÚTempDirectory)ÚMYPY_CHECK_RUNNING)	ÚAnyÚCallableÚDictÚIterableÚIteratorÚListÚOptionalÚSetÚTuple)ÚDistributionc                 C   sl   t | ƒrt}nt}tj ||¡}|g}trh| |d ¡ | |d ¡ |rZ| |d ¡ n| |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
    z.exez.exe.manifestz-script.pywz
-script.py)r   r   r   ÚosÚpathÚjoinr   Úappend)ÚdistÚscript_nameÚis_guiÚbin_dirÚexe_nameÚpaths_to_remove© r+   úM/var/www/auris/lib/python3.9/site-packages/pip/_internal/req/req_uninstall.pyÚ_script_names0   s    r-   c                    s   t  ˆ ¡‡ fdd„ƒ}|S )Nc                  ?   s6   t ƒ }ˆ | i |¤ŽD ]}||vr| |¡ |V  qd S ©N)ÚsetÚadd)ÚargsÚkwÚseenÚitem©Úfnr+   r,   ÚuniqueH   s
    
z_unique.<locals>.unique)Ú	functoolsÚwraps)r6   r7   r+   r5   r,   Ú_uniqueF   s    r:   c                 c   s’   t  t|  d¡ƒ¡}|D ]t}tj | j|d ¡}|V  | d¡rt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].
    ÚRECORDr   ú.pyNéýÿÿÿú.pycú.pyo)
ÚcsvÚreaderr   Úget_metadata_linesr!   r"   r#   ÚlocationÚendswithÚsplit)r%   ÚrÚrowr"   Údnr6   Úbaser+   r+   r,   Úuninstallation_pathsS   s    
rJ   c                    sJ   t jj‰tƒ }t| tdD ]*‰ t‡ ‡fdd„|D ƒƒ}|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.©Úkeyc                 3   s:   | ]2}ˆ   | d ¡¡o0ˆ t| d ¡ ˆ¡ƒ ˆkV  qdS )Ú*N)Ú
startswithÚrstripÚlen)Ú.0Ú	shortpath©r"   Úsepr+   r,   Ú	<genexpr>u   s   þzcompact.<locals>.<genexpr>)r!   r"   rT   r/   ÚsortedrP   Úanyr0   )ÚpathsÚshort_pathsÚshould_skipr+   rS   r,   Úcompactk   s    ýr[   c           	         sø   t dd„ | D ƒƒ}t|ƒ}ttdd„ | ¡ D ƒƒtd}tƒ }dd„ ‰|D ]˜‰t‡fdd„|D ƒƒrfqJtƒ }tƒ }t ˆ¡D ]B\‰ }}| ‡ ‡‡fdd„|D ƒ¡ | ‡ ‡‡fd	d„|D ƒ¡ q||| sJ| 	|¡ | 
ˆtj ¡ qJt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   | ]}t j |¡|fV  qd S r.   )r!   r"   Únormcase©rQ   Úpr+   r+   r,   rU   †   ó    z&compress_for_rename.<locals>.<genexpr>c                 s   s   | ]}t j |¡d  V  qdS )r   N)r!   r"   rE   r]   r+   r+   r,   rU   ˆ   s   ÿrK   c                  W   s   t j t jj| Ž ¡S r.   )r!   r"   r\   r#   )Úar+   r+   r,   Ú	norm_joinŒ   s    z&compress_for_rename.<locals>.norm_joinc                 3   s    | ]}t j ˆ ¡ |¡V  qd S r.   )r!   r"   r\   rN   )rQ   Úw)Úrootr+   r,   rU   ‘   s   ÿc                 3   s   | ]}ˆˆˆ |ƒV  qd S r.   r+   )rQ   Úd©Údirnamera   rc   r+   r,   rU   ™   s   ÿc                 3   s   | ]}ˆˆˆ |ƒV  qd S r.   r+   )rQ   Úfre   r+   r,   rU   ›   s   ÿ)Údictr/   rV   ÚvaluesrP   rW   r!   ÚwalkÚupdateÚdifference_updater0   rT   ÚmapÚ__getitem__)	rX   Úcase_mapÚ	remainingÚ	uncheckedÚ	wildcardsÚ	all_filesÚall_subdirsÚsubdirsÚfilesr+   re   r,   Úcompress_for_rename   s6    
ÿÿÿÿÿ

rw   c                 C   sü   t | ƒ}t ƒ }t ƒ }t ƒ }|D ]>}| d¡r.q| d¡s@d|v rR| tj |¡¡ | |¡ qt ttjj|ƒƒ}t|ƒ}|D ]d}t 	|¡D ]T\}}	}
|
D ]D}| d¡r¨q˜tj 
||¡}tj |¡r˜tj |¡|vr˜| |¡ q˜qŠq||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__.pyú
.dist-infoc                 S   s   h | ]}t j |d ¡’qS )rM   )r!   r"   r#   )rQ   Úfolderr+   r+   r,   Ú	<setcomp>Ó   s   z.compress_for_output_listing.<locals>.<setcomp>)r/   rD   r0   r!   r"   rf   rm   r\   r[   rj   r#   Úisfile)rX   Úwill_removeÚ	will_skipÚfoldersrv   r"   Ú_normcased_filesry   ÚdirpathÚ_ÚdirfilesÚfnameÚfile_r+   r+   r,   Úcompress_for_output_listing§   s4    

ÿÿr…   c                   @   sL   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	e
dd„ ƒZdS )ÚStashedUninstallPathSetzWA set of file rename operations to stash files while
    tentatively uninstalling them.c                 C   s   i | _ g | _d S r.   )Ú
_save_dirsÚ_moves©Úselfr+   r+   r,   Ú__init__Ý   s    z StashedUninstallPathSet.__init__c                 C   sB   zt |ƒ}W n ty(   tdd}Y n0 || jtj |¡< |jS )zStashes 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"   r\   )rŠ   r"   Úsave_dirr+   r+   r,   Ú_get_directory_stashæ   s    z,StashedUninstallPathSet._get_directory_stashc                 C   s¸   t j |¡}t j |¡d }}d}||krdz| j| }W q„W n tyN   Y n0 t j |¡| }}q"t j |¡}tdd}|| j|< t j ||¡}|r²|t jjkr²t 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"   r\   rf   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 )zStashes 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ˆ   r$   Ú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‡   ÚitemsÚcleanuprˆ   )rŠ   r   r   r+   r+   r,   Úcommit'  s    
zStashedUninstallPathSet.commitc                 C   sÌ   | j D ]}tjdg|¢R Ž  q| j D ]š\}}zTt d||¡ tj |¡sTtj |¡r`t |¡ ntj 	|¡rtt
|ƒ t||ƒ W q$ ty¼ } z$t d|¡ t d|¡ W Y d}~q$d}~0 0 q$|  ¡  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.rollbackc                 C   s
   t | jƒS r.   )Úboolrˆ   r‰   r+   r+   r,   Úcan_rollbackC  s    z$StashedUninstallPathSet.can_rollbackN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r‹   r‘   r—   r   r    r§   Úpropertyr©   r+   r+   r+   r,   r†   Ú   s   	r†   c                   @   s^   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zddd„Zdd„ Z	dd„ Z
dd„ Zedd„ ƒZdS )ÚUninstallPathSetzMA set of file paths to be removed in the uninstallation of a
    requirement.c                 C   s(   t ƒ | _t ƒ | _i | _|| _tƒ | _d S r.   )r/   rX   Ú_refuseÚpthr%   r†   Ú_moved_paths)rŠ   r%   r+   r+   r,   r‹   L  s
    zUninstallPathSet.__init__c                 C   s   t |ƒS )zs
        Return True if the given path is one we are permitted to
        remove/modify, False otherwise.

        )r   )rŠ   r"   r+   r+   r,   Ú
_permittedT  s    zUninstallPathSet._permittedc                 C   sˆ   t j |¡\}}t j t|ƒt j |¡¡}t j |¡s:d S |  |¡rR| j 	|¡ n| j
 	|¡ t j |¡d dkr„tr„|  	t|ƒ¡ d S )Né   r<   )r!   r"   rE   r#   r   r\   Úexistsr³   rX   r0   r°   Úsplitextr	   r   )rŠ   r"   r•   Útailr+   r+   r,   r0   ]  s    
zUninstallPathSet.addc                 C   sL   t |ƒ}|  |¡r<|| jvr*t|ƒ| j|< | j|  |¡ n| j |¡ d S r.   )r   r³   r±   ÚUninstallPthEntriesr0   r°   )rŠ   Úpth_fileÚentryr+   r+   r,   Úadd_pthq  s    

zUninstallPathSet.add_pthFc                 C   sÎ   | j st d| jj¡ dS | jjd | jj }t d|¡ tƒ z |sP|  |¡r¬| j}t	| j ƒ}t
t|ƒƒD ]}| |¡ t d|¡ ql| j ¡ D ]}| ¡  q’t d|¡ W d  ƒ n1 sÀ0    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)rX   r¡   r¢   r%   Úproject_nameÚversionr
   Ú_allowed_to_proceedr²   rw   rV   r[   r   r£   r±   ri   Úremove)rŠ   Úauto_confirmÚverboseÚdist_name_versionÚmovedÚ
for_renamer"   r±   r+   r+   r,   rÀ   {  s&    þÿ


zUninstallPathSet.removec                 C   sn   dd„ }|st | jƒ\}}nt| jƒ}tƒ }|d|ƒ |d|ƒ |d| jƒ |r`|dt| jƒƒ tddƒd	kS )
zIDisplay which files would be deleted and prompt for confirmation
        c                 S   sX   |sd S t  | ¡ tƒ , tt|ƒƒD ]}t  |¡ q&W d   ƒ n1 sJ0    Y  d S r.   )r¡   r¢   r
   rV   r[   )ÚmsgrX   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ÚnrÈ   )r…   rX   r/   r°   rw   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±   ri   )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ä  t |jƒ}t|ƒs.t d|j|tj¡ | |ƒS |dd„ t 	d¡t 	d¡hD ƒv rht d|j|¡ | |ƒS | |ƒ}t
|ƒ}d t |j¡¡}|joœtj |j¡}t|jdd ƒ}|r²|j d	¡r²|j |¡s²| |j¡ | d
¡r| d
¡ ¡ D ]&}tj tj |j|¡¡}	| |	¡ qôn| d¡rú| d¡rB| d¡‰ ng ‰ ‡ fdd„| d¡ ¡ D ƒD ]J}
tj |j|
¡}	| |	¡ | |	d ¡ | |	d ¡ | |	d ¡ qbnH|rÌtd |j¡ƒ‚n.|j d¡r"| |j¡ tj |j¡d }tj tj |j¡d¡}| |d| ¡ nØ|rR|j d¡rRt |ƒD ]}	| |	¡ q>n¨|rêt!|dƒ$}tj "| #¡  $¡ ¡}W d   ƒ n1 sŽ0    Y  ||jksºJ d ||j|j¡ƒ‚| |¡ tj tj |¡d¡}| ||j¡ nt %d||j¡ | d¡rj| &d¡rj| 'd¡D ]L}t(|ƒr0t)}nt*}| tj ||¡¡ t+r| tj ||¡d ¡ qg }|j,dd}| -¡ D ]}| .t/||dƒ¡ q‚|j,d d}| -¡ D ]}| .t/||d!ƒ¡ q°|D ]}| |¡ qÎ|S )"Nz1Not uninstalling %s at %s, outside environment %sc                 S   s   h | ]}|r|’qS r+   r+   r]   r+   r+   r,   rz   Ú  s   þz-UninstallPathSet.from_dist.<locals>.<setcomp>ÚstdlibÚ
platstdlibz<Not uninstalling %s at %s, as it is in the standard library.z{}.egg-infor"   z	.egg-infozinstalled-files.txtztop_level.txtznamespace_packages.txtc                    s   g | ]}|r|ˆ vr|‘qS r+   r+   r]   ©Ú
namespacesr+   r,   Ú
<listcomp>  s   þz.UninstallPathSet.from_dist.<locals>.<listcomp>r<   r>   r?   z©Cannot uninstall {!r}. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.z.eggr´   zeasy-install.pthz./rx   rF   z;Egg-link {} does not match installed location of {} (at {})z)Not sure how to uninstall: %s - Check: %sÚscriptsz.batÚconsole_scripts)ÚgroupFÚgui_scriptsT)0r   rC   r   r¡   r¢   rL   ÚsysÚprefixÚ	sysconfigÚget_pathr   Úformatr   Úto_filenamer½   Úegg_infor!   r"   rµ   ÚgetattrÚ	_providerrD   r0   Úhas_metadataÚget_metadataÚ
splitlinesÚnormpathr#   r   rE   rf   r»   rJ   Úopenr\   ÚreadlineÚstripr£   Úmetadata_isdirÚmetadata_listdirr   r   r   r   Úget_entry_mapÚkeysÚextendr-   )Úclsr%   Ú	dist_pathr*   Údevelop_egg_linkÚdevelop_egg_link_egg_infoÚegg_info_existsÚdistutils_egg_infoÚinstalled_filer"   Útop_level_pkgÚeasy_install_eggÚeasy_install_pthÚfhÚlink_pointerÚscriptr(   Ú_scripts_to_removerÐ   ÚnamerÒ   Úsr+   rÌ   r,   Ú	from_distÍ  sÈ    
üÿ
ý
ÿ
ÿÿÿ
þ

ýÿÿ4
þÿ
ÿþ
zUninstallPathSet.from_distN)FF)rª   r«   r¬   r­   r‹   r³   r0   r»   rÀ   r¿   r§   r    Úclassmethodrø   r+   r+   r+   r,   r¯   I  s   	

 r¯   c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
r¸   c                 C   s   || _ tƒ | _d | _d S r.   )Úfiler/   ÚentriesÚ_saved_lines)rŠ   r¹   r+   r+   r,   r‹   S  s    zUninstallPthEntries.__init__c                 C   s<   t j |¡}tr,t j |¡d s,| dd¡}| j |¡ d S )Nr   ú\ú/)r!   r"   r\   r   Ú
splitdriveÚreplacerû   r0   )rŠ   rº   r+   r+   r,   r0   Y  s    
zUninstallPthEntries.addc              	   C   s2  t  d| j¡ tj | j¡s.t  d| j¡ d S t| jdƒ}| ¡ }|| _	W d   ƒ n1 s^0    Y  t
dd„ |D ƒƒr€d}nd}|r²|d  | d	¡¡s²|d | d	¡ |d< | jD ]<}z$t  d
|¡ | ||  d	¡¡ W q¸ tyò   Y q¸0 q¸t| jdƒ}| |¡ W d   ƒ n1 s$0    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+   )rQ   Úliner+   r+   r,   rU   w  r_   z-UninstallPthEntries.remove.<locals>.<genexpr>z
Ú
éÿÿÿÿzutf-8zRemoving entry: %sÚwb)r¡   r£   rú   r!   r"   r{   Úwarningrà   Ú	readlinesrü   rW   rD   Úencoderû   rÀ   Ú
ValueErrorÚ
writelines)rŠ   rò   ÚlinesÚendlinerº   r+   r+   r,   rÀ   i  s,    ÿ$
zUninstallPthEntries.removec                 C   sf   | j d u rt d| j¡ dS t d| j¡ t| jdƒ}| | j ¡ W d   ƒ n1 sX0    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‹   r0   rÀ   r§   r+   r+   r+   r,   r¸   R  s   r¸   )=Ú
__future__r   r@   r8   Úloggingr!   rÓ   rÕ   Úpip._vendorr   Úpip._internal.exceptionsr   Úpip._internal.locationsr   r   Úpip._internal.utils.compatr   r   r	   Úpip._internal.utils.loggingr
   Úpip._internal.utils.miscr   r   r   r   r   r   r   r   r   Úpip._internal.utils.temp_dirr   r   Úpip._internal.utils.typingr   Útypingr   r   r   r   r   r   r   r   r   Zpip._vendor.pkg_resourcesr    Ú	getLoggerrª   r¡   r-   r:   rJ   r[   rw   r…   Úobjectr†   r¯   r¸   r+   r+   r+   r,   Ú<module>   s<   ,,

(3o  