
    f                        U d Z ddlmZ ddl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ded<   dZded<   dZded<   y)zExceptions for nbclient.    )annotations)Any)NotebookNodec                      e Zd ZdZy)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__     N/var/www/cvtools/html/venv/lib/python3.12/site-packages/nbclient/exceptions.pyr   r   	   s     	r   r   c                  2    e Zd ZdZe	 	 	 	 	 	 	 	 dd       Zy)CellTimeoutErrorzS
    A custom exception to capture when a cell has timed out during execution.
    c                    |r]|j                   rQ|j                   j                         j                  d      }t        |      dk  r|j                   n|dd  d|dd  }nd} | t        j                  |||            S )	z)Create an error from a timeout on a cell.
   N   z
...
zCell contents not found.)timeoutmsgcell_contents)sourcestripsplitlentimeout_err_msgformat)clsr   r   cellsrc_by_linessrcs         r   error_from_timeout_and_cellz,CellTimeoutError.error_from_timeout_and_cell   s    
 DKK;;,,.44T:L |$r) $Ra()bc1B0CD  -C?))'sRU)VWWr   N)r   strr   intr!   r   returnr   )r	   r
   r   r   classmethodr$   r   r   r   r   r      sA     XX #X+7X	X Xr   r   c                      e Zd ZdZy)DeadKernelErrorzA dead kernel error.Nr   r   r   r   r*   r*   )   s    r   r*   c                      e Zd ZdZy)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   r,   c                  F     e Zd ZdZd fdZddZddZed	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.
    c                N    t         |   |       || _        || _        || _        y)zInitialize the error.N)super__init__	tracebackenameevalue)selfr2   r3   r4   	__class__s       r   r1   zCellExecutionError.__init__B   s%    #"
r   c                ^    t        |       | j                  | j                  | j                  ffS )zReduce implementation.)typer2   r3   r4   r5   s    r   
__reduce__zCellExecutionError.__reduce__I   s$    DzDNNDJJDDDr   c                h    | j                   r| j                   S | j                   d| j                   S )z	Str repr.z: )r2   r3   r4   r9   s    r   __str__zCellExecutionError.__str__M   s,    >>>>!jj\DKK=11r   c                   g }|j                   D ]E  }|d   dk(  s|j                  t        j                  |d   |d   j	                                      G |r#|j                  dd       |j                  d       d	j                  |      }d	j                  |j                  d
g       xs g       } | t        j                  |||      |j                  dd      |j                  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   r2   )r!   stream_outputr2   r3   z<Error>r4   )r3   r4   )	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_msgT   s     %'ll 	Fm$0%%%,,&.vf~G\G\G^,_	
  !!!R(!!"67!YY~6YYsww{B/526+   
 '''9-778R(
 	
r   )r2   r%   r3   r%   r4   r%   r'   None)r'   z
tuple[Any])r'   r%   )r!   r   r   zdict[str, Any]r'   r.   )
r	   r
   r   r   r1   r:   r<   r(   rO   __classcell__)r6   s   @r   r.   r.   :   s,    E2 
 
r   r.   z----- {name} -----
{text}r%   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   
__future__r   typingr   nbformatr   	Exceptionr   TimeoutErrorr   RuntimeErrorr*   r,   r.   rF   __annotations__rK   r   r   r   r   <module>rY      s     "  !		 	X|%6 X,	l 		- 	7
* 7
t
 3 
c  r   