
    )h^                        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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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e+de+de,de
e+ddf   fdZ-dede
eddf   f   dede
eddf   f   fdZ.e.dede
e+ddf   fd       Z/dee+   dee+   fdZ0dee+   dee+   fdZ1dee+   deee+   ee+   f   fdZ2 G d d      Z3 G d d      Z4 G d d       Z5y)!    N)cache_from_source)	AnyCallableDict	GeneratorIterableListOptionalSetTuple)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script_nameis_guireturnc              #      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   )r   r   r   exe_names       R/var/www/html/venv/lib/python3.12/site-packages/pip/_internal/req/req_uninstall.py_script_namesr'      s^      ww||G[1H
NJd
Jm
$$
+&&
*%%s   AAfn.c           
      |     t        j                         dt        dt        dt        t        d d f   f fd       }|S )Nargskwr    c               ?   p   K   t               } | i |D ]  }||vs|j                  |       |  y wN)setadd)r*   r+   seenitemr(   s       r&   uniquez_unique.<locals>.unique+   s=     OO 	D4
	s   66)	functoolswrapsr   r   )r(   r2   s   ` r&   _uniquer5   (   sG     __Rc  3d?)C   M    distc              #     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)r7   r?   entriesentryr#   dnr(   bases           r&   uninstallation_pathsrG   6   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)pathsc                     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>a   sc      
  OOI,,S12 DS))#.55c:;<CD
s   AA)r"   r#   rS   r.   sortedrP   anyr/   )rH   short_pathsshould_skipr#   rS   s      @@r&   compactrY   X   sa     ''++CEKu#& " 
 )
 

 OOD!" r6   c                   
 | D ci c]"  }t         j                  j                  |      |$ }}t        |      }t	        |j                         D ch c]$  }t         j                  j                  |      d   & c}t              }t               }dt        dt        f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   rJ   ar    c                  t    t         j                  j                  t        j                  j                  |        S r-   )r"   r#   normcaser$   )r[   s    r&   	norm_joinz&compress_for_rename.<locals>.norm_joinv   s$    wwa 011r6   c              3   z   K   | ]2  }t         j                  j                        j                  |       4 y wr-   )r"   r#   r]   rN   )rQ   wroots     r&   rT   z&compress_for_rename.<locals>.<genexpr>z   s+     Grww%003Gs   8;c              3   2   K   | ]  } |        y wr-    )rQ   ddirnamer^   ra   s     r&   rT   z&compress_for_rename.<locals>.<genexpr>   s     Lqyw:L   c              3   2   K   | ]  } |        y wr-   rc   )rQ   fre   r^   ra   s     r&   rT   z&compress_for_rename.<locals>.<genexpr>   s     HQYtWa8Hrf   )r"   r#   r]   r.   rU   valuesrB   rP   strrV   walkupdatedifference_updater/   rS   map__getitem__)rH   pcase_map	remaining	unchecked	wildcards	all_filesall_subdirssubdirsfilesre   r^   ra   s             @@@r&   compress_for_renamery   k   sJ    1661  #Q&6H6HIX__5FGa(+GSQI%I2c 2c 2  )GYGG!e	 #')wwt} 	I#GWeLGLLH%HH	I I%''	2MM$-()" s8''34y@@3 7Gs   'F)F	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.
    r=   z__init__.pyz
.dist-inforM   )r.   rA   r/   r"   r#   re   rn   r]   rY   rk   r$   isfile)rH   will_remove	will_skipfoldersrx   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                   n    e Zd ZdZddZdedefdZdedefdZdedefdZdd	Z	dd
Z
edefd       Zy)StashedUninstallPathSetzWA set of file rename operations to stash files while
    tentatively uninstalling them.r    Nc                      i | _         g | _        y r-   )
_save_dirs_movesselfs    r&   __init__z StashedUninstallPathSet.__init__   s     57 .0r6   r#   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#   r]   )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#   r]   re   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r6   c                 ~    | j                   j                         D ]  }|j                           g | _        i | _         y)z0Commits the uninstall by removing stashed files.N)r   ri   cleanupr   )r   r   s     r&   commitzStashedUninstallPathSet.commit  s8    ..0 	H	r6   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#   r{   r   unlinkr   r   r   r   errorr   )r   rp   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  r6   r    N)__name__
__module____qualname____doc__r   rj   r   r   r   r   r   propertyr   r   rc   r6   r&   r   r      sj    &0  C C 6# # *& !d ! !r6   r   c                       e Zd ZdZdeddfdZdedefdZdeddfdZ	d	ed
eddfdZ
ddededdfdZdedefdZddZddZededd fd       Zy)UninstallPathSetzMA set of file paths to be removed in the uninstallation of a
    requirement.r7   r    Nc                     t               | _        t               | _        i | _        || _        t               | _        t        j                  t              | _
        y r-   )r.   _paths_refuse_pth_distr   _moved_pathsr3   	lru_cacher   _normalize_path_cached)r   r7   s     r&   r   zUninstallPathSet.__init__+  sB     #!$46	
35 '0&9&9.&I#r6   r#   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   rN   r   sysprefix)r   r#   s     r&   
_permittedzUninstallPathSet._permitted6  s+     ()t::3::FGGr6   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   r;   )r"   r#   rB   r$   r   r]   existsr   r   r/   r   splitextr   )r   r#   r   tails       r&   r/   zUninstallPathSet.addA  s    WW]]4(
d ww||D77=rww?O?OPT?UVww~~d#??4 KKOOD!LLT" 77D!!$-HH&t,- .r6   pth_filerD   c                    | j                  |      }| j                  |      rE|| j                  vrt        |      | j                  |<   | j                  |   j	                  |       y | j
                  j	                  |       y r-   )r   r   r   UninstallPthEntriesr/   r   )r   r   rD   s      r&   add_pthzUninstallPathSet.add_pthT  sf    ..x8??8$tyy(&9(&C		(#IIh##E*LLX&r6   auto_confirmverbosec                    | 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   ry   rU   rY   r   r   r   ri   remove)r   r   r   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                 L   dt         dt        t            ddf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 confirmationmsgrH   r    Nc                     |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   rU   rY   )r   rH   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   )rj   r   r   r   r.   r   ry   r   )r   r   r   r|   r}   s        r&   r   z$UninstallPathSet._allowed_to_proceedz  s    	&# 	&hsm 	& 	& %@%M"K dkk*KI+.>	J8$,,G*,?,LM$n5<<r6   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   ri   )r   r   s     r&   r   zUninstallPathSet.rollback  s      --LL9

## 2DJJ4G4GH""$99##% 	CLLN	r6   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      "r6   c           
      l   |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t^        dt`        dtb        t`        d d f   fd} |||      D ]  }|j'                  |        |S c c}w # t2        $ r g }Y w xY wc c}w # 1 sw Y   xY w# t2        t\        f$ r Y {w 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)keependsr;   r=   r>   r9   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.batr7   r   r    c              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)r7   r   entry_points      r&   iter_scripts_to_removez:UninstallPathSet.from_dist.<locals>.iter_scripts_to_remove5  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;)2r?   info_locationr   r   canonical_namer   localr   r   	sysconfigget_pathr   r   "installed_with_setuptools_egg_infor"   r#   r   rA   setuptools_filenamer/   r@   r$   is_file	read_text
splitlinesFileNotFoundErrorinstalled_by_distutilsr   installed_as_eggrB   re   r   installed_with_dist_inforG   openr]   readlinestripr   samefiler   in_usersiter   r   iter_distutils_script_namesr   NotADirectoryErrorr   rj   r   )clsr7   dist_locationr   normalized_dist_locationrp   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  sk   ** 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 sD$'	N (g6 	#A"	# M(
T ) $!#J$&H F "#56 		sD   ?U8U= VAV9AV! 4V! =VVV!V32V3)FFr   )r   r   r   r   r   r   rj   r   r   r/   r   r   r   r   r   classmethodr  rc   r6   r&   r   r   '  s    	J- 	J$ 	J	Hs 	Ht 	H. . .&' 'C 'D 'N4 N$ N4 N:=4 =D =8# Z- Z2D Z Zr6   r   c                   @    e Zd ZdeddfdZdeddfdZd	dZdefdZy)
r   r   r    Nc                 >    || _         t               | _        d | _        y r-   )filer.   rC   _saved_lines)r   r   s     r&   r   zUninstallPthEntries.__init__F  s    	!$37r6   rD   c                     t         j                  j                  |      }t        r4t         j                  j	                  |      d   s|j                  dd      }| j                  j                  |       y )Nr   \/)r"   r#   r]   r   
splitdrivereplacerC   r/   )r   rD   s     r&   r/   zUninstallPthEntries.addK  sS      ' 277--e4Q7MM$,Er6   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   
Nrc   )rQ   lines     r&   rT   z-UninstallPthEntries.remove.<locals>.<genexpr>e  s     14w$1s   z

zutf-8zRemoving entry: %swb)r   r   r  r"   r#   r{   warningr   	readlinesr  rV   rA   encoderC   r   
ValueError
writelines)r   r  linesendlinerD   s        r&   r   zUninstallPthEntries.removeZ  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.rollbacku  so    $LLI499U8$))D$))T" 	-bMM$++,	-	-s   $B		Br   )	r   r   r   rj   r   r/   r   r   r   rc   r6   r&   r   r   E  s9    8 8 8
     !6$ r6   r   )6r3   r"   r   r   importlib.utilr   typingr   r   r   r   r   r	   r
   r   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   rj   r   r'   r5   rG   rY   ry   r   r   r   r   rc   r6   r&   <module>r>     sk    	 
  , W W W S @ 3 . D = I I M C	8	&&"&,0&sD$&&iT4001c9S$_--. 	/ Ic4o4N  	B8C= SX &Ax} AS AD."x} ."s3xS?Q9R ."bf! f!R[ [|7 7r6   