U
    ~f                     @   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)Command)CommandContextMixIn)CommandError)
SSLContext
PipSessionr	   returnc               
   C   s   t jdk rtdzdd l} W n  tk
r>   td Y d S X zddlm} W n0 tk
r } ztd| W 5 d }~X Y nX |	| j
S )N)   
   z9The truststore feature is only available for Python 3.10+r   z1Disabling truststore since ssl support is missing)
truststorez'The truststore feature is unavailable: )sysversion_infor   sslImportErrorloggerwarningpip._vendorr   r	   PROTOCOL_TLS_CLIENT)r   r   e r   R/home/mars/bis/venv/lib/python3.8/site-packages/pip/_internal/cli/index_command.py_create_truststore_ssl_context   s    

 r   c                       sr   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 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   2   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_urls6   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_sessionD   s    
z'SessionCommandMixin.get_default_sessionF)r%   retriestimeoutfallback_to_certifir   c           	      C   s
  ddl m} |j}|r&tj|s&td|jkr\z
t }W q` t	k
rX   |sP d }Y q`X nd }||rtt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_|S )Nr   r
   r   zhttp-v2)cacher5   trusted_hostsr-   ssl_context)httphttpsF)pip._internal.network.sessionr   	cache_dirospathisabsr3   features_enabledr   	Exceptionjoinr5   r9   r0   certverifyclient_certr6   proxyproxies	trust_envno_inputauth	promptingkeyring_provider)	r!   r%   r5   r6   r7   r   r>   r:   sessionr   r   r   r2   N   s@    

	

z"SessionCommandMixin._build_session)NNF)__name__
__module____qualname____doc__r   classmethodr   r   r   strr0   r4   intboolr2   __classcell__r   r   r"   r   r   -   s      r   r   )rO   r%   r   c                 C   s   ddl m} || | d S )Nr   )pip_self_version_check)!pip._internal.self_outdated_checkrY   )rO   r%   checkr   r   r   _pip_self_version_check   s    r\   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   sV   t |dst|js|jrdS | j|dtd|jdd}| t|| W 5 Q R X dS )z
        Do the pip version check if not disabled.

        This overrides the default behavior of not doing the check.
        r&   Nr      T)r5   r6   r7   )hasattrr3   disable_pip_version_checkr&   r2   minr6   r\   )r!   r%   rO   r   r   r   handle_pip_version_check   s    

z*IndexGroupCommand.handle_pip_version_check)rP   rQ   rR   rS   r   rb   r   r   r   r   r]      s   r]   )rS   loggingr?   r   optparser   typingr   r   r   pip._internal.cli.base_commandr   !pip._internal.cli.command_contextr   pip._internal.exceptionsr   r   r	   r=   r   	getLoggerrP   r   r   r   r\   r]   r   r   r   r   <module>   s    
Z