
    Ke                        d Z ddlmZ ddl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 e	j        ee	j        f         ZddZddZ G d de          ZdS )z5Manager to read and modify config data in JSON files.    )annotationsN)LoggingConfigurable)BoolUnicodetargetStrDictnewreturnNonec                    |                                 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)r   r	   kvs       =lib/python3.11/site-packages/jupyter_server/config_manager.pyr   r      s    
 		  1a 	q	VAY***!9 1IYJJq$ F1II     datadefaultsc                    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)r   r   keyvalues       r   r   r   (   s     4::<<((  
U(??%&& S	8C=999Cy "S	(3-''I r   c                  p    e Zd ZdZ ed          Z ed          ZddZdd	Z	dd
Z
dddZddZd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.
    .Tr
   r   c                    	 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	section_namestrc                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'   r*   s     r   	file_namezBaseJSONConfigManager.file_nameG   s    w||DO\G-CDDDr   c                R    t           j                            | j        |dz             S )zNReturns the directory name for the section name: {config_dir}/{section_name}.dz.dr-   r0   s     r   	directoryzBaseJSONConfigManager.directoryK   s    w||DO\D-@AAAr   include_rootboolt.Anyc                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)r1   read_directoryr!   r.   r/   r3   sortedgloblogdebugisfileopenr   jsonload)r'   r*   r4   pathspatternr   r.   fs           r   getzBaseJSONConfigManager.getO   sH    3?F--..B 	7gll4>>,#?#?JJG 49W--..6E8KK	
 	
 	

  	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	r   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)r4      )indentwr8   r9   N)r1   r)   r;   copydeepcopyrG   r   rB   dumpsrA   write)r'   r*   r   filenamer   json_contentrF   s          r   setzBaseJSONConfigManager.setm   s   >>,//%%''' 	,=&&Dxx5xAAHD(+++ z$q111(C'222 	"aGGL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s   B77B;>B;new_datac                |    |                      |          }t          ||           |                     ||           |S )zModify the config section by recursively updating it with new_data.

        Returns the modified config data as a dictionary.
        )rG   r   rR   )r'   r*   rS   r   s       r   updatezBaseJSONConfigManager.update~   s>    
 xx%%x(((t$$$r   N)r
   r   )r*   r+   r
   r+   )T)r*   r+   r4   r5   r
   r6   )r*   r+   r   r6   r
   r   )r*   r+   rS   r6   r
   r   )__name__
__module____qualname____doc__r   r#   r   r;   r)   r1   r3   rG   rR   rU    r   r   r   r   5   s          JT$ZZN   E E E EB B B B    <" " " ""     r   r   )r   r   r	   r   r
   r   )r   r   r   r   r
   r   )rY   
__future__r   rL   r%   r=   rB   r!   typingttraitlets.configr   traitlets.traitletsr   r   Dictr+   Anyr   r   r   r   rZ   r   r   <module>rb      s    ; ; # " " " " "     				     0 0 0 0 0 0 - - - - - - - -
&ae
   *
 
 
 
Q Q Q Q Q/ Q Q Q Q Qr   