o
    õ·iR  ã                   @  sz  U d dl m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 dd	lmZ dd
lmZ ddlmZ ddlmZ dLdd„ZG dd„ dƒZdZdZdZG dd„ dƒZG d d!„ d!eƒZG d"d#„ d#eƒZG d$d%„ d%eƒZejd&d'd(�Zeeed)œZ d*e!d+< 	dMdNd/d0„Z"dOd3d4„Z#dPd7d8„Z$dQd>d?„Z%dRdAdB„Z&dSdDdE„Z'dTdFdG„Z(dUdJdK„Z)dS )Vé    )ÚannotationsN)Úgettexté   )ÚArgument)ÚCommand)ÚContext)ÚGroup)ÚOption)Ú	Parameter)ÚParameterSource)ÚechoÚclir   Úctx_argsúcabc.MutableMapping[str, t.Any]Ú	prog_nameÚstrÚcomplete_varÚinstructionÚreturnÚintc           	      C  sf   |  d¡\}}}t|ƒ}|du rdS || |||ƒ}|dkr%t| ¡ ƒ dS |dkr1t| ¡ ƒ dS dS )a   Perform 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.
    Ú_Nr   Úsourcer   Úcomplete)Ú	partitionÚget_completion_classr   r   r   )	r   r   r   r   r   Úshellr   Zcomp_clsÚcomp© r   ú\C:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\click/shell_completion.pyÚshell_complete   s   r   c                   @  s.   e Zd ZdZdZ		dddd„Zddd„ZdS )Ú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.
    ©ÚvalueÚtypeÚhelpÚ_infoÚplainNr"   út.Anyr#   r   r$   ú
str | NoneÚkwargsr   ÚNonec                 K  ó   || _ || _|| _|| _d S ©Nr!   )Úselfr"   r#   r$   r)   r   r   r   Ú__init__N   ó   
zCompletionItem.__init__Únamec                 C  s   | j  |¡S r,   )r%   Úget)r-   r0   r   r   r   Ú__getattr__Z   s   zCompletionItem.__getattr__)r&   N)
r"   r'   r#   r   r$   r(   r)   r'   r   r*   )r0   r   r   r'   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r.   r2   r   r   r   r   r    9   s    ür    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
af  function %(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)";
c                   @  sz   e Zd ZU dZded< 	 ded< 	 d'dd„Zed(dd„ƒZd)dd„Zd(dd„Z	d*dd„Z
d+dd„Zd,d"d#„Zd(d$d%„Zd&S )-ÚShellCompletea¯  Base 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
    zt.ClassVar[str]r0   Úsource_templater   r   r   r   r   r   r   r   r*   c                 C  r+   r,   )r   r   r   r   )r-   r   r   r   r   r   r   r   r.   à   r/   zShellComplete.__init__c                 C  s*   t jdd| j dd¡t jd�}d|› d�S )zQThe name of the shell function defined by the completion
        script.
        z\W*Ú ú-r   )ÚflagsZ_completionN)ÚreÚsubr   ÚreplaceÚASCII)r-   Ú	safe_namer   r   r   Ú	func_nameì   s   zShellComplete.func_nameúdict[str, t.Any]c                 C  s   | j | j| jdœS )z—Vars for formatting :attr:`source_template`.

        By default this provides ``complete_func``, ``complete_var``,
        and ``prog_name``.
        )Zcomplete_funcr   r   N)rB   r   r   ©r-   r   r   r   Úsource_varsô   s   ýzShellComplete.source_varsc                 C  s   | j |  ¡  S )zÊProduce the shell script that defines the completion
        function. By default this ``%``-style formats
        :attr:`source_template` with the dict returned by
        :meth:`source_vars`.
        N)r9   rE   rD   r   r   r   r      s   zShellComplete.sourceútuple[list[str], str]c                 C  ó   t ‚)z˜Use the env vars defined by the shell script to return a
        tuple of ``args, incomplete``. This must be implemented by
        subclasses.
        N©ÚNotImplementedErrorrD   r   r   r   Úget_completion_args  s   z!ShellComplete.get_completion_argsÚargsú	list[str]Ú
incompleteúlist[CompletionItem]c                 C  s0   t | j| j| j|ƒ}t|||ƒ\}}| ||¡S )aT  Determine 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.
        N)Ú_resolve_contextr   r   r   Ú_resolve_incompleter   )r-   rK   rM   ÚctxÚobjr   r   r   Úget_completions  s   zShellComplete.get_completionsÚitemr    c                 C  rG   )z°Format a completion item into the form recognized by the
        shell script. This must be implemented by subclasses.

        :param item: Completion item to format.
        NrH   ©r-   rT   r   r   r   Úformat_completion  s   zShellComplete.format_completionc                   s4   ˆ   ¡ \}}ˆ  ||¡}‡ fdd„|D ƒ}d |¡S )zÛProduce 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.
        c                   s   g | ]}ˆ   |¡‘qS r   )rV   )Ú.0rT   rD   r   r   Ú
<listcomp>,  s    z*ShellComplete.complete.<locals>.<listcomp>Ú
N)rJ   rS   Újoin)r-   rK   rM   ZcompletionsÚoutr   rD   r   r   #  s   
zShellComplete.completeN)
r   r   r   r   r   r   r   r   r   r*   ©r   r   )r   rC   ©r   rF   )rK   rL   rM   r   r   rN   ©rT   r    r   r   )r3   r4   r5   r6   Ú__annotations__r.   ÚpropertyrB   rE   r   rJ   rS   rV   r   r   r   r   r   r8   È   s   
 





r8   c                      sL   e Zd ZdZdZeZeddd„ƒZd‡ fdd	„Z	ddd„Z
ddd„Z‡  ZS )ÚBashCompletezShell completion for Bash.Úbashr   r*   c                  C  s®   dd l } dd l}|  d¡}|d u rd }n|j|dddg|jd�}t d|j ¡ ¡}|d urM| 	¡ \}}|dk s?|dkrI|dk rKt
td	ƒd
d� d S d S d S t
tdƒd
d� d S )Nr   rb   z--norcz-czecho "${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Ú
subprocessÚwhichÚrunÚPIPEr=   Úsearchrc   ÚdecodeÚgroupsr   r   )rf   rg   Zbash_exeÚmatchÚoutputÚmajorÚminorr   r   r   Ú_check_version6  s0   

þÿ
ûÿ	
þzBashComplete._check_versionr   c                   s   |   ¡  tƒ  ¡ S r,   )rr   Úsuperr   rD   ©Ú	__class__r   r   r   W  s   
zBashComplete.sourcerF   c                 C  óX   t tjd ƒ}ttjd ƒ}|d|… }z	|| }W ||fS  ty+   d}Y ||fS w ©NÚ
COMP_WORDSÚ
COMP_CWORDr   r:   ©Úsplit_arg_stringÚosÚenvironr   Ú
IndexError©r-   ÚcwordsÚcwordrK   rM   r   r   r   rJ   [  ó   
ýýz BashComplete.get_completion_argsrT   r    c                 C  s   |j › d|j› �S )Nú,)r#   r"   rU   r   r   r   rV   g  s   zBashComplete.format_completion)r   r*   r\   r]   r^   )r3   r4   r5   r6   r0   Ú_SOURCE_BASHr9   Ústaticmethodrr   r   rJ   rV   Ú__classcell__r   r   rt   r   ra   0  s     
ra   c                   @  ó,   e Zd ZdZdZeZddd„Zdd
d„ZdS )ÚZshCompletezShell completion for Zsh.Úzshr   rF   c                 C  rv   rw   rz   r   r   r   r   rJ   q  r‚   zZshComplete.get_completion_argsrT   r    r   c                 C  s<   |j pd}|dkr|j dd¡n|j}|j› d|› d|› �S )Nr   ú:z\:rY   )r$   r"   r?   r#   )r-   rT   Úhelp_r"   r   r   r   rV   }  s   
zZshComplete.format_completionNr]   r^   )	r3   r4   r5   r6   r0   Ú_SOURCE_ZSHr9   rJ   rV   r   r   r   r   rˆ   k  s    
rˆ   c                   @  r‡   )ÚFishCompletezShell completion for Fish.Úfishr   rF   c                 C  sX   t tjd ƒ}tjd }|rt |ƒd }|dd … }|r(|r(|d |kr(| ¡  ||fS )Nrx   ry   r   r   éÿÿÿÿ)r{   r|   r}   Úpop)r-   r€   rM   rK   r   r   r   rJ   •  s   
z FishComplete.get_completion_argsrT   r    r   c                 C  s2   |j r|j› d|j› d|j › �S |j› d|j› �S )Nrƒ   ú	)r$   r#   r"   rU   r   r   r   rV   £  s   zFishComplete.format_completionNr]   r^   )	r3   r4   r5   r6   r0   Ú_SOURCE_FISHr9   rJ   rV   r   r   r   r   r�   �  s    
r�   ÚShellCompleteTypeztype[ShellComplete])Úbound)rb   rŽ   r‰   zdict[str, type[ShellComplete]]Ú_available_shellsÚclsr0   r(   c                 C  s   |du r| j }| t|< | S )am  Register 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.
    N)r0   r•   )r–   r0   r   r   r   Úadd_completion_class´  s   r—   r   útype[ShellComplete] | Nonec                 C  s
   t  | ¡S )zñLook 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.
    N)r•   r1   )r   r   r   r   r   È  s   
r   ÚstringrL   c                 C  sb   ddl }|j | dd�}d|_d|_g }z|D ]}| |¡ qW |S  ty0   | |j¡ Y |S w )aó  Split 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``.
    r   NT)Úposixr:   )ÚshlexÚwhitespace_splitÚ
commentersÚappendÚ
ValueErrorÚtoken)r™   r›   Úlexr[   r    r   r   r   r{   Ò  s   ÿúúr{   rQ   r   Úparamr
   Úboolc                 C  sl   t |tƒsdS |jdusJ ‚| j |j¡}|jdkp5|  |j¡tjup5|jdko5t |t	t
fƒo5t|ƒ|jk S )zìDetermine 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.
    FNr�   r   )Ú
isinstancer   r0   Úparamsr1   ÚnargsZget_parameter_sourcer   ZCOMMANDLINEÚtupleÚlistÚlen)rQ   r¢   r"   r   r   r   Ú_is_incomplete_argument÷  s   

ÿ
ÿúrª   r"   c                 C  s   |sdS |d }|| j v S )z5Check if the value looks like the start of an option.Fr   N)Z_opt_prefixes)rQ   r"   Úcr   r   r   Ú_start_of_option  s   
r¬   rK   c                 C  sn   t |tƒsdS |js|jrdS d}tt|ƒƒD ]\}}|d |jkr$ q.t| |ƒr-|} q.q|duo6||jv S )zºDetermine 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   )	r¤   r	   Zis_flagÚcountÚ	enumerateÚreversedr¦   r¬   Úopts)rQ   rK   r¢   Zlast_optionÚindexÚargr   r   r   Ú_is_incomplete_option  s   

þr³   c           
   	   C  s�  d|d< | j || ¡ fi |¤Ž�®}|j|j }|r®|j}t|tƒr£|js\| ||¡\}}}|du r:|W  d  ƒ S |j |||dd��}|}|j|j }W d  ƒ nQ1 sVw   Y  nH|}|r˜| ||¡\}}}|du rv|W  d  ƒ S |j |||dddd��}	|	}|j}W d  ƒ n1 s‘w   Y  |s`|}g |j¢|j¢}nq¶|sW d  ƒ |S W d  ƒ |S W d  ƒ |S 1 sÁw   Y  |S )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.
    TÚresilient_parsingN)Úparentr´   F)rµ   Zallow_extra_argsÚallow_interspersed_argsr´   )	Zmake_contextÚcopyZ_protected_argsrK   Úcommandr¤   r   ÚchainZresolve_command)
r   r   r   rK   rQ   r¸   r0   ÚcmdZsub_ctxZsub_sub_ctxr   r   r   rO   2  sf   
õÿüçú÷úÚ
ý+Ø
ý+þ
×+Õ+rO   rM   útuple[Command | Parameter, str]c                 C  s®   |dkrd}nd|v rt | |ƒr| d¡\}}}| |¡ d|vr+t | |ƒr+| j|fS | j | ¡}|D ]}t| ||ƒrA||f  S q3|D ]}t| |ƒrQ||f  S qD| j|fS )ah  Find 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--N)r¬   r   rž   r¸   Ú
get_paramsr³   rª   )rQ   rK   rM   r0   r   r¥   r¢   r   r   r   rP   o  s"   

ÿ
ÿ
rP   )r   r   r   r   r   r   r   r   r   r   r   r   r,   )r–   r“   r0   r(   r   r“   )r   r   r   r˜   )r™   r   r   rL   )rQ   r   r¢   r
   r   r£   )rQ   r   r"   r   r   r£   )rQ   r   rK   rL   r¢   r
   r   r£   )
r   r   r   r   r   r   rK   rL   r   r   )rQ   r   rK   rL   rM   r   r   r»   )*Ú
__future__r   Úcollections.abcÚabcZcabcr|   r=   ÚtypingÚtr   r   Úcorer   r   r   r   r	   r
   r   Úutilsr   r   r    r„   rŒ   r’   r8   ra   rˆ   r�   ÚTypeVarr“   r•   r_   r—   r   r{   rª   r¬   r³   rO   rP   r   r   r   r   Ú<module>   sJ    
&&&,h;$ýÿ



%

	
=