o
    ^i                     @  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                   @     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/home/ubuntu/hpml_nyu/venv/lib/python3.10/site-packages/nbclient/exceptions.pyr   	   s    r   c                   @  s   e Zd ZdZedd	d
ZdS )CellTimeoutErrorzS
    A custom exception to capture when a cell has timed out during execution.
    msgstrtimeoutintcellr   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 )	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   src_by_linessrcr   r   r   error_from_timeout_and_cell   s   
z,CellTimeoutError.error_from_timeout_and_cellN)r   r   r   r   r   r   r   r   )r   r	   r
   r   classmethodr#   r   r   r   r   r      s    r   c                   @  r   )DeadKernelErrorzA dead kernel error.Nr   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                      sD   e Zd ZdZd fdd	ZdddZdddZe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.
    	tracebackr   enameevaluer   Nonec                   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__
tuple[Any]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 )z	Str repr.z: )r(   r)   r*   r3   r   r   r   __str__M   s   zCellExecutionError.__str__r   r   r   dict[str, Any]c                 C  s   g }|j D ]}|d dkr|tj|d |d  d q|r+|dd |d d	|}d	|d
g p9g }| 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)r9   r:   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   stream_outputsoutputr<   tbr   r   r   from_cell_and_msgT   s*   




z$CellExecutionError.from_cell_and_msg)r(   r   r)   r   r*   r   r   r+   )r   r1   )r   r   )r   r   r   r6   r   r'   )
r   r	   r
   r   r-   r4   r5   r$   rH   __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}
rD   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   nbformatr   	Exceptionr   TimeoutErrorr   RuntimeErrorr%   r&   r'   r?   __annotations__rD   r   r   r   r   r   <module>   s    
: