
    ^hk                        S r SSKJr  SSKrSSKrSSKrSSKJr  SSK	J
r
  SSKJrJr  SSKJrJr  SSKJrJr   " S	 S
5      r " S S\
5      rg)z7Replacements for sys.displayhook that publish over ZMQ.    )annotationsN)
ContextVar)DisplayHook)Sessionextract_header)AnyInstance)encode_images
json_cleanc                  D    \ rS rSrSrSrS rS rS r\	S 5       r
S rS	rg
)ZMQDisplayHook   zKA simple displayhook that publishes the object's repr over a ZeroMQ
socket.s   execute_resultc                r    Xl         X l        [        S5      U l        U R                  R	                  0 5        g)zInitialize the hook.parent_headerN)session
pub_socketr   _parent_headerset)selfr   r   s      O/home/james-whalen/.local/lib/python3.13/site-packages/ipykernel/displayhook.py__init__ZMQDisplayHook.__init__   s-    $:D_:U#    c                    g)z$This method is replaced in kernelappr    r   s    r   get_execution_count"ZMQDisplayHook.get_execution_count!   s    r   c                N   Uc  gU[         l        [        R                  R	                  5         [        R
                  R	                  5         U R                  5       S[        U5      00 S.nU R                  R                  U R                  SUU R                  U R                  S9  g)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__ZMQDisplayHook.__call__%   s    ;




#779!49-

 	OO%%** 	 	
r   c                6    U R                   R                  5       $ Nr   getr   s    r   r   ZMQDisplayHook.parent_header:       ""&&((r   c                L    U R                   R                  [        U5      5        g)zSet the parent header.Nr   r   r   r   r$   s     r   
set_parentZMQDisplayHook.set_parent>       v 67r   )r   r   r   N)__name__
__module____qualname____firstlineno____doc__r.   r   r   r1   propertyr   r<   __static_attributes__r   r   r   r   r      s6     E$
* ) )8r   r   c                     ^  \ rS rSr% SrSr\" \SS9r\	" SS9r
S\S'   S\S	'   U 4S
 jr\S 5       rS rS rS rSS jrS rSrU =r$ )ZMQShellDisplayHookC   zA 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ContextVar[dict[str, Any]]r   zdict[str, t.Any] | Nonemsgc                |   > [         TU ]  " U0 UD6  [        S5      U l        U R                  R	                  0 5        g )Nr   )superr   r   r   r   )r   argskwargs	__class__s      r   r   ZMQShellDisplayHook.__init__O   s6    $)&)(9#r   c                6    U R                   R                  5       $ r4   r5   r   s    r   r   !ZMQShellDisplayHook.parent_headerT   r8   r   c                L    U R                   R                  [        U5      5        g)z%Set the parent for outbound messages.Nr:   r;   s     r   r<   ZMQShellDisplayHook.set_parentX   r>   r   c                    U R                   (       a.  U R                   R                  S0 0 S.U R                  S9U l        gg)zStart the display hook.r#   )r!   r"   )r$   N)r   rJ   r   r   s    r   start_displayhook%ZMQShellDisplayHook.start_displayhook\   sB    <<||''  " )) ( DH r   c                `    U R                   (       a  U R                  U R                   S   S'   gg)zWrite the output prompt.contentr    N)rJ   prompt_countr   s    r   write_output_prompt'ZMQShellDisplayHook.write_output_prompth   s(    88595F5FDHHY 12 r   c                    U R                   (       a6  [        [        U5      5      U R                   S   S'   X R                   S   S'   gg)z!Write format data to the message.rY   r!   r"   N)rJ   r   r
   )r   format_dictmd_dicts      r   write_format_data%ZMQShellDisplayHook.write_format_datam   s<    88*4];5O*PDHHY'.5HHY
+ r   c                n   [         R                  R                  5         [         R                  R                  5         U R                  (       aa  U R                  S   S   (       aJ  U R
                  (       a9  U R
                  R                  U R                  U R                  U R                  S9  SU l        g)z%Finish up all displayhook activities.rY   r!   )r%   N)	r(   r)   r*   r+   rJ   r   r-   r   r.   r   s    r   finish_displayhook&ZMQShellDisplayHook.finish_displayhooks   sk    



88+F3LLdootxxtzzJr   )r   rJ   r4   )r?   r@   rA   rB   rC   r.   r	   r   r   r   r   __annotations__r   rD   r   r<   rV   r[   r`   rc   rE   __classcell__)rO   s   @r   rG   rG   C   si    & Ew40G%J..	  $
 ) )8
G
6 r   rG   )rC   
__future__r   r&   r(   typingtcontextvarsr   IPython.core.displayhookr   jupyter_client.sessionr   r   	traitletsr   r	   ipykernel.jsonutilr
   r   r   rG   r   r   r   <module>ro      s<    = #  
  " 0 : # 8-8 -8`6+ 6r   