
    MhL                        d Z ddlmZ ddlZddlZddlZddlmZ ddl	m
Z
mZ ddlmZmZmZ ddlmZmZ  G d d	          Z G d
 de          ZdS )z7Replacements for sys.displayhook that publish over ZMQ.    )annotationsN)DisplayHook)Sessionextract_header)AnyDictInstance)encode_images
json_cleanc                  .    e Zd ZdZdZd Zd Zd Zd ZdS )ZMQDisplayHookzOA simple displayhook that publishes the object's repr over a ZeroMQ
    socket.s   execute_resultc                0    || _         || _        i | _        dS )zInitialize the hook.N)session
pub_socketparent_header)selfr   r   s      U/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/ipykernel/displayhook.py__init__zZMQDisplayHook.__init__   s    $    c                    dS )z$This method is replaced in kernelappr    r   s    r   get_execution_countz"ZMQDisplayHook.get_execution_count   s    qr   c                H   |dS |t           _        t          j                                         t          j                                         |                                 dt          |          ii d}| j        	                    | j
        d|| j        | j                   dS )zHandle a hook call.Nz
text/plain)execution_countdatametadataexecute_result)parentident)builtins_sysstdoutflushstderrr   reprr   sendr   r   topic)r   objcontentss      r   __call__zZMQDisplayHook.__call__"   s    ;F


#7799!499-
 

 	O-x@RZ^Zd 	 	
 	
 	
 	
 	
r   c                .    t          |          | _        dS )zSet the parent header.Nr   r   r   r   s     r   
set_parentzZMQDisplayHook.set_parent3       +F33r   N)	__name__
__module____qualname____doc__r)   r   r   r,   r0   r   r   r   r   r      sa          E       
 
 
"4 4 4 4 4r   r   c                      e Zd ZU dZdZ eed          Z ed          Z	 e
i           Zded<   d Zd Zd	 Zdd
Zd ZdS )ZMQShellDisplayHookzA displayhook subclass that publishes data using ZeroMQ. This is intended
    to work with an InteractiveShell instance. It sends a dict of different
    representations of the object.NT)
allow_nonezdict[str, t.Any] | Nonemsgc                .    t          |          | _        dS )z%Set the parent for outbound messages.Nr.   r/   s     r   r0   zZMQShellDisplayHook.set_parentD   r1   r   c                l    | j         r,| j                             di i d| j                  | _        dS dS )zStart the display hook.r   )r   r   )r   N)r   r9   r   r   s    r   start_displayhookz%ZMQShellDisplayHook.start_displayhookH   sS    < 	|''  "  ) (  DHHH	 	r   c                B    | j         r| j        | j         d         d<   dS dS )zWrite the output prompt.contentr   N)r9   prompt_countr   s    r   write_output_promptz'ZMQShellDisplayHook.write_output_promptT   s4    8 	G595FDHY 1222	G 	Gr   c                    | j         r<t          t          |                    | j         d         d<   || j         d         d<   dS dS )z!Write format data to the message.r>   r   r   N)r9   r   r
   )r   format_dictmd_dicts      r   write_format_dataz%ZMQShellDisplayHook.write_format_dataY   sN    8 	6*4];5O5O*P*PDHY'.5DHY
+++	6 	6r   c                &   t           j                                         t           j                                         | j        rF| j        d         d         r3| j        r,| j                            | j        | j        | j                   d| _        dS )z%Finish up all displayhook activities.r>   r   )r    N)	r#   r$   r%   r&   r9   r   r(   r   r)   r   s    r   finish_displayhookz&ZMQShellDisplayHook.finish_displayhook_   s    

8 	K+F3 	K 	KLdotxtzJJJr   )N)r2   r3   r4   r5   r)   r	   r   r   r   r   r   r   __annotations__r0   r<   r@   rD   rF   r   r   r   r7   r7   8   s         & & Ehw4000G%%%JDHHM    4 4 4
 
 
G G G
6 6 6 6    r   r7   )r5   
__future__r   r!   r#   typingtIPython.core.displayhookr   jupyter_client.sessionr   r   	traitletsr   r   r	   ipykernel.jsonutilr
   r   r   r7   r   r   r   <module>rO      s    = = # " " " " "  



     0 0 0 0 0 0 : : : : : : : : ) ) ) ) ) ) ) ) ) ) 8 8 8 8 8 8 8 8#4 #4 #4 #4 #4 #4 #4 #4L- - - - -+ - - - - -r   