
    @e$                    z   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jF                  e$      re jK                  ejF                         dddZ&e jK                  e&       i Z'de!d<    e"ejP                  e$      re'jK                  ejP                         ddejR                  iidfdddiidfdddiidfdZ*de!d<   e'jK                  e*        G d de+      Z, G d de      Z-e.d k(  re-j_                          yy)!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y)NoStartz6Exception to raise when an application shouldn't startN)__name__
__module____qualname____doc__     :/usr/lib/python3/dist-packages/jupyter_core/application.pyr"   r"   A   s    @r(   r"   c                      e Zd ZU dZdZdZeZeZ	ddZ
 e e             Zded<   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_defaultN   s    ||r(   zlist[str] | Listr   c                    t               S r-   )r   r0   s    r)   _jupyter_path_defaultz JupyterApp._jupyter_path_defaultS   s
    ~r(   c                    t               S r-   )r   r0   s    r)   _config_dir_defaultzJupyterApp._config_dir_defaultX   s    !##r(   c                n    t               }| j                  |vr|j                  d| j                         |S )Nr   )r   
config_dirinsert)r1   paths     r)   config_file_pathszJupyterApp.config_file_paths[   s-    "$??$&KK4??+r(   c                4    t               }t        |d       |S N  mode)r   r   )r1   ds     r)   _data_dir_defaultzJupyterApp._data_dir_defaulte   s    !%(r(   c                4    t               }t        |d       |S r=   )r   r   )r1   rds     r)   _runtime_dir_defaultzJupyterApp._runtime_dir_defaultl   s     ""5)	r(   runtime_dirc                $    t        |d   d       y )Nnewr>   r?   r   )r1   changes     r)   _runtime_dir_changedzJupyterApp._runtime_dir_changedq   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replacer0   s    r)   _config_file_name_defaultz$JupyterApp._config_file_name_defaulty   s(    yyyy  c*Y66r(   zFull path of a config file.zAnswer yes to any prompts.c                   | j                   r| j                   n7t        j                  j                  | j                  | j
                  dz         t        j                  j                        rb| j                  sVd}dfd} |       }|j                  d      s$t        d        |       }|j                  d      s$|j                  d      ry| j                         }t        |t              r|j                  d      }t        d	z         t        t        j                  j                  t        j                  j!                              d
       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.pyrM   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]nrM   )inputlowerKeyboardInterruptprint)promptconfig_files    r)   askz,JupyterApp.write_default_config.<locals>.ask   sC    B[P =..07C7( "Is   % <<)r   rV   zPlease answer 'yes' or 'no'rV   Nutf8zWriting default config to: %sr>   wzutf-8)r@   encodingreturnstr)r\   osr:   joinr8   config_file_nameexistsr   
startswithrZ   generate_config_file
isinstancebytesdecoder   abspathdirnameopenwrite)r1   answerr]   config_textfr\   s        @r)   write_default_configzJupyterApp.write_default_config   s.   **K'',,t8M8MPU8UVK77>>+&tF UF''
334 ''
3   %//1k5)%,,V4K-;<"''//"''//+*FGO+C': 	!aGGK 	! 	! 	!s   &FF
c                *   	 t        t        j                  j                  | j                  d      d      }|j                          y# t        $ r Y yt        $ r Y nw xY wddlm	}m} t        j                  j                   |             sy |        y)z"Migrate config/data from IPython 3migratedzr+Nr   )get_ipython_dirmigrate)ro   rd   r:   re   r8   closePermissionErrorFileNotFoundErrorrx   rw   rg   )r1   f_markerrw   rx   s       r)   migrate_configzJupyterApp.migrate_config   sv    
	BGGLL*EtLH NN  	  		 	6 ww~~o/0	s   4A 	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\   rd   r:   splitrf   	Exceptionraise_config_file_errorswarning)r1   suppress_errorsbase_configr:   rf   	__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 )NrN   rM   )rQ   r   )r1   rQ   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
subcommandr0   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   r}   r   update_configr   r   )r1   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   rd   execvr   r"   r   startr   rt   r0   s    r)   r   zJupyterApp.start  sw    ??HHT__t&7$))AB-&GH)O;;KK)O%%')O  r(   c                H    	 t        |   dd|i| y# t        $ r Y yw xY w)z+Launch an instance of a Jupyter Applicationr   Nr'   )r   launch_instancer"   )clsr   kwargsr   s      r)   r   zJupyterApp.launch_instance  s/    	G#888 		s    	!!)rb   int)rb   z	list[str]ra   )rI   t.Anyrb   None)rb   r   )T)r   r   rb   r   )rQ   rc   rb   rc   )rb   r   r-   )r   r   rb   r   )r   r   r   r   rb   r   ),r#   r$   r%   r&   rQ   descriptionr   aliasesr   flagsr2   r   r   r   __annotations__r4   r8   r6   propertyr;   data_dirrB   rF   rE   r	   rJ   r   r   rf   rS   r\   r   rt   r}   r   r   r   r   r   r   r   classmethodr   __classcell__)r   s   @r)   r   r   E   s6   -D)KGE &*')_L"4 J$   yH
 )K
 ]5 5 54WXOd1QR7
 .K
 eD/OPJ!B,$_N! L L J+ +,  r(   __main__)0r&   
__future__r   r.   rd   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   r   rj   r   dictupdate_jupyter_aliasesr   r   DEBUGr    r   r"   r   r#   r   r'   r(   r)   <module>r      s]   #  	 
    2 2 H 6   % "$ #k!!4(++,(&    $ %!
 !k&k''( 
gmm45B &(94'@ACab	d+,;

$  
   . !Ai AW Wt z  r(   