o
    i
                     @   s   d Z ddlZddlmZ ddlZddlmZ ddlmZ ddl	m
Z
 G dd	 d	eZG d
d deZG dd deZG dd de
eejZdS )z+Tornado handlers for the terminal emulator.    N)web)utcnow   )IPythonHandler)WebSocketMixinc                   @      e Zd ZdZejdd ZdS )TerminalHandlerzRender the terminal interface.c                 C   s   |  | jdd| d d S )Nzterminal.htmlzterminals/websocket/)ws_path)writerender_template)self	term_name r   U/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/notebook/terminal/handlers.pyget   s   zTerminalHandler.getN__name__
__module____qualname____doc__r   authenticatedr   r   r   r   r   r          r   c                   @   r   )NamedTerminalHandlerz/Creates and renders a named terminal interface.c                 C   s4   | j  }|d }| jjdd| }| | d S )Nnamezterminals/newz
terminals/)terminal_managercreaterequestpathreplaceredirect)r   modelr   new_pathr   r   r   r      s   
zNamedTerminalHandler.getNr   r   r   r   r   r      r   r   c                   @   r   )NewTerminalHandlerzBCreates and renders a terminal interface using the named argument.c                 C   s   |dkr
t dd| jjd| |}|| jjv r4| d| | d | 	t
| j| d S | j| | | d S )Nnewi  z Terminal name 'new' is reserved.znew/Locationi.  )r   	HTTPErrorr   r   r   r   	terminals
set_header
set_statusfinishjsondumpsget_terminal_modelcreate_with_namer   )r   r   r!   r   r   r   r   &   s   
zNewTerminalHandler.getNr   r   r   r   r   r"   $   r   r"   c                       sF   e Zd Zdd Z fddZ fddZd fdd		Zd
d Z  ZS )
TermSocketc                 C   s   dS )zvTerminado adds redundant origin_check

        Tornado already calls check_origin, so don't do anything here.
        Tr   r   r   r   r   origin_check7   s   zTermSocket.origin_checkc                    s>   |   s	td|d | jjvrtdt j|i |S )Ni  r   i  )get_current_userr   r%   term_managerr&   superr   )r   argskwargs	__class__r   r   r   >   s
   

zTermSocket.getc                    s   t  | |   d S )N)r3   
on_message_update_activity)r   messager6   r   r   r8   E   s   zTermSocket.on_messageFc                    s   t  j||d |   d S )N)binary)r3   write_messager9   )r   r:   r;   r6   r   r   r<   I   s   zTermSocket.write_messagec                 C   s6   t  | jjd< | j| jjv rt  | jj| j _d S d S )Nterminal_last_activity)r   applicationsettingsr   r   r&   last_activityr/   r   r   r   r9   M   s   zTermSocket._update_activity)F)	r   r   r   r0   r   r8   r<   r9   __classcell__r   r   r6   r   r.   5   s    r.   )r   r*   tornador   	terminadonotebook._tzr   base.handlersr   base.zmqhandlersr   r   r   r"   r.   r   r   r   r   <module>   s    
