Qg-] ddlZddlZddlZddlZddlmZddlmZmZm Z m Z m Z m Z m Z mZmZddlmZmZddlmZmZddlmZddlmZddlmZdd lmZmZdd lm Z m!Z!m"Z"m#Z#dd l$m%Z%m&Z&dd l'm(Z(ee)Z*d e+de+de,de e+ddffdZ-dede eddffdede eddfffdZ.e.dede e+ddffdZ/de e+dee+fdZ0de e+dee+fdZ1de e+deee+ee+ffdZ2GddZ3GddZ4Gdd Z5dS)!N)cache_from_source) AnyCallableDict GeneratorIterableListOptionalSetTuple)LegacyDistutilsInstallUninstallMissingRecord)get_bin_prefix get_bin_user)BaseDistribution)WINDOWS)egg_link_path_from_location) getLogger indent_log)asknormalize_pathrenamesrmtree)AdjacentTempDirectory TempDirectory)running_under_virtualenvbin_dir script_nameis_guireturnc#Ktj||}|VtsdS|dV|dV|r |dVdS|dVdS)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)ospathjoinr)rrrexe_names /builddir/build/BUILD/imunify360-venv-2.5.0/opt/imunify360/venv/lib/python3.11/site-packages/pip/_internal/req/req_uninstall.py _script_namesr'sw||G[11H NNN       $ $ $$$$ &&&&&&&&&%%%%%%%%fn.c tjdtdtdttddfffd }|S)Nargskwr c?xKt}|i|D]}||vr|||V dSN)setadd)r+r,seenitemr)s r&uniquez_unique..unique+sYBOOO  D4   r() functoolswrapsrr)r)r3s` r&_uniquer6(s__Rc3d?)C Mr(distc#K|j}| Jd|}|t||D]}tj||}|V|drztj|\}}|dd}tj||dz}|Vtj||dz}|VdS)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)locationiter_declared_entriesrr"r#r$endswithsplit)r7r?entriesentryr#dnr)bases r&uninstallation_pathsrG6s}H      ((**G$$7777  w||He,, ==   W]]4((FBcrc7D7<<D6M22DJJJ7<<D6M22DJJJ  r(pathsctjjt}t |t D]5t fd|D}|s|6|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.keyc3K|]k}|do>t|dkVldS)*N) startswithrstriplen).0 shortpathr#seps r& zcompact..as   OOI,,S11 2 2 DS))#..55c::;;<C      r()r"r#rSr/sortedrPanyr0)rH short_paths should_skipr#rSs @@r&compactrYXs '+CEEKu#&&&""     )      " OOD ! ! ! r(c d|D}t|}td|Dt}t}dtdtfd |D]׊ t fd|Drt}t}t j D]L\ }}| fd|D| fd |DM||z s7| || t j ztt|j ||zS) 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. cNi|]"}tj||#S)r"r#normcaserQps r& z'compress_for_rename..qs*6661  ##Q666r(cXh|]'}tj|d(S)r)r"r#rBr^s r& z&compress_for_rename..ss+GGG a((+GGGr(rJar cbtjtjj|Sr.)r"r#r]r$)rcs r& norm_joinz&compress_for_rename..norm_joinvs!w a 0111r(c3|K|]6}tj|V7dSr.)r"r#r]rN)rQwroots r&rTz&compress_for_rename..zsAGGrw%%0033GGGGGGr(c32K|]}|VdSr.r\)rQddirnamererhs r&rTz&compress_for_rename..s1LLqyyw::LLLLLLr(c32K|]}|VdSr.r\)rQfrkrerhs r&rTz&compress_for_rename..s1HHQYYtWa88HHHHHHr()r/rUvaluesrPstrrVr"walkupdatedifference_updater0rSmap __getitem__) rHcase_map remaining unchecked wildcards all_files all_subdirssubdirsfilesrkrerhs @@@r&compress_for_renamer}ks 76666HH IGGX__5F5FGGGSQQQI%%I2c2c2222)) GGGGYGGG G G  !ee # ')wt}} I I #GWe   LLLLLLGLLL L L L   HHHHHH%HHH H H H HI% )  ' ' 2 2 2 MM$- ( ( ( s8'33 4 4y @@r(cft|}t}t}t}|D]x}|dr|dsd|vr2|tj|||ytt tjj|}t|}|D]}tj |D]\}} } | D]} | drtj || } tj | r6tj| |vr|| |d|Dz}||fS)asReturns 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-infocNh|]"}tj|d#S)rM)r"r#r$)rQfolders r&rbz.compress_for_output_listing..s(KKK27<<44KKKr() r/rAr0r"r#rkrsr]rYrpr$isfile) rH will_remove will_skipfoldersr|r#_normcased_filesrdirpath_dirfilesfnamefile_s r&compress_for_output_listingrse**KIeeG EEE ==    == ' ' /<4+?+? KK-- . . . $3rw/7788gG ) )$&GFOO ) ) GQ! ) )>>&)) We44GNN5)))((//7GGGMM%((( ) )KK7KKKKK  !!r(cveZdZdZd dZdedefdZdedefdZdedefdZd d Z d d Z e de fd Z dS) StashedUninstallPathSetzWA set of file rename operations to stash files while tentatively uninstalling them.r Nc"i|_g|_dSr.) _save_dirs_movesselfs r&__init__z StashedUninstallPathSet.__init__s57.0 r(r#c t|}n #t$rtd}YnwxYw||jtj|<|jS)zStashes a directory. Directories are stashed adjacent to their original location if possible, or else moved/copied into the user's temp dir. uninstallkind)rOSErrorrrr"r#r])rr#save_dirs r&_get_directory_stashz,StashedUninstallPathSet._get_directory_stashsi  7&;D&A&AHH 7 7 7$+666HHH 72:((../}s //cVtj|}tj|d}}d}||krF |j|}np#t $rYnwxYwtj||}}||kFtj|}t d}||j|<tj||}|r:|tjjkr%tj |j|S|jS)zStashes a file. If no root has been provided, one will be created for the directory in the user's temp directory.Nrr) r"r#r]rkrKeyErrorrrelpathcurdirr$)rr#headold_headrrs r&_get_file_stashz'StashedUninstallPathSet._get_file_stashs w%%..hh ?40    W__T22D(D h7??4((D$+666H$,DOD !'//$--  8w"'.007<< w77 7}s A A%$A%ctj|otj| }|r||}n||}|j||f|r3tj|rtj|t|||S)zStashes the directory or file and returns its new location. Handle symlinks as files to avoid modifying the symlink targets. ) r"r#isdirislinkrrrappendrmdirr)rr# path_is_dirnew_paths r&stashzStashedUninstallPathSet.stashsgmmD))F"'..2F2F.F  20066HH++D11H D(+,,,  27==22  HX   hr(c|jD]}|g|_i|_dS)z0Commits the uninstall by removing stashed files.N)rrncleanupr)rrs r&commitzStashedUninstallPathSet.commitsF..00  H        r(cx|jD]}tjdg|R|jD]\}} td||tj|stj|rt j|n.tj |rt|t||#t$r@}t d|td|Yd}~d}~wwxYw|dS)z2Undoes the uninstall by moving stashed files back.zMoving to %s from %szReplacing %s from %szFailed to restore %sz Exception: %sN)rloggerinfodebugr"r#rrunlinkrrrrerrorr)rr_rr#exs r&rollbackz StashedUninstallPathSet.rollbacks? 6 6A K0 51 5 5 5 5 5"k 2 2NHd 2 3XtDDD7>>(++%rw~~h/G/G%Ih''''W]]8,,%8$$$h'''' 2 2 2 3X>>> _b11111111 2 sB-C D##6DD#c*t|jSr.)boolrrs r& can_rollbackz$StashedUninstallPathSet.can_rollback"sDK   r(r N)__name__ __module__ __qualname____doc__rrorrrrrpropertyrrr\r(r&rrs&&0000      CC6##*&!d!!!X!!!r(rceZdZdZdeddfdZdedefdZdeddfdZ d ed eddfd Z dd ededdfdZ dedefdZ ddZ ddZededdfdZdS)UninstallPathSetzMA set of file paths to be removed in the uninstallation of a requirement.r7r Nct|_t|_i|_||_t |_tjt|_ dSr.) r/_paths_refuse_pth_distr _moved_pathsr4 lru_cacher_normalize_path_cached)rr7s r&rzUninstallPathSet.__init__+sO # !$ 46  355'0&9.&I&I###r(r#ctsdS||tjS)zs Return True if the given path is one we are permitted to remove/modify, False otherwise. T)rrNrsysprefix)rr#s r& _permittedzUninstallPathSet._permitted6s9()) 4t::3:FFGGGr(cZtj|\}}tj||tj|}tj|sdS||r|j |n|j |tj |ddkr$| t|dSdS)Nr;) r"r#rBr$rr]existsrrr0rsplitextr)rr#rtails r&r0zUninstallPathSet.addAsW]]4(( dw||D77==rw?O?OPT?U?UVVw~~d##  F ??4  # KOOD ! ! ! ! L  T " " " 7  D ! !! $ - - HH&t,, - - - - - . -r(pth_filerDc||}||rB||jvrt||j|<|j||dS|j|dSr.)rrrUninstallPthEntriesr0r)rrrDs r&add_pthzUninstallPathSet.add_pthTs..x88 ??8 $ $ 'ty((&9(&C&C (# Ih  # #E * * * * * L  X & & & & &r(F auto_confirmverbosec|js'td|jjdS|jjd|jj}td|t 5|s||r|j}t|j}tt|D]2}| |t d|3|jD]}|td|ddddS#1swxYwYdS)z\Remove paths in ``self._paths`` with confirmation (unless ``auto_confirm`` is True).z7Can't uninstall '%s'. No files were found to uninstall.N-zUninstalling %s:zRemoving file or directory %szSuccessfully uninstalled %s)rrrrraw_name raw_versionr_allowed_to_proceedrr}rUrYrrrrnremove)rrrdist_name_versionmoved for_renamer#pths r&rzUninstallPathSet.remove]s{  KKI #    F#z2MMTZ5KMM &(9::: \\ N N Nt77@@ N)0== "7:#6#677JJDKK%%%NN#BDIIII9++--!!CJJLLLL 9;LMMM N N N N N N N N N N N N N N N N N Ns3C E  EEcrdtdttddfd}|st|j\}}n"t |j}t }|d||d||d|j|r|d t |jtd d d kS) z@Display which files would be deleted and prompt for confirmationmsgrHr Nc|sdSt|t5tt |D]}t| ddddS#1swxYwYdSr.)rrrrUrY)rrHr#s r&_displayz6UninstallPathSet._allowed_to_proceed.._display}s  KK    & &"75>>22&&DKK%%%%& & & & & & & & & & & & & & & & & & &s:A55A9<A9z Would remove:z+Would not remove (might be manually added):z%Would not remove (outside of prefix):zWill actually move:zProceed (Y/n)? )ynr)rorrrr/rr}r)rrrrrs r&rz$UninstallPathSet._allowed_to_proceedzs &# &hsm & & & & & %@%M%M "Kdk**KI+...> JJJ8$,GGG  N H*,? ,L,L M M M$n55<.s.( ( ( ( ( ( ( r(stdlib platstdlibzz.UninstallPathSet.from_dist..s8&&&&j00000r(r;r=r>r9rzeasy-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.batr7rr c3K|D]Q}|jdkrt||jdEd{V*|jdkrt||jdEd{VRdS)Nconsole_scriptsF gui_scriptsT)iter_entry_pointsgroupr'name)r7r entry_points r&iter_scripts_to_removez:UninstallPathSet.from_dist..iter_scripts_to_remove2s $5577 N N $(999,Wk6FNNNNNNNNNN &-77,Wk6FMMMMMMMMM  N Nr()2r? info_locationrrcanonical_namerlocalrr sysconfigget_pathrr"installed_with_setuptools_egg_infor"r#rrAsetuptools_filenamer0r@r$is_file read_text splitlinesFileNotFoundErrorinstalled_by_distutilsr installed_as_eggrBrkrinstalled_with_dist_inforGopenr]readlinestriprsamefiler in_usersiterriter_distutils_script_namesrNotADirectoryErrorrror)clsr7 dist_locationrnormalized_dist_locationpaths_to_removedevelop_egg_linksetuptools_flat_installationinstalled_filesinstalled_filenamespace_packages top_level_pkgr#easy_install_eggeasy_install_pthfh link_pointernormalized_link_pointerrscriptrsrs @r& from_distzUninstallPathSet.from_dists *  KK?#   3t99 #1-#@#@ z  KKC#(     3t99  #( ( (22I4F|4T4TU( ( (   KKN#(    3t99 #d))6t}EE  3 ST) S}-- S "**d.F+Q+Q+QRRR % (H (##M222"88::O*&5UUN#'' ]N(S(STTTTU o.. 7O)-8P)Q)Q&"4!>!>!>!N!NJJ)$$$!#JJJ$&&&&!^^O<<GGII&&& 7 7M 7<< }EED#''---#''4 555#''4 666#''4 6666  (, (d;;; ;  ")     . . .!w}}];;A> !w|| .."     # #$4d=M6M N N N N  * ,T22 * *##D)))) * &'' 2!w// 0C0C0E0EFF *9*P*P ++'                7##')A  N,NN<NN)-NN=JNNN      0 1 1 1!w|| 0113E     # #$4m D D D D LL;      '"nnGG$&&G ::<< P P##BGLL&$A$ABBBP#'' Wooo(N(NOOO P"#56    D  N" N NsD$ ' N N N N('g66 # #A    " " " "s8G== H  H 6APP"P BVV('V()FFr)rrrrrrrorrr0rrrrr classmethodr!r\r(r&rr'sr J- J$ J J J J Hs Ht H H H H......&''C'D''''NN4N$N4NNNN:=4=D====8    ####W-W2DWWW[WWWr(rcBeZdZdeddfdZdeddfdZd dZdefdZdS) rrr NcH||_t|_d|_dSr.)filer/rC _saved_lines)rrs r&rzUninstallPthEntries.__init__Cs" !$ 37r(rDctj|}tr;tj|ds|dd}|j|dS)Nr\/)r"r#r]r splitdrivereplacerCr0)rrDs r&r0zUninstallPthEntries.addHsl  ''  -27--e44Q7 -MM$,,E r(ctd|jtj|js"td|jdSt|jd5}|}||_ dddn #1swxYwYtd|Drd}nd}|rO|d | ds!|d| dz|d<|j D]Y} td ||||z dJ#t$rYVwxYwt|jd 5}||ddddS#1swxYwYdS) NzRemoving pth entries from %s:z.Cannot remove entries from nonexistent file %srbc3K|]}d|vV dS)s Nr\)rQlines r&rTz-UninstallPthEntries.remove..bs&114w$111111r(z  zutf-8zRemoving entry: %swb)rrr%r"r#rwarningr  readlinesr&rVrAencoderCr ValueError writelines)rrlinesendlinerDs r&rzUninstallPthEntries.removeWs76 BBBw~~di((  NNKTY W W W F $)T " " &bLLNNE %D  & & & & & & & & & & & & & & & 115111 1 1 GGG  <r++GNN7,C,CDD <b GNN7$;$;;E"I\  E 3U;;; ego55g>>????     $)T " " !b MM%  ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !s7<B$$B(+B((AE// E<;E<F77F;>F;c&|j"td|jdStd|jt |jd5}||jdddn #1swxYwYdS)Nz.Cannot roll back changes to %s, none were madeFz!Rolling %s back to previous stater2T)r&rrr%rr r7)rrs r&rzUninstallPthEntries.rollbackrs   $ LLI49 U U U5 8$)DDD $)T " " -b MM$+ , , , - - - - - - - - - - - - - - -tsBB  B r) rrrrorr0rrrr\r(r&rrBs888888         !!!!6$r(r)6r4r"rrimportlib.utilrtypingrrrrrr r r r pip._internal.exceptionsr rpip._internal.locationsrrpip._internal.metadatarpip._internal.utils.compatrpip._internal.utils.egg_linkrpip._internal.utils.loggingrrpip._internal.utils.miscrrrrpip._internal.utils.temp_dirrrpip._internal.utils.virtualenvrrrrorr'r6rGrYr}rrrrr\r(r&rFsN ,,,,,,WWWWWWWWWWWWWWWWWWWWWWSSSSSSSS@@@@@@@@333333......DDDDDD========IIIIIIIIIIIIMMMMMMMMCCCCCC 8  & &"&,0&sD$&&&&& iT4001  c9S$_--.     /Ic4o4N B8C=SX&Ax}ASAAAAD."x}."s3xS?Q9R."."."."bf!f!f!f!f!f!f!f!RXXXXXXXXv7777777777r(