
    lCe#                       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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 de!d<    e"ej#        e$          re %                    ej#                   dddZ&e %                    e&           i Z'd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*de!d<   e'%                    e*            G d de+          Z, G d de          Z-e.d k    re-/                                 dS dS )!zh
A base Application class for Jupyter applications.

All Jupyter applications should inherit from this.
    )annotationsN)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_existsz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                      e Zd ZdZdS )NoStartz6Exception to raise when an application shouldn't startN)__name__
__module____qualname____doc__     8lib/python3.11/site-packages/jupyter_core/application.pyr"   r"   A   s        @@@@r(   r"   c                      e Zd ZdZdZdZeZeZ	d)dZ
 e e                      Zd*dZ e            Zd+d
Zed*d            Z e            Zd+dZ e            Zd+dZ ed          d,d            Z eddd          Z edd          Zd+dZ edd          Z eddd          Zd-dZd-dZ d.d/ fdZ!d0d!Z"ed1d"            Z# e            Z$e%d2d3d%            Z&d-d&Z'e(d2d4 fd(            Z) xZ*S )5r   z#Base class for Jupyter applicationsjupyterzA Jupyter Applicationreturnintc                    t           j        S N)loggingINFOselfs    r)   _log_level_defaultzJupyterApp._log_level_defaultN   s
    |r(   	list[str]c                    t                      S r/   )r   r2   s    r)   _jupyter_path_defaultz JupyterApp._jupyter_path_defaultS   s    ~~r(   strc                    t                      S r/   )r   r2   s    r)   _config_dir_defaultzJupyterApp._config_dir_defaultX   s    !###r(   c                j    t                      }| j        |vr|                    d| j                   |S )Nr   )r   
config_dirinsert)r3   paths     r)   config_file_pathszJupyterApp.config_file_paths[   s5    "$$?$&&KK4?+++r(   c                D    t                      }t          |d           |S N  mode)r   r   )r3   ds     r)   _data_dir_defaultzJupyterApp._data_dir_defaulte   s%    !%((((r(   c                D    t                      }t          |d           |S rA   )r   r   )r3   rds     r)   _runtime_dir_defaultzJupyterApp._runtime_dir_defaultl   s%     """5))))	r(   runtime_dirchanget.AnyNonec                4    t          |d         d           d S )NnewrB   rC   r   )r3   rK   s     r)   _runtime_dir_changedzJupyterApp._runtime_dir_changedq   s    &-e444444r(   FTzGenerate default config file.)r   helpzSpecify a config file to load.c                P    | j         sdS | j                             dd          dz   S )N -__config)namereplacer2   s    r)   _config_file_name_defaultz$JupyterApp._config_file_name_defaulty   s.    y 	2y  c**Y66r(   zFull path of a config file.zAnswer yes to any prompts.c                   | j         r| j         n-t          j                            | j        | j        dz             t          j                                      rs| j        sld}dfd} |            }|                    d          s.t          d            |            }|                    d          .|                    d          rd	S | 
                                }t          d
z             t          t          j                            t          j                                                d           t          dd          5 }|                    |           d	d	d	           d	S # 1 swxY w Y   d	S )z-Write our default config to a .py config filez.pyrS   r,   r8   c                     dz  } 	 t          |                                           pdS # t          $ r t          d           Y dS w xY w)Nz'Overwrite %s with default config? [y/N]nrS   )inputlowerKeyboardInterruptprint)promptconfig_files    r)   askz,JupyterApp.write_default_config.<locals>.ask   s\    B[P ==..007C7(   "III33s   "+ AA)r   r\   zPlease answer 'yes' or 'no'r\   NzWriting default config to: %srB   wzutf-8)rD   encodingr,   r8   )rb   osr>   joinr<   config_file_nameexistsr   
startswithr`   generate_config_filer   abspathdirnameopenwrite)r3   answerrc   config_textfrb   s        @r)   write_default_configzJupyterApp.write_default_config   s    	W*KK',,t8MPU8UVVK7>>+&& 	t 	F      SUUF''
33 3444 ''
33    %% //11-;<<<"'//"'//+*F*FGGOOO+C'::: 	!aGGK   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!s   E55E9<E9c                H   	 t          t          j                            | j        d          d          }|                                 dS # t          $ r Y dS t          $ r Y nw xY wddlm	}m} t          j        
                     |                      sdS  |             dS )z"Migrate config/data from IPython 3migratedzr+Nr   )get_ipython_dirmigrate)ro   rg   r>   rh   r<   closePermissionErrorFileNotFoundErrorrx   rw   rj   )r3   f_markerrw   rx   s       r)   migrate_configzJupyterApp.migrate_config   s    
	BGLL*EEtLLH NNF  	 	 	FF  	 	 	D	 	65555555 w~~oo//00 	F					s   3A 
A$	A$#A$suppress_errorsboolc                   | j                             d| j                   d}	 t                                          || j                   n+# t
          $ r | j                             d|           Y nw xY w| j        r(t          j        	                    | j                  \  }}n| j        }| j
        }|r||k    rdS 	 t                                          ||           dS # t
          $ r | j                             d|           Y dS t          $ r+ |r| j        r | j                             d|d	           Y dS w xY 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)r>   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   rb   rg   r>   splitri   	Exceptionraise_config_file_errorswarning)r3   r~   base_configr>   ri   	__class__s        r)   r   zJupyterApp.load_config_file   s    	68NOOO&	DGG$$+ %     " 	D 	D 	DHNN5{CCCCC	D  	%'W]]43C%D%D"D"")D#4# (8K(G(G		_GG$$%5D$AAAAA! 	T 	T 	THNN@BRSSSSSS 	_ 	_ 	_ $ (E H<>NY]^^^^^^	_s)   (A %A65A6#C& &%E0EErW   c                <    | j          d| }t          |          pdS )NrT   rS   )rW   r   )r3   rW   s     r)   _find_subcommandzJupyterApp._find_subcommand   s(    )$$d$$T{{ b r(   c                F    t          | j        p| j        p| j                  S )z\Return whether we are dispatching to another command

        or running ourselves.
        )r   r   subapp
subcommandr2   s    r)   _dispatchingzJupyterApp._dispatching   s#     D(JDKJ4?KKKr(   Nargvc                   |t           j        dd         }|r-|                     |d                   }|r|| _        || _        dS |                     |           t          | j                  }| j        rdS |                                  | 	                                 | 
                    |           t          rt                       dS dS )zInitialize the application.Nr   r   )sysr   r   r   parse_command_liner   r   r   r}   r   update_configr   r   )r3   r   subc	cl_configs       r)   
initializezJupyterApp.initialize   s     <8ABB<D 	((a11D  	"&%%%T[))	 	F9%%%  	+(*****	+ 	+r(   c                >   | j         r>t          j        | j         | j         g| j        dd         z              t	                      | j        r'| j                                         t	                      | j        r"|                                  t	                      dS )zStart the whole thingr   N)	r   rg   execvr   r"   r   startr   rt   r2   s    r)   r   zJupyterApp.start  s    ? 	HT_t&7$)ABB-&GHHH))O; 	K))O 	%%'''))O	 	r(   kwargsc                b    	  t                      j        dd|i| dS # t          $ r Y dS w xY w)z+Launch an instance of a Jupyter Applicationr   Nr'   )r   launch_instancer"   )clsr   r   r   s      r)   r   zJupyterApp.launch_instance  sR    	#EGG#88888888 	 	 	FF	s     
..)r,   r-   )r,   r5   rf   )rK   rL   r,   rM   )r,   rM   )T)r~   r   r,   rM   )rW   r8   r,   r8   )r,   r   r/   )r   rL   r,   rM   )r   rL   r   rL   r,   rM   )+r#   r$   r%   r&   rW   descriptionr   aliasesr   flagsr4   r   r   r   r7   r<   r:   propertyr?   data_dirrF   rJ   rI   r	   rP   r   r   ri   rY   rb   r   rt   r}   r   r   r   r   r   r   r   classmethodr   __classcell__)r   s   @r)   r   r   E   s       --D)KGE    4		??L    J$ $ $ $    X wyyH   
 '))K   
 W]5 5 5 5 d54WXXXOwd1QRRR7 7 7 7
 '.  K
 eD/OPPPJ! ! ! !>   ,$_ $_ $_ $_ $_ $_ $_N! ! ! ! L L L XL J+ + + + +,          [    r(   __main__)0r&   
__future__r   r0   rg   r   typingtcopyr   shutilr   	traitletsr   r   r   r	   traitlets.config.applicationr
   r   traitlets.config.loaderr   pathsr   r   r   r   r   r   r   utilsr   r   __annotations__
isinstancer   dictupdate_jupyter_aliasesr   r   DEBUGr    r   r"   r   r#   r   r'   r(   r)   <module>r      s     # " " " " "  				 



                 2 2 2 2 2 2 2 2 2 2 2 2 H H H H H H H H 6 6 6 6 6 6                  % $ $ $ $ $ "$ # # # #:k!4(( -+,,,(&     $ % % %!
 ! ! ! !:k&& )k'((( 
gm45B &(94'@ACab	d+,;

$ 
$ 
 
 
 
   . ! ! !A A A A Ai A A AU U U U U U U Up z      r(   