o
    ­—ŽjP  ã                   @  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   ú\/var/www/kodo/Anonymous/send/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  s  ddl m} |j}|rtj |¡sJ ‚d|jvrtƒ }nd }||r(tj |d¡nd |d ur/|n|j	|j
|j|  |¡|t|dtƒ ƒd�}|jrJ|j|_|jrQ|j|_|jsV|r`|d ur\|n|j|_|jd ush|jr~|jrs|j|jdœ|_d|_|j|_|j|_|j |j_|j|j_|S )	Nr   r   zlegacy-certszhttp-v2Úrefresh_package)Úcacher6   Úresume_retriesÚtrusted_hostsr/   Ússl_contextr9   )ÚhttpÚhttpsF)Úpip._internal.network.sessionr   Ú	cache_dirÚosÚpathÚisabsÚdeprecated_features_enabledr   Újoinr6   r;   r<   r2   r+   ÚsetÚcertÚverifyÚclient_certr8   ÚproxyÚno_proxy_envÚproxiesÚ	trust_envÚ	pip_proxyÚpip_no_proxy_envÚno_inputÚauthÚ	promptingÚkeyring_provider)r#   r&   r6   r8   r   rA   r=   Úsessionr   r   r   r4   W   s@   
ù
þ
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   rU   r   r&   r   úUpgradePrompt | Nonec                 C  s   ddl m} || |ƒS )Nr   )Úpip_self_version_check_fetch)Ú!pip._internal.self_outdated_checkr]   )rU   r&   r]   r   r   r   Ú_pip_self_version_check_fetch‘   s   
r_   Úupgrade_promptr   c                 C  s   ddl m} || ƒ d S )Nr   )Úpip_self_version_check_emit)r^   ra   )r`   ra   r   r   r   Ú_pip_self_version_check_emit™   s   rb   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   Úboolc                 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&   rd   Ú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   r_   Ú	Exceptionr   r   Údebugrb   )r#   r&   rj   r`   rU   r   r   r   Úpip_version_check·   sD   €
ýÿ€
þ
þþ
þz#IndexGroupCommand.pip_version_checkN)r&   r   rd   r   r   re   )r&   r   rj   rk   r   rl   )rV   rW   rX   rY   ri   Ú
contextlibÚcontextmanagerrt   r   r   r   r   rc   Ÿ   s
    
rc   )r   r   )rU   r   r&   r   r   r\   )r`   r\   r   r   )$rY   Ú
__future__r   ru   ÚloggingrB   Úcollections.abcr   Ú	functoolsr   Úoptparser   Útypingr   r   r   Úpip._internal.cli.base_commandr   Ú!pip._internal.cli.command_contextr	   r   r
   Úpip._vendor.packaging.utilsr   r@   r   r^   r   Ú	getLoggerrV   r   r   r   r_   rb   rc   r   r   r   r   Ú<module>   s0    

[
