o
    ­—Žj¡  ã                   @  s”  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j2dd�Z3e 4e5¡Z6d4dd„Z7G dd„ dƒZ8eG dd„ dƒƒZ9d5d$d%„Z:d6d,d-„Z;d7d.d/„Z<d8d2d3„Z=dS )9é    )Ú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é   )ÚdaysÚkeyÚstrÚreturnc                 C  s   |   ¡ }t |¡ ¡ }|S ©N)ÚencodeÚhashlibÚsha224Ú	hexdigest)r   Ú	key_bytesÚname© r&   ú^/var/www/kodo/Anonymous/send/lib/python3.10/site-packages/pip/_internal/self_outdated_check.pyÚ_get_statefile_name/   s   r(   c                   @  s8   e Zd Zddd„Zeddd„ƒZddd„Zddd„ZdS )ÚSelfCheckStateÚ	cache_dirr   r   ÚNonec              
   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__6   s   ÿ&ÿýùzSelfCheckState.__init__c                 C  s   t jS r   )ÚsysÚprefix)r9   r&   r&   r'   r   G   s   zSelfCheckState.keyÚcurrent_timeúdatetime.datetimeú
str | Nonec                 C  sR   | j sdS d| j vrdS d| j vrdS t| j d ƒ}|| }|tkr$dS | j d S )z7Check if we have a not-outdated version loaded already.NÚ
last_checkÚpypi_version)r.   r   Ú_WEEK)r9   r>   rA   Útime_since_last_checkr&   r&   r'   ÚgetK   s   


zSelfCheckState.getrB   c                 C  sº   | j sd S tj | j ¡}t|ƒsd S t|ƒ | j| ¡ |dœ}tj	|ddd�}t
| j ƒ�}| | ¡ ¡ t||ƒ W d   ƒ n1 sCw   Y  z
t|j| j ƒ W d S  ty\   Y d S w )N)r   rA   rB   T)ú,ú:)Ú	sort_keysÚ
separators)r/   r0   r1   Údirnamer   r   r   Ú	isoformatr4   Údumpsr   Úwriter    r   r   r%   r6   )r9   rB   r>   Ústatefile_directoryÚstateÚtextÚfr&   r&   r'   Úset^   s(   ûþþzSelfCheckState.setN)r*   r   r   r+   )r   r   )r>   r?   r   r@   )rB   r   r>   r?   r   r+   )Ú__name__Ú
__module__Ú__qualname__r;   Úpropertyr   rE   rR   r&   r&   r&   r'   r)   5   s    

r)   c                   @  s(   e Zd ZU ded< ded< d	dd„ZdS )
ÚUpgradePromptr   ÚoldÚnewr   r   c              
   C  s\   t r	tƒ › d�}ntƒ }d}ttƒ t |› d| j› d| j› d�¡t |› 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_markuprX   rY   r   )r9   Úpip_cmdÚnoticer&   r&   r'   Ú__rich__‰   s&   ÿÿÿÿÿúzUpgradePrompt.__rich__N)r   r   )rS   rT   rU   Ú__annotations__r]   r&   r&   r&   r'   rW   „   s   
 rW   Úsessionr   Úoptionsúoptparse.Valuesr@   c                 C  sT   t j| |dd�}tdtdhd�d�}tj||d�}| d¡j}|d u r%d S t|jƒS )NT)r`   Úsuppress_no_indexFÚpip)Ú
only_final)Úallow_yankedÚrelease_control)Úlink_collectorÚselection_prefs)	r	   Úcreater   r   r
   Úfind_best_candidateÚbest_candidater   Úversion)r_   r`   rg   rh   Úfinderrk   r&   r&   r'   Ú_get_current_remote_pip_version�   s"   ý
þþ
rn   Úlocal_versionr   Úremote_version_strÚinstalled_by_pipÚboolúUpgradePrompt | Nonec                 C  s`   t |ƒ}t d|¡ t d| ¡ t d|¡ |sd S | |k o#| j|jk}|r.tt| ƒ|d�S d S )NzRemote version of pip: %szLocal version of pip:  %szWas pip installed by pip? %s)rX   rY   )Úparse_versionÚloggerÚdebugÚbase_versionrW   r   )ro   rp   rq   Úremote_versionÚlocal_version_is_olderr&   r&   r'   Ú_compute_upgrade_prompt¹   s   
þrz   c                 C  s¤   t ƒ  d¡}|s
dS ztƒ  W n
 ty   Y dS w t|jd�}tj tjj	¡}| 
|¡}|du rGt| |ƒ}|du rAt d¡ dS | ||¡ t|j||jdkd�S )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.
    rc   N)r*   zNo remote pip version found)ro   rp   rq   )r   Úget_distributionr   r   r)   r*   ÚdatetimeÚnowÚtimezoneÚutcrE   rn   ru   rv   rR   rz   rl   Ú	installer)r_   r`   Úinstalled_distrO   r>   rp   r&   r&   r'   Úpip_self_version_check_fetchÎ   s,   
ÿ


ýr‚   Úupgrade_promptr+   c                 C  s$   | durt jd| ddid� dS dS )zIEmit the upgrade prompt captured by :func:`pip_self_version_check_fetch`.Nz%sÚrichT)Úextra)ru   Úwarning)rƒ   r&   r&   r'   Úpip_self_version_check_emitó   s   ÿr‡   )r   r   r   r   )r_   r   r`   ra   r   r@   )ro   r   rp   r   rq   rr   r   rs   )r_   r   r`   ra   r   rs   )rƒ   rs   r   r+   )>Ú
__future__r   r|   r!   r4   ÚloggingÚoptparseÚos.pathr0   r<   Údataclassesr   Úpip._vendor.packaging.versionr   r   rt   Ú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   Ú	getLoggerrS   ru   r(   r)   rW   rn   rz   r‚   r‡   r&   r&   r&   r'   Ú<module>   sF    

O


%