
    Mh	                    V    d Z ddlmZ ddlZddlmZmZ ddlmZ  G d de          Z	dS )	zc
Module containing a preprocessor that removes cells if they match
one or more regular expression.
    )annotationsN)ListUnicode   )Preprocessorc                  l    e Zd ZdZ e e                                          d          Zd Zd Z	dS )RegexRemovePreprocessora  
    Removes cells from a notebook that match one or more regular expression.

    For each cell, the preprocessor checks whether its contents match
    the regular expressions in the ``patterns`` traitlet which is a list
    of unicode strings. If the contents match any of the patterns, the cell
    is removed from the notebook.

    To modify the list of matched patterns,
    modify the patterns traitlet. For example, execute the following command
    to convert a notebook to html and remove cells containing only whitespace::

      jupyter nbconvert --RegexRemovePreprocessor.patterns="['\s*\Z']" mynotebook.ipynb

    The command line argument
    sets the list of patterns to ``'\s*\Z'`` which matches an arbitrary number
    of whitespace characters followed by the end of the string.

    See https://regex101.com/ for an interactive guide to regular expressions
    (make sure to select the python flavor). See
    https://docs.python.org/library/re.html for the official regular expression
    documentation in python.
    T)configc                    t          j        d                    d | j        D                                 }|                    |j                   S )z
        Checks that a cell matches the pattern.

        Returns: Boolean.
        True means cell should *not* be removed.
        |c              3      K   | ]	}d |z  V  
dS )z(?:%s)N ).0patterns     c/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/nbconvert/preprocessors/regexremove.py	<genexpr>z;RegexRemovePreprocessor.check_conditions.<locals>.<genexpr>7   s'      %V%VWh&8%V%V%V%V%V%V    )recompilejoinpatternsmatchsource)selfcellr   s      r   check_conditionsz(RegexRemovePreprocessor.check_conditions,   sI     *SXX%V%V%V%V%VVVWW ==----r   c                R      j         s||fS  fd|j        D             |_        ||fS )zS
        Preprocessing to apply to each notebook. See base.py for details.
        c                >    g | ]}                     |          |S r   )r   )r   r   r   s     r   
<listcomp>z6RegexRemovePreprocessor.preprocess.<locals>.<listcomp>E   s,    MMMT1F1Ft1L1LMDMMMr   )r   cells)r   nb	resourcess   `  r   
preprocessz"RegexRemovePreprocessor.preprocess<   sC    
 } 	!y=  NMMMRXMMM9}r   N)
__name__
__module____qualname____doc__r   r   tagr   r   r#   r   r   r   r	   r	      sb         0 tGGII""$"//H. . .     r   r	   )
r'   
__future__r   r   	traitletsr   r   baser   r	   r   r   r   <module>r,      s     # " " " " " 				 # # # # # # # #      6 6 6 6 6l 6 6 6 6 6r   