o
    Df                     @   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   I/home/ubuntu/webapp/venv/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|rq{nbzt|||}|du rW 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