o
    BZh	                     @  sj   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dZG dd de	ZdS )z6Manager to read and modify config data in JSON files.
    )annotationsN)Any)LoggingConfigurable)Unicodetargetdict[Any, Any]newreturnNonec                 C  sl   |  D ]/\}}t|tr$|| vri | |< t| | | | | s#| |= q|du r/| |d q|| |< qdS )z^Recursively update one dictionary using another.

    None values will delete their keys.
    N)items
isinstancedictrecursive_updatepop)r   r   kv r   O/var/www/html/lang_env/lib/python3.10/site-packages/traitlets/config/manager.pyr      s   

r   c                   @  sJ   e Zd ZdZedZdddZdd	d
ZdddZdddZ	dddZ
dS )BaseJSONConfigManagerzYGeneral JSON config manager

    Deals with persisting/storing config in a json file
    .r	   r
   c              
   C  sJ   z
t | jd W d S  ty$ } z|jtjkr W Y d }~d S d }~ww )Ni  )osmakedirs
config_dirOSErrorerrnoEEXIST)selfer   r   r   ensure_config_dir_exists-   s   z.BaseJSONConfigManager.ensure_config_dir_existssection_namestrc                 C  s   t j| j|d S )Nz.json)r   pathjoinr   )r   r   r   r   r   	file_name4   s   zBaseJSONConfigManager.file_namer   c                 C  sT   |  |}tj|r(t|dd}t|W  d   S 1 s!w   Y  dS i S )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fr   r   r   get7   s   
$zBaseJSONConfigManager.getdatac                 C  sV   |  |}|   t|ddd}tj||dd W d   dS 1 s$w   Y  dS )zStore the given config data.wr$   r%      )indentN)r#   r   r(   r)   dump)r   r   r.   r+   r,   r   r   r   setD   s
   
"zBaseJSONConfigManager.setnew_datac                 C  s$   |  |}t|| | || |S )zModify the config section by recursively updating it with new_data.

        Returns the modified config data as a dictionary.
        )r-   r   r3   )r   r   r4   r.   r   r   r   updateL   s   

zBaseJSONConfigManager.updateN)r	   r
   )r   r    r	   r    )r   r    r	   r   )r   r    r.   r   r	   r
   )r   r    r4   r   r	   r   )__name__
__module____qualname____doc__r   r   r   r#   r-   r3   r5   r   r   r   r   r   %   s    



r   )r   r   r   r   r	   r
   )r9   
__future__r   r   r)   r   typingr   Ztraitlets.configr   Ztraitlets.traitletsr   r   r   r   r   r   r   <module>   s    
