
     Ce                         U d Z ddlmZmZ ddlmZ  G d de          Z G d dee          Z	 G d d	e
          Z G d
 de          Z G d de          ZdZeed<   dZeed<   dZeed<   dS )zExceptions for nbclient.    )DictList)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__     3lib/python3.11/site-packages/nbclient/exceptions.pyr   r      s          	Dr   r   c            	       :    e Zd ZdZededededd fd            ZdS )CellTimeoutErrorzS
    A custom exception to capture when a cell has timed out during execution.
    msgtimeoutcellreturnc                     |re|j         r^|j                                                             d          }t          |          dk     r|j         n|dd          d|dd          }nd} | t                              |||                    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srcs         r   error_from_timeout_and_cellz,CellTimeoutError.error_from_timeout_and_cell   s    
  	-DK 	-;,,..44T::L |$$r)) $RaR(DDbcc1BDD C -Cs?))'sRU)VVWWWr   N)	r	   r
   r   r   classmethodstrintr   r%   r   r   r   r   r      sh          XX #X+7X	X X X [X X Xr   r   c                       e Zd ZdZdS )DeadKernelErrorzA dead kernel error.Nr   r   r   r   r*   r*   '   s        Dr   r*   c                       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          	Dr   r,   c                   p     e Zd ZdZdedededdf fdZdefdZdefd	Ze	d
e
dedd fd            Z x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                 t    t                                          |           || _        || _        || _        dS )zInitialize the error.N)super__init__r/   r0   r1   )selfr/   r0   r1   	__class__s       r   r4   zCellExecutionError.__init__@   s4    ###"
r   c                 H    t          |           | j        | j        | j        ffS )zReduce implementation.)typer/   r0   r1   r5   s    r   
__reduce__zCellExecutionError.__reduce__G   s     DzzDNDJDDDr   c                 @    | j         r| j         S | j         d| j         S )z	Str repr.z: )r/   r0   r1   r9   s    r   __str__zCellExecutionError.__str__K   s,    > 	2>!j11DK111r   r   r   c                 H   g }|j         D ][}|d         dk    rM|                    t                              |d         |d                                                              \|r+|                    dd           |                    d           d	                    |          }d	                    |                    d
g           pg           } | t                              |||          |                    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)r@   rA   r    z------------------r   r/   )r   stream_outputr/   r0   z<Error>r1   )r0   r1   )	outputsappendstream_output_msgr!   rstripinsertjoingetexec_err_msg)r"   r   r   stream_outputsoutputrC   tbs          r   from_cell_and_msgz$CellExecutionError.from_cell_and_msgR   s7    %'l 	 	Fm$00%%%,,&.vf~G\G\G^G^,__    	8 !!!R(((!!"6777!YY~66YYsww{B//5266s+    
 '''9--778R((
 
 
 	
r   )r	   r
   r   r   r'   r4   tupler:   r<   r&   r   r   rO   __classcell__)r6   s   @r   r.   r.   8   s         # c 3 4      EE E E E E2 2 2 2 2 
\ 
 
AU 
 
 
 [
 
 
 
 
r   r.   z----- {name} -----
{text}rF   zAn error occurred while executing the following cell:
------------------
{cell.source}
------------------
{stream_output}

{traceback}
rK   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   typingr   r   nbformatr   	Exceptionr   TimeoutErrorr   RuntimeErrorr*   r,   r.   rF   r'   __annotations__rK   r    r   r   r   <module>rX      sk              ! ! ! ! ! !	 	 	 	 		 	 	 	X X X X X|%6 X X X,	 	 	 	 	l 	 	 		 	 	 	 	- 	 	 	7
 7
 7
 7
 7
* 7
 7
 7
t
 3 
 
 
c        r   