a
    ø£Beœ  ã                   @   sœ   U d Z ddlmZ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eed< dZeed< dZeed< dS )zExceptions for nbclient.é    )ÚDictÚList)Ú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   úV/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/nbclient/exceptions.pyr      s   r   c                   @   s(   e Zd ZdZeeeed dœdd„ƒZdS )ÚCellTimeoutErrorzS
    A custom exception to capture when a cell has timed out during execution.
    )Ú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
   ÚclassmethodÚstrÚintr   r   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eeeddœ‡ fdd„Zedœdd„Zedœd	d
„Ze	e
e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.
    N)Ú	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*   @   s    zCellExecutionError.__init__)r   c                 C   s   t | ƒ| j| j| jffS )zReduce implementation.)Útyper&   r'   r(   ©r+   r   r   r   Ú
__reduce__G   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(   r/   r   r   r   Ú__str__K   s    zCellExecutionError.__str__)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)r4   r5   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Úoutputr7   Útbr   r   r   Úfrom_cell_and_msgR   s(    
ÿ

ý

ùz$CellExecutionError.from_cell_and_msg)r   r   r	   r
   r!   r*   Útupler0   r1   r    r   r   rB   Ú__classcell__r   r   r,   r   r%   8   s   r%   z----- {name} -----
{text}r:   z‡An error occurred while executing the following cell:
------------------
{cell.source}
------------------
{stream_output}

{traceback}
r?   z¿A 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   Znbformatr   Ú	Exceptionr   ÚTimeoutErrorr   ÚRuntimeErrorr#   r$   r%   r:   r!   Ú__annotations__r?   r   r   r   r   r   Ú<module>   s   
: