o
    i2                     @   s   d 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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	eed
Zdd Zdd Z dddZ!dd Z"dddZ#dddZ$G dd deZ%dd Z&dS )zJupyterLab Server config    N)iglob)chain)join)SYSTEM_CONFIG_PATHjupyter_config_dirjupyter_path)ConfigManagerrecursive_update)url_path_join)Bool	HasTraitsListUnicodedefault	templatesc                 C   sF   d| v r
| d }|S d| v rt | d tr| d dd}|S d}|S )z#Get the url from the extension datahomepage
repositoryurl )
isinstancedictget)datar    r   S/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/jupyterlab_server/config.pyget_package_url   s   r   c                 C   s(  i }| D ]}t tt|ddtt|dddD ]x}t|dd}t|}W d   n1 s0w   Y  |d |vrt|d |d	 |d
dt||t	
|d|dt |dt d	}t	t	
|d}t	|rt|dd}t||d< W d   n1 sw   Y  |||d < qq|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$   r%   zinstall.jsoninstall)r   r   pjoinopenjsonloadr   r   r   ospdirnamer   exists)labextensions_pathfederated_extensionsr&   r'   fidpkgdatar   install_pathr   r   r   get_federated_extensions%   s<   

r6   allc                 C   s   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   )app_settings_dirloggerlevelcmr   r   r   get_static_page_configD   s   

r>   c                 C   s\   t | dd}| drt|W  d   S t|W  d   S 1 s'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)r+   endswithjson5r-   r,   )pathr3   r   r   r   load_configR   s   
$rB   c                    s  i }d}|r;t |dt |dg}|D ](}t|r:t|}|dfD ]}||v r2dd || D ||< q!t||  nqt|dd}	t||	 i }
g  }|d	< t| }||i  | D ][\}}d
|d vrp|	d|d   q\|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 < q\|r	t|}t |dd}t|r	t|dd}t|}W d   n1 sw   Y  |d di }| D ]\}}||
v rq||r|| |
|< qi }t|
D ]}|| |du rq|
| }|D ]}d||< q#q|}|||g  |||< | D ]\} t trU fdd D ||< q@|S )z/Get the page config for the application handlerdisabledExtensionszpage_config.json5zpage_config.jsondeferredExtensionsc                 S   s   i | ]}|d qS )Tr   ).0keyr   r   r   
<dictcomp>y   s    z#get_page_config.<locals>.<dictcomp>r7   )r;   r<   r2   _buildr%   z%s is not a valid extensionr!   r-   )r!   r-   	extensionmimeExtensionstylestaticr   r   r   NextensionMetadataTc                    s   g | ]} | r|qS r   r   )rE   subkeyvaluer   r   
<listcomp>   s    z#get_page_config.<locals>.<listcomp>)r*   r.   r0   rB   r	   r>   r6   
setdefaultitemswarningappendr   r/   r+   r,   r-   sortedupdater   r   )r1   r:   r;   r8   disabled_keyconfig_pathsrA   r   rF   static_page_configdisabled_by_extensions_all
extensionsfederated_exts_ext_dataextbuildrI   r!   app_dirpackage_data_filer3   app_dataall_ext_dataextdisabled_by_extensionsdisabled_listitemrollup_disabledr   rO   r   get_page_configf   s   




rj   c                 C   s   t |}|d|  dS )zWrite page config to diskr8   N)r9   set)r8   r<   r=   r   r   r   write_page_config   s   rl   c                   @   s  e Zd ZdZedddjddZedddjddZedddjddZed	d
djddZ	edddjddZ
ee ddjddZee ddjddZedddjddZedddjddZedddjddZeddjddZedddjddZedddjddZeddjddZedddjddZeddjddZeddjddZeddZedddjddZeddjddZeddjddZedddjddZedddjddZedddj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/d0d1 Z&e d2d3d4 Z'e d5d6d7 Z(e d8d9d: Z)e d;d<d= Z*e d>d?d@ Z+dAS )B	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_dirc                 C   s   t S )N)DEFAULT_TEMPLATE_PATHselfr   r   r   _default_template_dir,  s   zLabConfig._default_template_dirlabextensions_urlc                 C      t | jdS )Nzextensions/ujoinapp_urlrr   r   r   r   _default_labextensions_url0     z$LabConfig._default_labextensions_urlr1   c                 C   s   t dS )Nlabextensions)r   rr   r   r   r   _default_labextensions_path4  s   z%LabConfig._default_labextensions_pathworkspaces_urlc                 C   rv   )Nworkspaces/rw   rr   r   r   r   _default_workspaces_url8  r{   z!LabConfig._default_workspaces_urlworkspaces_api_urlc                 C      t | jddS )Napir   rw   rr   r   r   r   _default_workspaces_api_url<     z%LabConfig._default_workspaces_api_urlsettings_urlc                 C   r   )Nr   z	settings/rw   rr   r   r   r   _default_settings_url@  r   zLabConfig._default_settings_urllistings_urlc                 C   r   )Nr   z	listings/rw   rr   r   r   r   _default_listings_urlD  r   zLabConfig._default_listings_url
themes_urlc                 C   r   )Nr   zthemes/rw   rr   r   r   r   _default_themes_urlH  r   zLabConfig._default_themes_urllicenses_urlc                 C   r   )Nr   z	licenses/rw   rr   r   r   r   _default_licenses_urlL  r   zLabConfig._default_licenses_urltree_urlc                 C   rv   )Nztree/rw   rr   r   r   r   _default_tree_urlP  r{   zLabConfig._default_tree_urltranslations_api_urlc                 C   r   )Nr   ztranslations/rw   rr   r   r   r   _default_translations_api_urlT  r   z'LabConfig._default_translations_api_urlN),__name__
__module____qualname____doc__r   tagapp_nameapp_versionapp_namespacery   r:   r   extra_labextensions_pathr1   templates_dir
static_dirru   r   user_settings_dirschemas_dirr   workspaces_dirr   r   r   
themes_dirr   r   r   cache_filesnotebook_starts_kernelcopy_absolute_pathr   rt   rz   r}   r   r   r   r   r   r   r   r   r   r   r   r   rm      s    			

	









rm   c                 C   s   g d}| |vrd| }t |d}| dkrt|dS | dkr$t }n| dkr3dd	lm} |d }ntd }t||}t|g|d
S )zgGet the location of config files for the current context
    Returns the string to the environment
    )r7   user
sys_prefixsystemapprI   z"Page config level must be one of: 	labconfigr7   )config_dir_namer   r   r   )ENV_CONFIG_PATH)read_config_pathwrite_config_dir)
ValueErrorr   r   jupyter_core.pathsr   r   r.   r   )r<   allowedmsgconfig_name
config_dirr   full_config_pathr   r   r   r9   Y  s   


r9   )NNr7   )NN)r7   )'r   r,   os.pathrA   r.   globr   	itertoolsr   r   r*   r@   r   r   r   r   &jupyter_server.services.config.managerr   r	   jupyter_server.utilsr
   rx   	traitletsr   r   r   r   r   r/   __file__rq   r   r6   r>   rB   rj   rl   rm   r9   r   r   r   r   <module>   s*    


_ 