
    vg                      x   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/  e j`                  d      Z1 ejd                  e3      Z4de5de5fdZ6de5de j                   fdZ7 G d d      Z8e
 G d d             Z9de5de:fdZ;de$d ejx                  dee5   fd!Z=d"e8d#e j                   d$e d%eg ee5   f   dee9   f
d&Z>de$d ejx                  ddfd'Z?y)(    N)	dataclass)AnyCallableDictOptional)parse)Group)escape)Text)LinkCollector)PackageFinder)get_default_environment)DistributionVersion)SelectionPreferences)
PipSession)WINDOWS) get_best_invocation_for_this_pip#get_best_invocation_for_this_python)adjacent_tmp_filecheck_path_ownerreplace)
ensure_dir   )dayskeyreturnc                 l    | j                         }t        j                  |      j                         }|S N)encodehashlibsha224	hexdigest)r   	key_bytesnames      f/home/mcse/projects/flask/flask-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)selfr0   	statefiles      r%   __init__zSelfCheckState.__init__4   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)r?   s    r%   r   zSelfCheckState.keyE   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)r4   r-   _WEEK)r?   rE   rG   time_since_last_checks       r%   getzSelfCheckState.getI   sd    {{t{{*, #4;;|#<=
 ,z 9 5({{>**r'   rH   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   rG   rH   T),:)	sort_keys
separators)r5   r   r6   r7   dirnamer   r   	isoformatr:   dumpsr   writer   r   r$   r<   )r?   rH   rE   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__strrA   propertyr   r+   r   rK   rX    r'   r%   r/   r/   3   sm    # $ " S  + 1 1 +hsm +&   83D3D    r'   r/   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_markupra   rb   r
   )r?   pip_cmdnotices      r%   __rich__zUpgradePrompt.__rich__   s    <>?wGG68GBF( z!3DHH:WF (  /**@B

 
	
r'   N)rY   rZ   r[   r\   __annotations__r	   rg   r^   r'   r%   r`   r`      s    	H	H
% 
r'   r`   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)ri   dists     r%   was_installed_by_pipro      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)rq   suppress_no_indexF)allow_yankedallow_all_prereleases)link_collectorselection_prefsrk   )r   creater   r   find_best_candidatebest_candidater\   version)rp   rq   rv   rw   finderrz   s         r%   _get_current_remote_pip_versionr}      sy     #))N +#O
 !!%'F //6EEN~%%&&r'   rU   rE   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:  %srk   zWas pip installed by pip? %s)ra   rb   )	rK   loggerdebugrX   parse_versionro   base_versionr`   r\   )rU   rE   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        |j                        t
        j
                  j                  t
        j                  j                        |j                  t        j                  t        | |            }|t        j                  d|ddi       yy# t        $ r/ t        j                  d	       t        j!                  d
d       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.
    rk   N)r0   )rU   rE   r~   r   z%srichT)extraz6There was an error checking the latest version of pip.zSee below for error)exc_info)r   rl   r   r/   r0   r+   nowtimezoneutcr{   	functoolspartialr}   r   warning	Exceptionr   )rp   rq   installed_distupgrade_prompts       r%   pip_self_version_checkr      s     -.??FN;2 7+<+<=!**..x/@/@/D/DE(00(00/' 	
 %NN4~NF & ;OP*T:;s   BB7 75C/.C/)@r+   r   r    r:   loggingoptparseos.pathr6   rC   dataclassesr   typingr   r   r   r   pip._vendor.packaging.versionr   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.metadata.baser   $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   	timedeltarI   	getLoggerrY   r   r\   r&   r-   r/   r`   boolro   Valuesr}   r   r   r^   r'   r%   <module>r      sv          
 ! 0 0 @ * * & 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;J ; ;T ;r'   