L iRUddlmZddlmZddlZddlZddlZddl m Z ddl m Z ddl m Z ddl mZddl mZdd l mZdd l mZdd l mZdd lmZ d)d ZGddZdZdZdZGddZGddeZGddeZGddeZej<ddZeeedZ de!d < d* d+d!Z"d,d"Z#d-d#Z$d.d$Z%d/d%Z&d0d&Z' d1d'Z( d2d(Z)y)3) annotationsN)gettext)Argument)Command)Context)Group)Option) Parameter)ParameterSource)echoc|jd\}}}t|}|y|||||}|dk(rt|jy|dk(rt|j yy)aPerform shell completion for the given CLI program. :param cli: Command being called. :param ctx_args: Extra arguments to pass to ``cli.make_context``. :param prog_name: Name of the executable in the shell. :param complete_var: Name of the environment variable that holds the completion instruction. :param instruction: Value of ``complete_var`` with the completion instruction and shell, in the form ``instruction_shell``. :return: Status code to exit with. _rsourcercomplete) partitionget_completion_classr rr) clictx_args prog_name complete_var instructionshellrcomp_clscomps \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/click/shell_completion.pyshell_completerss&(11#6E1k#E*H C9l ;Dh T[[]j  T]]_ c<eZdZdZdZ d ddZddZy) CompletionItema)Represents a completion value and metadata about the value. The default metadata is ``type`` to indicate special shell handling, and ``help`` if a shell supports showing a help string next to the value. Arbitrary parameters can be passed when creating the object, and accessed using ``item.attr``. If an attribute wasn't passed, accessing it returns ``None``. :param value: The completion suggestion. :param type: Tells the shell script to provide special completion support for the type. Click uses ``"dir"`` and ``"file"``. :param help: String shown next to the value if supported. :param kwargs: Arbitrary metadata. The built-in implementations don't use this, but custom type completions paired with custom shell support could use it. valuetypehelp_infoNc <||_||_||_||_yNr!)selfr"r#r$kwargss r__init__zCompletionItem.__init__Ns "  $  rc8|jj|Sr')r%get)r(names r __getattr__zCompletionItem.__getattr__Zszz~~d##r)plainN) r"t.Anyr#strr$ str | Noner)r0returnNone)r-r1r3r0)__name__ __module__ __qualname____doc__ __slots__r*r.rrr r 9sP$3I         $rr a%(complete_func)s() { local IFS=$'\n' local response response=$(env COMP_WORDS="${COMP_WORDS[*]}" COMP_CWORD=$COMP_CWORD %(complete_var)s=bash_complete $1) for completion in $response; do IFS=',' read type value <<< "$completion" if [[ $type == 'dir' ]]; then COMPREPLY=() compopt -o dirnames elif [[ $type == 'file' ]]; then COMPREPLY=() compopt -o default elif [[ $type == 'plain' ]]; then COMPREPLY+=($value) fi done return 0 } %(complete_func)s_setup() { complete -o nosort -F %(complete_func)s %(prog_name)s } %(complete_func)s_setup; a#compdef %(prog_name)s %(complete_func)s() { local -a completions local -a completions_with_descriptions local -a response (( ! $+commands[%(prog_name)s] )) && return 1 response=("${(@f)$(env COMP_WORDS="${words[*]}" COMP_CWORD=$((CURRENT-1)) %(complete_var)s=zsh_complete %(prog_name)s)}") for type key descr in ${response}; do if [[ "$type" == "plain" ]]; then if [[ "$descr" == "_" ]]; then completions+=("$key") else completions_with_descriptions+=("$key":"$descr") fi elif [[ "$type" == "dir" ]]; then _path_files -/ elif [[ "$type" == "file" ]]; then _path_files -f fi done if [ -n "$completions_with_descriptions" ]; then _describe -V unsorted completions_with_descriptions -U fi if [ -n "$completions" ]; then compadd -U -V unsorted -a completions fi } if [[ $zsh_eval_context[-1] == loadautofunc ]]; then # autoload from fpath, call function directly %(complete_func)s "$@" else # eval/source/. command, register function for later compdef %(complete_func)s %(prog_name)s fi affunction %(complete_func)s; set -l response (env %(complete_var)s=fish_complete COMP_WORDS=(commandline -cp) COMP_CWORD=(commandline -t) %(prog_name)s); for completion in $response; set -l metadata (string split "," $completion); if test $metadata[1] = "dir"; __fish_complete_directories $metadata[2]; else if test $metadata[1] = "file"; __fish_complete_path $metadata[2]; else if test $metadata[1] = "plain"; echo $metadata[2]; end; end; end; complete --no-files --command %(prog_name)s --arguments "(%(complete_func)s)"; ceZdZUdZded< ded< ddZeddZddZddZ dd Z dd Z dd Z dd Z y ) ShellCompleteaBase class for providing shell completion support. A subclass for a given shell will override attributes and methods to implement the completion instructions (``source`` and ``complete``). :param cli: Command being called. :param prog_name: Name of the executable in the shell. :param complete_var: Name of the environment variable that holds the completion instruction. .. versionadded:: 8.0 zt.ClassVar[str]r-source_templatec<||_||_||_||_yr')rrrr)r(rrrrs rr*zShellComplete.__init__s!  "(rctjdd|jjddtj}d|dS)zQThe name of the shell function defined by the completion script. z\W*-r)flags _completion)resubrreplaceASCII)r( safe_names r func_namezShellComplete.func_names< FF62t~~'='=c3'GrxxX 9+[))rcJ|j|j|jdS)zVars for formatting :attr:`source_template`. By default this provides ``complete_func``, ``complete_var``, and ``prog_name``. ) complete_funcrr)rIrrr(s r source_varszShellComplete.source_varss%"^^ --  rc<|j|jzS)zProduce the shell script that defines the completion function. By default this ``%``-style formats :attr:`source_template` with the dict returned by :meth:`source_vars`. )r=rMrLs rrzShellComplete.sources ##d&6&6&888rct)zUse the env vars defined by the shell script to return a tuple of ``args, incomplete``. This must be implemented by subclasses. NotImplementedErrorrLs rget_completion_argsz!ShellComplete.get_completion_argss "!rct|j|j|j|}t |||\}}|j ||S)aTDetermine the context and last complete command or parameter from the complete args. Call that object's ``shell_complete`` method to get the completions for the incomplete value. :param args: List of complete args before the incomplete value. :param incomplete: Value being completed. May be empty. )_resolve_contextrrr_resolve_incompleter)r(args incompletectxobjs rget_completionszShellComplete.get_completionssEtxxM-c4DZ!!#z22rct)zFormat a completion item into the form recognized by the shell script. This must be implemented by subclasses. :param item: Completion item to format. rPr(items rformat_completionzShellComplete.format_completions "!rc|j\}}|j||}|Dcgc]}|j|}}dj|Scc}w)zProduce the completion data to send back to the shell. By default this calls :meth:`get_completion_args`, gets the completions, then calls :meth:`format_completion` for each completion.  )rRrZr^join)r(rVrW completionsr]outs rrzShellComplete.complete#s[ 335j**4< 8CDt%%d+DDyy~EsAN) rrrcabc.MutableMapping[str, t.Any]rr1rr1r3r4r3r1)r3zdict[str, t.Any]r3ztuple[list[str], str])rV list[str]rWr1r3zlist[CompletionItem]r]r r3r1)r5r6r7r8__annotations__r*propertyrIrMrrRrZr^rr:rrr<r<s   %$ )  )2 ) )  )  )**  9" 3" rr<cNeZdZdZdZeZeddZdfd Z d dZ d dZ xZ S) BashCompletezShell completion for Bash.bashcddl}ddl}|jd}|d}nO|j|dddg|j}t j d|jj}|;|j\}}|dks |dk(r|dkrttd d yyyttd d y) Nrrmz--norcz-czecho "${BASH_VERSION}")stdoutz^(\d+)\.(\d+)\.\d+4zCShell completion is not supported for Bash versions older than 4.4.T)errz@Couldn't detect Bash version, shell completion is not supported.) shutil subprocesswhichrunPIPErDsearchrodecodegroupsr r)rrrsbash_exematchoutputmajorminors r_check_versionzBashComplete._check_version6s<<'  E^^8T+CD!$FII3V]]5I5I5KLE   <<>LE5s{eslus{4 0;l TU rc@|jt| Sr')rsuperr)r( __class__s rrzBashComplete.sourceWs w~rcttjd}ttjd}|d|} ||}||fS#t$rd}Y||fSwxYwN COMP_WORDS COMP_CWORDrr@split_arg_stringosenvironint IndexErrorr(cwordscwordrVrWs rrRz BashComplete.get_completion_args[o!"**\":;BJJ|,-a JZ JZ A AAc8|jd|jS)N,)r#r"r\s rr^zBashComplete.format_completiongs))Adjj\**r)r3r4rerfrh) r5r6r7r8r- _SOURCE_BASHr= staticmethodrrrRr^ __classcell__)rs@rrlrl0s2$ D"O@   +rrlc(eZdZdZdZeZddZddZy) ZshCompletezShell completion for Zsh.zshcttjd}ttjd}|d|} ||}||fS#t$rd}Y||fSwxYwrrrs rrRzZshComplete.get_completion_argsqrrc|jxsd}|dk7r|jjddn |j}|jd|d|S)Nr:z\:r`)r$r"rFr#)r(r]help_r"s rr^zZshComplete.format_completion}sO  S383, ""3.DJJ))BugRw//rNrfrh) r5r6r7r8r- _SOURCE_ZSHr=rRr^r:rrrrks# D!O  0rrc(eZdZdZdZeZddZddZy) FishCompletezShell completion for Fish.fishcttjd}tjd}|rt|d}|dd}|r|r|d|k(r|j||fS)Nrrrr)rrrpop)r(rrWrVs rrRz FishComplete.get_completion_argssf!"**\":;ZZ - )*5a8Jabz $48z#9 HHJZrc|jr(|jd|jd|jS|jd|jS)Nr )r$r#r"r\s rr^zFishComplete.format_completionsE 99ii[$**R {; ;))Adjj\**rNrfrh) r5r6r7r8r- _SOURCE_FISHr=rRr^r:rrrrs$ D"O  +rrShellCompleteTypeztype[ShellComplete])bound)rmrrzdict[str, type[ShellComplete]]_available_shellsc4| |j}|t|<|S)amRegister a :class:`ShellComplete` subclass under the given name. The name will be provided by the completion instruction environment variable during completion. :param cls: The completion class that will handle completion for the shell. :param name: Name to register the class under. Defaults to the class's ``name`` attribute. )r-r)clsr-s radd_completion_classrs" |xx!d Jrc,tj|S)zLook up a registered :class:`ShellComplete` subclass by the name provided by the completion instruction environment variable. If the name isn't registered, returns ``None``. :param shell: Name the class is registered under. )rr,)rs rrrs   ''rcddl}|j|d}d|_d|_g} |D]}|j| |S#t$r|j|j Y|SwxYw)aSplit an argument string as with :func:`shlex.split`, but don't fail if the string is incomplete. Ignores a missing closing quote or incomplete escape sequence and uses the partial token as-is. .. code-block:: python split_arg_string("example 'my file") ["example", "my file"] split_arg_string("example my\") ["example", "my"] :param string: String to split. .. versionchanged:: 8.2 Moved to ``shell_completion`` from ``parser``. rNT)posixr@)shlexwhitespace_split commentersappend ValueErrortoken)stringrlexrcrs rrrs|$ ++fD+ )CCCN C E JJu   J  399 J sA$A,+A,ct|tsy|jJ|jj |j}|j dk(xsn|j |jtjuxsA|j dkDxr0t|ttfxrt||j kS)zDetermine if the given parameter is an argument that can still accept values. :param ctx: Invocation context for the command represented by the parsed complete args. :param param: Argument object being checked. Frr) isinstancerr-paramsr,nargsget_parameter_sourcer COMMANDLINEtuplelistlen)rXparamr"s r_is_incomplete_argumentrs eX & :: !! ! JJNN5:: &E r  # #EJJ /7R7R R  KK!O )55$-0 )E U[[( rc.|sy|d}||jvS)z5Check if the value looks like the start of an option.Fr) _opt_prefixes)rXr"cs r_start_of_optionrs"  aA !! !!rct|tsy|js |jryd}t t |D])\}}|dz|j kDrnt||s'|}n|duxr||jvS)zDetermine if the given parameter is an option that needs a value. :param args: List of complete args before the incomplete value. :param param: Option object being checked. FNr) rr is_flagcount enumeratereversedrropts)rXrVr last_optionindexargs r_is_incomplete_optionrs eV $ }} K/ s 19u{{ "  C %K   d " @{ejj'@@rc d|d<|j||jfi|5}|j|jz}|r|j}t |t r|js]|j||\}}}| |cdddS|j|||d5}|}|j|jz}dddnv|}|rT|j||\}}}| |cdddS|j|||ddd5} | }|j}ddd|rT|}g|j|j}nn|rddd|S#1swYxYw#1swYCxYw#1swYSxYw)a`Produce the context hierarchy starting with the command and traversing the complete arguments. This only follows the commands, it doesn't trigger input prompts or callbacks. :param cli: Command being called. :param prog_name: Name of the executable in the shell. :param args: List of complete args before the incomplete value. Tresilient_parsingN)parentrF)rallow_extra_argsallow_interspersed_argsr) make_contextcopy_protected_argsrVcommandrr chainresolve_command) rrrrVrXrr-cmdsub_ctx sub_sub_ctxs rrTrT2s%)H !   )TYY[ =H =)""SXX-kkG'5)}}&-&=&=c4&HOD#t{"))))d3$*> %"22SXX= >> "G*1*A*A#t*Lc4;#&3))6!--  #&-149.2 . 0)&1G#*<> 0 07)V JsNAE$E$$E &E$0E$E E$! E$ E E$E! E$$E.cr|dk(rd}n6d|vr2t||r&|jd\}}}|j|d|vrt||r|j|fS|jj |}|D]}t |||s||fcS|D]}t ||s||fcS|j|fS)ahFind the Click object that will handle the completion of the incomplete value. Return the object and the incomplete value. :param ctx: Invocation context for the command represented by the parsed complete args. :param args: List of complete args before the incomplete value. :param incomplete: Value being completed. May be empty. =r@z--)rrrr get_paramsrr)rXrVrWr-rrrs rrUrUosS /Z@(2237a D  4,S*={{J&& [[ # #C (F% dE 2*$ $% % "3 .*$ $% ;; ""r) rrrrdrr1rr1rr1r3rr')rrr-r2r3r)rr1r3ztype[ShellComplete] | None)rr1r3rg)rXrrr r3bool)rXrr"r1r3r)rXrrVrgrr r3r) rrrrdrr1rVrgr3r)rXrrVrgrWr1r3ztuple[Command | Parameter, str])* __future__rcollections.abcabccabcrrDtypingtrrcorerrrr r r r utilsr rr rrrr<rlrrTypeVarrrrirrrrrrrTrUr:rrrs"  !# # -# #  #  #  # L"$"$L L* X .eeP8+=8+v!0-!0H+=+6AII19NO   5104 ",(("J2"A2: :-::  :  :z,# ,#!,#/2,#$,#r