
    ^h                     :    S r SSKJrJr  SSKJr   " S S\5      rg)zFModule containing a preprocessor that removes metadata from code cells    )BoolSet   )Preprocessorc                      ^  \ rS rSrSr\" SSS9R                  SS9r\" SSS9R                  SS9r\	" S/S	S9R                  SS9r
\	" S	S9R                  SS9rS
 rS rS rS rS rU 4S jrSrU =r$ )ClearMetadataPreprocessor   z=
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                 Z    [        U[        5      (       a  U$ [        U5      S:X  a  gUS   $ )z#Get the current key for a mask key.r   N)
isinstancestrlen)selfmask_keys     _/home/james-whalen/.local/lib/python3.13/site-packages/nbconvert/preprocessors/clearmetadata.pycurrent_key%ClearMetadataPreprocessor.current_key(   s-    h$$Ox=A{    c                 v    U Vs1 s H'  o R                  U5      c  M  U R                  U5      iM)     sn$ s  snf )z Get the current mask for a mask.)r   r   maskks      r   current_mask&ClearMetadataPreprocessor.current_mask1   s3    -1UT5E5Ea5H#  #TUUUs   66c                     U Vs0 s HL  nU(       d  M  [        U[        5      (       a  M#  [        U5      S:  d  M4  U R                  US   5      USS _MN     sn$ s  snf )z Get the nested masks for a mask.r   r   N)r   r   r   r   r   s      r   nested_masks&ClearMetadataPreprocessor.nested_masks5   sg     
 *#As+ *03A
 *DQqT"AabE)
 	
 
s   AAAAc              #   2  #    U R                  U5      nU R                  U5      nU Hk  u  pVUR                  U5      nXS;   d  M  UbF  [        U[        5      (       a/  U[	        U R                  UR                  5       U5      5      4v   Md  Mf  XV4v   Mm     g7f)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$   'ClearMetadataPreprocessor.nested_filter=   s     ((.!..t4DA,003K *!!T**d&8&8K&P!QQQ + $J s   >BABc                     U R                   (       aX  UR                  S:X  aH  SU;   aB  [        U R                  UR                  R                  5       U R                  5      5      Ul        X4$ )z?
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_cell)ClearMetadataPreprocessor.preprocess_cellJ   sY     ##&(@T! $&&t}}':':'<d>^>^_! r   c                    > [         TU ]  X5      u  pU R                  (       aH  SU;   aB  [        U R	                  UR
                  R                  5       U R                  5      5      Ul        X4$ )a(  
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   nbr2   	__class__s      r   r8   $ClearMetadataPreprocessor.preprocessV   s_     *29''J",<""2;;#4#4#68V8VWBK }r    )__name__
__module____qualname____firstlineno____doc__r   tagr.   r9   r   r:   r0   r   r   r   r$   r4   r8   __static_attributes____classcell__)r<   s   @r   r   r      s     b 
cc  #b 
cc  !$	"#E! 
cc  #&E# 
cc  V

 r   r   N)rC   	traitletsr   r   baser   r   r>   r   r   <module>rI      s    L
   ^ ^r   