o
    i!                     @   sz  U d 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	 ddl
mZ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mZmZ dd
lmZ i Zee d< e!ej"erce#ej" dddZ$e#e$ i Z%ee d< e!ej&ere%#ej& ddej'iidfdddiidfdddiidfdZ(ee d< e%#e( G dd de)Z*G dd deZ+e,dkre+-  dS dS )zh
A base Application class for Jupyter applications.

All Jupyter applications should inherit from this.
    N)deepcopy)which)BoolListUnicodeobserve)Applicationcatch_config_error)ConfigFileNotFound   )allow_insecure_writesissue_insecure_write_warningjupyter_config_dirjupyter_config_pathjupyter_data_dirjupyter_pathjupyter_runtime_dirensure_dir_existsbase_aliaseszApplication.log_levelzJupyterApp.config_file)z	log-levelconfig
base_flagsr   	log_levelz8set log level to logging.DEBUG (maximize logging output)
JupyterAppgenerate_configTzgenerate default config file
answer_yesz1Answer yes to any questions instead of prompting.)debugzgenerate-configy_jupyter_flagsc                   @   s   e Zd ZdZdS )NoStartz6Exception to raise when an application shouldn't startN)__name__
__module____qualname____doc__ r$   r$   S/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/jupyter_core/application.pyr   >   s    r   c                       s  e Zd ZU dZdZdZeZeZ	dd Z
ee Zejeje ef ed< dd Ze Zejeef ed	< d
d Zedd Ze Zejeef ed< dd Ze Zejeef ed< dd Zeddd ZeddddZejeef ed< edddZ ejeef ed< dd Z!edddZ"ejeef ed < eddd!dZ#ejeef ed"< d#d$ Z$d%d& Z%d4 fd'd(	Z&d)d* Z'ed+d, Z(e Z)e*d5d.d/Z+d0d1 Z,e-d5 fd2d3	Z.  Z/S )6r   z#Base class for Jupyter applicationsjupyterzA Jupyter Applicationc                 C   s   t jS N)loggingINFOselfr$   r$   r%   _log_level_defaultK      zJupyterApp._log_level_defaultr   c                 C      t  S r'   )r   r*   r$   r$   r%   _jupyter_path_defaultP   r-   z JupyterApp._jupyter_path_default
config_dirc                 C   r.   r'   )r   r*   r$   r$   r%   _config_dir_defaultU   r-   zJupyterApp._config_dir_defaultc                 C   s"   t  }| j|vr|d| j |S )Nr   )r   r0   insert)r+   pathr$   r$   r%   config_file_pathsX   s   
zJupyterApp.config_file_pathsdata_dirc                 C      t  }t|dd |S N  mode)r   r   )r+   dr$   r$   r%   _data_dir_defaultb      zJupyterApp._data_dir_defaultruntime_dirc                 C   r6   r7   )r   r   )r+   rdr$   r$   r%   _runtime_dir_defaulti   r=   zJupyterApp._runtime_dir_defaultc                 C   s   t |d dd d S )Nnewr8   r9   r   )r+   changer$   r$   r%   _runtime_dir_changedn   s   zJupyterApp._runtime_dir_changedFTzGenerate default config file.)r   helpr   zSpecify a config file to load.config_file_namec                 C   s   | j sdS | j ddd S )N -__config)namereplacer*   r$   r$   r%   _config_file_name_defaultz   s   z$JupyterApp._config_file_name_defaultzFull path of a config file.config_filezAnswer yes to any prompts.r   c                    s   | j r| j  ntj| j| jd  tj r>| js>d} fdd}| }|ds7t	d | }|dr+|dr>dS | 
 }t|trL|d	}t	d
   ttjtj d t ddd}|| W d   dS 1 sww   Y  dS )z-Write our default config to a .py config filez.pyrF   c                     s8   d  } z	t |  pdW S  ty   td Y dS w )Nz'Overwrite %s with default config? [y/N]nrF   )inputlowerKeyboardInterruptprint)promptrM   r$   r%   ask   s   z,JupyterApp.write_default_config.<locals>.ask)r   rN   zPlease answer 'yes' or 'no'rN   Nutf8zWriting default config to: %sr8   wzutf-8)r:   encoding)rM   osr3   joinr0   rE   existsr   
startswithrR   generate_config_file
isinstancebytesdecoder   abspathdirnameopenwrite)r+   answerrU   config_textfr$   rT   r%   write_default_config   s*   




"zJupyterApp.write_default_configc                 C   sH   t jt j| jdrdS ddlm}m} t j| sdS |  dS )z"Migrate config/data from IPython 3migratedNr   )get_ipython_dirmigrate)rY   r3   r[   rZ   r0   rk   rj   )r+   rj   rk   r$   r$   r%   migrate_config   s   
zJupyterApp.migrate_configc                    s   | j d| j d}zt j|| jd W n ty%   | j d| Y nw | jr3tj	| j\}}n| j}| j
}|r?||krAdS zt j||d W dS  ty]   | j d| Y dS  tyu   |rh| jri | j jd|dd	 Y dS w )
zLoad the config file.

        By default, errors in loading config are handled, and a warning
        printed on screen. For testing, the suppress_errors option is set
        to False, so errors will make tests fail.
        zSearching %s for config filesjupyter_config)r3   zConfig file %s not foundNz#Config file not found, skipping: %szError loading config file: %sT)exc_info)logr   r4   superload_config_filer
   rM   rY   r3   splitrE   	Exceptionraise_config_file_errorswarning)r+   suppress_errorsbase_configr3   rE   	__class__r$   r%   rq      s2   

zJupyterApp.load_config_filec                 C   s   | j  d| }t|S )NrG   )rJ   r   )r+   rJ   r$   r$   r%   _find_subcommand   s   zJupyterApp._find_subcommandc                 C   s   t | jp	| jp	| jS )z\Return whether we are dispatching to another command

        or running ourselves.
        )boolr   subapp
subcommandr*   r$   r$   r%   _dispatching   s   zJupyterApp._dispatchingNc                 C   s   |du rt jdd }|r| |d }|r|| _|| _dS | | t| j}| jr-dS |   | 	  | 
| trAt  dS dS )zInitialize the application.Nr   r   )sysargvrz   r}   parse_command_liner   r   r~   rl   rq   update_configr   r   )r+   r   subc	cl_configr$   r$   r%   
initialize   s$   



zJupyterApp.initializec                 C   sZ   | j rt| j | j g| jdd   t | jr!| j  t | jr+|   t dS )zStart the whole thingr   N)	r}   rY   execvr   r   r|   startr   rh   r*   r$   r$   r%   r     s    
zJupyterApp.startc                    s.   zt  jdd|i|W S  ty   Y dS w )z+Launch an instance of a Jupyter Applicationr   Nr$   )rp   launch_instancer   )clsr   kwargsrx   r$   r%   r     s
   zJupyterApp.launch_instance)Tr'   )0r    r!   r"   r#   rJ   descriptionr   aliasesr   flagsr,   r   r   r   tUnionstr__annotations__r/   r0   r1   propertyr4   r5   r<   r>   r@   r   rC   r   r   r{   rE   rL   rM   r   rh   rl   rq   rz   r~   r}   r	   r   r   classmethodr   __classcell__r$   r$   rx   r%   r   B   sZ   
 "

!'
__main__).r#   r(   rY   r   typingr   copyr   shutilr   	traitletsr   r   r   r   traitlets.config.applicationr   r	   traitlets.config.loaderr
   pathsr   r   r   r   r   r   r   utilsr   r   dictr   r^   r   update_jupyter_aliasesr   r   DEBUGr   rs   r   r   r    r   r$   r$   r$   r%   <module>   sJ    	$	


 Y