U
    nufh  ã                   @   s6   d Z ddlZddlmZ e d¡ZG dd„ deƒZdS )zHPreprocessor for merging consecutive stream outputs for easier handling.é    N)ÚPreprocessorz.*\r(?=[^\n])c                   @   s   e Zd ZdZdd„ ZdS )ÚCoalesceStreamsPreprocessorz
    Merge consecutive sequences of stream output into single stream
    to prevent extra newlines inserted at flush calls
    c                 C   s´   |  dg ¡}|s||fS |d }|g}|dd… D ]D}|jdkrh|jdkrh|j|jkrh| j|j7  _q2| |¡ |}q2|D ](}|jdkr|d|jkr|t d|j¡|_q|||_||fS )zO
        Apply a transformation on each cell. See base.py for details.
        Úoutputsr   é   NÚstreamúÚ )ÚgetÚoutput_typeÚnameÚtextÚappendÚCR_PATÚsubr   )ÚselfÚcellÚ	resourcesZ
cell_indexr   ÚlastZnew_outputsÚoutput© r   úK/tmp/pip-unpacked-wheel-nxpdnluh/nbconvert/preprocessors/coalescestreams.pyÚpreprocess_cell   s(    ÿþ
ý
z+CoalesceStreamsPreprocessor.preprocess_cellN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s   r   )r   ÚreZnbconvert.preprocessorsr   Úcompiler   r   r   r   r   r   Ú<module>   s   
