
    辙h                         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Zi ddfdZddZy)    )with_statementN)PromptSession)InMemoryHistory   )ClickCompleter)	ClickExit)CommandLineParserErrorExitReplExceptionInvalidGroupFormat)_execute_internal_and_sys_cmds)bootstrap_promptregister_replreplc                 Z    t               t        | |      dd}|j                  |       |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   defaultss       L/var/www/Befach/backend/env/lib/python3.12/site-packages/click_repl/_repl.pyr   r      s1     #$#Es3H OOM"O    Tc           	         | }| j                   0t        | j                  t        j                        s| j                   }|j                  }|j
                  D ]~  }t        |t        j                        s|j
                  |j                     8|j                  rEt        t        |      j                   d|j                   d|j                   d       t        j                  j                         }| j                  j                  }t        |j                  t        j                        rK|j                  j                   D 	
ci c]'  }	|	j"                  j%                         D ]  \  }
}|
|
 ) }}
}	}n|j                  j"                  }|j'                  |d      }|rt)        |||      }t+        di |fd}nt        j                  j,                  }	 	  |       }|s|rnA	 t3        |||      }| 	 	 |j8                  }	 ||_        |j;                  |       ||_        	 O||||<   yyc c}}
}	w # t.        $ r Y kt0        $ r Y %w xY w# t4        $ r Y t6        $ r Y >w xY w# ||_        w xY w# t        j<                  $ r}|j?                          Y d}~wd}~wt@        tB        f$ r Y t6        $ r Y w xY w)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                  $     j                         S N)prompt)sessions   r   get_commandzrepl.<locals>.get_commanda   s    >>##r    )"parent
isinstancecommandclickGroupparamsArgumentnamerequiredr   type__name__sysstdinisattyCommandCollectionsourcescommandsitemspopr   r   readlineKeyboardInterruptEOFErrorr   r	   r
   protected_argsinvokeClickExceptionshowr   
SystemExit)old_ctxr   allow_system_commandsallow_internal_commands	group_ctxr   paramr/   repl_command_namesourcecmd_namecmd_objavailable_commandsoriginal_commandr    r$   argsold_protected_argser   s                      @r   r   r   '   s    I ~~!*W__ekk*RNN	E uenn-  ,4NN$;''(5::, 7)).ND   YYF
  ,,)##U%<%<= $++33
 
%+__%:%:%<
 "' g

 
 '..77)--.?F(yI0-0	$ ii((
	!mG 	102GD | 	!*!9!9>+/	(Y'+=	(E V #0@,- $
. ! 	 		  & 	  		 ,>	(## 	FFHH:& 	  		sr   ,H7 H> .I  I< I0 %I< >	I	II	I-"I-,I-0	I99I< <KJ$$K8KKc                 b     | j                  |      t        j                  t                     y)z9Register :func:`repl()` as sub-command *name* of *group*.)r)   N)r$   r%   pass_contextr   )r   r)   s     r   r   r      s"    EMMtMU//56r   r   )r   )
__future__r   r%   r-   prompt_toolkitr   prompt_toolkit.historyr   
_completerr   
exceptionsr   r	   r
   r   utilsr   __all__r   r   r   r!   r   r   <module>rT      sK    %  
 ( 2 & ! U U 1 8 	. TSWlA^7r   