o
    iL                     @   st   d Z ddlZddlmZmZ ddlmZ ddlmZ ddl	m
Z
 G dd	 d	eZG d
d deZG dd de
ZdS )zeImplements a fully blocking kernel client.

Useful for test suites and blocking terminal interfaces.
    N)EmptyQueue)Type   )InProcessChannel)InProcessKernelClientc                       sB   e Zd ZdZ fddZdd Zddd	Zd
d Zdd Z  Z	S )BlockingInProcessChannelzA blocking in-process channel.c                    s   t  j|i | t | _dS )zInitialize the channel.N)super__init__r   	_in_queue)selfargskwds	__class__ W/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/ipykernel/inprocess/blocking.pyr
      s   z!BlockingInProcessChannel.__init__c                 C   s   | j | dS )z Call the handlers for a message.N)r   putr   msgr   r   r   call_handlers    s   z&BlockingInProcessChannel.call_handlersTNc                 C   s   |du rd}| j ||S )z-Gets a message if there is one that is ready.Ni:	 )r   get)r   blocktimeoutr   r   r   get_msg$   s   z BlockingInProcessChannel.get_msgc                 C   s4   g }	 z| | jdd W n
 ty   Y |S w q)z*Get all messages that are currently ready.TF)r   )appendr   r   )r   msgsr   r   r   get_msgs,   s   z!BlockingInProcessChannel.get_msgsc                 C   s   | j   S )z*Is there a message that has been received?)r   empty)r   r   r   r   	msg_ready6   s   z"BlockingInProcessChannel.msg_ready)TN)
__name__
__module____qualname____doc__r
   r   r   r   r   __classcell__r   r   r   r   r      s    

r   c                   @   s   e Zd ZdZdd ZdS )BlockingInProcessStdInChannelz$A blocking in-process stdin channel.c                 C   sh   |d d }|dkr2| j jj}|d d }t|dtjd tjdus$J tj  | j |  dS dS )	zfOverridden for the in-process channel.

        This methods simply calls raw_input directly.
        headermsg_typeinput_requestcontentprompt )endfileN)clientkernel_sys_raw_inputprintsys
__stdout__flushinput)r   r   r'   
_raw_inputr*   r   r   r   r   >   s   

z+BlockingInProcessStdInChannel.call_handlersN)r    r!   r"   r#   r   r   r   r   r   r%   ;   s    r%   c                   @   s0   e Zd ZdZeeZeeZeeZ	dd Z
dS )BlockingInProcessKernelClientz$A blocking in-process kernel client.c                 C   s   	 |    z
| jjddd}W n	 ty   Y n!w |d dkr9z
| jjddd W n	 ty2   Y nw | | nq	 z| jjddd}t|d  W n
 tyU   Y dS w q;)z,Wait for kernel info reply on shell channel.Tr   )r   r   r'   kernel_info_replyg?N)kernel_infoshell_channelr   r   iopub_channel_handle_kernel_info_replyr1   r   r   r   r   wait_for_readyU   s0   
z,BlockingInProcessKernelClient.wait_for_readyN)r    r!   r"   r#   r   r   shell_channel_classiopub_channel_classr%   stdin_channel_classr=   r   r   r   r   r7   M   s    r7   )r#   r2   queuer   r   	traitletsr   channelsr   r.   r   r   r%   r7   r   r   r   r   <module>   s    #