
    ~f	                    n    d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	 ddl
mZ d
dZ G d d	e	      Zy)z6Manager to read and modify config data in JSON files.
    )annotationsN)Any)LoggingConfigurable)Unicodec                    |j                         D ]Q  \  }}t        |t              r"|| vri | |<   t        | |   |       | |   r4| |= 8|| j	                  |d       M|| |<   S y)z^Recursively update one dictionary using another.

    None values will delete their keys.
    N)items
isinstancedictrecursive_updatepop)targetnewkvs       S/var/www/cvtools/html/venv/lib/python3.12/site-packages/traitlets/config/manager.pyr   r      sq    
 		 1aq	VAY*!91IYJJq$ F1I    c                  H    e Zd ZdZ ed      Zd	dZd
dZddZddZ	ddZ
y)BaseJSONConfigManagerzYGeneral JSON config manager

    Deals with persisting/storing config in a json file
    .c                    	 t        j                  | j                  d       y # t        $ r(}|j                  t        j
                  k7  r Y d }~y d }~ww xY w)Ni  )osmakedirs
config_dirOSErrorerrnoEEXIST)selfes     r   ensure_config_dir_existsz.BaseJSONConfigManager.ensure_config_dir_exists-   sA    	KK/ 	ww%,,& '	s    # 	AAAc                \    t         j                  j                  | j                  |dz         S )Nz.json)r   pathjoinr   )r   section_names     r   	file_namezBaseJSONConfigManager.file_name4   s     ww||DOO\G-CDDr   c                    | j                  |      }t        j                  j                  |      r,t	        |d      5 }t        j                  |      cddd       S i S # 1 sw Y   yxY w)zRetrieve the config data for the specified section.

        Returns the data as a dictionary, or an empty dictionary if the file
        doesn't exist.
        utf-8encodingN)r$   r   r!   isfileopenjsonload)r   r#   filenamefs       r   getzBaseJSONConfigManager.get7   sZ     >>,/77>>(#h1 $Qyy|$ $ I$ $s   AA(c                    | j                  |      }| j                          t        |dd      5 }t        j                  ||d       ddd       y# 1 sw Y   yxY w)zStore the given config data.wr&   r'      )indentN)r$   r   r*   r+   dump)r   r#   datar-   r.   s        r   setzBaseJSONConfigManager.setD   sO    >>,/%%'(C'2 	)aIIdAa(	) 	) 	)s   AAc                d    | j                  |      }t        ||       | j                  ||       |S )zModify the config section by recursively updating it with new_data.

        Returns the modified config data as a dictionary.
        )r/   r   r6   )r   r#   new_datar5   s       r   updatezBaseJSONConfigManager.updateL   s/    
 xx%x(t$r   N)returnNone)r#   strr:   r<   )r#   r<   r:   r   )r#   r<   r5   r   r:   r;   )r#   r<   r8   r   r:   r   )__name__
__module____qualname____doc__r   r   r   r$   r/   r6   r9    r   r   r   r   %   s,    
 JE)r   r   )r   dict[Any, Any]r   rB   r:   r;   )r@   
__future__r   r   r+   r   typingr   traitlets.configr   traitlets.traitletsr   r   r   rA   r   r   <module>rG      s3    #   	  0 '*// /r   