
    oi                     `    d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	 d Z
 G d de      Zd
d	Zy)    )NotebookClient)CellExecutionError)ClearOutputPreprocessor)BoolUnicodeIntegerc                 t    | d   dk7  r| S | d   }|D cg c]  }|d   dk7  s|d   dk7  r| c}| d<   | S c c}w )z9Strip any warning outputs and traceback from a code cell.	cell_typecodeoutputsoutput_typestreamnamestderr )cellr   outputs      U/home/ubuntu/docker-apps/notebooks/venv/lib/python3.12/site-packages/voila/execute.pystrip_code_cell_warningsr      s_    KF"9oG - H,v(0J 	DO Ks   5c                        e Zd ZU dZ eddd      Z eddd      Z eddd	      Z e	d
dd      Z
eed<   d fd	ZddZd Zd Zd Zd Z xZS )VoilaExecutorz0Execute, but respect the output widget behaviouru   Please run Voilà with --show_tracebacks=True or --debug to see the error message, or configure VoilaConfiguration.show_tracebacks.Tz.instruction given to user to debug cell errors)confighelpup   Please run Voilà with --VoilaExecutor.interrupt_on_timeout=True to continue executing the rest of the notebook.z:instruction given to user to continue execution on timeoutFz4Whether to send tracebacks to clients on exceptions.<   z
            The time to wait (in seconds) for the kernel to start.
            If kernel startup takes longer, a RuntimeError is
            raised.
            startup_timeoutc                     	 t         |          }| j                         r| j                  |       |S # t        $ r)}| j                  j	                  |       ||f}Y d }~Pd }~ww xY wN)superexecuter   logerrorshould_strip_errorstrip_notebook_errors)selfnb	resourceskmresulte	__class__s         r   r   zVoilaExecutor.executeA   s`    	%W_&F ""$&&r* " 	%HHNN1)_F	%s   4 	A&A!!A&c                    K   	 | j                  |||       d {   }| j                         rt        |       | j                  |       |S 7 2# t        $ r3}| j                  j                  |       | j	                  |       |d }~ww xY wwr   )async_execute_cellTimeoutErrorr    r!   show_code_cell_timeoutr"   r   strip_code_cell_errors)r$   r   r&   
cell_indexstore_historyr(   r)   s          r   execute_cellzVoilaExecutor.execute_cellN   s     	224]SSF ""$$T*''- T 	HHNN1''-G	s7   BA AA .BA 	B.BBBc                     | j                    S )zmReturn True if errors should be stripped from the Notebook, False otherwise, depending on the current config.)show_tracebacks)r$   s    r   r"   z VoilaExecutor.should_strip_error]   s    ''''    c                     |d   }|D cg c]  }|d   dk(  s| }}|D ]  }t        |       | j                  |         |S c c}w )z3Strip error messages and traceback from a Notebook.cellsr
   r   )r   r/   )r$   r%   r7   r   
code_cellss        r   r#   z#VoilaExecutor.strip_notebook_errorsa   s\    7',Lt[0AV0KdL
L 	.D$T*''-	. 	 Ms
   AAc                     |d   dk7  r|S |d   }|D cg c]  }|d   dk(  s| }}dj                  |d   | j                        }|D ]  }d|d	<   d
|d<   |g|d<    |S c c}w )z7Strip any error outputs and traceback from a code cell.r
   r   r   r   r!   z/There was an error when executing cell [{}]. {}execution_countExecutionErrorenamezExecution errorevalue	traceback)formatcell_error_instruction)r$   r   r   r   error_outputserror_messages         r   r/   z$VoilaExecutor.strip_code_cell_errorsm   s     &Ky/ ")
F=,AW,LF
 
 JPP"#T%@%@
 $ 	2F.F7O0F8#0/F;	2
 
s
   A A c                 >    d| j                    }ddd|gd}|g|d<   y)z+Show a timeout error output in a code cell.z7Cell execution timed out, aborting notebook execution. r!   r-   zTimeout error)r   r<   r=   r>   r   N)cell_timeout_instruction)r$   r   timeout_messager   s       r   r.   z$VoilaExecutor.show_code_cell_timeout   s>     TTXTqTqSrs ##%)*	
 "(Yr5   r   )T)__name__
__module____qualname____doc__r   r@   rD   r   r4   r   r   int__annotations__r   r2   r"   r#   r/   r.   __classcell__)r*   s   @r   r   r       s    :$ 	N>  'zJ  DO #
	
OS 
(
.#r5   r   Nc                     i }|d|i|d<   t               j                  | |      \  } }t        | fd|i|}|j                  | ||      S )Npathmetadatar'   )r'   )r   
preprocessr   r   )r%   cwdr'   kwargsr&   executors         r   	executenbrT      s_    I
!'	*+-88YGMB	R1B1&1HB	b11r5   )NN)nbclient.clientr   nbclient.exceptionsr   #nbconvert.preprocessors.clearoutputr   	traitletsr   r   r   r   r   rT   r   r5   r   <module>rY      s/    + 2 G , , p#N p#f2r5   