o
    ñ‘OjQ  ã                   @   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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/ dZ0e 1e2¡Z3de4de4fdd„Z5G dd„ dƒZ6e
G dd„ dƒƒZ7de4de8fdd„Z9de$dej:de4fd d!„Z;d"e6d#e j d$e d%eg e4f dee7 f
d&d'„Z<de$dej:ddfd(d)„Z=dS )*é    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_dirz%Y-%m-%dT%H:%M:%SZÚkeyÚreturnc                 C   s   |   ¡ }t |¡ ¡ }|S ©N)ÚencodeÚhashlibÚsha224Ú	hexdigest)r   Ú	key_bytesÚname© r!   úg/var/www/html/pharmsmart-cdr-gen/venv/lib/python3.10/site-packages/pip/_internal/self_outdated_check.pyÚ_get_statefile_name%   s   r#   c                   @   s`   e Zd Zdeddfdd„Zedefdd„ƒZdejde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)r3   r!   r!   r"   r   =   s   zSelfCheckState.keyÚcurrent_timec                 C   s`   | j sdS d| j vrdS d| j vrdS d}tj | j d t¡}||  ¡ }||kr+dS | j d S )z7Check if we have a not-outdated version loaded already.NÚ
last_checkÚpypi_versioni€:	 )r(   ÚdatetimeÚstrptimeÚ	_DATE_FMTÚtotal_seconds)r3   r8   Úseven_days_in_secondsr9   Úseconds_since_last_checkr!   r!   r"   ÚgetA   s   


zSelfCheckState.getr:   c                 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   r9   r:   T)ú,ú:)Ú	sort_keysÚ
separators)r)   r   r*   r+   Údirnamer   r   Ústrftimer=   r.   Údumpsr   Úwriter   r   r    r0   )r3   r:   r8   ÚstateÚtextÚfr!   r!   r"   ÚsetV   s$   ûÿþzSelfCheckState.set)Ú__name__Ú
__module__Ú__qualname__Ústrr5   Úpropertyr   r;   r   rA   rM   r!   r!   r!   r"   r$   +   s    r$   c                   @   s,   e Zd ZU eed< eed< defdd„ZdS )ÚUpgradePromptÚoldÚnewr   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 available: [red]z[reset] -> [green]z[reset]z To update, run: [green]z install --upgrade pip)	r   r   r   r   r
   Úfrom_markuprT   rU   r	   )r3   Úpip_cmdÚnoticer!   r!   r"   Ú__rich__~   s&   ÿÿÿÿÿúzUpgradePrompt.__rich__N)rN   rO   rP   rQ   Ú__annotations__r   rY   r!   r!   r!   r"   rS   y   s   
 rS   Ú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)r[   Údistr!   r!   r"   Úwas_installed_by_pip’   s   r`   ÚsessionÚoptionsc                 C   sL   t j| |dd�}tddd�}tj||d�}| d¡j}|d u r!d S t|jƒS )NT)rb   Úsuppress_no_indexF)Úallow_yankedÚallow_all_prereleases)Úlink_collectorÚselection_prefsr\   )r   Úcreater   r   Úfind_best_candidateÚbest_candidaterQ   Úversion)ra   rb   rf   rg   Úfinderrj   r!   r!   r"   Ú_get_current_remote_pip_versionœ   s"   ýþþ
rm   rJ   r8   Úlocal_versionÚget_remote_versionc                 C   sŒ   |   |¡}|d u r|ƒ }|  ||¡ t|ƒ}t d|¡ t d|¡ tdƒ}t d|¡ |s0d S ||k o9|j|jk}|rDtt|ƒ|d�S d S )NzRemote version of pip: %szLocal version of pip:  %sr\   zWas pip installed by pip? %s)rT   rU   )	rA   rM   Úparse_versionÚloggerÚdebugr`   Úbase_versionrS   rQ   )rJ   r8   rn   ro   Úremote_version_strÚremote_versionÚpip_installed_by_pipÚlocal_version_is_olderr!   r!   r"   Ú_self_version_check_logic¸   s"   

þrx   c              	   C   sŒ   t ƒ  d¡}|s
dS z%tt|jd�tj ¡ |jt 	t
| |¡d�}|dur-t d|¡ W dS W dS  tyE   t d¡ 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.
    r\   N)r%   )rJ   r8   rn   ro   z[present-rich] %sz6There was an error checking the latest version of pip.zSee below for errorT)Úexc_info)r   r]   rx   r$   r%   r;   Úutcnowrk   Ú	functoolsÚpartialrm   rq   ÚinfoÚ	ExceptionÚwarningrr   )ra   rb   Úinstalled_distÚupgrade_promptr!   r!   r"   Úpip_self_version_check×   s&   
ÿüÿ
þr‚   )>r;   r{   r   r.   ÚloggingÚoptparseÚos.pathr*   r6   Údataclassesr   Útypingr   r   r   r   Úpip._vendor.packaging.versionr   rp   Ú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   r=   Ú	getLoggerrN   rq   rQ   r#   r$   rS   Úboolr`   ÚValuesrm   rx   r‚   r!   r!   r!   r"   Ú<module>   sd    
N
ÿÿ
þþýü
û
ú