o
    Ëý°jÁ  ã                   @   s  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	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mZ d d
lmZ dZe e ¡Z!de"de"fdd„Z#G dd„ dƒZ$de"de%fdd„Z&dedej'ddfdd„Z(dS )é    N)ÚAnyÚDict)Úparse)ÚLinkCollector)ÚPackageFinder)Úget_default_environment)ÚSelectionPreferences)Ú
PipSession)Úadjacent_tmp_fileÚcheck_path_ownerÚreplace)Ú
ensure_dirz%Y-%m-%dT%H:%M:%SZÚkeyÚreturnc                 C   s   |   ¡ }t |¡ ¡ }|S ©N)ÚencodeÚhashlibÚsha224Ú	hexdigest)r   Ú	key_bytesÚname© r   ú”/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/pip/_internal/self_outdated_check.pyÚ_get_statefile_name   s   r   c                   @   sH   e Zd Zdeddfdd„Zedefdd„ƒZded	ejddfd
d„ZdS )ÚSelfCheckStateÚ	cache_dirr   Nc              
   C   sŒ   i | _ d | _|rDtj |dt| jƒ¡| _z"t| jdd��}t 	|¡| _ W d   ƒ W d S 1 s/w   Y  W d S  t
ttfyC   Y d S w d S )NÚ	selfcheckzutf-8)Úencoding)ÚstateÚstatefile_pathÚosÚpathÚjoinr   r   ÚopenÚjsonÚloadÚOSErrorÚ
ValueErrorÚKeyError)Úselfr   Ú	statefiler   r   r   Ú__init__!   s   ÿ&ÿýùzSelfCheckState.__init__c                 C   s   t jS r   )ÚsysÚprefix)r)   r   r   r   r   2   s   zSelfCheckState.keyÚpypi_versionÚcurrent_timec                 C   s¸   | j sd S ttj | j ¡ƒsd S ttj | j ¡ƒ | j| t¡|dœ}t	j
|ddd�}t| j ƒ�}| | ¡ ¡ W d   ƒ n1 sBw   Y  z
t|j| j ƒ W d S  ty[   Y d S w )N)r   Ú
last_checkr.   T)ú,ú:)Ú	sort_keysÚ
separators)r   r   r    r!   Údirnamer   r   ÚstrftimeÚSELFCHECK_DATE_FMTr$   Údumpsr
   Úwriter   r   r   r&   )r)   r.   r/   r   ÚtextÚfr   r   r   Úsave6   s$   ûÿþzSelfCheckState.save)	Ú__name__Ú
__module__Ú__qualname__Ústrr+   Úpropertyr   Údatetimer<   r   r   r   r   r       s
    r   Úpkgc                 C   s   t ƒ  | ¡}|duod|jkS )zµChecks 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)rC   Údistr   r   r   Úwas_installed_by_pipY   s   rH   ÚsessionÚoptionsc                 C   sT  t ƒ  d¡}|s
dS |j}d}z‰t|jd�}tj ¡ }d|jv r<d|jv r<tj |jd t	¡}||  
¡ dk r<|jd }|du rqtj| |dd�}td	d	d
�}	tj||	d|jv d�}
|
 d¡j}|du rfW dS t|jƒ}| ||¡ t|ƒ}||k o‚|j|jko‚tdƒ}|sˆW dS tj› d�}t d|||¡ W dS  ty©   tjddd� Y dS w )zÛCheck 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.
    rD   N)r   r0   r.   i€:	 T)rJ   Úsuppress_no_indexF)Úallow_yankedÚallow_all_prereleasesÚhtml5lib)Úlink_collectorÚselection_prefsÚuse_deprecated_html5libz -m pipz‰You are using pip version %s; however, version %s is available.
You should consider upgrading via the '%s install --upgrade pip' command.z5There was an error checking the latest version of pip)Úexc_info)r   rE   Úversionr   r   rB   Úutcnowr   Ústrptimer7   Útotal_secondsr   Úcreater   r   Údeprecated_features_enabledÚfind_best_candidateÚbest_candidater@   r<   Úparse_versionÚbase_versionrH   r,   Ú
executableÚloggerÚwarningÚ	ExceptionÚdebug)rI   rJ   Úinstalled_distÚpip_versionr.   r   r/   r0   rO   rP   ÚfinderrZ   Úremote_versionÚlocal_version_is_olderÚpip_cmdr   r   r   Úpip_self_version_checkc   sn   

ÿ
ýþü

ÿý

úþÿrh   ))rB   r   r$   ÚloggingÚoptparseÚos.pathr    r,   Útypingr   r   Úpip._vendor.packaging.versionr   r[   Úpip._internal.index.collectorr   Ú"pip._internal.index.package_finderr   Úpip._internal.metadatar   Ú$pip._internal.models.selection_prefsr   Úpip._internal.network.sessionr	   Úpip._internal.utils.filesystemr
   r   r   Úpip._internal.utils.miscr   r7   Ú	getLoggerr=   r^   r@   r   r   ÚboolrH   ÚValuesrh   r   r   r   r   Ú<module>   s,    
9
