OwlCyberSecurity - MANAGER
Edit File: self_outdated_check.cpython-38.pyc
U �^I � @ sR d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl m Z d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d lmZ d d lmZmZmZ d dlmZmZmZ d dl m!Z! d d l"m#Z# e#�rd dl$Z$d dl$m%Z% d dl&m'Z'm(Z(m)Z)m*Z* d dl+m,Z, dZ-e�.e/�Z0ddd�Z1dd� Z2G dd� de3�Z4dd� Z5dd� Z6dS )� )�absolute_importN)� pkg_resources)�version)� ensure_binary)� LinkCollector)� PackageFinder)�SearchScope)�SelectionPreferences)�adjacent_tmp_file�check_path_owner�replace)� ensure_dir�get_installed_version�redact_auth_from_url)� get_installer)�MYPY_CHECK_RUNNING)�Values)�Any�Dict�Text�Union)� PipSessionz%Y-%m-%dT%H:%M:%SZFc C s` |j g|j }|jr8|s8t�dd�dd� |D ��� g }|jp@g }tj||d�}t | |d�}|S )z� :param session: The Session to use to make requests. :param suppress_no_index: Whether to ignore the --no-index option when constructing the SearchScope object. zIgnoring indexes: %s�,c s s | ]}t |�V qd S �N)r )�.0Zurl� r �C/usr/lib/python3/dist-packages/pip/_internal/self_outdated_check.py� <genexpr>? s z&make_link_collector.<locals>.<genexpr>)� find_links� index_urls)�session�search_scope) Z index_urlZextra_index_urlsZno_index�logger�debug�joinr r �creater )r �options�suppress_no_indexr r r! �link_collectorr r r �make_link_collector0 s � �r) c C s t | �}t�|��� }|S r )r �hashlibZsha224Z hexdigest)�keyZ key_bytes�namer r r �_get_statefile_nameO s r- c @ s( e Zd Zdd� Zedd� �Zdd� ZdS )�SelfCheckStatec C sn i | _ d | _|rjtj�|dt| j��| _z&t| j��}t� |�| _ W 5 Q R X W n t ttfk rh Y nX d S )NZ selfcheck) �state�statefile_path�os�pathr$ r- r+ �open�json�load�IOError� ValueError�KeyError)�self� cache_dirZ statefiler r r �__init__W s �zSelfCheckState.__init__c C s t jS r )�sys�prefix)r9 r r r r+ i s zSelfCheckState.keyc C s� | j s d S ttj�| j ��s d S ttj�| j �� | j|�t�|d�}t j |ddd�}t| j ��}|�t |�� W 5 Q R X zt|j| j � W n tk r� Y nX d S )N)r+ � last_check�pypi_versionT)r �:)Z sort_keysZ separators)r0 r r1 r2 �dirnamer r+ �strftime�SELFCHECK_DATE_FMTr4 �dumpsr �writer r r, �OSError)r9 r? �current_timer/ �text�fr r r �savem s �zSelfCheckState.saveN)�__name__� __module__�__qualname__r; �propertyr+ rJ r r r r r. V s r. c C s6 zt �| �}dt|�kW S t jk r0 Y dS X dS )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. �pipFN)r Zget_distributionr ZDistributionNotFound)�pkgZdistr r r �was_installed_by_pip� s rQ c C sT t d�}|sdS t�|�}d}�z t|jd�}tj�� }d|jkrzd|jkrztj�|jd t �}|| � � dk rz|jd }|dkr�t| |dd�}td d d �} t j|| d�} | �d�j}|dkr�W dS t|j�}|�||� t�|�}||k o�|j|jko�td�} | �sW dS d�tj�}t�d |||� W n$ tk �rN tjddd� Y nX dS )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. rO N)r: r>