
    eg_                        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 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Z/dee*   dee*   fdZ0dee*   deee*   ee*   f   fdZ1 G d d      Z2 G d d      Z3 G d d       Z4y)!    N)cache_from_source)	AnyCallableDict	GeneratorIterableListOptionalSetTuple)UninstallationError)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       |/var/www/html/FastMealFinder_FlaskServer-InitialRelease/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'   r1   s   ` r%   _uniquer4   (   sG     __Rc  3d?)C   M    distc              #   v  K   | j                   }|J d       | j                         }|\d|  d}| j                  }|r|dk(  r/| j                   d| j                   }|d| dz  }t        |      |d	| d
z  }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 UninstallationError,
    with possible information from the INSTALLER file.

    https://packaging.python.org/specifications/recording-installed-packages/
    Nznot installedzCannot uninstall z, RECORD file not found.pipz==zV You might be able to recover from this via: 'pip install --force-reinstall --no-deps z'.z$ Hint: The package was installed by ..py.pyc.pyo)locationiter_declared_entries	installerraw_nameversionr   r!   r"   r#   endswithsplit)r6   r>   entriesmsgr@   depentryr"   dnr'   bases              r%   uninstallation_pathsrK   6   sH     }}H00((*G!$'?@NN	I.]]O2dll^4C<<?5DC "#&& 9)AFFC!#&& 	ww||He,
==WW]]4(FBcr7D77<<D6M2DJ77<<D6M2DJ	s   B>D9A8D9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>k   sc      
  OOI,,S12 DS))#.55c:;<CD
s   AA)r!   r"   rW   r-   sortedrT   anyr.   )rL   short_pathsshould_skipr"   rW   s      @@r%   compactr]   b   sa     ''++CEKu#& " 
 )
 

 OOD!" r5   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   rN   ar   c                  t    t         j                  j                  t        j                  j                  |        S r,   )r!   r"   normcaser#   )r_   s    r%   	norm_joinz&compress_for_rename.<locals>.norm_join   s$    wwa 011r5   c              3   z   K   | ]2  }t         j                  j                        j                  |       4 y wr,   )r!   r"   ra   rR   )rU   wroots     r%   rX   z&compress_for_rename.<locals>.<genexpr>   s+     Grww%003Gs   8;c              3   2   K   | ]  } |        y wr,    )rU   ddirnamerb   re   s     r%   rX   z&compress_for_rename.<locals>.<genexpr>   s     Lqyw:L   c              3   2   K   | ]  } |        y wr,   rg   )rU   fri   rb   re   s     r%   rX   z&compress_for_rename.<locals>.<genexpr>   s     HQYtWa8Hrj   )r!   r"   ra   r-   rY   valuesrD   rT   strrZ   walkupdatedifference_updater.   rW   map__getitem__)rL   pcase_map	remaining	unchecked	wildcards	all_filesall_subdirssubdirsfilesri   rb   re   s             @@@r%   compress_for_renamer}   u   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-inforQ   )r-   rC   r.   r!   r"   ri   rr   ra   r]   ro   r#   isfile)rL   will_remove	will_skipfoldersr|   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r5   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"   ra   )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"   ra   ri   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r5   c                 ~    | j                   j                         D ]  }|j                           g | _        i | _         y)z0Commits the uninstall by removing stashed files.N)r   rm   cleanupr   )r   r   s     r%   commitzStashedUninstallPathSet.commit  s8    ..0 	H	r5   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   rt   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  r5   r   N)__name__
__module____qualname____doc__r   rn   r   r   r   r   r   propertyr   r   rg   r5   r%   r   r      sj    &0  C C 6# # *& !d ! !r5   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.r6   r   Nc                     t               | _        t               | _        i | _        || _        t               | _         t        j                         t              | _
        y r,   )r-   _paths_refuse_pth_distr   _moved_pathsr2   	lru_cacher   _normalize_path_cached)r   r6   s     r%   r   zUninstallPathSet.__init__5  sG     #!$46	
35 '<i&9&9&;N&K#r5   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   rR   r   sysprefix)r   r"   s     r%   
_permittedzUninstallPathSet._permitted@  s+     ()t::3::FGGr5   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"   rD   r#   r   ra   existsr   r   r.   r   splitextr   )r   r"   r   tails       r%   r.   zUninstallPathSet.addK  s    WW]]4(
d ww||D77=rww?O?OPT?UVww~~d#??4 KKOOD!LLT" 77D!!$-HH&t,- .r5   pth_filerH   c                    | j                  |      }| j                  |      rE|| j                  vrt        |      | j                  |<   | j                  |   j	                  |       y | j
                  j	                  |       y r,   )r   r   r   UninstallPthEntriesr.   r   )r   r   rH   s      r%   add_pthzUninstallPathSet.add_pth^  sf    ..x8??8$tyy(&9(&C		(#IIh##E*LLX&r5   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   rA   rB   r   _allowed_to_proceedr   r}   rY   r]   r   r   r   rm   remove)r   r   r   dist_name_versionmoved
for_renamer"   pths           r%   r   zUninstallPathSet.removeg  s    {{KKI

## #zz2231TZZ5G5G4HI&(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 confirmationrF   rL   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   rY   r]   )rF   rL   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   )rn   r   r   r   r-   r   r}   r   )r   r   r   r   r   s        r%   r   z$UninstallPathSet._allowed_to_proceed  s    	&# 	&hsm 	& 	& %@%M"K dkk*KI+.>	J8$,,G*,?,LM$n5<<r5   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   rA   r   r   r   rm   )r   r   s     r%   r   zUninstallPathSet.rollback  s      --LL9

## 2DJJ4G4GH""$99##% 	CLLN	r5   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      "r5   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        dj9                  |j                              |j:                  r|j'                  |       t        j                  j=                  |      d   }t        j                  j+                  t        j                  j?                  |      d      }|jA                  |d|z          nG|jB                  r#tE        |      D ]  }|j'                  |        n|rtG        |      5 }t        j                  jI                  |jK                         jM                               }|jO                  |      }d d d        t        j                  jQ                  |      sJ d| d d|j                   d| d	       |j'                  |       t        j                  j+                  t        j                  j?                  |      d      }|jA                  ||       nt        jS                  d||       |jT                  rtW               }n
tY               }	 |j[                         D ]j  }|j'                  t        j                  j+                  ||             t\        s9|j'                  t        j                  j+                  || d             l 	 dt`        dtb        dtd        tb        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=   zCannot 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.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.batr6   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)r6   r   entry_points      r%   iter_scripts_to_removez:UninstallPathSet.from_dist.<locals>.iter_scripts_to_removeB  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;)3r>   info_locationr   r   canonical_namer   localr   r   	sysconfigget_pathr   rA   "installed_with_setuptools_egg_infor!   r"   r   rC   setuptools_filenamer.   r?   r#   is_file	read_text
splitlinesFileNotFoundErrorinstalled_by_distutilsr   formatinstalled_as_eggrD   ri   r   installed_with_dist_inforK   openra   readlinestripr   samefiler   in_usersiter   r   iter_distutils_script_namesr   NotADirectoryErrorr   rn   r   )clsr6   dist_locationr   normalized_dist_locationrt   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 ((%FFLfMMG  "" .!ww}}];A>!ww||."  ##$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"	# S(
T ) $!#J$&N F "#56 		sD   ?VV V'$AV,AV9 4V9 V$#V$,V69W
W)FFr   )r   r   r   r   r   r   rn   r   r   r.   r   r   r   r   r   classmethodr  rg   r5   r%   r   r   1  s    	L- 	L$ 	L	Hs 	Ht 	H. . .&' 'C 'D 'N4 N$ N4 N:=4 =D =8# ]- ]2D ] ]r5   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-   rE   _saved_lines)r   r   s     r%   r   zUninstallPthEntries.__init__S  s    	!$37r5   rH   c                     t         j                  j                  |      }t        r4t         j                  j	                  |      d   s|j                  dd      }| j                  j                  |       y )Nr   \/)r!   r"   ra   r   
splitdrivereplacerE   r.   )r   rH   s     r%   r.   zUninstallPthEntries.addX  sS      ' 277--e4Q7MM$,Er5   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   
Nrg   )rU   lines     r%   rX   z-UninstallPthEntries.remove.<locals>.<genexpr>r  s     14w$1s   z

zutf-8zRemoving entry: %swb)r   r   r  r!   r"   r   warningr  	readlinesr   rZ   rC   encoderE   r   
ValueError
writelines)r   r  linesendlinerH   s        r%   r   zUninstallPthEntries.removeg  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  r1  )r   r  s     r%   r   zUninstallPthEntries.rollback  so    $LLI499U8$))D$))T" 	-bMM$++,	-	-s   $B		Br   )	r   r   r   rn   r   r.   r   r   r   rg   r5   r%   r   r   R  s9    8 8 8
     !6$ r5   r   )5r2   r!   r   r   importlib.utilr   typingr   r   r   r   r   r	   r
   r   r   pip._internal.exceptionsr   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   rn   r   r&   r4   rK   r]   r}   r   r   r   r   rg   r5   r%   <module>r@     sk    	 
  , W W W 8 @ 3 . D = I I M C	8	&&"&,0&sD$&&iT4001c9S$_--. 	(/ (Ic4o4N ( 	(V8C= SX &Ax} AS AD."x} ."s3xS?Q9R ."bf! f!R^ ^B	7 7r5   