a
    ©lc		  ã                   @   sP   d 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„ ZG dd„ deƒZ	dS )	z6Manager to read and modify config data in JSON files.
é    N)ÚLoggingConfigurable)ÚUnicodec                 C   sl   |  ¡ D ]^\}}t|tƒrH|| vr*i | |< t| | |ƒ | | sf| |= 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)ÚtargetÚnewÚkÚv© r   úT/var/www/html/django/DPS/env/lib/python3.9/site-packages/traitlets/config/manager.pyr      s    
r   c                   @   s@   e Zd ZdZedƒZdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dS )ÚBaseJSONConfigManagerzYGeneral JSON config manager

    Deals with persisting/storing config in a json file
    Ú.c              
   C   sJ   zt  | jd¡ W n2 tyD } z|jtjkr0‚ W Y d }~n
d }~0 0 d S )Nií  )ÚosÚmakedirsÚ
config_dirÚOSErrorÚerrnoÚEEXIST)ÚselfÚer   r   r   Úensure_config_dir_exists*   s
    z.BaseJSONConfigManager.ensure_config_dir_existsc                 C   s   t j | j|d ¡S )Nz.json)r   ÚpathÚjoinr   )r   Úsection_namer   r   r   Ú	file_name1   s    zBaseJSONConfigManager.file_namec                 C   sV   |   |¡}tj |¡rNt|dd}t |¡W  d  ƒ S 1 sB0    Y  ni S dS )z¡Retrieve 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   Úget4   s
    
*zBaseJSONConfigManager.getc                 C   sX   |   |¡}|  ¡  t|ddd}|  tj||dd W d  ƒ n1 sJ0    Y  dS )zStore the given config data.Úwr   r   é   )ÚindentN)r   r   r"   r#   Údump)r   r   Údatar%   r&   r   r   r   ÚsetA   s
    
zBaseJSONConfigManager.setc                 C   s$   |   |¡}t||ƒ |  ||¡ |S )z‡Modify the config section by recursively updating it with new_data.

        Returns the modified config data as a dictionary.
        )r'   r   r-   )r   r   Znew_datar,   r   r   r   ÚupdateJ   s    

zBaseJSONConfigManager.updateN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r'   r-   r.   r   r   r   r   r   "   s   	r   )
r2   r   r#   r   Ztraitlets.configr   Ztraitlets.traitletsr   r   r   r   r   r   r   Ú<module>   s   