
    f(                       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jL                  e'      re#jQ                  ejL                         dddZ)e#jQ                  e)       i Z*de$d<    e%ejV                  e'      re*jQ                  ejV                         ddejX                  iidfdddiidfdddiidfdZ-de$d<   e*jQ                  e-        G d de.      Z/ G d  de      Z0 G d! d"e0      Z1e2d#k(  re0jg                          yy)$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y)NoStartz6Exception to raise when an application shouldn't startN)__name__
__module____qualname____doc__     S/var/www/cvtools/html/venv/lib/python3.12/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!d#dZ"ed$d       Z# e       Z$e%d%d&d       Z&d dZ'e(d%d' fd       Z) xZ*S )(r   z#Base class for Jupyter applicationsjupyterzA Jupyter Applicationc                "    t         j                  S N)loggingINFOselfs    r*   _log_level_defaultzJupyterApp._log_level_defaultO   s    ||r)   c                    t               S r.   )r   r1   s    r*   _jupyter_path_defaultz JupyterApp._jupyter_path_defaultT   s
    ~r)   c                    t               S r.   )r   r1   s    r*   _config_dir_defaultzJupyterApp._config_dir_defaultY   s    !##r)   c                n    t               }| j                  |vr|j                  d| j                         |S )Nr   )r   
config_dirinsert)r2   paths     r*   config_file_pathszJupyterApp.config_file_paths\   s-    "$??$&KK4??+r)   c                4    t               }t        |d       |S N  mode)r   r   )r2   ds     r*   _data_dir_defaultzJupyterApp._data_dir_defaultf   s    !%(r)   c                4    t               }t        |d       |S r>   )r   r   )r2   rds     r*   _runtime_dir_defaultzJupyterApp._runtime_dir_defaultm   s     ""5)	r)   runtime_dirc                $    t        |d   d       y )Nnewr?   r@   )r   )r2   changes     r*   _runtime_dir_changedzJupyterApp._runtime_dir_changedr   s    &-e4r)   FTzGenerate default config file.)r   helpzSpecify a config file to load.c                Z    | j                   sy| j                   j                  dd      dz   S )N -__config)namereplacer1   s    r*   _config_file_name_defaultz$JupyterApp._config_file_name_defaultz   s(    yyyy  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              j                         rb| j                  sVd}dfd} |       }|j                  d      s$t        d        |       }|j                  d      s$|j                  d      ry| j                         }t        dz         t        t              j                  j                         d	       t        j                  t              d
d      5 }|j                  |       ddd       y# 1 sw Y   yxY w)z-Write our default config to a .py config filez.pyrN   c                 ~    dz  } 	 t        |       j                         xs dS # t        $ r t        d       Y yw xY w)Nz'Overwrite %s with default config? [y/N]nrN   )inputlowerKeyboardInterruptprint)promptconfig_files    r*   askz,JupyterApp.write_default_config.<locals>.ask   sC    B[P =..07C7( "Is   % <<)r    rW   zPlease answer 'yes' or 'no'rW   NzWriting default config to: %sr?   wzutf-8)rA   encodingreturnstr)r]   rc   r   r9   config_file_nameexistsr   
startswithr[   generate_config_filer   parentresolveopenwrite)r2   answerr^   config_textfr]   s        @r*   write_default_configzJupyterApp.write_default_config   s   **Kd4??D4I4IE4QRSK##%dooF UF''
334 ''
3   %//1-;<${+22::<eDYYtK(sWE 	!GGK 	! 	! 	!s   .E		Ec                
   	 t        j                  t        | j                  d      d      }|j                          y# t        $ r Y nt
        $ r Y yw xY wddlm}m} t         |             j                         sy |        y)z"Migrate config/data from IPython 3migratedzr+Nr   )get_ipython_dirmigrate)	r   rj   r9   closeFileNotFoundErrorOSErrorrs   rr   re   )r2   f_markerrr   rs   s       r*   migrate_configzJupyterApp.migrate_config   ss    
	yydooz!BDIH NN ! 	 		 	6 O%&--/	s   *= 	AAAc                ~   | j                   j                  d| j                         d}	 t        |   || j                         | j                  r-t        j                  j                  | j                        \  }}n | j                  }| j                  }|r||k(  ry	 t        |   ||       y# t
        $ r | j                   j                  d|       Y w xY w# t
        $ r | j                   j                  d|       Y yt        $ r0 |r| j                  r | j                   j                  d|d	       Y y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   r]   osr;   splitrd   	Exceptionraise_config_file_errorswarning)r2   suppress_errorsbase_configr;   rd   	__class__s        r*   r~   zJupyterApp.load_config_file   s/    	68N8NO&	DG$++ %  %'WW]]43C3C%D"D"))D#44#(8K(G		_G$%5D$A " 	DHHNN5{C	D " 	THHNN@BRS 	_ $(E(EHH<>NY]^	_s)   B2  C 2%CC%D<5D<;D<c                B    | j                    d| }t        |      xs dS )NrO   rN   )rR   r   )r2   rR   s     r*   _find_subcommandzJupyterApp._find_subcommand   s%    ))AdV$T{ b r)   c                d    t        | j                  xs | j                  xs | j                        S )z\Return whether we are dispatching to another command

        or running ourselves.
        )boolr   subapp
subcommandr1   s    r*   _dispatchingzJupyterApp._dispatching   s'     D((JDKKJ4??KKr)   c                f   |t         j                  dd }|r%| j                  |d         }|r|| _        || _        y| j	                  |       t        | j                        }| j                  ry| j                          | j                          | j                  |       t        rt                yy)zInitialize the application.Nr   r   )sysargvr   r   parse_command_liner   r   r   rx   r~   update_configr   r   )r2   r   subc	cl_configs       r*   
initializezJupyterApp.initialize   s     <88AB<D((a1D 	"&%T[[)	9% (* !r)   c                R   | j                   rEt        j                  | j                   | j                   g| j                  dd z          t	               | j
                  r$| j
                  j                          t	               | j                  r| j                          t	               y)zStart the whole thingr   N)	r   r   execvr   r#   r   startr   ro   r1   s    r*   r   zJupyterApp.start  sw    ??HHT__t&7$))AB-&GH)O;;KK)O%%')O  r)   c                |    t               }	 t        |   dd|i| |j	                          y# t        $ r Y yw xY w)z+Launch an instance of a Jupyter Applicationr   Nr(   )r   r}   launch_instancer#   rt   )clsr   kwargsloopr   s       r*   r   zJupyterApp.launch_instance  sF     !"	G#888 	

  		s   / 	;;)rb   int)rb   z	list[str]ra   )rJ   t.Anyrb   Nonerb   r   )T)r   r   rb   r   )rR   rc   rb   rc   )rb   r   r.   r   r   rb   r   r   r   r   r   rb   r   )+r$   r%   r&   r'   rR   descriptionr   aliasesr   flagsr3   r   r	   r   r5   r9   r7   propertyr<   data_dirrC   rG   rF   r
   rK   r   r   rd   rT   r]   r   ro   rx   r~   r   r   r   r   r   r   classmethodr   __classcell__)r   s   @r*   r   r   F   s/   -D)KGE 	?L J$   yH
 )K
 ]5 5 54WXOd1QR7
 .K
 eD/OPJ!>,$_N! L L J+ +,  r)   c                  V    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y)JupyterAsyncAppz3A Jupyter application that runs on an asyncio loop.jupyter_asynczAn Async Jupyter ApplicationFNc                   K   yw)z+Initialize the application asynchronoously.Nr(   )r2   r   s     r*   initialize_asyncz JupyterAsyncApp.initialize_async*          c                   K   yw)z%Run the application in an event loop.Nr(   r1   s    r*   start_asynczJupyterAsyncApp.start_async-  r   r   c                   K    | j                   di |}|j                  |       |j                  |       d {    |j                          d {    y 7 7 w)Nr(   )instancer   r   r   )r   r   r   apps       r*   _launch_instancez JupyterAsyncApp._launch_instance0  sR     cll$V$t""4(((oo 	)s!   8AAAAAAc                    t        | j                        } | j                  |fi |}|j                  |       |j	                          y)z2Launch an instance of an async Jupyter ApplicationN)r   _prefer_selector_loopr   run_until_completert   )r   r   r   r   coros        r*   r   zJupyterAsyncApp.launch_instance7  sB     !!:!:;#s##D3F3%

r)   r.   r   r   r   )r$   r%   r&   r'   rR   r   r   r   r   r   r   r   r(   r)   r*   r   r   !  sI    =D0K ":4      r)   r   __main__)4r'   
__future__r   r/   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      sl   #  	 
     2 2 H 6   8 "$ #k!!4(++,(&    $ %!
 !k&k''( 
gmm45B &(94'@ACab	d+,;

$  
   . !Ai AX Xvj > z  r)   