o
    ~îjà  ã                   @  s  d Z ddlm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 ddlmZ ddlmZ dd	lmZ dd
lmZ erXddlmZ ddlmZ ddlmZ ddlmZ e e¡Ze	d"dd„ƒZG dd„ deƒZ d#dd„Z!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.
é    )ÚannotationsN)ÚIterator)Ú	lru_cache)ÚValues)ÚTYPE_CHECKING)Úcertifi)ÚCommand)ÚCommandContextMixIn)Ú
SSLContext)ÚNormalizedName©Ú
PipSession)ÚUpgradePromptÚreturnúSSLContext | Nonec                  C  sz   zdd l } W n ty   t d¡ Y d S w zddlm} W n ty-   t d¡ Y d S w | | j¡}| t	 
¡ ¡ |S )Nr   z1Disabling truststore since ssl support is missing)Ú
truststorez5Disabling truststore because platform isn't supported)ÚsslÚImportErrorÚloggerÚwarningÚpip._vendorr   r
   ÚPROTOCOL_TLS_CLIENTÚload_verify_locationsr   Úwhere)r   r   Úctx© r   úi/raid/bulk_storage/M2HATS/real-image-venv/lib/python3.10/site-packages/pip/_internal/cli/index_command.pyÚ_create_truststore_ssl_context#   s   
þ
þr   c                      sJ   e Zd ZdZd‡ fdd„Zedd	d
„ƒZddd„Z		dddd„Z‡  Z	S )ÚSessionCommandMixinzE
    A class mixin for command classes needing _build_session().
    r   ÚNonec                   s   t ƒ  ¡  d | _d S )N)ÚsuperÚ__init__Ú_session)Úself©Ú	__class__r   r   r!   ;   s   

zSessionCommandMixin.__init__Úoptionsr   úlist[str] | Nonec                 C  sL   g }t |ddƒst |ddƒ}|r| |¡ t |ddƒ}|r"| |¡ |p%d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u r|  |  |¡¡| _ | j dusJ ‚| j S )zGet a default-managed session.N)r"   Úenter_contextÚ_build_session)r#   r&   r   r   r   Úget_default_sessionM   s   
z'SessionCommandMixin.get_default_sessionNÚretriesú
int | NoneÚtimeoutc           	      C  sT  ddl m} |j}|rtj |¡sJ ‚d|jvrtƒ }nd }t|j	ƒ}|j
d u r;|js;|p:ttj d¡p9tj d¡ƒ}||rEtj |d¡nd |d urL|n|j|j|j|  |¡|| t|dtƒ ƒd�}|j	ri|j	|_|jrp|j|_	|jsu|r|d ur{|n|j|_|j
d us‡|jr�|j
r’|j
|j
d	œ|_d
|_|j
|_|j|_|j |j_|j|j_|S )Nr   r   zlegacy-certsÚREQUESTS_CA_BUNDLEÚCURL_CA_BUNDLEzhttp-v2Úrefresh_package)Úcacher6   Úresume_retriesÚtrusted_hostsr/   Ússl_contextÚuse_ssl_context_for_proxyr;   )ÚhttpÚhttpsF) Úpip._internal.network.sessionr   Ú	cache_dirÚosÚpathÚisabsÚdeprecated_features_enabledr   ÚboolÚcertÚproxyÚno_proxy_envÚenvironÚgetÚjoinr6   r=   r>   r2   r+   ÚsetÚverifyÚclient_certr8   ÚproxiesÚ	trust_envÚ	pip_proxyÚpip_no_proxy_envÚno_inputÚauthÚ	promptingÚkeyring_provider)	r#   r&   r6   r8   r   rD   r?   Úhas_custom_caÚsessionr   r   r   r4   W   sL   

ÿø
þ
z"SessionCommandMixin._build_session)r   r   )r&   r   r   r'   )r&   r   r   r   )NN)r&   r   r6   r7   r8   r7   r   r   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r!   Úclassmethodr2   r5   r4   Ú__classcell__r   r   r$   r   r   6   s    
ür   r\   r   r&   r   úUpgradePrompt | Nonec                 C  s   ddl m} || |ƒS )Nr   )Úpip_self_version_check_fetch)Ú!pip._internal.self_outdated_checkrd   )r\   r&   rd   r   r   r   Ú_pip_self_version_check_fetch™   s   
rf   Úupgrade_promptr   c                 C  s   ddl m} || ƒ d S )Nr   )Úpip_self_version_check_emit)re   rh   )rg   rh   r   r   r   Ú_pip_self_version_check_emit¡   s   ri   c                   @  s*   e Zd ZdZddd	„Zej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.
    r&   r   Úpackage_namer   r   rI   c                 C  s.   |j r|j  |¡}|du rdS |du rdS dS )zM
        Determine if pre-releases should be excluded for a package.
        TF)Úrelease_controlÚallows_prereleases)r#   r&   rk   Úallow_prereleasesr   r   r   Úshould_exclude_prerelease®   s   z+IndexGroupCommand.should_exclude_prereleaseÚargsú	list[str]úIterator[None]c                 c  s  � t |dƒsJ ‚|js|jrdV  dS d}z%| j|dtd|jƒd�}|� t||ƒ}W d  ƒ n1 s4w   Y  W n tyO   t 	d¡ tj
ddd	� Y nw z"dV  W zt|ƒ W dS  tyr   t 	d¡ tj
ddd	� Y dS w zt|ƒ W w  tyŽ   t 	d¡ tj
ddd	� Y w w )
z€
        Do the pip version check if not disabled.

        This overrides the default behavior of not doing the check.
        r(   Nr   é   )r6   r8   z6There was an error checking the latest version of pip.zSee below for errorT)Úexc_info)ÚhasattrÚdisable_pip_version_checkr(   r4   Úminr8   rf   Ú	Exceptionr   r   Údebugri   )r#   r&   rp   rg   r\   r   r   r   Úpip_version_check¿   sD   €
ýÿ€
þ
þþ
þz#IndexGroupCommand.pip_version_checkN)r&   r   rk   r   r   rI   )r&   r   rp   rq   r   rr   )r]   r^   r_   r`   ro   Ú
contextlibÚcontextmanagerrz   r   r   r   r   rj   §   s
    
rj   )r   r   )r\   r   r&   r   r   rc   )rg   rc   r   r   )$r`   Ú
__future__r   r{   ÚloggingrE   Úcollections.abcr   Ú	functoolsr   Úoptparser   Útypingr   r   r   Úpip._internal.cli.base_commandr   Ú!pip._internal.cli.command_contextr	   r   r
   Úpip._vendor.packaging.utilsr   rC   r   re   r   Ú	getLoggerr]   r   r   r   rf   ri   rj   r   r   r   r   Ú<module>   s0    

c
