o
    Zh(                     @  s  U d Z ddlm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 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!m"Z" i Z#de$d< e%ej&e'rqe#(ej& dddZ)e#(e) i Z*de$d< e%ej+e're*(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-de$d< e*(e- G dd de.Z/G d d deZ0G d!d" d"e0Z1e2d#kre03  dS dS )$zh
A base Application class for Jupyter applications.

All Jupyter applications should inherit from this.
    )annotationsN)deepcopy)Path)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ensure_event_loopzdict[str, t.Any]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&   O/var/www/html/lang_env/lib/python3.10/site-packages/jupyter_core/application.pyr!   B   s    r!   c                      s@  e Zd ZdZdZdZeZeZ	d9ddZ
ee Zd:d	d
Ze Zd;ddZed:ddZe Zd;ddZe Zd;ddZedd<ddZeddddZedddZd;dd Zedd!dZeddd"dZd=d#d$Zd=d%d&Z d>d? fd)d*Z!d@d,d-Z"edAd.d/Z#e Z$e%dBdCd2d3Z&d=d4d5Z'e(dBdD fd7d8Z)  Z*S )Er   z#Base class for Jupyter applicationsjupyterzA Jupyter Applicationreturnintc                 C  s   t jS N)loggingINFOselfr&   r&   r'   _log_level_defaultO      zJupyterApp._log_level_default	list[str]c                 C     t  S r+   )r   r.   r&   r&   r'   _jupyter_path_defaultT   r1   z JupyterApp._jupyter_path_defaultstrc                 C  r3   r+   )r   r.   r&   r&   r'   _config_dir_defaultY   r1   zJupyterApp._config_dir_defaultc                 C  s"   t  }| j|vr|d| j |S )Nr   )r   
config_dirinsert)r/   pathr&   r&   r'   config_file_paths\   s   
zJupyterApp.config_file_pathsc                 C     t  }t|dd |S N  mode)r   r   )r/   dr&   r&   r'   _data_dir_defaultf      zJupyterApp._data_dir_defaultc                 C  r;   r<   )r   r   )r/   rdr&   r&   r'   _runtime_dir_defaultm   rB   zJupyterApp._runtime_dir_defaultruntime_dirchanget.AnyNonec                 C  s   t |d dd d S )Nnewr=   r>   )r   )r/   rF   r&   r&   r'   _runtime_dir_changedr   s   zJupyterApp._runtime_dir_changedFTzGenerate default config file.)r   helpzSpecify a config file to load.c                 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.zAnswer yes to any prompts.c                   s   | j r| j  ntt| j| jd  t  r?| js?d}d fdd}| }|ds8td | }|dr,|d	r?d
S | 	 }td   t
t j d tjt ddd}|| W d
   d
S 1 snw   Y  d
S )z-Write our default config to a .py config filez.pyrL   r)   r5   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]nrL   )inputlowerKeyboardInterruptprint)promptconfig_filer&   r'   ask   s   z,JupyterApp.write_default_config.<locals>.ask)r   rS   zPlease answer 'yes' or 'no'rS   NzWriting default config to: %sr=   wzutf-8)r?   encodingr)   r5   )rZ   r5   r   r7   config_file_nameexistsr   
startswithrW   Zgenerate_config_filer   parentresolveopenwrite)r/   Zanswerr[   Zconfig_textfr&   rY   r'   write_default_config   s&   


"zJupyterApp.write_default_configc                 C  sv   zt t | jdd}W n ty   Y n ty   Y dS w |  dS ddlm}m} t |  s6dS |  dS )z"Migrate config/data from IPython 3Zmigratedzr+Nr   )get_ipython_dirmigrate)	r   rd   r7   FileNotFoundErrorOSErrorcloseri   rh   r`   )r/   Zf_markerrh   ri   r&   r&   r'   migrate_config   s   
zJupyterApp.migrate_configsuppress_errorsboolc                   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 filesZjupyter_config)r9   zConfig file %s not foundNz#Config file not found, skipping: %szError loading config file: %sT)exc_info)logr   r:   superload_config_filer   rZ   osr9   splitr_   	ExceptionZraise_config_file_errorswarning)r/   rn   Zbase_configr9   r_   	__class__r&   r'   rs      s2   

zJupyterApp.load_config_filerP   c                 C  s   | j  d| }t|pdS )NrM   rL   )rP   r   )r/   rP   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.
        )ro   r   subapp
subcommandr.   r&   r&   r'   _dispatching   s   zJupyterApp._dispatchingNargvc                 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   )sysr~   rz   r|   Zparse_command_liner   r   r}   rm   rs   Zupdate_configr   r   )r/   r~   ZsubcZ	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|   rt   execvr~   r!   r{   startr   rg   r.   r&   r&   r'   r     s    
zJupyterApp.startkwargsc                   sB   t  }zt jdd|i| W n
 ty   Y dS w |  dS )z+Launch an instance of a Jupyter Applicationr~   Nr&   )r   rr   launch_instancer!   rl   )clsr~   r   looprx   r&   r'   r     s   zJupyterApp.launch_instance)r)   r*   )r)   r2   r^   )rF   rG   r)   rH   r)   rH   )T)rn   ro   r)   rH   )rP   r5   r)   r5   )r)   ro   r+   r~   rG   r)   rH   r~   rG   r   rG   r)   rH   )+r"   r#   r$   r%   rP   descriptionr   aliasesr   flagsr0   r   r   r   r4   r7   r6   propertyr:   data_dirrA   rE   rD   r	   rJ   r   r   r_   rR   rZ   r   rg   rm   rs   rz   r}   r|   r   r   r   classmethodr   __classcell__r&   r&   rx   r'   r   F   sN    









'
c                   @  sR   e Zd ZdZdZdZdZddd
dZdddZe	ddddZ
e	ddddZdS )JupyterAsyncAppz3A Jupyter application that runs on an asyncio loop.Zjupyter_asynczAn Async Jupyter ApplicationFNr~   rG   r)   rH   c                      dS )z+Initialize the application asynchronoously.Nr&   )r/   r~   r&   r&   r'   initialize_async*      z JupyterAsyncApp.initialize_asyncc                   r   )z%Run the application in an event loop.Nr&   r.   r&   r&   r'   start_async-  r   zJupyterAsyncApp.start_asyncr   c                   s>   | j di |}|| ||I d H  | I d H  d S )Nr&   )instancer   r   r   )r   r~   r   Zappr&   r&   r'   _launch_instance0  s
   
z JupyterAsyncApp._launch_instancec                 K  s2   t | j}| j|fi |}|| |  dS )z2Launch an instance of an async Jupyter ApplicationN)r   _prefer_selector_loopr   run_until_completerl   )r   r~   r   r   coror&   r&   r'   r   7  s   

zJupyterAsyncApp.launch_instancer+   r   r   r   )r"   r#   r$   r%   rP   r   r   r   r   r   r   r   r&   r&   r&   r'   r   !  s    
r   __main__)4r%   
__future__r   r,   rt   r   typingtcopyr   pathlibr   shutilr   Z	traitletsr   r   r   r	   Ztraitlets.config.applicationr
   r   Ztraitlets.config.loaderr   pathsr   r   r   r   r   r   r   utilsr   r   r   __annotations__
isinstancer   dictupdateZ_jupyter_aliasesr   r   DEBUGr    rv   r!   r   r   r"   r   r&   r&   r&   r'   <module>   sP    $	


 \