
    Xf                        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    r	d dlmZmZ nd dlmZmZ ddZi Zdd
ZddZddZd Zd Z eg ded            eg ded           	 	 ddZd Zd Z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                    | r|j         }t          |t          j                  r|j        sG|                    ||           \  }}} ||S |                    || |d          }|j        |j        z   } nX| rB|                    ||           \  }}} ||S |                    || |ddd          }|j        } | B|}g |j        |j        } nn| |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_ctxs         B/var/www/html/env/lib/python3.11/site-packages/click_repl/utils.pyr   r       s%      +gu122 	= @")"9"9#t"D"Dc4;J&&tT#QU&VV)CH4 (&-&=&=c4&H&HOD#t{"
!..")-05*. /  G #<D  (  ?/?',?A   D J    Tc                     t          j         | |          }d|_        d|_        g }	 |D ]}|                    |           n*# t          $ r |                    |j                   Y nw xY w|S )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outr0   s        r&   r   r   Q   s     +fE
*
*
*CCCN
C 	 	EJJu	    	

39	 Js   A $A*)A*c                 T   t          |d          st          d          t          | t                    r| g} n^t          | t                    st          | t
                    s4t          d                    t          |           j                            | D ]}||ft          |<   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#   s       r&   r   r   n   s    6:&& @>???% 
	E7	#	# 
:eX+F+F 
KRRU$ 
 
 	
  9 9$*K#84  9 9r'   c                 N    t                               |           }|r|d         S |S )Nr   )r;   get)r#   defaulttarget_infos      r&   r	   r	      s,    $((..K 1~Nr'   c                      t                      N)r    r'   r&   r   r      s    


r'   c                     t          j                    } |                     d           |                                  |                     d          5  |                     d           d d d            n# 1 swxY w Y   |                     d          5  |                     d           t          t                    }t          	                                D ]&\  }}||d                  
                    |           '|                     d |	                                D                        d d d            n# 1 swxY w Y   |                                 }|S )Nz	REPL helpzExternal Commandsz!prefix external commands with "!"zInternal Commandsz!prefix internal commands with ":"r   c           	   3      K   | ]>\  }}d                      t          dj        t          |                              |fV  ?dS )z, z:{}N)joinmapr8   sorted).0r>   	mnemonicss      r&   	<genexpr>z!_help_internal.<locals>.<genexpr>   sd       
 

 'Y 		#elF9,=,=>>??
 
 
 
 
 
r'   )r   HelpFormatterwrite_headingindentsection
write_textr   listr;   itemsr.   write_dlgetvalue)	formatter
info_tablemnemonicrB   vals        r&   r
   r
      s   #%%IK(((			.	/	/ B B@AAAB B B B B B B B B B B B B B B 
		.	/	/ 
 
@AAA &&
%7%=%=%?%? 	8 	8!Hk{1~&--h7777 
 

 +5*:*:*<*<
 
 
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 



CJs%   A44A8;A8BD;;D?D?)qquitr   zexits the repl)?hhelpz!displays general help informationc                 (   |rt          |           rdS |r:t          |           }t          |t                    rt	          j        |           dS 	 t          |           S # t          $ r'}t          d	                    |                    d}~ww xY w)z_
    Executes internal, system, and all the other registered click commands from the input
    Nz{})
r   r   r   r7   r   echor   r/   r   r8   )r   allow_internal_commandsallow_system_commandsresultes        r&   r   r      s      !7!@!@ t )'22fc"" 	Jv45((( 5 5 5$T[[^^4445s   A   
B*"BBc                  "    t                       dS )zExit the replN)r   rE   r'   r&   r   r      s    r'   c                 l    |                      d          rt          j        | 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   s    r&   r   r      s<     # 
	'!""+t5r'   c                 ~    |                      d          r%t          | dd         d          }|r |            S dS dS )ze
    Run repl-internal commands.

    Repl-internal commands are all commands starting with ":".
    :r   N)rA   )ri   r	   )r   r=   s     r&   r   r      s[     # 'TBBB 	688O 	 	r'   rD   )T)TT)r   rj   r+   syscollectionsr   
exceptionsr   r   __all__version_infocollections.abcr   r   r   r;   r   r   r	   r   r
   r   r   r   r   rE   r'   r&   <module>rt      s    				  



 # # # # # # A A A A A A A A    v111111111--------+ + + +\     :9 9 9 9$       6  000.BR S S S  (K   !5 5 5 5.  

 
 
	 	 	 	 	r'   