o
    a+)h                     @   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ee4 fd d!Z;d"e6d#e j d$e d%eg ee4 f 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!   `C:\Users\User\Downloads\Proyecto_IoT\venv\Lib\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 is 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 )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)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| }|d u rtd d S | || t|}td| td| td}td| |s;d S ||k oD|j|jk}|rOtt||dS d S )NzNo remote pip version foundzRemote version of pip: %szLocal version of pip:  %sr\   zWas pip installed by pip? %s)rT   rU   )	rA   loggerdebugrM   parse_versionr`   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 )
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.
    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   rp   warning	Exceptionrq   )ra   rb   installed_distupgrade_promptr!   r!   r"   pip_self_version_check   s&   

r   )>r;   r{   r   r.   loggingoptparseZos.pathr*   r6   dataclassesr   typingr   r   r   r   Zpip._vendor.packaging.versionr   rr   pip._vendor.rich.consoler   Zpip._vendor.rich.markupr	   pip._vendor.rich.textr
   pip._internal.index.collectorr   "pip._internal.index.package_finderr   pip._internal.metadatar   Z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   rp   rQ   r#   r$   rS   boolr`   Valuesrm   rx   r   r!   r!   r!   r"   <module>   sd    
N


"