
    i                       d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dl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/m0Z0m1Z1  ejd                  d      Z3 ejh                  e5      Z6ddZ7 G d d      Z8e G d d             Z9	 	 	 	 	 	 d dZ:	 	 	 	 	 	 	 	 d!dZ;	 	 	 	 	 	 d"dZ<d#dZ=y)$    )annotationsN)	dataclass)Version)parse)Group)escape)Text)LinkCollector)PackageFinder)get_default_environment)ReleaseControl)SelectionPreferences)
PipSession)WINDOWS)parse_iso_datetime) get_best_invocation_for_this_pip#get_best_invocation_for_this_python)adjacent_tmp_filecheck_path_ownercopy_directory_permissionsreplace)ExternallyManagedEnvironmentcheck_externally_managed
ensure_dir   )daysc                l    | j                         }t        j                  |      j                         }|S N)encodehashlibsha224	hexdigest)key	key_bytesnames      T/root/searxng-venv/lib/python3.12/site-packages/pip/_internal/self_outdated_check.py_get_statefile_namer'   /   s)    

I>>)$..0DK    c                  6    e Zd ZddZedd       ZddZd	dZy)
SelfCheckStatec                Z   i | _         d | _        |rut        j                  j	                  |dt        | j                              | _        	 t        | j                  d      5 }t        j                  |      | _         d d d        y y # 1 sw Y   y xY w# t        t        t        f$ r Y y w xY w)N	selfcheckzutf-8)encoding)_state_statefile_pathospathjoinr'   r#   openjsonloadOSError
ValueErrorKeyError)self	cache_dir	statefiles      r&   __init__zSelfCheckState.__init__6   s    &(# #%77<<;(;DHH(E$D $..A 7Y"&))I"6DK7 7 
7 7Z2  s0   B "B=B BB B B*)B*c                "    t         j                  S r   )sysprefix)r9   s    r&   r#   zSelfCheckState.keyG   s    zzr(   c                    | j                   syd| j                   vryd| j                   vryt        | j                   d         }||z
  }|t        kD  ry| j                   d   S )z7Check if we have a not-outdated version loaded already.N
last_checkpypi_version)r.   r   _WEEK)r9   current_timerA   time_since_last_checks       r&   getzSelfCheckState.getK   sd    {{t{{*, (L(AB
 ,z 9 5({{>**r(   c                   | j                   sy t        j                  j                  | j                         }t	        |      sy t        |       | j                  |j                         |d}t        j                  |dd      }t        | j                         5 }|j                  |j                                t        ||       d d d        	 t        j                  | j                          y # 1 sw Y   +xY w# t         $ r Y y w xY w)N)r#   rA   rB   T),:)	sort_keys
separators)r/   r0   r1   dirnamer   r   r#   	isoformatr4   dumpsr   writer   r   r   r%   r6   )r9   rB   rD   statefile_directorystatetextfs          r&   setzSelfCheckState.set^   s    ## ggood.B.BC   34 	&'
 88&002(
 zz%4JGt334 	?GGDKKM"&':A>	?	 AFFD001	? 	?  		s   ,C/ C; /C8;	DDN)r:   strreturnNone)rV   rU   )rD   datetime.datetimerV   
str | None)rB   rU   rD   rX   rV   rW   )__name__
__module____qualname__r<   propertyr#   rF   rT    r(   r&   r*   r*   5   s%    "  +&#r(   r*   c                  *    e Zd ZU ded<   ded<   ddZy)UpgradePromptrU   oldnewc                   t         rt                d}n
t               }d}t        t	               t	        j
                  | d| j                   d| j                   d      t	        j
                  | dt        |       d            S )Nz -m pipz/[bold][[reset][blue]notice[reset][bold]][reset]z) A new release of pip is available: [red]z[reset] -> [green]z[reset]z To update, run: [green]z install --upgrade pip)	r   r   r   r   r	   from_markupra   rb   r   )r9   pip_cmdnotices      r&   __rich__zUpgradePrompt.__rich__   s    <>?wGG68GBF( z!3DHH:WF (  /**@B

 
	
r(   N)rV   r   )rZ   r[   r\   __annotations__rg   r^   r(   r&   r`   r`      s    	H	H
r(   r`   c                    t        j                  | |d      }t        dt        dh            }t	        j                  ||      }|j                  d      j                  }|y t        |j                        S )NT)optionssuppress_no_indexFpip)
only_final)allow_yankedrelease_control)link_collectorselection_prefs)	r
   creater   r   r   find_best_candidatebest_candidaterU   version)sessionrj   rp   rq   finderrt   s         r&   _get_current_remote_pip_versionrx      s     #))N +&5':O
 !!%'F //6EEN~%%&&r(   c                   t        |      }t        j                  d|       t        j                  d|        t        j                  d|       |sy | |k  xr | j                  |j                  k7  }|rt	        t        |       |      S y )NzRemote version of pip: %szLocal version of pip:  %szWas pip installed by pip? %s)ra   rb   )parse_versionloggerdebugbase_versionr`   rU   )local_versionremote_version_strinstalled_by_pipremote_versionlocal_version_is_olders        r&   _compute_upgrade_promptr      s     ##56N
LL,n=
LL,m<
LL/1AB 	& 	F&&.*E*EE  ]!39KLLr(   c                   t               j                  d      }|sy	 t                t	        |j
                        }t        j                  j                  t        j                  j                        }|j                  |      }|6t        | |      }|t        j                  d       y|j                  ||       t        |j                   ||j"                  dk(        S # t        $ r Y yw xY w)an  Compute the pip upgrade prompt, if any, before the command runs.

    Limit the frequency of checks to once per week. State is stored either in
    the active virtualenv or in the user's USER_CACHE_DIR keyed off the prefix
    of the pip script path.

    Pair with :func:`pip_self_version_check_emit`, which displays the prompt
    after the command body runs.
    rl   N)r:   zNo remote pip version found)r~   r   r   )r   get_distributionr   r   r*   r:   datetimenowtimezoneutcrF   rx   r{   r|   rT   r   ru   	installer)rv   rj   installed_distrQ   rD   r   s         r&   pip_self_version_check_fetchr      s     -.??FN " W%6%67E$$(():):)>)>?L<0!<WgN%LL67		$l3"$,,-'11U:  ( s   
C# #	C/.C/c                >    | t         j                  d| ddi       yy)zIEmit the upgrade prompt captured by :func:`pip_self_version_check_fetch`.Nz%srichT)extra)r{   warning)upgrade_prompts    r&   pip_self_version_check_emitr      s#    !t^FD>B "r(   )r#   rU   rV   rU   )rv   r   rj   optparse.ValuesrV   rY   )r~   r   r   rU   r   boolrV   UpgradePrompt | None)rv   r   rj   r   rV   r   )r   r   rV   rW   )>
__future__r   r   r    r4   loggingoptparseos.pathr0   r>   dataclassesr   pip._vendor.packaging.versionr   r   rz   pip._vendor.rich.consoler   pip._vendor.rich.markupr   pip._vendor.rich.textr	   pip._internal.index.collectorr
   "pip._internal.index.package_finderr   pip._internal.metadatar   $pip._internal.models.release_controlr   $pip._internal.models.selection_prefsr   pip._internal.network.sessionr   pip._internal.utils.compatr   pip._internal.utils.datetimer   pip._internal.utils.entrypointsr   r   pip._internal.utils.filesystemr   r   r   r   pip._internal.utils.miscr   r   r   	timedeltarC   	getLoggerrZ   r{   r'   r*   r`   rx   r   r   r   r^   r(   r&   <module>r      s   "       
 ! 1 @ * * & 7 < : ? E 4 . ;   	"			8	$L L^ 
 
 
0''"1''803GK*"""1""JCr(   