
     )Me 5                    V   d Z ddlmZ ddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZ ddlZdd	lmZmZmZ dd
lmZmZ ddlmZ ddlmZmZmZm Z m!Z!  ej         ej"        e#          d          Z$d(dZ%d)dZ&	 d*d+dZ'd,dZ(	 d-d.d Z)d/d0d#Z* G d$ d%e          Z+d1d'Z,dS )2zJupyterLab Server config    )annotationsN)iglob)chain)Logger)join)Any)SYSTEM_CONFIG_PATHjupyter_config_dirjupyter_path)ConfigManagerrecursive_update)url_path_join)Bool	HasTraitsListUnicodedefault	templatesdatadict[str, Any]returnstrc                    d| v r	| d         }n>d| v r8t          | d         t                    r| d                             dd          }nd}|S )z#Get the url from the extension datahomepage
repositoryurl )
isinstancedictget)r   r   s     8lib/python3.11/site-packages/jupyterlab_server/config.pyget_package_urlr"      s`     T:			*T,-?"F"F	< $$UB//J    labextensions_path	list[str]c                (   i }| D ]}t          t          t          |dd                    t          t          |ddd                              D ]}t          |d          5 }t	          j        |          }ddd           n# 1 swxY w Y   |d         |vrrt          |d         |d	         |                    d
d          t          |          |t          j
        |          d|                    dt                                |                    dt                                	  	        }d|v rQd|                    di           v r9t          |                    d                              d                    |d<   t          j        t          j
        |          d          }t          j        |          r@t          |d          5 }t	          j        |          |d<   ddd           n# 1 swxY w Y   |||d         <   |S )z+Get the metadata about federated extensionsz[!@]*package.jsonz@**utf-8encodingNnameversiondescriptionr   Fdependencies
jupyterlab)	r,   r-   r.   r   ext_dirext_pathis_localr/   r0   r   r   )r   zinstall.jsoninstall)r   r   pjoinopenjsonloadr   r    r"   ospdirnamer   exists)r$   federated_extensionsr1   r2   fidpkgdatar   install_paths           r!   get_federated_extensionsr@   (   sv   % : :%.99::%sN;;<<
 
 	: 	:H h111 )S)C..) ) ) ) ) ) ) ) ) ) ) ) ) ) )v&::: #I. 'M2 > >'00# [22"!(^TVV!D!D&{{<@@
 
 
  7**uLRT8U8U/U/U)-'++l2K2K2O2OPU2V2V)W)W)WD&"xH(=(=~NN:l++ 9lW=== 9*.)C..Y9 9 9 9 9 9 9 9 9 9 9 9 9 9 959$T&\27	:8  s$   %BB
B
G88G<?G<allapp_settings_dir
str | NoneloggerLogger | Nonelevelc                J    t          |          }|                    d          S )a  Get the static page config for JupyterLab

    Parameters
    ----------
    logger: logger, optional
        An optional logging object
    level: string, optional ['all']
        The level at which to get config: can be 'all', 'user', 'sys_prefix', or 'system'
    page_config)_get_config_managerr    )rB   rD   rF   cms       r!   get_static_page_configrK   L   s#     
U	#	#B66-   r#   pathr   c                    t          | d          5 }|                     d          r t          j        |          cddd           S t	          j        |          cddd           S # 1 swxY w Y   dS )zLoad either a json5 or a json config file.

    Parameters
    ----------
    path : str
        Path to the file to be loaded

    Returns
    -------
    Dict[Any, Any]
        Dictionary of json or json5 data
    r)   r*   z.json5N)r6   endswithjson5r8   r7   )rL   r=   s     r!   load_configrP   \   s     
dW	%	%	% "=="" 	":c??" " " " " " " " 9S>>	" " " " " " " " " " " " " " " " " "s   )A(A((A,/A,c                t   i }d}|rzt          |d          t          |d          g}|D ]W}t          j        |          rAt          |          }|dfD ]}||v rd ||         D             ||<   t	          ||            nXt          |d          }	t	          ||	           i }
g x}|d<   t          |           }|                    |i            |                                D ]\  }}d	|d
         vr!|r|	                    d|d         z             0|d
         d	         }|d         |d         d}d|v r|d         |d<   d|v r|d         |d<   d|v r|d         |d<   |
                    |           |d         }|d
                             |          r|d
         |         |
|d         <   |rt          j        |          }t          |dd          }t          j        |          rt          |d          5 }t          j        |          }ddd           n# 1 swxY w Y   |d
                             di           }|                                D ]*\  }}||
v r
|                    |          r||         |
|<   +i }t!          |
          D ]2}||                             |          du r |
|         }|D ]}d||<   3|}|                    |                    |g                      |||<   |                                D ]+\  }t%          t&                    rfdD             ||<   ,|S )z/Get the page config for the application handlerdisabledExtensionszpage_config.json5zpage_config.jsondeferredExtensionsc                    i | ]}|d S )T ).0keys     r!   
<dictcomp>z#get_page_config.<locals>.<dictcomp>   s    $D$D$D3S$$D$D$Dr#   rA   )rD   rF   r<   _buildr0   z%s is not a valid extensionr,   r8   )r,   r8   	extensionmimeExtensionstylestaticr'   r)   r*   NextensionMetadataTc                $    g | ]}|         
|S rU   rU   )rV   subkeyvalues     r!   
<listcomp>z#get_page_config.<locals>.<listcomp>   s"    LLL6eFmLLLLr#   )r5   r9   r;   rP   r   rK   r@   
setdefaultitemswarningappendr    r:   r6   r7   r8   sortedupdater   r   )r$   rB   rD   rH   disabled_keyconfig_pathsrL   r   rW   static_page_configdisabled_by_extensions_all
extensionsfederated_exts_ext_dataextbuildrZ   r,   app_dirpackage_data_filer=   app_dataall_ext_dataextdisabled_by_extensionsdisabled_listitemrollup_disabledra   s                               @r!   get_page_configr{   p   sl   
 K'L  "$788"$677
 ! 		 		Dz$ "4(((*>? E ECd{{$D$D$s)$D$D$DS	 d333 0vUKKK["4555 "$799J34-.@AAN <,,,%++-- ` `88L111 Q<x?OOPPPL)(3%f-x7GHH	(""%-k%:Ik"h&&)1/)BIo&h!)'!2Ig)$$$ L!%%l33 	`;CL;QR^;_&x'78  M+.//!'8^DD:'(( 	M''::: *c9S>>* * * * * * * * * * * * * * *#L1556I2NNL!-!3!3!5!5 M MX444<<-- M6>|6L.s3122 0 0|$((..$66248! 	0 	0D+/"4((	0 -O;??<<<=== /K "'')) M M
UeT"" 	MLLLLULLLKs   =HH"%H"rH   Nonec                P    t          |          }|                    d|            dS )zWrite page config to diskrH   N)rI   set)rH   rF   rJ   s      r!   write_page_configr      s)    	U	#	#BFF=+&&&&&r#   c                     e Zd ZdZ edd                              d          Z edd                              d          Z edd                              d          Z ed	d
                              d          Z	 edd                              d          Z
 e e            d                              d          Z e e            d                              d          Z edd                              d          Z edd                              d          Z edd                              d          Z ed                              d          Z edd                              d          Z edd                              d          Z ed                              d          Z edd                              d          Z ed                              d          Z ed                              d          Z ed          Z edd                              d          Z ed                              d          Z ed                              d          Z edd                              d          Z edd                              d          Z edd                              d          Z e d           d:d#            Z! e d$          d:d%            Z" e d&          d;d(            Z# e d)          d:d*            Z$ e d+          d:d,            Z% e d-          d:d.            Z& e d/          d:d0            Z' e d1          d:d2            Z( e d3          d:d4            Z) e d5          d:d6            Z* e d7          d:d8            Z+d9S )<	LabConfigz)The lab application configuration object.r   zThe name of the application.)helpT)configzThe version of the application.z!The namespace of the application.z/labz!The url path for the application.z#The application settings directory.z7Extra paths to look for federated JupyterLab extensionszAThe standard paths to look in for federated JupyterLab extensionsz$The application templates directory.z[The optional location of local static files. If given, a static file handler will be added.z+The url for federated JupyterLab extensionsz%The url path of the settings handler.z5The optional location of the user settings directory.zhThe optional location of the settings schemas directory. If given, a handler will be added for settings.z#The url path of the workspaces API.zjThe optional location of the saved workspaces directory. If given, a handler will be added for workspaces.zThe listings url.zThe theme url.zThe third-party licenses url.z\The optional location of the themes directory. If given, a handler will be added for themes.z)The url path of the translations handler.z!The url path of the tree handler.zOWhether to cache files on the server. This should be `True` except in dev mode.z7Whether a notebook should start a kernel automatically.FzOWhether getting a relative (False) or absolute (True) path when copying a path.template_dirr   r   c                    t           S )N)DEFAULT_TEMPLATE_PATHselfs    r!   _default_template_dirzLabConfig._default_template_dir9  s    $$r#   labextensions_urlc                ,    t          | j        d          S )Nzextensions/ujoinapp_urlr   s    r!   _default_labextensions_urlz$LabConfig._default_labextensions_url=      T\=111r#   r$   r%   c                     t          d          S )Nlabextensions)r   r   s    r!   _default_labextensions_pathz%LabConfig._default_labextensions_pathA  s    O,,,r#   workspaces_urlc                ,    t          | j        d          S )Nworkspaces/r   r   s    r!   _default_workspaces_urlz!LabConfig._default_workspaces_urlE  r   r#   workspaces_api_urlc                .    t          | j        dd          S )Napir   r   r   s    r!   _default_workspaces_api_urlz%LabConfig._default_workspaces_api_urlI  s    T\5-888r#   settings_urlc                .    t          | j        dd          S )Nr   z	settings/r   r   s    r!   _default_settings_urlzLabConfig._default_settings_urlM      T\5+666r#   listings_urlc                .    t          | j        dd          S )Nr   z	listings/r   r   s    r!   _default_listings_urlzLabConfig._default_listings_urlQ  r   r#   
themes_urlc                .    t          | j        dd          S )Nr   zthemes/r   r   s    r!   _default_themes_urlzLabConfig._default_themes_urlU  s    T\5)444r#   licenses_urlc                .    t          | j        dd          S )Nr   z	licenses/r   r   s    r!   _default_licenses_urlzLabConfig._default_licenses_urlY  r   r#   tree_urlc                ,    t          | j        d          S )Nztree/r   r   s    r!   _default_tree_urlzLabConfig._default_tree_url]  s    T\7+++r#   translations_api_urlc                .    t          | j        dd          S )Nr   ztranslations/r   r   s    r!   _default_translations_api_urlz'LabConfig._default_translations_api_urla  s    T\5/:::r#   N)r   r   )r   r%   ),__name__
__module____qualname____doc__r   tagapp_nameapp_versionapp_namespacer   rB   r   extra_labextensions_pathr$   templates_dir
static_dirr   r   user_settings_dirschemas_dirr   workspaces_dirr   r   r   
themes_dirr   r   r   cache_filesnotebook_starts_kernelcopy_absolute_pathr   r   r   r   r   r   r   r   r   r   r   r   rU   r#   r!   r   r      s
       33wr >???CC4CPPH'"#DEEEIIQUIVVKGB%HIIIMMUYMZZMgf#FGGGKKSWKXXGwr(MNNNRRZ^R__#t		U     	cc  		[  	cc  GB%KLLLPPX\P]]M
   
cc   )VWWW[[ \   7 GHHHLLTXLYYL
I  	cc  '
%   
cc  !&KLLLPPX\P]]W
,   
cc  7 3444888EEL.///3343@@J7 ?@@@L
   
cc  #7(STTTXX Y   w?@@@DDDDQQH$_   
cc 
 "TL  	cc  ^   
cc 
 W^% % % % W !!2 2 2 "!2 W!""- - - #"- W2 2 2 2 W!""9 9 9 #"9 W^7 7 7 7 W^7 7 7 7 W\5 5 5 5 W^7 7 7 7 WZ, , , , W#$$; ; ; %$; ; ;r#   r   r   c                &   g d}| |vrd| }t          |          d}| dk    rt          |          S | dk    rt                      }n"| dk    rdd	lm} |d         }nt
          d         }t          j        ||          }t          |g|
          S )zgGet the location of config files for the current context
    Returns the string to the environment
    )rA   user
sys_prefixsystemapprZ   z"Page config level must be one of: 	labconfigrA   )config_dir_namer   r   r   )ENV_CONFIG_PATH)read_config_pathwrite_config_dir)
ValueErrorr   r
   jupyter_core.pathsr   r	   r9   r   )rF   allowedmsgconfig_name
config_dirr   full_config_paths          r!   rI   rI   f  s     JIIGG<7<<ooK~~[9999'))

	,		666666$Q'

'*
x
K88+;*<O_````r#   )r   r   r   r   )r$   r%   r   r   )NNrA   )rB   rC   rD   rE   rF   r   r   r   )rL   r   r   r   )NN)r$   r%   rB   rC   rD   rE   r   r   )rA   )rH   r   rF   r   r   r|   )rF   r   r   r   )-r   
__future__r   r7   os.pathrL   r9   globr   	itertoolsr   loggingr   r   r5   typingr   rO   r   r	   r
   r   &jupyter_server.services.config.managerr   r   jupyter_server.utilsr   r   	traitletsr   r   r   r   r   r:   __file__r   r"   r@   rK   rP   r{   r   r   rI   rU   r#   r!   <module>r      s$     # " " " " "                          ! ! ! ! ! !        S S S S S S S S S S R R R R R R R R 7 7 7 7 7 7 = = = = = = = = = = = = = = !X!6!6DD 	 	 	 	!  !  !  ! J UZ! ! ! ! ! " " " "* ae_ _ _ _ _D' ' ' ' 'K; K; K; K; K;	 K; K; K;\a a a a a ar#   