B
    [                 @   sf   d Z ddlmZ ddlmZmZ yddlmZ W n  ek
rP   ddl	mZ Y nX G dd deZ
dS )z* ZMQ Kernel History accessor and manager.     )HistoryAccessorBase)DictList)Emptyc               @   sx   e Zd ZdZedgZe Ze Ze Z	dd Z
ddd	ZdddZdddZdddZdddZdd ZdddZdS ) ZMQHistoryManagerz2History accessor and manager for ZMQ-based kernels c             C   s
   || _ dS )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    r
   9lib/python3.7/site-packages/jupyter_console/zmqhistory.py__init__   s    zZMQHistoryManager.__init__TFrangec             K   s   g }t | jdr~| jjf |||d|}xRy| jjdd}W n tk
rT   P Y q,X |d d|kr,|d dg }P q,W |S )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   )ZtimeoutZparent_headermsg_idZcontent)hasattrr   r   Zget_shell_msgr   get)r	   r   r   r   kwargsr   r   Zreplyr
   r
   r   _load_history*   s    zZMQHistoryManager._load_history
   c             C   s   | j d|||dS )Ntail)r   nr   r   )r   )r	   r   r   r   Zinclude_latestr
   r
   r   get_tailA   s    
zZMQHistoryManager.get_tail*Nc          	   C   s   | j d||||||dS )Nsearch)r   patternr   
search_rawr   r   unique)r   )r	   r   r   r   r   r   r    r
   r
   r   r   E   s    zZMQHistoryManager.searchr   c             C   s   | j d|||||dS )Nr   )r   r   r   startstopsession)r   )r	   r#   r!   r"   r   r   r
   r
   r   	get_rangeK   s    zZMQHistoryManager.get_rangec             C   s   | j d|||dS )Nr   )r   r   r   rangestr)r   )r	   r%   r   r   r
   r
   r   get_range_by_strP   s    z"ZMQHistoryManager.get_range_by_strc             C   s   dS )z8
        Nothing to do for ZMQ-based histories.
        Nr
   )r	   r
   r
   r   end_sessionT   s    zZMQHistoryManager.end_sessionc             C   s   dS )z8
        Nothing to do for ZMQ-based histories.
        Nr
   )r	   Znew_sessionr
   r
   r   resetZ   s    zZMQHistoryManager.reset)TFr   )r   TFF)r   TTFNF)r   NTF)TF)T)__name__
__module____qualname____doc__r   Zinput_hist_parsedr   Zoutput_histZdir_histZoutput_hist_reprsr   r   r   r   r$   r&   r'   r(   r
   r
   r
   r   r      s   


 


r   N)r,   ZIPython.core.historyr   Z	traitletsr   r   Zqueuer   ImportErrorZQueuer   r
   r
   r
   r   <module>   s   