
    Mh                     B    d Z ddlmZmZ ddlmZ  G d de          ZdS )zFModule containing a preprocessor that removes metadata from code cells    )BoolSet   )Preprocessorc                   H    e Zd ZdZ edd                              d          Z edd                              d          Z edgd                              d          Z	 ed                              d          Z
d	 Zd
 Zd Zd Zd Z fdZ xZS )ClearMetadataPreprocessorzE
    Removes all the metadata from all code cells in a notebook.
    TzRFlag to choose if cell metadata is to be cleared in addition to notebook metadata.)help)configzRFlag to choose if notebook metadata is to be cleared in addition to cell metadata.)language_infonamezIndicates the key paths to preserve when deleting metadata across both cells and notebook metadata fields. Tuples of keys can be passed to preserved specific nested valuesc                 j    t          |t                    r|S t          |          dk    rdS |d         S )z#Get the current key for a mask key.r   N)
isinstancestrlen)selfmask_keys     e/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/nbconvert/preprocessors/clearmetadata.pycurrent_keyz%ClearMetadataPreprocessor.current_key(   s9    h$$ 	Ox==A4{    c                        fd|D             S )z Get the current mask for a mask.c                 d    h | ],}                     |                               |          -S )N)r   .0kr   s     r   	<setcomp>z9ClearMetadataPreprocessor.current_mask.<locals>.<setcomp>3   s:    UUUT5E5Ea5H5H5T  ##5T5T5Tr    r   masks   ` r   current_maskz&ClearMetadataPreprocessor.current_mask1   s    UUUUTUUUUr   c                        fd|D             S )z Get the nested masks for a mask.c                     i | ]P}|rLt          |t                    s7t          |          d k    ,                    |d                   |d d         QS )r   r   N)r   r   r   r   r   s     r   
<dictcomp>z:ClearMetadataPreprocessor.nested_masks.<locals>.<dictcomp>7   sj     
 
 

 $As++
 14A

 QqT""AabbE0:

r   r   r   s   ` r   nested_masksz&ClearMetadataPreprocessor.nested_masks5   s.    
 
 
 

 
 
 	
r   c              #   N  K   |                      |          }|                     |          }|D ]u\  }}|                    |          }||v rW|Ot          |t                    r9|t	          |                     |                                |                    fV  o||fV  vdS )z-Get the nested filter for items given a mask.N)r   r#   getr   dictnested_filteritems)r   r(   r   keep_currentkeep_nested_lookupr   vkeep_nesteds           r   r'   z'ClearMetadataPreprocessor.nested_filter=   s      ((..!..t44 	 	DAq,0033KL  *!!T** Rd&8&8K&P&P!Q!QQQQQQ$JJJ	 	r   c                     | j         rS|j        dk    rHd|v rDt          |                     |j                                        | j                            |_        ||fS )zO
        All the code cells are returned with an empty metadata field.
        codemetadata)clear_cell_metadata	cell_typer&   r'   r/   r(   preserve_cell_metadata_mask)r   cell	resources
cell_indexs       r   preprocess_cellz)ClearMetadataPreprocessor.preprocess_cellJ   sg     # 	&(@(@T!! $&&t}':':'<'<d>^__! ! Yr   c                     t                                          ||          \  }}| j        rHd|v rDt          |                     |j                                        | j                            |_        ||fS )ax  
        Preprocessing to apply on each notebook.

        Must return modified nb, resources.

        Parameters
        ----------
        nb : NotebookNode
            Notebook being converted
        resources : dictionary
            Additional resources used in the conversion process.  Allows
            preprocessors to pass variables into the Jinja engine.
        r/   )super
preprocessclear_notebook_metadatar&   r'   r/   r(   preserve_nb_metadata_mask)r   nbr4   	__class__s      r   r9   z$ClearMetadataPreprocessor.preprocessV   sx     **2y99I' 	J",<,<""2;#4#4#6#68VWW BK 9}r   )__name__
__module____qualname____doc__r   tagr0   r:   r   r;   r2   r   r   r#   r'   r6   r9   __classcell__)r=   s   @r   r   r      s^         $b   
cc  #db   
cc  !$	"#E! ! ! 
cc  #&#E# # # 
cc    V V V
 
 
  
 
 
        r   r   N)rA   	traitletsr   r   baser   r   r   r   r   <module>rF      su    L L
               ^ ^ ^ ^ ^ ^ ^ ^ ^ ^r   