
    xdh                         d 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.    N)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      5lib/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_parent1       +F33r   N)	__name__
__module____qualname____doc__r(   r   r   r+   r/   r   r   r   r   r      sa          E       
 
 
"4 4 4 4 4r   r   c                   ~    e Zd ZdZdZ eed          Z ed          Z	 e
i           Z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_nonec                 .    t          |          | _        dS )z%Set the parent for outbound messages.Nr-   r.   s     r   r/   zZMQShellDisplayHook.set_parentA   r0   r   c                 Z    | j                             di i d| j                  | _        dS )zStart the display hook.r   )r   r   )r   N)r   msgr   r   s    r   start_displayhookz%ZMQShellDisplayHook.start_displayhookE   s?    <##  % $ 
 
r   c                 0    | j         | j        d         d<   dS )zWrite the output prompt.contentr   N)prompt_countr:   r   s    r   write_output_promptz'ZMQShellDisplayHook.write_output_promptP   s    151B-...r   c                 z    t          t          |                    | j        d         d<   || j        d         d<   dS )z!Write format data to the message.r=   r   r   N)r
   r	   r:   )r   format_dictmd_dicts      r   write_format_dataz%ZMQShellDisplayHook.write_format_dataT   s:    &0{1K1K&L&LF#*1J'''r   c                 
   t           j                                         t           j                                         | j        d         d         r,| j                            | j        | j        | j                   d| _        dS )z%Finish up all displayhook activities.r=   r   )r   N)	r"   r#   r$   r%   r:   r   r'   r   r(   r   s    r   finish_displayhookz&ZMQShellDisplayHook.finish_displayhookY   sm    

8Iv& 	KLdotxtzJJJr   )N)r1   r2   r3   r4   r(   r   r   r   r   r   r   r   r/   r;   r?   rC   rE   r   r   r   r6   r6   6   s        & & Ehw4000G%%%JDHHM4 4 4	
 	
 	
C C C2 2 2 2
    r   r6   )r4   r    r"   IPython.core.displayhookr   jupyter_client.sessionr   r   	traitletsr   r   r   ipykernel.jsonutilr	   r
   r   r6   r   r   r   <module>rJ      s    = =
  



 0 0 0 0 0 0 : : : : : : : : ) ) ) ) ) ) ) ) ) ) 8 8 8 8 8 8 8 8#4 #4 #4 #4 #4 #4 #4 #4L) ) ) ) )+ ) ) ) ) )r   