
    Xh                          d 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	m
Z
mZ ddlmZmZ  G d	 d
e      Z ej                   e       y)z A client for in-process kernels.    N)KernelClient)KernelClientABC)run_sync)InstanceTypedefault   )InProcessChannelInProcessHBChannelc                   f    e Zd ZdZ ee      Z ee      Z ee      Z ee      Z	 ee
      Z edd      Z ed      d        Z fdZ fdZed	        Zed
        Zed        Zed        Zed        Z	 ddZddZddZddZd dZd ZddZd Zd Z d Z!d!dZ"d!dZ#d!dZ$d!dZ% xZ&S )"InProcessKernelClienta  A client for an in-process kernel.

    This class implements the interface of
    `jupyter_client.clientabc.KernelClientABC` and allows
    (asynchronous) frontends to be used seamlessly with an in-process kernel.

    See `jupyter_client.client.KernelClient` for docstrings.
    z,ipykernel.inprocess.ipkernel.InProcessKernelT)
allow_noneblocking_classc                     ddl m} |S )Nr	   )BlockingInProcessKernelClient)blockingr   )selfr   s     N/var/www/html/myenv/lib/python3.12/site-packages/ipykernel/inprocess/client.py_default_blocking_classz-InProcessKernelClient._default_blocking_class6   s    ;,,    c                 B    t         |          }| j                  |d<   |S )z'Get the connection info for the client.kernel)superget_connection_infor   )r   d	__class__s     r   r   z)InProcessKernelClient.get_connection_info<   s"    G')kk(r   c                     t         |           | j                  r&| j                  j                  j	                  |        yy)z!Start the channels on the client.N)r   start_channelsr   	frontendsappend)r   argskwargsr   s      r   r   z$InProcessKernelClient.start_channelsB   s2     ;;KK!!((. r   c                 ^    | j                   | j                  |       | _         | j                   S N)_shell_channelshell_channel_classr   s    r   shell_channelz#InProcessKernelClient.shell_channelH   -    &"&":":4"@D"""r   c                 ^    | j                   | j                  |       | _         | j                   S r$   )_iopub_channeliopub_channel_classr'   s    r   iopub_channelz#InProcessKernelClient.iopub_channelN   r)   r   c                 ^    | j                   | j                  |       | _         | j                   S r$   )_stdin_channelstdin_channel_classr'   s    r   stdin_channelz#InProcessKernelClient.stdin_channelT   r)   r   c                 ^    | j                   | j                  |       | _         | j                   S r$   )_control_channelcontrol_channel_classr'   s    r   control_channelz%InProcessKernelClient.control_channelZ   s-      ($($>$>t$DD!$$$r   c                 ^    | j                   | j                  |       | _         | j                   S r$   )_hb_channelhb_channel_classr'   s    r   
hb_channelz InProcessKernelClient.hb_channel`   s-    ##44T:Dr   c                     || j                   }t        ||||xs i |      }| j                  j                  d|      }| j	                  |       |d   d   S )zExecute code on the client.)codesilentstore_historyuser_expressionsallow_stdinexecute_requestheadermsg_id)r?   dictsessionmsg_dispatch_to_kernel)r   r;   r<   r=   r>   r?   contentrE   s           r   executezInProcessKernelClient.executei   si     **K'-3#
 ll0':  %8}X&&r   c                     |t        |      }t        ||      }| j                  j                  d|      }| j	                  |       |d   d   S )zGet code completion.)r;   
cursor_poscomplete_requestrA   rB   lenrC   rD   rE   rF   )r   r;   rJ   rG   rE   s        r   completezInProcessKernelClient.completez   sQ    TJDZ8ll17;  %8}X&&r   c                     |t        |      }t        |||      }| j                  j                  d|      }| j	                  |       |d   d   S )zGet code inspection.)r;   rJ   detail_levelinspect_requestrA   rB   rL   )r   r;   rJ   rP   rG   rE   s         r   inspectzInProcessKernelClient.inspect   sZ    TJ!%

 ll0':  %8}X&&r   c                     t        d|||d|}| j                  j                  d|      }| j                  |       |d   d   S )zGet code history.)rawoutputhist_access_typehistory_requestrA   rB    rC   rD   rE   rF   )r   rT   rU   rV   kwdsrG   rE   s          r   historyzInProcessKernelClient.history   sN    Y3v@PYTXYll0':  %8}X&&r   c                     d}t        |      )zHandle shutdown.z!Cannot shutdown in-process kernel)NotImplementedError)r   restartrE   s      r   shutdownzInProcessKernelClient.shutdown   s     2!#&&r   c                 j    | j                   j                  d      }| j                  |       |d   d   S )zRequest kernel info.kernel_info_requestrA   rB   rD   rE   rF   )r   rE   s     r   kernel_infoz!InProcessKernelClient.kernel_info   s4    ll45  %8}X&&r   c                     |i nt        |      }| j                  j                  d|      }| j                  |       |d   d   S )z6Request a dictionary of valid comms and their targets.)target_namecomm_info_requestrA   rB   rY   )r   re   rG   rE   s       r   	comm_infozInProcessKernelClient.comm_info   sG    #+"+1Nll2G<  %8}X&&r   c                 X    | j                   d}t        |      || j                   _        y)zHandle kernel input.Nz*Cannot send input reply. No kernel exists.)r   RuntimeErrorraw_input_str)r   stringrE   s      r   inputzInProcessKernelClient.input   s(    ;;>Cs##$*!r   c                 p    | j                   j                  dd|i      }| j                  |       |d   d   S )zHandle an is_complete request.is_complete_requestr;   rA   rB   rb   )r   r;   rE   s      r   is_completez!InProcessKernelClient.is_complete   s:    ll4vtnE  %8}X&&r   c                    | j                   }|d}t        |      |j                  }| j                  j	                  ||       |j                         }t        t        |j                        } ||       n4t        j                         }|j                  |j                  |             | j                  j                  |d      \  }}| j                  j                  |       y)z0Send a message to the kernel and handle a reply.Nz&Cannot send request. No kernel exists.F)copy)r   ri   shell_streamrD   sendrecv_multipartr   dispatch_shellasyncioget_event_looprun_until_completerecvr(   call_handlers_later)	r   rE   r   stream	msg_partsru   loopidents	reply_msgs	            r   rF   z)InProcessKernelClient._dispatch_to_kernel   s    >:Cs##$$&#&))+	%f&;&;<N9%))+D##F$9$9)$DE LL--f5-A	..y9r   c                 :    | j                   j                  ||      S )zGet a shell message.)r(   get_msgr   blocktimeouts      r   get_shell_msgz#InProcessKernelClient.get_shell_msg       !!))%99r   c                 :    | j                   j                  ||      S )zGet an iopub message.)r-   r   r   s      r   get_iopub_msgz#InProcessKernelClient.get_iopub_msg   r   r   c                 :    | j                   j                  ||      S )zGet a stdin message.)r1   r   r   s      r   get_stdin_msgz#InProcessKernelClient.get_stdin_msg   r   r   c                 :    | j                   j                  ||      S )zGet a control message.)r5   r   r   s      r   get_control_msgz%InProcessKernelClient.get_control_msg   s    ##++E7;;r   )FTNNr$   )Nr   )TFrange)F)TN)'__name__
__module____qualname____doc__r   r
   r&   r,   r0   r4   r   r8   r   r   r   r   r   r   propertyr(   r-   r1   r5   r9   rH   rN   rR   r[   r_   rc   rg   rl   ro   rF   r   r   r   r   __classcell__)r   s   @r   r   r      s)    /0/0/0 !12./DQUVF - -
/ # #
 # #
 # #
 % %
     Z^'"''''''+':&:::<r   r   )r   rv   jupyter_client.clientr   jupyter_client.clientabcr   jupyter_core.utilsr   	traitletsr   r   r   channelsr
   r   r   registerrX   r   r   <module>r      sE    &  . 4 ' . - ;y<L y<@   . /r   