
    @=d                     v    d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	m
Z
 d Zd Z G d de          ZdS )	z5Manager to read and modify config data in JSON files.    N)LoggingConfigurable)UnicodeBoolc                     |                                 D ]c\  }}t          |t                    r+|| vri | |<   t          | |         |           | |         s| |= E||                     |d           ^|| |<   ddS )z^Recursively update one dictionary using another.

    None values will delete their keys.
    N)items
isinstancedictrecursive_updatepop)targetnewkvs       8lib/python3.11/site-packages/nbclassic/config_manager.pyr
   r
      s    
 		  1a 	q	VAY***!9 1IYJJq$ F1II     c                     t          |                                           D ]U\  }}||v rLt          |t                    r(t	          | |         ||                    | |         s| |= F|||         k    r| |= VdS )z?Recursively remove items from dict that are already in defaultsN)listr   r   r	   remove_defaults)datadefaultskeyvalues       r   r   r   %   s     4::<<(( " "
U(??%&& "S	8C=999Cy "S	HSM))S	" "r   c                   d    e Zd ZdZ ed          Z ed          Zd Zd Z	d Z
ddZd Zd	 Zd
S )BaseJSONConfigManagerzGeneral JSON config manager

    Deals with persisting/storing config in a json file with optionally
    default values in a {section_name}.d directory.
    .Tc                     	 t          j        | j        d           dS # t          $ r!}|j        t          j        k    r Y d}~dS d}~ww xY w)z,Will try to create the config_dir directory.i  N)osmakedirs
config_dirOSErrorerrnoEEXIST)selfes     r   ensure_config_dir_existsz.BaseJSONConfigManager.ensure_config_dir_exists=   sf    	K///// 	 	 	w%,&& '&&&&&	s    
A	AA	c                 R    t           j                            | j        |dz             S )zPReturns the json filename for the section_name: {config_dir}/{section_name}.jsonz.jsonr   pathjoinr   r#   section_names     r   	file_namezBaseJSONConfigManager.file_nameE   s    w||DO\'-ABBBr   c                 R    t           j                            | j        |dz             S )zNReturns the directory name for the section name: {config_dir}/{section_name}.dz.dr'   r*   s     r   	directoryzBaseJSONConfigManager.directoryI   s    w||DO\$->???r   c                 6   |r|                      |          gng }| j        rWt          j                            |                     |          d          }t          t          j        |                    |z   }| j        	                    d|d                    |                     i }|D ]l}t          j        
                    |          rKt          |d          5 }t          |t          j        |                     ddd           n# 1 swxY w Y   m|S )a  Retrieve the config data for the specified section.

        Returns the data as a dictionary, or an empty dictionary if the file
        doesn't exist.

        When include_root is False, it will not read the root .json file,
        effectively returning the default values.
        z*.jsonz(Paths used for configuration of %s: 
	%sz
	utf-8encodingN)r,   read_directoryr   r(   r)   r.   sortedgloblogdebugisfileopenr
   jsonload)r#   r+   include_rootpathspatternr   r(   fs           r   getzBaseJSONConfigManager.getM   sB    3?F--..B 	7gll4>>,#?#?JJG 49W--..6EC\SYS^S^_dSeSefff 	9 	9Dw~~d## 9$111 9Q$T49Q<<8889 9 9 9 9 9 9 9 9 9 9 9 9 9 9s   #DD	D	c                    |                      |          }|                                  | j        r;t          j        |          }|                     |d          }t          ||           t          j        |d          }t          |dd          }|5  |
                    |           ddd           dS # 1 swxY w Y   dS )	z%Store the given config data.
        F)r<      )indentwr0   r1   N)r,   r%   r3   copydeepcopyr@   r   r:   dumpsr9   write)r#   r+   r   filenamer   json_contentr?   s          r   setzBaseJSONConfigManager.setg   s    >>,//%%''' 	,=&&Dxx5xAAHD(+++ z$q1113111 	" 	"GGL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s   B99B= B=c                 |    |                      |          }t          ||           |                     ||           |S )zModify the config section by recursively updating it with new_data.

        Returns the modified config data as a dictionary.
        )r@   r
   rK   )r#   r+   new_datar   s       r   updatezBaseJSONConfigManager.update{   s>    
 xx%%x(((t$$$r   N)T)__name__
__module____qualname____doc__r   r   r   r3   r%   r,   r.   r@   rK   rN    r   r   r   r   3   s          JT$ZZN  C C C@ @ @   4" " "(    r   r   )rR   r!   r5   r:   r   rE   traitlets.configr   traitlets.traitletsr   r   r
   r   r   rS   r   r   <module>rV      s    ; ;
    				  0 0 0 0 0 0 - - - - - - - -  *" " "P P P P P/ P P P P Pr   