U
    luf                     @  s   U d 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	eZ
G d	d
 d
eZG dd deZG dd deZdZded< dZded< dZded< dS )zExceptions for nbclient.    )annotations)Any)NotebookNodec                   @  s   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   7/tmp/pip-unpacked-wheel-72rqhnyi/nbclient/exceptions.pyr   	   s   r   c                   @  s(   e Zd ZdZedddd dddZdS )	CellTimeoutErrorzS
    A custom exception to capture when a cell has timed out during execution.
    strintr   )msgtimeoutcellreturnc                 C  sd   |rL|j rL|j  d}t|dk r,|j n|dd  d|dd  }nd}| tj|||dS )	z)Create an error from a timeout on a cell.
   N   z
...
zCell contents not found.)r   r   cell_contents)sourcestripsplitlentimeout_err_msgformat)clsr   r   r   Zsrc_by_linessrcr   r   r   error_from_timeout_and_cell   s    

z,CellTimeoutError.error_from_timeout_and_cellN)r   r   r	   r
   classmethodr!   r   r   r   r   r      s   r   c                   @  s   e Zd ZdZdS )DeadKernelErrorzA dead kernel error.Nr   r   r   r   r   r#   )   s   r#   c                   @  s   e Zd ZdZdS )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                      s^   e Zd ZdZddddd fddZddd	d
ZddddZeddd d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.
    r   None)	tracebackenameevaluer   c                   s"   t  | || _|| _|| _dS )zInitialize the error.N)super__init__r'   r(   r)   )selfr'   r(   r)   	__class__r   r   r+   B   s    zCellExecutionError.__init__z
tuple[Any])r   c                 C  s   t | | j| j| jffS )zReduce implementation.)typer'   r(   r)   r,   r   r   r   
__reduce__I   s    zCellExecutionError.__reduce__c                 C  s"   | j r| j S | j d| j S dS )z	Str repr.z: N)r'   r(   r)   r0   r   r   r   __str__M   s    zCellExecutionError.__str__r   zdict[str, Any])r   r   r   c                 C  s   g }|j D ]0}|d dkr
|tj|d |d  d q
|rV|dd |d d	|}d	|d
g prg }| tj|||d|dd|dddS )zvInstantiate from a code cell object and a message contents
        (message is either execute_reply or error)
        output_typestreamnametext)r5   r6   r    z------------------r   r'   )r   stream_outputr'   r(   z<Error>r)   )r(   r)   )	outputsappendstream_output_msgr   rstripinsertjoingetexec_err_msg)r   r   r   Zstream_outputsoutputr8   tbr   r   r   from_cell_and_msgT   s(    




z$CellExecutionError.from_cell_and_msg)
r   r   r	   r
   r+   r1   r2   r"   rC   __classcell__r   r   r-   r   r%   :   s   r%   z----- {name} -----
{text}r   r;   zAn error occurred while executing the following cell:
------------------
{cell.source}
------------------
{stream_output}

{traceback}
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)r
   
__future__r   typingr   Znbformatr   	Exceptionr   TimeoutErrorr   RuntimeErrorr#   r$   r%   r;   __annotations__r@   r   r   r   r   r   <module>   s   
: