
    dh#^                       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 d dl	m
Z
 d dlmZ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(	 	 	 	 	 	 	 	 ddZ)	 	 	 	 ddZ*e*dd       Z+ddZ,ddZ-ddZ. G d d      Z/ G d d      Z0 G d d      Z1y)     )annotationsN)	GeneratorIterable)cache_from_source)AnyCallable)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_virtualenvc              #     K   t         j                  j                  | |      }| t        sy| d | d |r| d y| d yw)zCreate 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   )bin_dirscript_nameis_guiexe_names       a/var/www/html/vivango/api/ia/venv/lib/python3.12/site-packages/pip/_internal/req/req_uninstall.py_script_namesr"      s^      ww||G[1H
NJd
Jm
$$
+&&
*%%s   AAc                D     t        j                         d fd       }|S )Nc               ?  p   K   t               } | i |D ]  }||vs|j                  |       |  y wN)setadd)argskwseenitemfns       r!   uniquez_unique.<locals>.unique.   s=     OO 	D4
	s   66)r(   r   r)   r   returnzGenerator[Any, None, None])	functoolswraps)r,   r-   s   ` r!   _uniquer1   +   s'     __R  M    c              #    K   | j                   }|J d       | j                         }|t        |       |D ]  }t        j                  j                  ||      }| |j                  d      s9t        j                  j                  |      \  }}|dd }t        j                  j                  ||dz         }| t        j                  j                  ||dz         }|  yw)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)distr:   entriesentryr   dnr,   bases           r!   uninstallation_pathsrC   9   s      }}H00((*G$$77 	ww||He,
==WW]]4(FBcr7D77<<D6M2DJ77<<D6M2DJ	s   A.C)1A8C)c                    t         j                  j                  t               }t	        | t
              D ]+  t        fd|D              }|r|j                         - |S )zCompact 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     K   | ]U  }j                  |j                  d             xr/ t        |j                  d       j                                 k(   W yw)*N)
startswithrstriplen).0	shortpathr   seps     r!   	<genexpr>zcompact.<locals>.<genexpr>d   sc      
  OOI,,S12 DS))#.55c:;<CD
s   AA)r   r   rN   r&   sortedrK   anyr'   )pathsshort_pathsshould_skipr   rN   s      @@r!   compactrU   [   sa     ''++CEKu#& " 
 )
 

 OOD!" r2   c                  
 | D ci c]"  }t         j                  j                  |      |$ }}t        |      }t	        |j                         D ch c]$  }t         j                  j                  |      d   & c}t              }t               }dd|D ]  t        fd|D              rt               }t               }t        j                        D ]>  \  
}}	|j                  
fd|D               |j                  
fd|	D               @ ||z
  r|j                  |       |j                  t         j                  z           t        t        |j                  |            |z  S c c}w c c}w )zReturns 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.
    r   rE   c                 t    t         j                  j                  t        j                  j                  |        S r%   )r   r   normcaser   )as    r!   	norm_joinz&compress_for_rename.<locals>.norm_joiny   s$    wwa 011r2   c              3  z   K   | ]2  }t         j                  j                        j                  |       4 y wr%   )r   r   rX   rI   )rL   wroots     r!   rO   z&compress_for_rename.<locals>.<genexpr>}   s+     Grww%003Gs   8;c              3  2   K   | ]  } |        y wr%    )rL   ddirnamerZ   r]   s     r!   rO   z&compress_for_rename.<locals>.<genexpr>   s     Lqyw:L   c              3  2   K   | ]  } |        y wr%   r_   )rL   fra   rZ   r]   s     r!   rO   z&compress_for_rename.<locals>.<genexpr>   s     HQYtWa8Hrb   )rY   strr.   re   )r   r   rX   r&   rP   valuesr=   rK   rQ   walkupdatedifference_updater'   rN   map__getitem__)rR   pcase_map	remaining	unchecked	wildcards	all_filesall_subdirssubdirsfilesra   rZ   r]   s             @@@r!   compress_for_renameru   n   s<    1661  #Q&6H6HIX__5FGa(+GSQI%I2  )GYGG!e	 #')wwt} 	I#GWeLGLLH%HH	I I%''	2MM$-()" s8''34y@@3 7Gs   'E8)E=c                t   t        |       }t               }t               }t               }|D ]h  }|j                  d      r|j                  d      sd|v r.|j                  t        j                  j                  |             |j                  |       j t        t        t        j                  j                  |            }t        |      }|D ]  }t        j                  |      D ]  \  }}	}
|
D ]  }|j                  d      rt        j                  j                  ||      }t        j                  j                  |      sUt        j                  j                  |      |vsw|j                  |          ||D ch c]"  }t        j                  j                  |d      $ c}z  }||fS c c}w )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.
    r8   z__init__.pyz
.dist-inforH   )r&   r<   r'   r   r   ra   rj   rX   rU   rg   r   isfile)rR   will_remove	will_skipfoldersrt   r   _normcased_filesfolderdirpath_dirfilesfnamefile_s                r!   compress_for_output_listingr      so    e*KI eGEE == =='<4+?KK-.		$ 3rww//78gG  )$&GGFO 	) GQ! 
)>>&)We4GGNN5)((/7GG MM%(
)	)) 7K277<<4KKK	!! Ls   'F5c                  R    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y	)StashedUninstallPathSetzWA set of file rename operations to stash files while
    tentatively uninstalling them.c                     i | _         g | _        y r%   )
_save_dirs_movesselfs    r!   __init__z StashedUninstallPathSet.__init__   s     57 .0r2   c                    	 t        |      }|| j                  t        j
                  j                  |      <   |j
                  S # t        $ r t        d      }Y Ow xY w)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   rX   )r   r   save_dirs      r!   _get_directory_stashz,StashedUninstallPathSet._get_directory_stash   sU    	7&;D&AH 3;((./}}	  	7$+6H	7s   A AAc                ~   t         j                  j                  |      }t         j                  j                  |      d}}d}||k7  r	 | j                  |   }n:t         j                  j                  |      }t        d      }|| j                  |<   t         j                  j                  ||      }|rG|t         j                  j                  k7  r*t         j                  j                  |j                  |      S |j                  S # t
        $ r Y nw xY wt         j                  j                  |      |}}||k7  r)zStashes 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   ra   r   KeyErrorr   relpathcurdirr   )r   r   headold_headr   r   s         r!   _get_file_stashz'StashedUninstallPathSet._get_file_stash   s    
 ww%.hh??40 77??4(D$+6H$,DOOD!''//$-w"''..077<<w77}}  WW__T2D(D hs   	D 	DDc                   t         j                  j                  |      xr  t         j                  j                  |       }|r| j	                  |      }n| j                  |      }| j                  j                  ||f       |r4t         j                  j                  |      rt        j                  |       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   appendrmdirr   )r   r   path_is_dirnew_paths       r!   stashzStashedUninstallPathSet.stash   s     ggmmD)F"''..2F.F006H++D1HD(+,277==2 HHXhr2   c                ~    | j                   j                         D ]  }|j                           g | _        i | _         y)z0Commits the uninstall by removing stashed files.N)r   rf   cleanupr   )r   r   s     r!   commitzStashedUninstallPathSet.commit  s8    ..0 	H	r2   c                b   | j                   D ]  }t        j                  dg|   | j                   D ]  \  }}	 t        j                  d||       t        j
                  j                  |      st        j
                  j                  |      rt	        j                  |       n*t        j
                  j                  |      rt        |       t        ||        | j                          y# t        $ r6}t        j                  d|       t        j                  d|       Y d}~d}~ww xY w)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   rw   r   unlinkr   r   r   r   errorr   )r   rl   r   r   exs        r!   rollbackz StashedUninstallPathSet.rollback  s     	6AKK0515	6 #kk 
	2NHd	23XtD77>>(+rww~~h/GIIh'WW]]8,8$h'
	2 		  23X>_b112s   B!C//	D.8,D))D.c                ,    t        | j                        S r%   )boolr   r   s    r!   can_rollbackz$StashedUninstallPathSet.can_rollback%  s    DKK  r2   Nr.   None)r   re   r.   re   r.   r   )__name__
__module____qualname____doc__r   r   r   r   r   r   propertyr   r_   r2   r!   r   r      s9    &06*& ! !r2   r   c                  d    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y)UninstallPathSetzMA set of file paths to be removed in the uninstallation of a
    requirement.c                    t               | _        t               | _        i | _        || _        t               | _        t        j                  t              | _
        y r%   )r&   _paths_refuse_pth_distr   _moved_pathsr/   	lru_cacher   _normalize_path_cached)r   r>   s     r!   r   zUninstallPathSet.__init__.  sB     #!$46	
35 '0&9&9.&I#r2   c                t    t               sy|j                  | j                  t        j                              S )zs
        Return True if the given path is one we are permitted to
        remove/modify, False otherwise.

        T)r   rI   r   sysprefix)r   r   s     r!   
_permittedzUninstallPathSet._permitted9  s+     ()t::3::FGGr2   c                0   t         j                  j                  |      \  }}t         j                  j                  | j	                  |      t         j                  j                  |            }t         j                  j                  |      sy | j                  |      r| j                  j                  |       n| j                  j                  |       t         j                  j                  |      d   dk(  r| j                  t        |             y y )N   r6   )r   r   r=   r   r   rX   existsr   r   r'   r   splitextr   )r   r   r   tails       r!   r'   zUninstallPathSet.addD  s    WW]]4(
d ww||D77=rww?O?OPT?UVww~~d#??4 KKOOD!LLT" 77D!!$-HH&t,- .r2   c                   | j                  |      }| j                  |      rE|| j                  vrt        |      | j                  |<   | j                  |   j	                  |       y | j
                  j	                  |       y r%   )r   r   r   UninstallPthEntriesr'   r   )r   pth_filer@   s      r!   add_pthzUninstallPathSet.add_pthW  sf    ..x8??8$tyy(&9(&C		(#IIh##E*LLX&r2   c                   | j                   s+t        j                  d| j                  j                         y| j                  j                   d| j                  j
                   }t        j                  d|       t               5  |s| j                  |      r| j                  }t        | j                         }t        t        |            D ])  }|j                  |       t        j                  d|       + | j                  j                         D ]  }|j!                           t        j                  d|       ddd       y# 1 sw Y   yxY w)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   ru   rP   rU   r   verboser   rf   remove)r   auto_confirmr   dist_name_versionmoved
for_renamer   pths           r!   r   zUninstallPathSet.remove`  s    {{KKI

## #zz2231TZZ5K5K4LM&(9:\ 	Nt77@))0=
"7:#67 JDKK%NN#BDIJ  99++- !CJJL! 9;LM	N 	N 	Ns   B:E

Ec                "   d	d}|st        | j                        \  }}nt        | j                        }t               } |d|        |d|        |d| j                         |r |dt	        | j                               t        dd      dk7  S )
z@Display which files would be deleted and prompt for confirmationc                    |sy t         j                  |        t               5  t        t	        |            D ]  }t         j                  |        	 d d d        y # 1 sw Y   y xY wr%   )r   r   r   rP   rU   )msgrR   r   s      r!   _displayz6UninstallPathSet._allowed_to_proceed.<locals>._display  sR    KK &"75>2 &DKK%&& & &s   /AA%z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n r   )r   re   rR   Iterable[str]r.   r   )r   r   r&   r   ru   r   )r   r   r   rx   ry   s        r!   r   z$UninstallPathSet._allowed_to_proceed}  s    	& %@%M"K dkk*KI+.>	J8$,,G*,?,LM$n5<<r2   c                l   | j                   j                  s+t        j                  d| j                  j
                         yt        j                  d| j                  j
                         | j                   j                          | j                  j                         D ]  }|j                           y)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   rf   )r   r   s     r!   r   zUninstallPathSet.rollback  s      --LL9

## 2DJJ4G4GH""$99##% 	CLLN	r2   c                8    | j                   j                          y)z?Remove temporary save dir: rollback will no longer be possible.N)r   r   r   s    r!   r   zUninstallPathSet.commit  s      "r2   c           
     @   |j                   }|j                  }|(t        j                  d|j                          | |      S t        |      }|j                  s8t        j                  d|j                  |t        j                          | |      S |t        j                  d      t        j                  d      hD ch c]  }|r| c}v r)t        j                  d|j                  |        | |      S  | |      }t        |j                        }|j                  xrF |d uxr@ t        j                  j!                  |      xr |j#                  |j$                   d       }|r:||j'                  |       |j)                         }	|	8|	D ]1  }
|j'                  t        j                  j+                  ||
             3 n|j-                  d      r	 |j/                  d      }|j1                  d	
      }|j/                  d      j1                         D cg c]
  }|r||vr| c}D ]o  }t        j                  j+                  ||      }|j'                  |       |j'                  | d       |j'                  | d       |j'                  | d       q n|j4                  rt7        |      |j8                  r|j'                  |       t        j                  j;                  |      d   }t        j                  j+                  t        j                  j=                  |      d      }|j?                  |d|z          nG|j@                  r#tC        |      D ]  }|j'                  |        n|rtE        |      5 }t        j                  jG                  |jI                         jK                               }|jM                  |      }d d d        t        j                  jO                  |      sJ d| d d|j                   d| d	       |j'                  |       t        j                  j+                  t        j                  j=                  |      d      }|j?                  ||       nt        jQ                  d||       |jR                  rtU               }n
tW               }	 |jY                         D ]j  }|j'                  t        j                  j+                  ||             tZ        s9|j'                  t        j                  j+                  || d             l 	 	 	 	 	 	 	 dd} |||      D ]  }|j'                  |        |S c c}w # t2        $ r g }Y ww xY wc c}w # 1 sw Y   xY w# t2        t\        f$ r Y ew xY w)Nz-Not uninstalling %s since it is not installedz1Not uninstalling %s at %s, outside environment %sstdlib
platstdlibz<Not uninstalling %s at %s, as it is in the standard library.z	.egg-infoztop_level.txtznamespace_packages.txtF)keependsr6   r8   r9   r4   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.batc              3     K   | j                         D ]`  }|j                  dk(  r t        ||j                  d      E d {    2|j                  dk(  sBt        ||j                  d      E d {    b y 7 77 	w)Nconsole_scriptsFgui_scriptsT)iter_entry_pointsgroupr"   name)r>   r   entry_points      r!   iter_scripts_to_removez:UninstallPathSet.from_dist.<locals>.iter_scripts_to_remove8  sv       $557 N$$(99,Wk6F6FNNN &&-7,Wk6F6FMMM	NNMs(   =A;A7 A;A;/A90A;9A;)r>   r   r   re   r.   Generator[str, None, None])/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
splitlinesFileNotFoundErrorinstalled_by_distutilsr	   installed_as_eggr=   ra   r   installed_with_dist_inforC   openrX   readlinestripr   samefiler   in_usersiter   r   iter_distutils_script_namesr   NotADirectoryError)clsr>   dist_locationr   normalized_dist_locationrl   paths_to_removedevelop_egg_linksetuptools_flat_installationinstalled_filesinstalled_filenamespace_packages
namespacestop_level_pkgr   easy_install_eggeasy_install_pthfhlink_pointernormalized_link_pointerr   scriptr   ss                           r!   	from_distzUninstallPathSet.from_dist  s`   ** KK?## t9#1-#@ zzKKC##(

	 t9#((2I4F4F|4TU(
 (
 

 KKN##(
 t9d)6t}}E 33 ST)S}-S
 "**d.F.F-Gy+QRR 	% ((##M2"88:O*&5 UN#'']N(STU
 o.O)-8P)Q& "4!>!>!>!NJ "^^O<GGI&Qj0 & 	7M
 77<<}ED#''-#''4&5#''4&6#''4&6	7 (((d;;""  89!ww}}-EFqI!ww|| 89"  ##$4d=M6MN**,T2 *##D)*  &' 2!ww//0C0C0EF*9*P*P +'
 77##')A  ,-U<. A))-u]O1N   01!ww|| 013E  ##$4mD LL; "nG$&G	::< P##BGGLL&$AB#''Wo(NOP	N"	N	N (	N (g6 	#A"	# M(
T ) $!#J$&H F "#56 		sD   ?U"U' U9AU>9AV 4V 'U65U6>VVVN)r>   r   r.   r   )r   re   r.   r   )r   re   r.   r   )r   re   r@   re   r.   r   )FF)r   r   r   r   r.   r   )r   r   r.   r   r   )r>   r   r.   r   )r   r   r   r   r   r   r'   r   r   r   r   r   classmethodr  r_   r2   r!   r   r   *  sH    	J	H.&'N:=8# Z Zr2   r   c                  ,    e Zd ZddZddZddZd	dZy)
r   c                >    || _         t               | _        d | _        y r%   )filer&   r?   _saved_lines)r   r   s     r!   r   zUninstallPthEntries.__init__I  s    	!$04r2   c                    t         j                  j                  |      }t        r4t         j                  j	                  |      d   s|j                  dd      }| j                  j                  |       y )Nr   \/)r   r   rX   r   
splitdrivereplacer?   r'   )r   r@   s     r!   r'   zUninstallPthEntries.addN  sS      ' 277--e4Q7MM$,Er2   c                4   t         j                  d| j                         t        j                  j                  | j                        s!t         j                  d| j                         y t        | j                  d      5 }|j                         }|| _	        d d d        t        d D              rd}nd}|r=|d   j                  |j                  d            s|d   |j                  d      z   |d<   | j                  D ]<  }	 t         j                  d	|       |j                  ||z   j                  d             > t        | j                  d
      5 }|j!                  |       d d d        y # 1 sw Y   xY w# t        $ r Y w xY w# 1 sw Y   y xY w)NzRemoving pth entries from %s:z.Cannot remove entries from nonexistent file %srbc              3  $   K   | ]  }d |v  
 yw)s   
Nr_   )rL   lines     r!   rO   z-UninstallPthEntries.remove.<locals>.<genexpr>h  s     14w$1s   z

zutf-8zRemoving entry: %swb)r   r   r  r   r   rw   warningr   	readlinesr  rQ   r<   encoder?   r   
ValueError
writelines)r   r  linesendliner@   s        r!   r   zUninstallPthEntries.remove]  sX   6		B ww~~dii(NNKTYYW$))T" 	&bLLNE %D	& 1511GGr++GNN7,CDb	GNN7$;;E"I\\ 	E3U;ego55g>?	 $))T" 	!bMM% 	! 	!#	& 	&  	! 	!s*   E39E?F3E<?	F
FFc                *   | j                   !t        j                  d| j                         yt        j	                  d| j                         t        | j                  d      5 }|j                  | j                          d d d        y# 1 sw Y   yxY w)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  s     r!   r   zUninstallPthEntries.rollbackx  so    $LLI499U8$))D$))T" 	-bMM$++,	-	-s   $B		BN)r   re   r.   r   )r@   re   r.   r   r   r   )r   r   r   r   r'   r   r   r_   r2   r!   r   r   H  s    5
 !6r2   r   )r   re   r   re   r   r   r.   r   )r,   )Callable[..., Generator[Any, None, None]]r.   r3  )r>   r   r.   r   )rR   r   r.   zset[str])rR   r   r.   ztuple[set[str], set[str]])2
__future__r   r/   r   r   r   collections.abcr   r   importlib.utilr   typingr   r   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"   r1   rC   rU   ru   r   r   r   r   r_   r2   r!   <module>rA     s    "  	 
  / ,   S @ 3 . D = I I M C	8	&&"&,0&&&1. 	 	B&AD."bf! f!R[ [|7 7r2   