o
    i-                     @   s   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mZ dd	lmZ d
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdZG dd dZdS )    )wraps)deepcopy)
TraitError)Config)
JupyterApp)	ServerApp)ExtensionApp   )NotebookAppTraitsc                 C      dj | dS )Nz'{trait_name}' was found in both NotebookApp and ServerApp. This is likely a recent change. This config will only be set in NotebookApp. Please check if you should also config these traits in ServerApp for your purpose.
trait_nameformatr    r   M/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/notebook_shim/shim.pyNBAPP_AND_SVAPP_SHIM_MSG   s
   r   c                 C   r   )Nz'{trait_name}' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.r   r   r   r   r   r   NBAPP_TO_SVAPP_SHIM_MSG   s
   r   c                 C      dj | |dS )Nz'{trait_name}' is found in {extapp_name}, NotebookApp, and ServerApp. This is a recent change. This config will only be set in {extapp_name}. Please check if you should also config these traits in NotebookApp and ServerApp for your purpose.r   extapp_namer   r   r   r   r   #EXTAPP_AND_NBAPP_AND_SVAPP_SHIM_MSG"      r   c                 C   r   )Nz'{trait_name}' is found in both {extapp_name} and ServerApp. This is a recent change. This config will only be set in {extapp_name}. Please check if you should also config these traits in ServerApp for your purpose.r   r   r   r   r   r   EXTAPP_AND_SVAPP_SHIM_MSG.   r   r   c                 C   r   )Nz'{trait_name}' is found in both {extapp_name} and NotebookApp. This is a recent change. This config will only be set in {extapp_name}. Please check if you should also config these traits in NotebookApp for your purpose.r   r   r   r   r   r   EXTAPP_AND_NBAPP_SHIM_MSG:   r   r   c                 C   r   )Na  '{trait_name}' is not found in {extapp_name}, but it was found in both NotebookApp and ServerApp. This is likely a recent change. This config will only be set in ServerApp. Please check if you should also config these traits in NotebookApp for your purpose.r   r   r   r   r   r   #NOT_EXTAPP_NBAPP_AND_SVAPP_SHIM_MSGF   s   r   c                 C   r   )Nzp'{trait_name}' has moved from {extapp_name} to ServerApp. Be sure to update your config before our next release.r   r   r   r   r   r   EXTAPP_TO_SVAPP_SHIM_MSGS      r   c                 C   r   )Nzr'{trait_name}' has moved from {extapp_name} to NotebookApp. Be sure to update your config before our next release.r   r   r   r   r   r   EXTAPP_TO_NBAPP_SHIM_MSG]   r   r   )open_browser	log_level
log_formatdefault_urlc                       s2   e Zd ZdZeej fddZdd Z  ZS )NotebookConfigShimMixina  A Mixin class for shimming configuration from
    NotebookApp to ServerApp. This class handles warnings, errors,
    etc.

    This class should be used during a transition period for apps
    that are switching from depending on NotebookApp to ServerApp.

    After one release cycle, this class can be safely removed
    from the inheriting class.

    TL;DR

    The entry point to shimming is at the `update_config` method.
    Once traits are loaded, before updating config across all
    configurable objects, this class injects a method to reroute
    traits to their *most logical* classes.

    This class raises warnings when:
        1. a trait has moved.
        2. a trait is redundant across classes.

    Redundant traits across multiple classes now must be
    configured separately, *or* removed from their old
    location to avoid this warning.

    For a longer description on how individual traits are handled,
    read the docstring under `shim_config_from_notebook_to_jupyter_server`.
    c                    s   |  |}t | d S )N)+shim_config_from_notebook_to_jupyter_serversuperupdate_config)selfconfigshimmed_config	__class__r   r   r&      s   z%NotebookConfigShimMixin.update_configc                 C   s  | j j}|di }|di }||i }t|}i }i }i }	| j  t  }
t }t t  }|| d}|	 D ]O\}}||v }||v }|t
v rX|||i n/|rh|rht|}|||i n|rvt|}|||i n|r|||i ntd||r| j| q@d}|	 D ]\}}||
v }||v }||v }|t
v r|	||i nzt|||grt||}|	||i nf|r|rt||}|	||i nU|r|rt||}|	||i nD|r|	||i n:|r|rt||}|||i n'|rt||}|||i n|r%t||}|||i ntd||r5| j| qt||d}|	rK|t| j j|	i || |S )u  Reorganizes a config object to reroute traits to their expected destinations
        after the transition from NotebookApp to ServerApp.

        A detailed explanation of how traits are handled:

        1. If the argument is prefixed with `ServerApp`,
            pass this trait to `ServerApp`.
        2. If the argument is prefixed with `NotebookApp`,
            * If the argument is a trait of `NotebookApp` *and* `ServerApp`:
                1. Raise a warning—**for the extension developers**—that
                    there's redundant traits.
                2. Pass trait to `NotebookApp`.
            * If the argument is a trait of just `ServerApp` only
                (i.e. the trait moved from `NotebookApp` to `ServerApp`):
                1. Raise a "this trait has moved" **for the user**.
                3. Pass trait to `ServerApp`.
            * If the argument is a trait of `NotebookApp` only, pass trait
                to `NotebookApp`.
            * If the argument is not found in any object, raise a
                `"Trait not found."` error.
        3. If the argument is prefixed with `ExtensionApp`:
            * If the argument is a trait of `ExtensionApp`,
                `NotebookApp`, and `ServerApp`,
                1. Raise a warning about redundancy.
                2. Pass to the ExtensionApp
            * If the argument is a trait of `ExtensionApp` and `NotebookApp`,
                1. Raise a warning about redundancy.
                2. Pass to ExtensionApp.
            * If the argument is a trait of `ExtensionApp` and `ServerApp`,
                1. Raise a warning about redundancy.
                2. Pass to ExtensionApp.
            * If the argument is a trait of `ExtensionApp`.
                1. Pass to ExtensionApp.
            * If the argument is a trait of `NotebookApp` but not `ExtensionApp`,
                1. Raise a warning that trait has likely moved to NotebookApp.
                2. Pass to NotebookApp
            * If the arguent is a trait of `ServerApp` but not `ExtensionApp`,
                1. Raise a warning that the trait has likely moved to ServerApp.
                2. Pass to ServerApp.
            * else
                * Raise a TraitError: "trait not found."
        NotebookAppr   NzTrait, {}, not found.)r,   r   )r+   __name__popr   class_trait_namesr   r   r
   updateitemsIGNORED_TRAITSr   r   r   r   logwarningallr   r   r   r   r   r   r   )r'   r(   r   nbapp_configsvapp_configextapp_configconfig_shimsvapp_config_shimnbapp_config_shimextapp_config_shimextapp_traitssvapp_traitsnbapp_traitswarning_msgr   trait_valuein_svappin_nbapp	in_extapp
new_configr   r   r   r$      s   +

zCNotebookConfigShimMixin.shim_config_from_notebook_to_jupyter_server)	r-   
__module____qualname____doc__r   r   r&   r$   __classcell__r   r   r*   r   r#   l   s
    r#   N)	functoolsr   copyr   	traitletsr   traitlets.config.loaderr   jupyter_core.applicationr   jupyter_server.serverappr   $jupyter_server.extension.applicationr   traitsr
   r   r   r   r   r   r   r   r   r2   r#   r   r   r   r   <module>   s$    

