U
    ;»{j-  ã                   @   sÐ   d 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	 ddl
mZ ddlmZ ddlmZ er|ddlmZ dd	lmZ e e¡Ze	d
 dœdd„ZG dd„ deƒZdeddœdd„ZG dd„ deeƒZdS )a&  
Contains command classes which may interact with an index / the network.

Unlike its sister module, req_command, this module still uses lazy imports
so commands which don't always hit the network (e.g. list w/o --outdated or
--uptodate) don't need waste time importing PipSession and friends.
é    N)ÚValues)ÚTYPE_CHECKINGÚListÚOptional)Úcertifi)ÚCommand)ÚCommandContextMixIn)Ú
SSLContext©Ú
PipSessionr	   ©Úreturnc                  C   s–   t jdk rt d¡ d S zdd l} W n  tk
rD   t d¡ Y d S X zddlm} W n  tk
rv   t d¡ Y d S X | 	| j
¡}| t ¡ ¡ |S )N)é   é
   z7Disabling truststore because Python version isn't 3.10+r   z1Disabling truststore since ssl support is missing)Ú
truststorez5Disabling truststore because platform isn't supported)ÚsysÚversion_infoÚloggerÚdebugÚsslÚImportErrorÚwarningÚpip._vendorr   r	   ÚPROTOCOL_TLS_CLIENTÚload_verify_locationsr   Úwhere)r   r   Úctx© r   ú@/tmp/pip-install-zsn1f9xv/pip/pip/_internal/cli/index_command.pyÚ_create_truststore_ssl_context   s     



r   c                       sp   e Zd ZdZddœ‡ fdd„Zeeeee	  dœdd„ƒZ
ed	dœd
d„Zdeee ee d	dœdd„Z‡  ZS )ÚSessionCommandMixinzE
    A class mixin for command classes needing _build_session().
    Nr   c                    s   t ƒ  ¡  d | _d S )N)ÚsuperÚ__init__Ú_session)Úself©Ú	__class__r   r   r"   7   s    
zSessionCommandMixin.__init__©Úoptionsr   c                 C   sL   g }t |ddƒs*t |ddƒ}|r*| |¡ t |ddƒ}|rD| |¡ |pJdS )z7Return a list of index urls from user-provided options.Úno_indexFÚ	index_urlNÚextra_index_urls)ÚgetattrÚappendÚextend)Úclsr(   Ú
index_urlsÚurlÚurlsr   r   r   Ú_get_index_urls;   s    

z#SessionCommandMixin._get_index_urlsr   c                 C   s0   | j dkr*|  |  |¡¡| _ | j dk	s*t‚| j S )zGet a default-managed session.N)r#   Úenter_contextÚ_build_sessionÚAssertionError)r$   r(   r   r   r   Úget_default_sessionI   s    
z'SessionCommandMixin.get_default_session)r(   ÚretriesÚtimeoutr   c                 C   sî   ddl m} |j}|r&tj |¡s&t‚d|jkr8tƒ }nd }||rPtj 	|d¡nd |d k	r^|n|j
|j|  |¡|d�}|jr„|j|_|jr’|j|_|jsœ|r°|d k	r¨|n|j|_|jrÔ|j|jdœ|_d|_|j|_|j |j_|j|j_|S )Nr   r
   zlegacy-certszhttp-v2)Úcacher8   Útrusted_hostsr0   Ússl_context)ÚhttpÚhttpsF)Úpip._internal.network.sessionr   Ú	cache_dirÚosÚpathÚisabsr6   Zdeprecated_features_enabledr   Újoinr8   r;   r3   ÚcertÚverifyÚclient_certr9   ÚproxyÚproxiesÚ	trust_envZ	pip_proxyÚno_inputÚauthÚ	promptingZkeyring_provider)r$   r(   r8   r9   r   r@   r<   Úsessionr   r   r   r5   S   s8    
û	
þ
z"SessionCommandMixin._build_session)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r"   Úclassmethodr   r   r   Ústrr3   r7   Úintr5   Ú__classcell__r   r   r%   r   r    2   s     üûr    r   )rN   r(   r   c                 C   s   ddl m} || |ƒ d S )Nr   )Úpip_self_version_check)Z!pip._internal.self_outdated_checkrW   )rN   r(   Úcheckr   r   r   Ú_pip_self_version_check‡   s    rY   c                   @   s    e Zd ZdZeddœdd„ZdS )ÚIndexGroupCommandz–
    Abstract base class for commands with the index_group options.

    This also corresponds to the commands that permit the pip version check.
    Nr'   c              	   C   s†   t |dƒst‚|js|jrdS z6| j|dtd|jƒd�}|� t||ƒ W 5 Q R X W n, tk
r€   t	 
d¡ t	jddd	� Y nX dS )
z€
        Do the pip version check if not disabled.

        This overrides the default behavior of not doing the check.
        r)   Nr   é   )r8   r9   z6There was an error checking the latest version of pip.zSee below for errorT)Úexc_info)Úhasattrr6   Údisable_pip_version_checkr)   r5   Úminr9   rY   Ú	Exceptionr   r   r   )r$   r(   rN   r   r   r   Úhandle_pip_version_check”   s    
ý
z*IndexGroupCommand.handle_pip_version_check)rO   rP   rQ   rR   r   ra   r   r   r   r   rZ   �   s   rZ   )rR   ÚloggingrA   r   Úoptparser   Útypingr   r   r   r   r   Úpip._internal.cli.base_commandr   Z!pip._internal.cli.command_contextr   r   r	   r?   r   Ú	getLoggerrO   r   r   r    rY   rZ   r   r   r   r   Ú<module>   s    
U