
    Mh                        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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       ]/var/www/html/test/jupyter/venv/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_nameH   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.directoryL   s    w||DO\D-@AAAr   include_rootbooldict[str, t.Any]c                   |r|                      |          gng }| j        rWt          j                            |                     |          d          }t          t          j        |                    |z   }| j        	                    d|d                    |                     i }|D ]}t          j        
                    |          rt          j                            |          rt          |d          5 }	 t          |t          j        |                     n5# t          j        j        $ r | j                            d|           Y nw xY wddd           n# 1 swxY w Y   |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encodingzInvalid JSON in %s, skippingN)r1   read_directoryr!   r.   r/   r3   sortedgloblogdebugisfilegetsizeopenr   jsonloaddecoderJSONDecodeErrorwarning)r'   r*   r4   pathspatternr   r.   fs           r   getzBaseJSONConfigManager.getP   s    3?F--..B 	7gll4>>,#?#?JJG 49W--..6E8KK	
 	
 	

 "$ 	O 	ODw~~d## O(=(= O$111 OQO(ty||<<<<<7 O O O(()GNNNNNOO O O O O O O O O O O O O O O
 s6   =E#?"D"!E#"/EE#EE##E'	*E'	r   t.Anyc                   |                      |          }|                                  | 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deepcopyrK   r   rC   dumpsrB   write)r'   r*   r   filenamer   json_contentrJ   s          r   setzBaseJSONConfigManager.setq   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.
        )rK   r   rW   )r'   r*   rX   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   rL   r
   r   )r*   r+   rX   rL   r
   r6   )__name__
__module____qualname____doc__r   r#   r   r;   r)   r1   r3   rK   rW   rZ    r   r   r   r   6   s          JT$ZZN   E E E EB B B B    B" " " ""     r   r   )r   r   r	   r   r
   r   )r   r   r   r   r
   r   )r^   
__future__r   rQ   r%   r=   rC   r!   typingttraitlets.configr   traitlets.traitletsr   r   r   r+   Anyr   r   r   r   r_   r   r   <module>rf      s    ; ; # " " " " "     				     0 0 0 0 0 0 - - - - - - - -
sAEz
   *
 
 
 
T T T T T/ T T T T Tr   