File: //lib/python3/dist-packages/distlib/__pycache__/index.cpython-310.pyc
o
    ��d_Q  �                   @   s�   d dl Z d dlZd dlZd dlZd dlZd dlZzd dlmZ W n ey/   d dl	mZ Y nw ddl
mZ ddlm
Z
mZmZmZmZmZ ddlmZmZ e�e�ZdZdZG d	d
� d
e�ZdS )�    N)�Thread�   )�DistlibException)�HTTPBasicAuthHandler�Request�HTTPPasswordMgr�urlparse�build_opener�string_types)�zip_dir�ServerProxyzhttps://pypi.org/pypi�pypic                   @   s�   e Zd ZdZdZd*dd�Zdd� Zdd	� Zd
d� Zdd
� Z	dd� Z
dd� Z	d*dd�Zd*dd�Z
d*dd�Z		d+dd�Zdd� Z	d*dd�Z	d*d d!�Zd,d"d#�Zd$d%� Zd&d'� Zd*d(d)�ZdS )-�PackageIndexzc
    This class represents a package index compatible with PyPI, the Python
    Package Index.
    s.   ----------ThIs_Is_tHe_distlib_index_bouNdaRY_$Nc              
   C   s�   |pt | _| ��  t| j�\}}}}}}|s|s|s|dvr%td| j ��d| _d| _d| _d| _t	t
jd��5}dD ]!}	ztj
|	dg||d�}
|
dkrQ|	| _W  nW q: ty[   Y q:w W d  � dS W d  � dS 1 sow   Y  dS )	z�
        Initialise an instance.
        :param url: The URL of the index. If not specified, the URL for PyPI is
                    used.
        )�http�httpszinvalid repository: %sN�w)�gpg�gpg2z	--version��stdout�stderrr   )�
DEFAULT_INDEX�url�read_configurationr   r   �password_handler�ssl_verifierr   �gpg_home�open�os�devnull�
subprocess�
check_call�OSError)�selfr   �scheme�netloc�path�params�query�frag�sink�s�rc� r-   �//usr/lib/python3/dist-packages/distlib/index.py�__init__$   s4   
�����	"�zPackageIndex.__init__c                 C   s   ddl m} |� S )zs
        Get the distutils command for interacting with PyPI configurations.
        :return: the command.
        r   )�_get_pypirc_command)�utilr0   )r#   �cmdr-   r-   r.   r0   A   s   z PackageIndex._get_pypirc_commandc                 C   sN   ddl m} || �}|�d�| _|�d�| _|�dd�| _|�d| j�| _dS )	z�
        Read the PyPI access configuration as supported by distutils. This populates
        ``username``, ``password``, ``realm`` and ``url`` attributes from the
        configuration.
        r   )�_load_pypirc�username�password�realmr
   �
repositoryN)r1   r3   �getr4   r5   r6   r   )r#   r3   �cfgr-   r-   r.   r   I   s   zPackageIndex.read_configurationc                 C   s    | � �  ddlm} || � dS )z�
        Save the PyPI access configuration. You must have set ``username`` and
        ``password`` attributes before calling this method.
        r   )�
_store_pypircN)�check_credentialsr1   r:   )r#   r:   r-   r-   r.   �save_configurationV   s   zPackageIndex.save_configurationc                 C   s\   | j du s
| jdu rtd��t� }t| j�\}}}}}}|�| j|| j | j� t|�| _	dS )zp
        Check that ``username`` and ``password`` have been set, and raise an
        exception if not.
        Nz!username and password must be set)
r4   r5   r   r   r   r   �add_passwordr6   r   r   )r#   �pm�_r%   r-   r-   r.   r;   _   s   zPackageIndex.check_credentialsc                 C   s\   | � �  |��  |�� }d|d<