
    Mh                        d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z
 ddlmZ ddlmZ d	d
lmZ d Z G d dee          ZdS )zQModule containing a preprocessor that executes the code cells
and updates outputs    )annotationsN)KernelManager)NotebookClient)execute)CellExecutionError)NotebookNode   )Preprocessorc                 L    ddl m}  |dt          d           t          | i |S )zDEPRECATED.r   )warnzThe 'nbconvert.preprocessors.execute.executenb' function was moved to nbclient.execute. We recommend importing that library directly.   )
stacklevel)warningsr   FutureWarning_execute)argskwargsr   s      _/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/nbconvert/preprocessors/execute.py	executenbr      sM    D	8	    T$V$$$    c                  0    e Zd ZdZd Zd Z	 dddZd ZdS )ExecutePreprocessorz.
    Executes all the cells in a notebook
    c                    |                     d          }|t                      }t          j        | fd|i| t	          j        | |fi | dS )zInitialize the preprocessor.nbN)getr   r
   __init__r   )selfkwr   s      r   r   zExecutePreprocessor.__init__+   s^    VVD\\:Bd00r0R000b//B/////r   c                <    |st          | d          s	|| _        d S d S )N	resources)hasattrr    )r   r    s     r   _check_assign_resourcesz+ExecutePreprocessor._check_assign_resources3   s0     	'GD+66 	'&DNNN	' 	'r   Nr   r   r    t.AnykmKernelManager | Nonereturn%tuple[NotebookNode, dict[str, t.Any]]c                2   t          j        | ||           |                                  |                     |           |                                 5  | j        sJ |                     | j                                                  }|sJ |d         d         | j        j	        d<   t          | j        j                  D ]\  }}|                     |||           	 ddd           n# 1 swxY w Y   |                                  | j        | j        fS )a  
        Preprocess notebook executing each code cell.

        The input argument *nb* is modified in-place.

        Note that this function recalls NotebookClient.__init__, which may look wrong.
        However since the preprocess call acts line an init on execution state it's expected.
        Therefore, we need to capture it here again to properly reset because traitlet
        assignments are not passed. There is a risk if traitlets apply any side effects for
        dual init.
        The risk should be manageable, and this approach minimizes side-effects relative
        to other alternatives.

        One alternative but rejected implementation would be to copy the client's init internals
        which has already gotten out of sync with nbclient 0.5 release before nbconvert 6.0 released.

        Parameters
        ----------
        nb : NotebookNode
            Notebook being executed.
        resources : dictionary (optional)
            Additional resources used in the conversion process. For example,
            passing ``{'metadata': {'path': run_path}}`` sets the
            execution path to ``run_path``.
        km: KernelManager (optional)
            Optional kernel manager. If none is provided, a kernel manager will
            be created.

        Returns
        -------
        nb : NotebookNode
            The executed notebook.
        resources : dictionary
            Additional resources used in the conversion process.
        contentlanguage_infoN)r   r   reset_execution_trackersr"   setup_kernelkcwait_for_replykernel_infor   metadata	enumeratecellspreprocess_cellset_widgets_metadatar    )r   r   r    r$   info_msgindexcells          r   
preprocesszExecutePreprocessor.preprocess7   sW   L 	b"---%%'''$$Y///   	= 	=7NNN**47+>+>+@+@AAHOOO080CO0TDG_-(77 = =t$$T9e<<<<=	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	!!###w&&s   BC,,C03C0c                n    |                      |           |                     ||d          }|| j        fS )a  
        Override if you want to apply some preprocessing to each cell.
        Must return modified cell and resource dictionary.

        Parameters
        ----------
        cell : NotebookNode cell
            Notebook cell being processed
        resources : dictionary
            Additional resources used in the conversion process.  Allows
            preprocessors to pass variables into the Jinja engine.
        index : int
            Index of the cell being processed
        T)store_history)r"   execute_cellr    )r   r7   r    r6   s       r   r3   z#ExecutePreprocessor.preprocess_celll   s?     	$$Y///  uD AAT^##r   )NN)r   r   r    r#   r$   r%   r&   r'   )__name__
__module____qualname____doc__r   r"   r8   r3    r   r   r   r   &   sl         0 0 0' ' '
 UY3' 3' 3' 3' 3'j$ $ $ $ $r   r   )r?   
__future__r   typingtjupyter_client.managerr   nbclient.clientr   r   r   nbclient.exceptionsr   nbformatr   baser
   r   r   r@   r   r   <module>rI      s     # " " " " "     0 0 0 0 0 0 * * * * * * / / / / / / 3 2 2 2 2 2 ! ! ! ! ! !      
% 
% 
% W$ W$ W$ W$ W$, W$ W$ W$ W$ W$r   