
    Xh                     F    d Z ddlmZ ddlmZmZ ddlmZ  G d de      Zy)z* ZMQ Kernel History accessor and manager.     )HistoryAccessorBase)DictList)Emptyc                       e Zd ZdZ edg      Z e       Z e       Z e       Z	d Z
ddZddZ	 	 ddZddZdd	Zd
 ZddZy)ZMQHistoryManagerz2History accessor and manager for ZMQ-based kernels c                     || _         y)a  
        Class to load the command-line history from a ZMQ-based kernel,
        and access the history.

        Parameters
        ----------

        client: `IPython.kernel.KernelClient`
          The kernel client in order to request the history.
        N)client)selfr   s     N/var/www/html/myenv/lib/python3.12/site-packages/jupyter_console/zmqhistory.py__init__zZMQHistoryManager.__init__   s         c                 2   g }t        | j                  d      rn | j                  j                  d|||d|}	 	 | j                  j                  d      }|d   j	                  d      |k(  r|d   j	                  dg       }	 |S M|S # t
        $ r Y |S w xY w)	z
        Load the history over ZMQ from the kernel. Wraps the history
        messaging with loop to wait to get history results.
        history)rawoutputhist_access_type   )timeoutparent_headermsg_idcontent )hasattrr   r   get_shell_msggetr   )r   r   r   r   kwargsr   r   replys           r   _load_historyzZMQHistoryManager._load_history(   s     4;;	*(T[[(( 3S:J3+13F  KK55a5@E _-11(;vE"'	"2"6"6y""E    
 s   B	 		BBc                 ,    | j                  d|||      S )Ntail)r   nr   r   r    )r   r#   r   r   include_latests        r   get_tailzZMQHistoryManager.get_tail?   s#    !!6QC)/ " 1 	1r   Nc           	      2    | j                  d||||||      S )Nsearch)r   patternr   
search_rawr   r#   uniquer$   )r   r)   r   r*   r   r#   r+   s          r   r(   zZMQHistoryManager.searchC   s,    !!8W&)j)/1V " E 	Er   c                 0    | j                  d|||||      S )Nrange)r   r   r   startstopsessionr$   )r   r0   r.   r/   r   r   s         r   	get_rangezZMQHistoryManager.get_rangeI   s(    !!7)/u4*1 " 3 	3r   c                 ,    | j                  d|||      S )Nr-   )r   r   r   rangestrr$   )r   r3   r   r   s       r   get_range_by_strz"ZMQHistoryManager.get_range_by_strN   s%    !!7)/( " D 	Dr   c                      yz8
        Nothing to do for ZMQ-based histories.
        Nr   )r   s    r   end_sessionzZMQHistoryManager.end_sessionR        	r   c                      yr6   r   )r   new_sessions     r   resetzZMQHistoryManager.resetX   r8   r   )TFr-   )
   TFF)*TTFNF)r   NTF)TF)T)__name__
__module____qualname____doc__r   input_hist_parsedr   output_histdir_histoutput_hist_reprsr   r    r&   r(   r1   r4   r7   r;   r   r   r   r   r      sY    <bT
&KvH.1 8<,1E3
Dr   r   N)	rA   IPython.core.historyr   	traitletsr   r   queuer   r   r   r   r   <module>rI      s"    0 5   H+ Hr   