o
    Œ¨Êh¡  ã                   @   sž   d dl m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mZmZ dd	lmZ g d
¢Z	ddd„Zi ddfdd„Zddd„ZdS )é    )Úwith_statementN)ÚPromptSession)ÚInMemoryHistoryé   )ÚClickCompleter)Ú	ClickExit)ÚCommandLineParserErrorÚExitReplExceptionÚInvalidGroupFormat)Ú_execute_internal_and_sys_cmds)Úbootstrap_promptÚregister_replÚreplc                 C   s$   t ƒ t| |d�ddœ}| |¡ |S )z 
    Bootstrap prompt_toolkit kwargs or use user defined values.

    :param group: click Group
    :param prompt_kwargs: The user specified prompt kwargs.
    )Úctxz> )ÚhistoryÚ	completerÚmessage)r   r   Úupdate)ÚgroupÚprompt_kwargsr   Údefaults© r   úB/var/www/html/env/lib/python3.10/site-packages/click_repl/_repl.pyr      s   
ý
r   Tc              
      s  | }| j durt| jtjƒs| j }|j}|jD ]%}t|tjƒr<|j|j du r<|js<t	t
|ƒj› d|j› d|j› d�ƒ‚qtj ¡ }| jj}t|jtjƒrWdd„ |jjD ƒ}	n|jj}	|	 |d¡}
|rwt|||ƒ}td
i |¤Ž‰ ‡ fdd„}ntjj}	 z|ƒ }W n tyŠ   Y q{ ty’   Y niw |s™|r˜q{nbzt|||ƒ}|du r¦W q{W n ty°   Y q{ ty¸   Y nCw z|j}z||_| |¡ W ||_n||_w W n) tjyç } z
| ¡  W Y d}~nd}~w tt fyñ   Y n	 tyù   Y nw q||
du�r|
|	|< dS dS )a8  
    Start an interactive shell. All subcommands are available in it.

    :param old_ctx: The current Click context.
    :param prompt_kwargs: Parameters passed to
        :py:func:`prompt_toolkit.PromptSession`.

    If stdin is not a TTY, no prompt will be printed, but only commands read
    from stdin.
    Nz 'z+' requires value for an optional argument 'z' in REPL modec                 S   s&   i | ]}|j  ¡ D ]\}}||“q	qS r   )ÚcommandsÚitems)Ú.0ÚsourceÚcmd_nameÚcmd_objr   r   r   Ú
<dictcomp>S   s    ýþÿzrepl.<locals>.<dictcomp>c                      s   ˆ   ¡ S ©N)Úpromptr   ©Úsessionr   r   Úget_commanda   s   zrepl.<locals>.get_commandTr   )!ÚparentÚ
isinstanceÚcommandÚclickÚGroupÚparamsÚArgumentÚnameÚrequiredr
   ÚtypeÚ__name__ÚsysÚstdinÚisattyÚCommandCollectionÚsourcesr   Úpopr   r   ÚreadlineÚKeyboardInterruptÚEOFErrorr   r   r	   Úprotected_argsÚinvokeÚClickExceptionÚshowr   Ú
SystemExit)Úold_ctxr   Úallow_system_commandsÚallow_internal_commandsÚ	group_ctxr   Úparamr2   Úrepl_command_nameÚavailable_commandsÚoriginal_commandr$   r'   ÚargsÚold_protected_argsÚer   r"   r   r   '   sŽ   

ÿÿÿÿ€
þ
ÿÿÿÿ€ÿØ
+ÿr   c                 C   s   | j |d�t t¡ƒ dS )z9Register :func:`repl()` as sub-command *name* of *group*.)r,   N)r'   r(   Úpass_contextr   )r   r,   r   r   r   r   –   s   r   r    )r   )Ú
__future__r   r(   r0   Úprompt_toolkitr   Úprompt_toolkit.historyr   Ú
_completerr   Ú
exceptionsr   r   r	   r
   Úutilsr   Ú__all__r   r   r   r   r   r   r   Ú<module>   s    
ý
ÿo