
    Yd                         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<   y)zExceptions for nbclient.    )DictList)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__     5/usr/lib/python3/dist-packages/nbclient/exceptions.pyr   r      s     	r   r   c            	       2    e Zd ZdZededededd fd       Zy)CellTimeoutErrorzS
    A custom exception to capture when a cell has timed out during execution.
    msgtimeoutcellreturnc                     |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.)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    
 DKK;;,,.44T:L |$r) $Ra()bc1B0CD  -C?))'sRU)VWWr   N)	r	   r
   r   r   classmethodstrintr   r%   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                   j     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                 N    t         |   |       || _        || _        || _        y)zInitialize the error.N)super__init__r/   r0   r1   )selfr/   r0   r1   	__class__s       r   r4   zCellExecutionError.__init__@   s%    #"
r   c                 ^    t        |       | j                  | j                  | j                  ffS )zReduce implementation.)typer/   r0   r1   r5   s    r   
__reduce__zCellExecutionError.__reduce__G   s$    DzDNNDJJDDDr   c                 h    | j                   r| j                   S | j                   d| j                   S )z	Str repr.z: )r/   r0   r1   r9   s    r   __str__zCellExecutionError.__str__K   s,    >>>>!jj\DKK=11r   r   r   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   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   s     %'ll 	Fm$0%%%,,&.vf~G\G\G^,_	
  !!!R(!!"67!YY~6YYsww{B/526+   
 '''9-778R(
 	
r   )r	   r
   r   r   r'   r4   tupler:   r<   r&   r   r   rO   __classcell__)r6   s   @r   r.   r.   8   sm    # c 3 4 EE E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      s}      !		 	X|%6 X,	l 		- 	7
* 7
t
 3 
c  r   