o
    i                     @   s   U d dl mZ d dlmZ G dd deZG dd deeZG dd deZ	G d	d
 d
eZ
G dd deZdZeed< dZeed< dS )    )Dict)NotebookNodec                   @      e Zd ZdZdS )CellControlSignalz
    A custom exception used to indicate that the exception is used for cell
    control actions (not the best model, but it's needed to cover existing
    behavior without major refactors).
    N__name__
__module____qualname____doc__ r   r   N/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/nbclient/exceptions.pyr      s    r   c                	   @   s.   e Zd ZdZededededd fddZdS )	CellTimeoutErrorzS
    A custom exception to capture when a cell has timed out during execution.
    msgtimeoutcellreturnc                 C   sd   |r&|j r&|j  d}t|dk r|j n|d d  d|dd   }nd}| tj|||dS )N
      z
...
zCell contents not found.)r   r   cell_contents)sourcestripsplitlentimeout_err_msgformat)clsr   r   r   src_by_linessrcr   r   r   error_from_timeout_and_cell   s   
z,CellTimeoutError.error_from_timeout_and_cellN)	r   r   r	   r
   classmethodstrintr   r    r   r   r   r   r      s    r   c                   @   s   e Zd ZdS )DeadKernelErrorN)r   r   r	   r   r   r   r   r$   %   s    r$   c                   @   r   )CellExecutionCompletez
    Used as a control signal for cell execution across execute_cell and
    process_message function calls. Raised when all execution requests
    are completed and no further messages are expected from the kernel
    over zeromq channels.
    Nr   r   r   r   r   r%   )   s    r%   c                       sv   e Zd ZdZdedededdf fddZdefd	d
ZdefddZdefddZ	e
dededd fddZ  ZS )CellExecutionErrorz
    Custom exception to propagate exceptions that are raised during
    notebook execution to the caller. This is mostly useful when
    using nbconvert as a library, since it allows to deal with
    failures gracefully.
    	tracebackenameevaluer   Nc                    s"   t  | || _|| _|| _d S N)super__init__r'   r(   r)   )selfr'   r(   r)   	__class__r   r   r,   <   s   
zCellExecutionError.__init__c                 C   s   t | | j| j| jffS r*   )typer'   r(   r)   r-   r   r   r   
__reduce__B   s   zCellExecutionError.__reduce__c                 C   s"   |   }t|ts|dd}|S )Nutf8replace)__unicode__
isinstancer"   encode)r-   sr   r   r   __str__E   s   
zCellExecutionError.__str__c                 C   s   | j S r*   )r'   r1   r   r   r   r5   K   s   zCellExecutionError.__unicode__r   r   c              	   C   sR   d |dg p	g }| tj|||dd|ddd|dd|dddS )	zvInstantiate from a code cell object and a message contents
        (message is either execute_reply or error)
        r   r'   r(   z<Error>r)    )r   r'   r(   r)   )r(   r)   )joingetexec_err_msgr   )r   r   r   tbr   r   r   from_cell_and_msgN   s   



z$CellExecutionError.from_cell_and_msg)r   r   r	   r
   r"   r,   tupler2   r9   r5   r!   r   r   r?   __classcell__r   r   r.   r   r&   4   s     r&   zAn error occurred while executing the following cell:
------------------
{cell.source}
------------------

{traceback}
{ename}: {evalue}
r=   zA cell timed out while it was being executed, after {timeout} seconds.
The message was: {msg}.
Here is a preview of the cell contents:
-------------------
{cell_contents}
-------------------
r   N)typingr   nbformatr   	Exceptionr   TimeoutErrorr   RuntimeErrorr$   r%   r&   r=   r"   __annotations__r   r   r   r   r   <module>   s    
,