
    9Ee                     b    d Z ddlZddlZddlmZ d Z ej        d          Zed             ZdS )zHPreprocessor for merging consecutive stream outputs for easier handling.    N)
get_loggerc                 F     t          j                    fd            }|S )a  
    Wrap a function to be executed on all cells of a notebook

    The wrapped function should have these 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
    c                     t                                          dj                   t          | j                  D ]\  }} |||          \  | j        |<   }| |fS )NzApplying preprocessor: %s)r   debug__name__	enumeratecells)nb	resourcesindexcellfunctions       Glib/python3.11/site-packages/nbconvert/preprocessors/coalescestreams.pywrappedfuncz&cell_preprocessor.<locals>.wrappedfunc   sj    68IJJJ$RX.. 	J 	JKE4)1$	5)I)I&BHUOYY9}    )	functoolswraps)r   r   s   ` r   cell_preprocessorr      s;     _X     r   z.*\r(?=[^\n])c                    |                      dg           }|s| |fS |d         }|g}|dd         D ]U}|j        dk    r1|j        dk    r&|j        |j        k    r|xj        |j        z  c_        >|                    |           |}V|D ];}|j        dk    r.d|j        v r%t
                              d|j                  |_        <|| _        | |fS )a  
    Merge consecutive sequences of stream output into single stream
    to prevent extra newlines inserted at flush calls

    Parameters
    ----------
    cell : NotebookNode cell
        Notebook cell being processed
    resources : dictionary
        Additional resources used in the conversion process.  Allows
        transformers to pass variables into the Jinja engine.
    index : int
        Index of the cell being processed
    outputsr      Nstream )getoutput_typenametextappendcr_patsubr   )r   r   r   r   lastnew_outputsoutputs          r   coalesce_streamsr%   (   s    " hhy"%%G Y1:D&K!""+ 
 
(** H,,	V[((II$III v&&&DD  6 6))dfk.A.A **R55FKDL?r   )	__doc__r   retraitlets.logr   r   compiler    r%    r   r   <module>r+      s}    N N
     				 $ $ $ $ $ $  2 
$	%	% ( ( ( ( (r   