
    ^h                        S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKr	SSK
Jr  SSKJrJr  \\\	R"                  4   rS
S jrSS jr " S S	\5      rg)z5Manager to read and modify config data in JSON files.    )annotationsN)LoggingConfigurable)BoolUnicodec                    UR                  5        H[  u  p#[        U[        5      (       a&  X ;  a  0 X'   [        X   U5        X   (       d  X	 M>  M@  Uc  U R	                  US5        MW  X0U'   M]     g)zVRecursively update one dictionary using another.

None values will delete their keys.
N)items
isinstancedictrecursive_updatepop)targetnewkvs       W/home/james-whalen/.local/lib/python3.13/site-packages/jupyter_server/config_manager.pyr   r      sh    
 		a	VY*9I  YJJq$ 1I     c                    [        U R                  5       5       HL  u  p#X!;   d  M  [        U[        5      (       a  [	        X   X   5        X   (       d  X	 M>  M@  X1U   :X  d  MJ  X	 MN     g)z?Recursively remove items from dict that are already in defaultsN)listr   r	   r
   remove_defaults)datadefaultskeyvalues       r   r   r   )   sY     4::<(
?%&&	8=9y	 !3-'I )r   c                  x    \ rS rSrSr\" S5      r\" S5      rSS jr	SS jr
SS jrSSS jjrSS	 jrSS
 jrSrg)BaseJSONConfigManager6   zGeneral JSON config manager

Deals with persisting/storing config in a json file with optionally
default values in a {section_name}.d directory.
.Tc                     [         R                  " U R                  S5        g! [         a)  nUR                  [        R
                  :w  a  e  SnAgSnAff = f)z,Will try to create the config_dir directory.i  N)osmakedirs
config_dirOSErrorerrnoEEXIST)selfes     r   ensure_config_dir_exists.BaseJSONConfigManager.ensure_config_dir_exists@   sA    	KK/ 	ww%,,& '	s   !$ 
AAAc                \    [         R                  R                  U R                  US-   5      $ )zPReturns the json filename for the section_name: {config_dir}/{section_name}.jsonz.jsonr   pathjoinr!   r%   section_names     r   	file_nameBaseJSONConfigManager.file_nameH   s     ww||DOO\G-CDDr   c                \    [         R                  R                  U R                  US-   5      $ )zNReturns the directory name for the section name: {config_dir}/{section_name}.dz.dr*   r-   s     r   	directoryBaseJSONConfigManager.directoryL   s     ww||DOO\D-@AAr   c                   U(       a  U R                  U5      /O/ nU R                  (       aQ  [        R                  R	                  U R                  U5      S5      n[        [        R                  " U5      5      U-   nU R                  R                  SUSR	                  U5      5        0 nU H  n[        R                  R                  U5      (       d  M)  [        R                  R                  U5      (       d  MO  [        USS9 n [        U[        R                  " U5      5        SSS5        M     U$ ! [        R                   R"                   a    U R                  R%                  SU5         NJf = f! , (       d  f       M  = f)zRetrieve 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)r/   read_directoryr   r+   r,   r2   sortedgloblogdebugisfilegetsizeopenr   jsonloaddecoderJSONDecodeErrorwarning)r%   r.   include_rootpathspatternr   r+   fs           r   getBaseJSONConfigManager.getP   s    3?-.Bggll4>>,#?JG 499W-.6E8KK	

 "$Dww~~d##(=(=$1QO(tyy|< 21    <<77 O(()GNO 21s*   E7	 D77:E41E73E44E77
F	c                `   U R                  U5      nU R                  5         U R                  (       a1  [        R                  " U5      nU R                  USS9n[        X$5        [        R                  " USS9n[        USSS9 nUR                  U5        SSS5        g! , (       d  f       g= f)	zStore the given config data.F)rE      )indentwr5   r6   N)r/   r'   r8   copydeepcopyrI   r   r@   dumpsr?   write)r%   r.   r   filenamer   json_contentrH   s          r   setBaseJSONConfigManager.setq   s    >>,/%%'==&Dxx5xAHD+ zz$q1(C'2aGGL! 322s   B
B-c                `    U R                  U5      n[        X25        U R                  X5        U$ )zwModify the config section by recursively updating it with new_data.

Returns the modified config data as a dictionary.
)rI   r   rU   )r%   r.   new_datar   s       r   updateBaseJSONConfigManager.update   s+    
 xx%($r    N)returnNone)r.   strr\   r^   )T)r.   r^   rE   boolr\   dict[str, t.Any])r.   r^   r   t.Anyr\   r]   )r.   r^   rX   ra   r\   r`   )__name__
__module____qualname____firstlineno____doc__r   r!   r   r8   r'   r/   r2   rI   rU   rY   __static_attributes__r[   r   r   r   r   6   s<     J$ZNEBB""r   r   )r   StrDictr   rh   r\   r]   )r   rh   r   rh   r\   r]   )rf   
__future__r   rO   r#   r:   r@   r   typingttraitlets.configr   traitlets.traitletsr   r   r
   r^   Anyrh   r   r   r   r[   r   r   <module>ro      sP    ; #     	  0 -
sAEEz
*
T/ Tr   