
    Mh(                       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'          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          Z0 G d! d"e0          Z1e2d#k    re03                                 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                      e Zd ZdZdS )NoStartz6Exception to raise when an application shouldn't startN)__name__
__module____qualname____doc__     X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jupyter_core/application.pyr#   r#   B   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_defaultO   s
    |r)   	list[str]c                    t                      S r0   )r   r3   s    r*   _jupyter_path_defaultz JupyterApp._jupyter_path_defaultT   s    ~~r)   strc                    t                      S r0   )r   r3   s    r*   _config_dir_defaultzJupyterApp._config_dir_defaultY   s    !###r)   c                j    t                      }| j        |vr|                    d| j                   |S )Nr   )r   
config_dirinsert)r4   paths     r*   config_file_pathszJupyterApp.config_file_paths\   s5    "$$?$&&KK4?+++r)   c                D    t                      }t          |d           |S N  mode)r   r   )r4   ds     r*   _data_dir_defaultzJupyterApp._data_dir_defaultf   s%    !%((((r)   c                D    t                      }t          |d           |S rB   )r   r   )r4   rds     r*   _runtime_dir_defaultzJupyterApp._runtime_dir_defaultm   s%     """5))))	r)   runtime_dirchanget.AnyNonec                4    t          |d         d           d S )NnewrC   rD   )r   )r4   rL   s     r*   _runtime_dir_changedzJupyterApp._runtime_dir_changedr   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replacer3   s    r*   _config_file_name_defaultz$JupyterApp._config_file_name_defaultz   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          t          | j        | j        dz                       t                                                    rs| j        sld}dfd} |            }|                    d          s.t          d            |            }|                    d          .|                    d          rd	S | 	                                }t          d
           t          t                    j                                        d           t          j        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.pyrT   r-   r9   c                     dd} 	 t          |                                           pdS # t          $ r t          d           Y dS w xY w)Nz
Overwrite z with default config? [y/N]nrT   )inputlowerKeyboardInterruptprint)promptconfig_files    r*   askz,JupyterApp.write_default_config.<locals>.ask   sb    PkPPP ==..007C7(   "III33s   ", A	A	)r    r]   zPlease answer 'yes' or 'no'r]   Nz*Writing default config to: {config_file!r}rC   wzutf-8)rE   encodingr-   r9   )rc   r9   r   r=   config_file_nameexistsr   
startswithra   generate_config_filer   parentresolveopenwrite)r4   answerrd   config_textfrc   s        @r*   write_default_configzJupyterApp.write_default_config   s     	T*KKd4?D4IE4QRRSSK##%% 	do 	F      SUUF''
33 3444 ''
33    %% //11:;;;${++2::<<eDDDYtK((sWEEE 	!GGK   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!s   
E--E14E1c                6   	 t          j        t          | j        d          d          }|                                 dS # t          $ r Y nt
          $ r Y dS w xY wddlm}m} t           |                                                      sdS  |             dS )z"Migrate config/data from IPython 3migratedzr+Nr   )get_ipython_dirmigrate)	r   rn   r=   closeFileNotFoundErrorOSErrorrw   rv   ri   )r4   f_markerrv   rw   s       r*   migrate_configzJupyterApp.migrate_config   s    
	ydoz!B!BDIIH NNF ! 	 	 	D 	 	 	FF	 	65555555 OO%%&&--// 	F					s   (A   
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   rc   osr?   splitrh   	Exceptionraise_config_file_errorswarning)r4   r}   base_configr?   rh   	__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rX   c                <    | j          d| }t          |          pdS )NrU   rT   )rX   r   )r4   rX   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
subcommandr3   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   )r4   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   r   execvr   r#   r   startr   rs   r3   s    r*   r   zJupyterApp.start  s    ? 	HT_t&7$)ABB-&GHHH))O; 	K))O 	%%'''))O	 	r)   kwargsc                    t                      }	  t                      j        dd|i| n# t          $ r Y dS w xY w|                                 dS )z+Launch an instance of a Jupyter Applicationr   Nr(   )r   r   launch_instancer#   rx   )clsr   r   loopr   s       r*   r   zJupyterApp.launch_instance  sm     !""	#EGG#8888888 	 	 	FF	

s   - 
;;)r-   r.   )r-   r6   rg   )rL   rM   r-   rN   r-   rN   )T)r}   r~   r-   rN   )rX   r9   r-   r9   )r-   r~   r0   r   rM   r-   rN   r   rM   r   rM   r-   rN   )+r$   r%   r&   r'   rX   descriptionr   aliasesr   flagsr5   r   r	   r   r8   r=   r;   propertyr@   data_dirrG   rK   rJ   r
   rQ   r   r   rh   rZ   rc   r   rs   r|   r   r   r   r   r   r   r   classmethodr   __classcell__)r   s   @r*   r   r   F   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)   c                  d    e Zd ZdZdZdZdZddd
ZddZe	ddd            Z
e	ddd            ZdS )JupyterAsyncAppz3A Jupyter application that runs on an asyncio loop.jupyter_asynczAn Async Jupyter ApplicationFNr   rM   r-   rN   c                
   K   dS )z+Initialize the application asynchronoously.Nr(   )r4   r   s     r*   initialize_asyncz JupyterAsyncApp.initialize_async+  
        r)   c                
   K   dS )z%Run the application in an event loop.Nr(   r3   s    r*   start_asynczJupyterAsyncApp.start_async.  r   r)   r   c                   K    | j         di |}|                    |           |                    |           d {V  |                                 d {V  d S )Nr(   )instancer   r   r   )r   r   r   apps       r*   _launch_instancez JupyterAsyncApp._launch_instance1  s}      cl$$V$$t""4(((((((((oor)   c                    t          | j                  } | j        |fi |}|                    |           |                                 dS )z2Launch an instance of an async Jupyter ApplicationN)r   _prefer_selector_loopr   run_until_completerx   )r   r   r   r   coros        r*   r   zJupyterAsyncApp.launch_instance8  sS     !!:;;#s#D33F33%%%

r)   r0   r   r   r   )r$   r%   r&   r'   rX   r   r   r   r   r   r   r   r(   r)   r*   r   r   "  s        ==D0K ": : : : :4 4 4 4         [      [  r)   r   __main__)4r'   
__future__r   r1   r   r   typingtcopyr   pathlibr   shutilr   	traitletsr   r   r	   r
   traitlets.config.applicationr   r   traitlets.config.loaderr   pathsr   r   r   r   r   r   r   utilsr   r   r   __annotations__
isinstancer   dictupdate_jupyter_aliasesr   r   DEBUGr!   r   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                  8 7 7 7 7 7 7 7 "$ # # # #:k!4(( -+,,,(&     $ % % %!
 ! ! ! !:k&& )k'((( 
gm45B &(94'@ACab	d+,;

$ 
$ 
 
 
 
   . ! ! !A A A A Ai A A AY Y Y Y Y Y Y Yx    j   > z      r)   