
    Xhi                         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	e      Z G d
 de      Z G d de
      Zy)zf Implements a fully blocking kernel client.

Useful for test suites and blocking terminal interfaces.
    N)EmptyQueue)Type   )InProcessChannel)InProcessKernelClientc                   <     e Zd ZdZ fdZd ZddZd Zd Z xZ	S )BlockingInProcessChannelzA blocking in-process channel.c                 B    t        |   |i | t               | _        y)zInitialize the channel.N)super__init__r   	_in_queue)selfargskwds	__class__s      P/var/www/html/myenv/lib/python3.12/site-packages/ipykernel/inprocess/blocking.pyr   z!BlockingInProcessChannel.__init__   s    $'$'(-    c                 :    | j                   j                  |       y)z Call the handlers for a message.N)r   putr   msgs     r   call_handlersz&BlockingInProcessChannel.call_handlers   s    3r   c                 B    |d}| j                   j                  ||      S )z-Gets a message if there is one that is ready.i:	 )r   get)r   blocktimeouts      r   get_msgz BlockingInProcessChannel.get_msg#   s%    ? G~~!!%11r   c                 n    g }	 	 |j                  | j                  d             ## t        $ r Y |S w xY w)z*Get all messages that are currently ready.F)r   )appendr   r   )r   msgss     r   get_msgsz!BlockingInProcessChannel.get_msgs+   sD    DLLuL56   s   !' 	44c                 8    | j                   j                          S )z*Is there a message that has been received?)r   empty)r   s    r   	msg_readyz"BlockingInProcessChannel.msg_ready5   s    >>'')))r   )TN)
__name__
__module____qualname____doc__r   r   r   r"   r%   __classcell__)r   s   @r   r
   r
      s    (0
 2*r   r
   c                       e Zd ZdZd Zy)BlockingInProcessStdInChannelz$A blocking in-process stdin channel.c                 $   |d   d   }|dk(  r| j                   j                  j                  }|d   d   }t        |dt        j
                         t        j
                  j                          | j                   j                   |              yy)	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_inputr2   s        r   r   z+BlockingInProcessStdInChannel.call_handlers=   sv    
 x=,&++::J^H-F&bs~~6NN  "KKjl+ 'r   N)r&   r'   r(   r)   r    r   r   r,   r,   :   s
    .,r   r,   c                   F    e Zd ZdZ ee      Z ee      Z ee      Z	d Z
y)BlockingInProcessKernelClientz$A blocking in-process kernel client.c                    	 | j                          	 | j                  j                  dd      }|d   dk(  r0	 | j                  j                  dd       | j	                  |       ng	 	 | j                  j                  dd      }t        |d          -# t
        $ r Y :w xY w# t
        $ r Y Iw xY w# t
        $ r Y yw xY w)z,Wait for kernel info reply on shell channel.Tr   )r   r   r/   kernel_info_replyg?N)kernel_infoshell_channelr   iopub_channel_handle_kernel_info_replyr   r9   r   s     r   wait_for_readyz,BlockingInProcessKernelClient.wait_for_readyS   s    ((00tQ0G z?&99**22s2K 66s; $ ((00tS0Ic*o&  !   $  s4   B& B ++B5 	B#"B#&	B21B25	C CN)r&   r'   r(   r)   r   r
   shell_channel_classiopub_channel_classr,   stdin_channel_classrH   r?   r   r   rA   rA   K   s0    . 7878<=r   rA   )r)   r:   queuer   r   	traitletsr   channelsr   r6   r   r
   r,   rA   r?   r   r   <module>rO      sI       ' ) */  *F,$< ,"!$9 !r   