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mZ ddd„Zddd„Zddd„ZdS )zALogic that powers autocompletion installed by ``pip completion``.é    )ÚannotationsN)ÚIterable)Úchain)ÚAny)Úcreate_main_parser)Úcommands_dictÚcreate_commandÚreturnÚNonec                    sD  dt jvrdS t j d¡rt j d¡sdS t jd  ¡ dd… ‰tt jd ƒ} zˆ| d  ‰ W n ty:   d‰ Y nw tƒ }ttƒ}g }d}ˆD ]
}||v rR|} nqH|du�rN|dkrat	 
d¡ ˆ  d¡ oj|d	v }|r˜d
dlm} |ƒ }ˆ  ¡ ‰‡‡fdd„|jdd�D ƒ}	|	r˜|	D ]}
t|
ƒ qŒt	 
d¡ ˆ  d¡ o¡|dk}|rµtˆ dƒD ]}t|ƒ q©t	 
d¡ t|ƒ}|jjD ]‰ˆjtjkrÔ|‡fdd„ˆjˆj D ƒ7 }q½dd„ ˆd| d … D ƒ‰‡fdd„|D ƒ}‡ fdd„|D ƒ}tˆ| |jjƒ}|�rtˆ |ƒ}dd„ |D ƒ}|D ]}|d
 }|d �r'|d
 dd… dk�r'|d7 }t|ƒ �qt‡fdd„| ¡ D ƒƒ�sM| ¡ D ]}| ˆ ¡�rKt|ƒ �q?nMdd„ |jD ƒ}| |j¡ t  !|¡}ˆ  d¡�r}|D ]‰ˆjtjk�rz|ˆjˆj 7 }�qintˆ| |ƒ}|�r�ttˆ |ƒƒ}td "‡ fdd„|D ƒ¡ƒ t	 
d¡ dS )z:Entry Point for completion of main and subcommand options.ZPIP_AUTO_COMPLETENZ
COMP_WORDSZ
COMP_CWORDé   Ú Úhelpú-)ZshowZ	uninstallr   )Úget_default_environmentc                   s0   g | ]}|j  ˆ¡r|j ˆ d d… vr|j ‘qS )r   N)Zcanonical_nameÚ
startswith)Ú.0Údist)ÚcwordsÚlc© ú[/var/www/html/chatgpt/venv/lib/python3.10/site-packages/pip/_internal/cli/autocompletion.pyÚ
<listcomp>;   s    
ýýz autocomplete.<locals>.<listcomp>T)Z
local_onlyZinstallÚpathc                   s   g | ]}|ˆ j f‘qS r   )Únargs)r   Zopt_str)Úoptr   r   r   S   s    
ÿc                 S  s   g | ]	}|  d ¡d ‘qS )ú=r   )Úsplit©r   Úxr   r   r   r   X   ó    c                   s    g | ]\}}|ˆ vr||f‘qS r   r   )r   r   Úv)Ú	prev_optsr   r   r   Y   s     c                   s"   g | ]\}}|  ˆ ¡r||f‘qS r   ©r   )r   Úkr    ©Úcurrentr   r   r   [   s   " c                 S  s   g | ]}|d f‘qS )r   r   )r   r   r   r   r   r   f   s    é   z--r   c                 3  s   � | ]}|ˆ v V  qd S ©Nr   )r   Úname)r   r   r   Ú	<genexpr>o   s   € zautocomplete.<locals>.<genexpr>c                 S  s   g | ]}|j ‘qS r   )Úoption_list)r   Úir   r   r   r   v   s    ú c                   s   g | ]	}|  ˆ ¡r|‘qS r   r"   r   r$   r   r   r   ƒ   r   )#ÚosÚenvironÚgetr   ÚintÚ
IndexErrorr   Úlistr   ÚsysÚexitr   Zpip._internal.metadatar   ÚlowerZiter_installed_distributionsÚprintÚauto_complete_pathsr   ÚparserZoption_list_allr   ÚoptparseÚSUPPRESS_HELPZ
_long_optsZ_short_optsÚget_path_completion_typeÚanyZhandler_mapZoption_groupsÚappendr*   r   Úfrom_iterableÚjoin)Úcwordr8   ZsubcommandsZoptionsZsubcommand_nameZwordZshould_list_installedr   ÚenvZ	installedr   Zshould_list_installablesr   Z
subcommandÚcompletion_typeÚpathsZoptionZ	opt_labelZhandler_nameÚoptsZflattened_optsr   )r%   r   r   r   r!   r   Úautocomplete   s¦   
ÿþ


þ

ÿ


ÿ€ý
 €
€þrE   r   ú	list[str]r@   r0   rD   úIterable[Any]ú
str | Nonec                 C  s–   |dk s| |d    d¡sdS |D ]7}|jtjkrqt|ƒ d¡D ]&}| |d   d¡d |krG|jr@tdd„ |j d¡D ƒƒrG|j    S q!qdS )	aL  Get the type of path completion (``file``, ``dir``, ``path`` or None)

    :param cwords: same as the environmental variable ``COMP_WORDS``
    :param cword: same as the environmental variable ``COMP_CWORD``
    :param opts: The available options to check
    :return: path completion type (``file``, ``dir``, ``path`` or None)
    r&   r   Nú/r   r   c                 s  s   � | ]}|d v V  qdS ))r   ÚfileÚdirNr   r   r   r   r   r)   ˜   s   € 
ÿz+get_path_completion_type.<locals>.<genexpr>)r   r   r9   r:   Ústrr   Úmetavarr<   )r   r@   rD   r   Úor   r   r   r;   ‡   s   

ÿ€ûr;   r%   rL   rB   úIterable[str]c                 #  s¾   � t j | ¡\}‰ t j |¡}t  |t j¡sdS t j ˆ ¡‰ ‡ fdd„t  |¡D ƒ}|D ]0}t j ||¡}t j t j ||¡¡}|dkrNt j 	|¡rN|V  q,t j 
|¡r\t j |d¡V  q,dS )at  If ``completion_type`` is ``file`` or ``path``, list all regular files
    and directories starting with ``current``; otherwise only list directories
    starting with ``current``.

    :param current: The word to be completed
    :param completion_type: path completion type(``file``, ``path`` or ``dir``)
    :return: A generator of regular files and/or directories
    Nc                 3  s&   � | ]}t j |¡ ˆ ¡r|V  qd S r'   )r-   r   Únormcaser   r   ©Úfilenamer   r   r)   ¯   s   € ÿ
ÿz&auto_complete_paths.<locals>.<genexpr>rK   r   )r-   r   r   ÚabspathÚaccessÚR_OKrP   Úlistdirr?   ÚisfileÚisdir)r%   rB   Z	directoryZcurrent_pathZ	file_listÚfr   Z	comp_filer   rQ   r   r7   Ÿ   s$   €	
ÿ€÷r7   )r	   r
   )r   rF   r@   r0   rD   rG   r	   rH   )r%   rL   rB   rL   r	   rO   )Ú__doc__Ú
__future__r   r9   r-   r3   Úcollections.abcr   Ú	itertoolsr   Útypingr   Úpip._internal.cli.main_parserr   Úpip._internal.commandsr   r   rE   r;   r7   r   r   r   r   Ú<module>   s    

w