a
    0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	m
Z
 ddlmZ ddlmZmZ ddlmZ ddd	d
Ze	e eee e
e dddZeeee d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r&t jds*dS t jd  dd tt jd } z| d   W n tyt   d Y n0 t }tt}g }d}D ]}||v r|} qq|dur`|dkrt	
d  d o|d	v }|r*t }  fd
d|jddD }|r*|D ]}	t|	 qt	
d  d o>|dk}
|
rjt dD ]}t| qPt	
d t|}|jjD ]2jtjkrz|fddjj D 7 }qzdd d| d  D fdd|D } fdd|D }t| |jj}|rt |}dd |D }|D ]>}|d }|d rR|d dd dkrR|d7 }t| qndd |jD }||j t|} dr|D ]$jtjkr|jj 7 }qn t| |}|rtt |}td fdd|D  t	
d dS )z:Entry Point for completion of main and subcommand options.PIP_AUTO_COMPLETEN
COMP_WORDS
COMP_CWORD    help-)show	uninstallc                    s0   g | ](}|j r|j  d d vr|j qS )r   N)canonical_name
startswith).0dist)cwordslc Y/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pip/_internal/cli/autocompletion.py
<listcomp>6   s   z autocomplete.<locals>.<listcomp>T)
local_onlyinstallpathc                    s   g | ]}| j fqS r   )nargs)r   opt_str)optr   r   r   N   s   c                 S   s   g | ]}| d d qS )=r   )splitr   xr   r   r   r   S       c                    s    g | ]\}}| vr||fqS r   r   )r   r'   v)	prev_optsr   r   r   T   r(   c                    s"   g | ]\}}|  r||fqS r   r   )r   kr)   currentr   r   r   V   r(   c                 S   s   g | ]}|d fqS )r   r   )r   r    r   r   r   r   a   r(   r      z--r$   c                 S   s   g | ]
}|j qS r   )option_list)r   ir   r   r   r   k   r(    c                    s   g | ]}|  r|qS r   r+   r&   r-   r   r   r   x   r(   ) osenvirongetr%   int
IndexErrorr   listr   sysexitr   r
   loweriter_installed_distributionsprintauto_complete_pathsr	   parseroption_list_allr   optparseSUPPRESS_HELP
_long_opts_short_optsget_path_completion_typeoption_groupsappendr0   r   from_iterablejoin)cwordr?   subcommandsoptionssubcommand_namewordshould_list_installedenv	installedr   should_list_installablesr    
subcommandcompletion_typepathsoption	opt_labeloptsflattened_optsr   )r.   r   r   r#   r*   r   autocomplete   s    








 
rZ   )r   rJ   rX   r   c                 C   s   |dk s| |d   dsdS |D ]n}|jtjkr4q"t|dD ]L}| |d  dd |krB|jrtdd |jdD rB|j    S qBq"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   rA   rB   strr%   metavarany)r   rJ   rX   r#   or   r   r   rE   |   s    

rE   )r.   rT   r   c                 #   s   t j| \} t j|}t |t js.dS t j   fddt |D }|D ]`}t j||}t jt j||}|dkrt j	|r|V  qVt j
|rVt j|dV  qVd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 )N)r3   r    normcaser   r&   filenamer   r   r^      s   z&auto_complete_paths.<locals>.<genexpr>r]   r   )r3   r    r%   abspathaccessR_OKrc   listdirrI   isfileisdir)r.   rT   	directorycurrent_path	file_listfr#   	comp_filer   rd   r   r>      s    	
r>   )__doc__rA   r3   r9   	itertoolsr   typingr   r   r   r   pip._internal.cli.main_parserr   pip._internal.commandsr   r	   pip._internal.metadatar
   rZ   r_   r6   rE   r>   r   r   r   r   <module>   s   n