o
    Df                     @   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$   I/home/ubuntu/webapp/venv/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    

.




