
    _d		                     T    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 Z G d de      Z	y)z6Manager to read and modify config data in JSON files.
    N)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       :/usr/lib/python3/dist-packages/traitlets/config/manager.pyr	   r	      sq    
 		 1aq	VAY*!91IYJJq$ F1I    c                   >    e Zd ZdZ ed      Zd Zd Zd Zd Z	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_name1   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.get4   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.setA   sR    >>,/%%'31 	)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	   r4   )r   r!   new_datar3   s       r   updatezBaseJSONConfigManager.updateJ   s/    
 xx%x(t$r   N)__name__
__module____qualname____doc__r   r   r   r"   r-   r4   r7    r   r   r   r   "   s,    
 JE)r   r   )
r;   r   r)   r   traitlets.configr   traitlets.traitletsr   r	   r   r<   r   r   <module>r?      s-      	 0 '*0/ 0r   