
    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y)zHPreprocessor for merging consecutive stream outputs for easier handling.    N)
get_loggerc                 B     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               j                  dj                         t        | j                        D ]  \  }} |||      \  | j                  |<   }! | |fS )NzApplying preprocessor: %s)r   debug__name__	enumeratecells)nb	resourcesindexcellfunctions       I/usr/lib/python3/dist-packages/nbconvert/preprocessors/coalescestreams.pywrappedfuncz&cell_preprocessor.<locals>.wrappedfunc   s_    68I8IJ$RXX. 	JKE4)1$	5)I&BHHUOY	J9}    )	functoolswraps)r   r   s   ` r   cell_preprocessorr      s(     __X  r   z.*\r(?=[^\n])c                    | j                  dg       }|s| |fS |d   }|g}|dd D ]l  }|j                  dk(  rH|j                  dk(  r9|j                  |j                  k(  r |xj                  |j                  z  c_        Z|j	                  |       |}n |D ]F  }|j                  dk(  sd|j                  v s"t
        j                  d|j                        |_        H || _        | |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$I v&D
  6)dfkk.A **R5FK6 DL?r   )	__doc__r   retraitlets.logr   r   compiler    r%    r   r   <module>r+      s?    N
  	 $2 
$	% ( (r   