
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
ÝPfe  ã               @   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m	Z	 d dl
mZ d dlmZmZ d dlmZ d dlmZmZ d dlmZmZ d d	lmZ d
ZejeƒZG dd„ deƒZG dd„ deƒZ dd„ Z!dd„ Z"dd„ Z#dS )é    )Úabsolute_importN)Úlockfile)Úversion)Útotal_secondsÚWINDOWS)ÚPyPI)ÚUSER_CACHE_DIRÚrunning_under_virtualenv)Ú
ensure_dirÚget_installed_version)Úcheck_path_ownerz%Y-%m-%dT%H:%M:%SZc               @   s   e Zd Zdd„ Zdd„ ZdS )ÚVirtualenvSelfCheckStatec             C   s\   t jjtjdƒ| _y&t| jƒ�}tj|ƒ| _	W d Q R X W n t
tfk
rV   i | _	Y nX d S )Nzpip-selfcheck.json)ÚosÚpathÚjoinÚsysÚprefixÚstatefile_pathÚopenÚjsonÚloadÚstateÚIOErrorÚ
ValueError)ÚselfÚ	statefile© r   ú/usr/lib/python3.6/outdated.pyÚ__init__   s    z!VirtualenvSelfCheckState.__init__c             C   s:   t | jdƒ�$}tj|jtƒ|dœ|ddd� W d Q R X d S )NÚw)Ú
last_checkÚpypi_versionTú,ú:)Ú	sort_keysÚ
separators)r"   r#   )r   r   r   ÚdumpÚstrftimeÚSELFCHECK_DATE_FMT)r   r!   Úcurrent_timer   r   r   r   Úsave$   s    zVirtualenvSelfCheckState.saveN)Ú__name__Ú
__module__Ú__qualname__r   r*   r   r   r   r   r      s   
r   c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚGlobalSelfCheckStatec             C   sb   t jjtdƒ| _y,t| jƒ�}tj|ƒtj	 | _
W d Q R X W n  tttfk
r\   i | _
Y nX d S )Nzselfcheck.json)r   r   r   r   r   r   r   r   r   r   r   r   r   ÚKeyError)r   r   r   r   r   r   3   s     zGlobalSelfCheckState.__init__c             C   s¸   t tjj| jƒƒsd S ttjj| jƒƒ tj| jƒ�z tjj| jƒrft	| jƒ�}t
j|ƒ}W d Q R X ni }|jtƒ|dœ|tj< t	| jdƒ�}t
j||ddd� W d Q R X W d Q R X d S )N)r    r!   r   Tr"   r#   )r$   r%   )r"   r#   )r   r   r   Údirnamer   r
   r   ZLockFileÚexistsr   r   r   r'   r(   r   r   r&   )r   r!   r)   r   r   r   r   r   r*   =   s    
zGlobalSelfCheckState.saveN)r+   r,   r-   r   r*   r   r   r   r   r.   2   s   
r.   c               C   s   t ƒ rtƒ S tƒ S d S )N)r	   r   r.   r   r   r   r   Úload_selfcheck_statefileX   s    r2   c              C   sF   ddl } y"| jdƒ}|jdƒo*d|jdƒkS  | jk
r@   dS X dS )zµChecks whether pip 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.
    r   NÚpipZ	INSTALLERF)Úpkg_resourcesZget_distributionZhas_metadataZget_metadata_linesZDistributionNotFound)r4   Zdistr   r   r   Úpip_installed_by_pip_   s    

r5   c       
      C   sF  t dƒ}|dkrdS tj|ƒ}d}� yøtƒ }tjjƒ }d|jkrxd|jkrxtjj|jd tƒ}t	|| ƒdk rx|jd }|dkrÐ| j
tjdd	id
�}|jƒ  dd„ tt|jƒ d ƒtjd�D ƒd }|j||ƒ tj|ƒ}||k �r|j|jk�rtƒ �rt�rd}	nd}	tjd|||	ƒ W n$ tk
�r@   tjddd� Y nX dS )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.
    r3   Nr    r!   é   é   é<   ZAcceptzapplication/json)Zheadersc             S   s   g | ]}t j|ƒjs|‘qS r   )Úpackaging_versionÚparseZis_prerelease)Ú.0Úvr   r   r   ú
<listcomp>‘   s    z%pip_version_check.<locals>.<listcomp>Zreleases)Úkeyé   zpython -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 pipT)Úexc_infoé¨   i`'  i€:	 éÿÿÿÿ)r   r9   r:   r2   ÚdatetimeZutcnowr   Zstrptimer(   r   Úgetr   Zpip_json_urlZraise_for_statusÚsortedÚlistr   r*   Zbase_versionr5   r   ÚloggerZwarningÚ	ExceptionÚdebug)
ZsessionZinstalled_versionZpip_versionr!   r   r)   r    ZrespZremote_versionZpip_cmdr   r   r   Úpip_version_checkn   sL    




rJ   )$Z
__future__r   rC   r   ZloggingZos.pathr   r   Zpip._vendorr   Zpip._vendor.packagingr   r9   Z
pip.compatr   r   Z
pip.modelsr   Zpip.locationsr   r	   Z	pip.utilsr
   r   Zpip.utils.filesystemr   r(   Z	getLoggerr+   rG   Úobjectr   r.   r2   r5   rJ   r   r   r   r   Ú<module>   s&   
&