o
    Œ¨Êhç  ã                   @   sö   d dl 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 g d¢Z	ej
dkr0d dlmZmZ nd dlmZmZ d!dd	„Zi Zd"dd„Zd!dd„Zd!dd„Zdd„ Zdd„ Zeg d¢edƒ eg d¢edƒ 	
	
d#dd„Zdd„ Zdd„ Zdd „ ZdS )$é    N)Údefaultdicté   )ÚCommandLineParserErrorÚExitReplException)
Ú_execute_internal_and_sys_cmdsÚ_exit_internalÚ_get_registered_targetÚ_help_internalÚ_resolve_contextÚ_register_internal_commandÚdispatch_repl_commandsÚhandle_internal_commandsÚsplit_arg_stringÚexit)é   r   )ÚIterableÚMappingc                 C   sÀ   | r^|j }t|tjƒrY|js-| || ¡\}}} |du r|S |j|| |dd�}|j|j } n/| rN| || ¡\}}} |du r>|S |j|| |dddd�}|j} | s/|}g |j¢|j¢} n	 |S | s|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 args: List of complete args before the incomplete value.
    :param cli_ctx: `click.Context` object of the CLI group
    NT)ÚparentÚresilient_parsingF)r   Úallow_extra_argsÚallow_interspersed_argsr   )	ÚcommandÚ
isinstanceÚclickÚMultiCommandÚchainÚresolve_commandÚmake_contextÚprotected_argsÚargs)r   Úctxr   ÚnameÚcmdÚsub_ctx© r$   úB/var/www/html/env/lib/python3.10/site-packages/click_repl/utils.pyr
       s:   	úòÞ"r
   Tc                 C   sZ   t j | |d�}d|_d|_g }z|D ]}| |¡ qW |S  ty,   | |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.
    )ÚposixTÚ )ÚshlexÚwhitespace_splitÚ
commentersÚappendÚ
ValueErrorÚtoken)Ústringr&   ÚlexÚoutr-   r$   r$   r%   r   Q   s   ÿúúr   c                 C   sf   t |dƒs	tdƒ‚t| tƒr| g} nt| tƒst| tƒs&td t| ƒj¡ƒ‚| D ]}||ft	|< q(d S )NÚ__call__z#Internal command must be a callablez="names" must be a string, or an iterable object, but got "{}")
Úhasattrr,   r   Ústrr   r   ÚformatÚtypeÚ__name__Ú_internal_commands)ÚnamesÚtargetÚdescriptionr!   r$   r$   r%   r   n   s   

ÿÿÿr   c                 C   s   t  | ¡}|r|d S |S )Nr   )r7   Úget)r!   ÚdefaultÚtarget_infor$   r$   r%   r   €   s   
r   c                   C   s   t ƒ ‚©N)r   r$   r$   r$   r%   r   ‡   s   r   c                  C   sÒ   t  ¡ } |  d¡ |  ¡  |  d¡� |  d¡ W d   ƒ n1 s"w   Y  |  d¡�/ |  d¡ ttƒ}t 	¡ D ]\}}||d   
|¡ q:|  dd„ | 	¡ D ƒ¡ W d   ƒ n1 s^w   Y  |  ¡ }|S )	Nz	REPL helpzExternal Commandsz!prefix external commands with "!"zInternal Commandsz!prefix internal commands with ":"r   c                 s   s.   � | ]\}}d   tdjt|ƒƒ¡|fV  qdS )z, z:{}N)ÚjoinÚmapr4   Úsorted)Ú.0r:   Ú	mnemonicsr$   r$   r%   Ú	<genexpr>š   s   € ýþ
ÿz!_help_internal.<locals>.<genexpr>)r   ÚHelpFormatterÚwrite_headingÚindentÚsectionÚ
write_textr   Úlistr7   Úitemsr+   Úwrite_dlÚgetvalue)Ú	formatterÚ
info_tableÚmnemonicr=   Úvalr$   r$   r%   r	   ‹   s"   
ÿ


ûùr	   )ÚqÚquitr   zexits the repl)ú?ÚhÚhelpz!displays general help informationc              
   C   sf   |rt | ƒrdS |rt| ƒ}t|tƒrt |¡ dS zt| ƒW S  ty2 } ztd 	|¡ƒ‚d}~ww )z_
    Executes internal, system, and all the other registered click commands from the input
    Nz{})
r   r   r   r3   r   Úechor   r,   r   r4   )r   Úallow_internal_commandsÚallow_system_commandsÚresultÚer$   r$   r%   r   ¬   s   


€ÿr   c                   C   s
   t ƒ  dS )zExit the replN)r   r$   r$   r$   r%   r   Ã   s   
r   c                 C   s$   |   d¡rt | dd… ¡ dS dS )zo
    Execute system commands entered in the repl.

    System commands are all commands starting with "!".
    ú!r   NTF)Ú
startswithÚosÚsystem)r   r$   r$   r%   r   È   s   
r   c                 C   s0   |   d¡rt| dd… dd�}|r|ƒ S dS dS )ze
    Run repl-internal commands.

    Repl-internal commands are all commands starting with ":".
    ú:r   N)r<   )r]   r   )r   r9   r$   r$   r%   r   Õ   s   
ýr   r>   )T)TT)r   r^   r(   ÚsysÚcollectionsr   Ú
exceptionsr   r   Ú__all__Úversion_infoÚcollections.abcr   r   r
   r7   r   r   r   r   r	   r   r   r   r   r$   r$   r$   r%   Ú<module>   s6    

.



ÿ
ý