o
    f}”eÿ  ã                	   @   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	m
Z
 ddlmZ ddlmZmZ ddlmZ dd	d
„Zde	e dedee de
e fdd„Zdededee fdd„ZdS )zBLogic that powers autocompletion installed by ``pip completion``.
é    N)Úchain)ÚAnyÚIterableÚListÚOptional)Úcreate_main_parser)Úcommands_dictÚcreate_command)Úget_default_environmentÚreturnc                     sœ  dt jvr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 rD|} nq:|durú|dkrRt 	d¡ ˆ  
d¡ o[|d	v }|rƒtƒ }ˆ  ¡ ‰‡‡fd
d„|jdd�D ƒ}|rƒ|D ]}	t|	ƒ qwt 	d¡ t|ƒ}
|
jjD ]}|jtjkr¤|j|j D ]
}| ||jf¡ q™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ÜnMdd„ |jD ƒ}| |j¡ t |¡}ˆ  
d¡�r)|D ]}|jtjk�r&||j|j 7 }�qntˆ| |ƒ}|�r9t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_WORDSé   Z
COMP_CWORDÚ Úhelpú-)ZshowZ	uninstallc                    s0   g | ]}|j  ˆ¡r|j ˆ d d… vr|j ‘qS )r   N)Zcanonical_nameÚ
startswith)Ú.0Údist)ÚcwordsÚlc© úi/Users/abhinavbhinder/Documents/map/venv/lib/python3.10/site-packages/pip/_internal/cli/autocompletion.pyÚ
<listcomp>2   s    
ýüÿz autocomplete.<locals>.<listcomp>T)Z
local_onlyc                 S   s   g | ]	}|  d ¡d ‘qS )ú=r   )Úsplit©r   Úxr   r   r   r   F   ó    c                    s    g | ]\}}|ˆ vr||f‘qS r   r   )r   r   Úv)Ú	prev_optsr   r   r   G   s     c                    s"   g | ]\}}|  ˆ ¡r||f‘qS r   ©r   )r   Úkr   ©Úcurrentr   r   r   I   s   " c                 S   s   g | ]}|d f‘qS )r   r   )r   Úpathr   r   r   r   T   s    r   é   z--r   c                 S   s   g | ]}|j ‘qS r   )Úoption_list)r   Úir   r   r   r   ^   s    ú c                    s   g | ]	}|  ˆ ¡r|‘qS r   r   r   r!   r   r   r   k   r   ) ÚosÚenvironr   ÚintÚ
IndexErrorr   Úlistr   ÚsysÚexitr   r
   ÚlowerZiter_installed_distributionsÚprintr	   ÚparserZoption_list_allr   ÚoptparseÚSUPPRESS_HELPZ
_long_optsZ_short_optsÚappendÚnargsÚget_path_completion_typeÚauto_complete_pathsZoption_groupsr%   r   Úfrom_iterableÚjoin)Úcwordr1   ZsubcommandsÚoptionsZsubcommand_nameÚwordZshould_list_installedÚenvZ	installedr   Z
subcommandÚoptZopt_strÚcompletion_typeÚpathsZoptionZ	opt_labelÚoptsZflattened_optsr   )r"   r   r   r   r   Úautocomplete   sŠ   
ÿþ

þ

€ý

û	
€þrB   r   r:   rA   c                 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   Ú	<genexpr>€   s   € 
ÿz+get_path_completion_type.<locals>.<genexpr>)r   r   r2   r3   Ústrr   ÚmetavarÚany)r   r:   rA   r>   Úor   r   r   r6   o   s   

ÿ€ûr6   r"   r?   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 )ao  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`)i
    :return: A generator of regular files and/or directories
    Nc                 3   s&   � | ]}t j |¡ ˆ ¡r|V  qd S )N)r(   r#   Únormcaser   r   ©Úfilenamer   r   rF   —   s   € ÿ
ÿz&auto_complete_paths.<locals>.<genexpr>rE   r   )r(   r#   r   ÚabspathÚaccessÚR_OKrK   Úlistdirr9   ÚisfileÚisdir)r"   r?   Z	directoryZcurrent_pathZ	file_listÚfr>   Z	comp_filer   rL   r   r7   ‡   s$   €	
ÿ€÷r7   )r   N)Ú__doc__r2   r(   r-   Ú	itertoolsr   Útypingr   r   r   r   Úpip._internal.cli.main_parserr   Úpip._internal.commandsr   r	   Zpip._internal.metadatar
   rB   rG   r*   r6   r7   r   r   r   r   Ú<module>   s(    
`ÿÿÿ
þ