3 ”Re“ã@s”dZddlZddlZddlZddlmZddlmZddlm Z m Z ddl m Z ddl mZerxddlmZmZmZmZd d „Zd d „Zd d„ZdS)zBLogic that powers autocompletion installed by ``pip completion``. éN)Úchain)Úcreate_main_parser)Ú commands_dictÚcreate_command)Úget_installed_distributions)ÚMYPY_CHECK_RUNNING)ÚAnyÚIterableÚListÚOptionalc sêdtjkrdStjdjƒdd…}ttjdƒ}y||d‰Wntk rZd‰YnXtƒ}ttƒ}g}d}x|D]}||krx|}PqxW|dk �r>|dkrªtj dƒ|dko¼ˆj d ƒ }|�r6g}ˆj ƒ} x}|d}|d�r.|ddd…dk�r.|d7}t|ƒ�qúWnždd„|jDƒ}|j|jƒtj|ƒ}ˆj d ƒ�r xN|D]$} | jtjk�rv|| j| j7}�qvWn t|||ƒ}|�rÀttˆ|ƒƒ}tdj‡fdd„|Dƒƒƒtj dƒdS)z?Entry Point for completion of main and subcommand options. ÚPIP_AUTO_COMPLETENÚ COMP_WORDSéÚ COMP_CWORDÚÚhelpÚshowÚ uninstallú-T)Ú local_onlycSsg|]}|jdƒd‘qS)ú=r)Úsplit)Ú.0Úx©rú�/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el8.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_internal/cli/autocompletion.pyú Hsz autocomplete..cs g|]\}}|ˆkr||f‘qSrr)rrÚv)Ú prev_optsrrrIscs"g|]\}}|jˆƒr||f‘qSr)Ú startswith)rÚkr)ÚcurrentrrrKscSsg|] }|df‘qS)rr)rÚpathrrrrTsréz--rcSsg|] }|j‘qSr)Ú option_list)rÚirrrr^sú csg|]}|jˆƒr|‘qSr)r)rr)r!rrrms)rr) ÚosÚenvironrÚintÚ IndexErrorrÚlistrÚsysÚexitrÚlowerrÚkeyÚappendÚprintrÚparserÚoption_list_allrÚoptparseÚ SUPPRESS_HELPÚ _long_optsÚ _short_optsÚnargsÚget_path_completion_typeÚauto_complete_pathsÚ option_groupsr$rÚ from_iterableÚjoin)ÚcwordsÚcwordr2Ú subcommandsÚoptionsÚsubcommand_nameÚwordÚshould_list_installedÚ installedÚlcÚdistÚ subcommandÚoptÚopt_strÚcompletion_typeÚpathsÚoptionÚ opt_labelÚoptsÚflattened_optsr)r!rrÚ autocompletes~               rQcCsš|dks||djdƒ r dSxt|D]l}|jtjkr8q&xXt|ƒjdƒD]F}||djdƒd|krH|j sˆtdd„|jjdƒDƒƒrH|jSqHWq&WdS) aLGet 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#rNú/rrcss|]}|dkVqdS)r"ÚfileÚdirN)r"rSrTr)rrrrrú ‚sz+get_path_completion_type..)rrr4r5ÚstrrÚmetavarÚany)r>r?rOrIÚorrrr9qs    r9c#sÀtjj|ƒ\}‰tjj|ƒ}tj|tjƒs.dStjjˆƒ‰‡fdd„tj|ƒDƒ}xh|D]`}tjj||ƒ}tjjtjj||ƒƒ}|dkrœtjj |ƒrœ|VqXtjj |ƒrXtjj|dƒVqXWdS)aoIf ``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 Nc3s$|]}tjj|ƒjˆƒr|VqdS)N)r'r"Únormcaser)rr)ÚfilenamerrrU™sz&auto_complete_paths..rTr) r'r"rÚabspathÚaccessÚR_OKrZÚlistdirr=ÚisfileÚisdir)r!rKÚ directoryÚ current_pathÚ file_listÚfrIÚ comp_filer)r[rr:ˆs     r:)Ú__doc__r4r'r,Ú itertoolsrÚpip._internal.cli.main_parserrÚpip._internal.commandsrrÚpip._internal.utils.miscrÚpip._internal.utils.typingrÚtypingrr r r rQr9r:rrrrÚs    _