
    )h~                         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Zd dl	m
Z
 d dlmZmZmZ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, d dl-m.Z.m/Z/m0Z0  e jb                  d      Z2 ejf                  e4      Z5de6de6fdZ7de6de j                   fdZ8 G d d      Z9e
 G d d             Z:de6de;fdZ<de#d ejz                  dee6   fd!Z>d"e9d#e j                   d$ed%eg ee6   f   dee:   f
d&Z?de#d ejz                  ddfd'Z@y)(    N)	dataclass)AnyCallableDictOptional)Version)parse)Group)escape)Text)LinkCollector)PackageFinder)get_default_environment)SelectionPreferences)
PipSession)WINDOWS) get_best_invocation_for_this_pip#get_best_invocation_for_this_python)adjacent_tmp_filecheck_path_ownerreplace)ExternallyManagedEnvironmentcheck_externally_managed
ensure_dir   )dayskeyreturnc                 l    | j                         }t        j                  |      j                         }|S N)encodehashlibsha224	hexdigest)r   	key_bytesnames      T/var/www/html/venv/lib/python3.12/site-packages/pip/_internal/self_outdated_check.py_get_statefile_namer(   (   s)    

I>>)$..0DK    isodatec                 `    t         j                   j                  | j                  dd            S )zConvert an ISO format string to a date.

    Handles the format 2020-01-22T14:24:01Z (trailing Z)
    which is not supported by older versions of fromisoformat.
    Zz+00:00)datetimefromisoformatr   )r*   s    r'   _convert_dater/   .   s&     **7??3+IJJr)   c                       e Zd ZdeddfdZedefd       Zdej                  dee   fdZ	dedej                  ddfd	Z
y)
SelfCheckState	cache_dirr   Nc                 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)selfr2   	statefiles      r'   __init__zSelfCheckState.__init__8   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)rA   s    r'   r   zSelfCheckState.keyI   s    zzr)   current_timec                     | 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)r6   r/   _WEEK)rA   rG   rI   time_since_last_checks       r'   getzSelfCheckState.getM   sd    {{t{{*, #4;;|#<=
 ,z 9 5({{>**r)   rJ   c                 F   | j                   sy t        t        j                  j	                  | j                               sy t        t        j                  j	                  | j                                | j                  |j                         |d}t        j                  |dd      }t        | j                         5 }|j                  |j                                d d d        	 t        j                  | j                          y # 1 sw Y   +xY w# t        $ r Y y w xY w)N)r   rI   rJ   T),:)	sort_keys
separators)r7   r   r8   r9   dirnamer   r   	isoformatr<   dumpsr   writer!   r   r&   r>   )rA   rJ   rG   statetextfs         r'   setzSelfCheckState.set`   s    ##  0D0D EF 	277??4#7#789
 88&002(
 zz%4JGt334 	#GGDKKM"	#	 AFFD001	# 	#  		s   > D' D D	D D )__name__
__module____qualname__strrC   propertyr   r-   r   rM   rZ    r)   r'   r1   r1   7   sm    # $ " S  + 1 1 +hsm +&   83D3D    r)   r1   c                   .    e Zd ZU eed<   eed<   defdZy)UpgradePromptoldnewr   c                    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_markuprc   rd   r   )rA   pip_cmdnotices      r'   __rich__zUpgradePrompt.__rich__   s    <>?wGG68GBF( z!3DHH:WF (  /**@B

 
	
r)   N)r[   r\   r]   r^   __annotations__r
   ri   r`   r)   r'   rb   rb      s    	H	H
% 
r)   rb   pkgc                 ^    t               j                  |       }|duxr d|j                  k(  S )zChecks whether pkg was installed by pip

    This is used not to display the upgrade message when pip is in fact
    installed by system package manager, such as dnf on Fedora.
    Npip)r   get_distribution	installer)rk   dists     r'   was_installed_by_piprq      s0     #$55c:Dt7 77r)   sessionoptionsc                     t        j                  | |d      }t        dd      }t        j                  ||      }|j	                  d      j
                  }|y t        |j                        S )NT)rs   suppress_no_indexF)allow_yankedallow_all_prereleases)link_collectorselection_prefsrm   )r   creater   r   find_best_candidatebest_candidater^   version)rr   rs   rx   ry   finderr|   s         r'   _get_current_remote_pip_versionr      sy     #))N +#O
 !!%'F //6EEN~%%&&r)   rW   rG   local_versionget_remote_versionc                    | j                  |      }|1 |       }|t        j                  d       y | j                  ||       t	        |      }t        j                  d|       t        j                  d|       t        d      }t        j                  d|       |sy ||k  xr |j                  |j                  k7  }|rt        t        |      |      S y )NzNo remote pip version foundzRemote version of pip: %szLocal version of pip:  %srm   zWas pip installed by pip? %s)rc   rd   )	rM   loggerdebugrZ   parse_versionrq   base_versionrb   r^   )rW   rG   r   r   remote_version_strremote_versionpip_installed_by_piplocal_version_is_olders           r'   _self_version_check_logicr      s     <0!/1%LL67		$l3"#56N
LL,n=
LL,m</6
LL/1EF 	& 	F&&.*E*EE  ]!39KLLr)   c           
         t               j                  d      }|sy	 t                t	        t        |j                        t        j                  j                  t        j                  j                        |j                  t        j                  t        | |            }|t        j!                  d|ddi       yy# t        $ r Y yw xY w)	zCheck for an update for pip.

    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.
    rm   N)r2   )rW   rG   r   r   z%srichT)extra)r   rn   r   r   r   r1   r2   r-   nowtimezoneutcr}   	functoolspartialr   r   warning)rr   rs   installed_distupgrade_prompts       r'   pip_self_version_checkr      s     -.??FN " /w'8'89&&**8+<+<+@+@A$,,$,,+Wg
	N !t^FD>B " ( s   
C 	CC)Ar-   r   r"   r<   loggingoptparseos.pathr8   rE   dataclassesr   typingr   r   r   r   pip._vendor.packaging.versionr   r	   r   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.selection_prefsr   pip._internal.network.sessionr   pip._internal.utils.compatr   pip._internal.utils.entrypointsr   r   pip._internal.utils.filesystemr   r   r   pip._internal.utils.miscr   r   r   	timedeltarK   	getLoggerr[   r   r^   r(   r/   r1   rb   boolrq   Valuesr   r   r   r`   r)   r'   <module>r      s          
 ! 0 0 1 @ * * & 7 < : E 4 . X W  	"			8	$S S K3 K8#4#4 KI IX 
 
 
08c 8d 8''"*//'c]'8 ## 	
 !Xc]!23 mDCJ C CT Cr)   