
    MhI              
       T   d Z ddl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mZ ddlmZmZ ddlmZmZ ddl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"m#Z#m$Z$ ej%        dk    r9ej&        '                    dd          Z(e( e) e	e(          dz            gZ*ng Z*nddgZ*g Z+ej,        -                    ej.        dd          Z/e/e*vre+0                    e/           ej&        '                    d          Z1e1dv rdZ2nEe13                                dv rdZ2n,e13                                dv rdZ2n ej4        de1z             i Z5 e6ej7        e8          re59                    ej7                   e59                    dddddd            e8            Z: e6ej;        e8          re:9                    ej;                   e:9                     e8dd ej<        iid!fdd ej=        iid"fd#ddd$id%f&                      G d' d(e          Z> G d) d#e          Z?dS )*a-  
An application for IPython.

All top-level applications should use the classes in this module for
handling configuration and creating configurables.

The job of an :class:`Application` is to create the master configuration
object and then create the configurable objects, passing the config to them.
    N)deepcopy)Path)Applicationcatch_config_error)ConfigFileNotFoundPyFileConfigLoader)releasecrashhandler)
ProfileDirProfileDirError)get_ipython_dirget_ipython_package_dir)ensure_dir_exists)	ListUnicodeTypeBoolSetInstance	UndefineddefaultobserventPROGRAMDATAipythonz/usr/local/etc/ipythonz/etc/ipythonetcIPYTHON_SUPPRESS_CONFIG_ERRORS>   N >   1trueT>   0falseFzUnsupported value for environment variable: 'IPYTHON_SUPPRESS_CONFIG_ERRORS' is set to '%s' which is none of  {'0', '1', 'false', 'true', ''}.ProfileDir.locationzBaseIPythonApplication.profilez"BaseIPythonApplication.ipython_dirzApplication.log_levelz(BaseIPythonApplication.extra_config_file)zprofile-dirprofilezipython-dirz	log-levelconfigr   	log_levelz8set log level to logging.DEBUG (maximize logging output)z;set log level to logging.CRITICAL (minimize logging output)BaseIPythonApplication)copy_config_filesauto_createzInitialize profile with default config files.  This is equivalent
            to running `ipython profile create <profile>` prior to startup.
            )debugquietinitc                   $     e Zd ZdZd fd	Z xZS )ProfileAwareConfigLoaderz>A Python file config loader that is aware of IPython profiles.Nc                     |;	 t          j        t                      |          }n# t          $ r Y d S w xY w|j        }t          t          |                               ||          S )Npath)r   find_profile_dir_by_namer   r   locationsuperr.   load_subconfig)selffnamer1   r$   profile_dir	__class__s        X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/IPython/core/application.pyr5   z'ProfileAwareConfigLoader.load_subconfigq   s    (A'))  #   'D-t44CCEPTCUUUs   !' 
55)NN)__name__
__module____qualname____doc__r5   __classcell__r9   s   @r:   r.   r.   o   sM        HH
V 
V 
V 
V 
V 
V 
V 
V 
V 
V    r.   c                   :    e Zd ZdZdZ eej                  ZeZ	e
Z eeg          ZeZ e            Z e            Z ed          d             Z ed          d             Z eej                             e            ddd                    Z e e                      Z ed	          d
             Z ed                              d          Z  ed          d             Z! edd                              d          Z" ed          d             Z# e$dd                              d          Z% ed                              d          Z& ed          d             Z'dZ( e)ed          Z* ed          d             Z+ e$dd                              d          Z, e$dd                              d          Z- e e                      Z. ed          d             Z/ e$dd                              d          Z0 e$dd                               d          Z1 e2e3j4                  Z5e6 fd!            Z7d" Z8d# Z9 ed          d$             Z:e;fd%Z<d& Z=d' Z>d( Z?e6d+d*            Z@ xZAS ),r'   r   z.IPython: an enhanced interactive Python shell.config_file_namec                 >    | j                             dd          dz   S )N-_z
_config.py)namereplacer6   s    r:   _config_file_name_defaultz0BaseIPythonApplication._config_file_name_default   s    y  S))M99rA   c                 n    |d         |d         k    r"| j                             |d                    d S d S )Nnewold)config_file_specifiedaddr6   changes     r:   _config_file_name_changedz0BaseIPythonApplication._config_file_name_changed   s>    %=F5M))&**6%=99999 *)rA   r%   r$   r   config_file_pathsc                     g S N rI   s    r:   _config_file_paths_defaultz1BaseIPythonApplication._config_file_paths_default   s    	rA   zPath to an extra config file to load.
    
    If specified, load this config file in addition to any other IPython config.
    )helpT)r%   extra_config_filec                     |d         }|d         }	 | j                             |           n# t          $ r Y nw xY w| j                            |           | j                             |           d S )NrM   rL   )config_filesremove
ValueErrorrN   rO   append)r6   rQ   rM   rL   s       r:   _extra_config_file_changedz1BaseIPythonApplication._extra_config_file_changed   s    UmUm	$$S)))) 	 	 	D	"&&s+++  %%%%%s   - 
::zThe IPython profile to use.c                 x    t           j                            t                      dd|d                   | _        d S )Nr%   r$   rL   )osr1   joinr   builtin_profile_dirrP   s     r:   _profile_changedz'BaseIPythonApplication._profile_changed   s3    #%7<<'))9j&-$
 $
   rA   Fah  Should the IPython profile directory be added to sys path ?

        This option was non-existing before IPython 8.0, and ipython_dir was added to
        sys path to allow import of extensions present there. This was historical
        baggage from when pip did not exist. This now default to false,
        but can be set to true for legacy reasons.
        a  
        The name of the IPython directory. This directory is used for logging
        configuration (through profiles), history storage, etc. The default
        is usually $HOME/.ipython. This option can also be specified through
        the environment variable IPYTHONDIR.
        ipython_dirc                 T    t                      }|                     d||d           |S )Nre   )rG   rM   rL   )r   _ipython_dir_changed)r6   ds     r:   _ipython_dir_defaultz+BaseIPythonApplication._ipython_dir_default   s?    !!!#
 #
 	 	 	
 rA   )
allow_noner8   c                 J    | j         rd S |                                  | j        S rU   )_in_init_profile_dirinit_profile_dirr8   rI   s    r:   _profile_dir_defaultz+BaseIPythonApplication._profile_dir_default   s/     $ 	FrA   z7Whether to overwrite existing config files when copyingz1Whether to create profile dir if it doesn't existr[   c                     | j         gS rU   )rC   rI   s    r:   _config_files_defaultz,BaseIPythonApplication._config_files_default   s    %&&rA   a,  Whether to install the default config files into the profile dir.
        If a new profile is being created, and IPython contains config files for that
        profile, then they will be staged into the new directory.  Otherwise,
        default config files will be automatically generated.
        zCreate a massive crash report when IPython encounters what may be an
        internal error.  The default is to append a short message to the
        usual tracebackc                      t          t          |           j        di | 	 t          j                     d S #  | j                            d           |                     d           Y d S xY w)Nz(Current working directory doesn't exist.   rV   )r4   r'   __init__ra   getcwdlogerrorexit)r6   kwargsr9   s     r:   rs   zBaseIPythonApplication.__init__  sn    4$d++4>>v>>>	IKKKKK	HNNEFFFIIaLLLLLLs	   8 1A,c                     |                      |           | _        | j        t          _        d }t	          j        |           dS )z?Create a crash handler, typically setting sys.excepthook to it.c                  2    t           j        t           _        d S rU   )sys__excepthook__
excepthookrV   rA   r:   unset_crashhandlerzEBaseIPythonApplication.init_crash_handler.<locals>.unset_crashhandler  s     /CNNNrA   N)crash_handler_classcrash_handlerr}   r{   atexitregister)r6   r~   s     r:   init_crash_handlerz)BaseIPythonApplication.init_crash_handler  sG    !55d;;	0 	0 	0*+++++rA   c                 j    | j         r|                     |||          S t          j        |||          S )zthis is sys.excepthook after init_crashhandler

        set self.verbose_crash=True to use our full crashhandler, instead of
        a regular traceback with a short message (crash_handler_lite)
        )verbose_crashr   r
   crash_handler_lite)r6   etypeevaluetbs       r:   r}   z!BaseIPythonApplication.excepthook  s=      	F%%eVR88825&"EEErA   c                    |d         }|d         }|t           urLt          j                            |          }|t          j        v rt          j                            |           | j        rst          j                            |          }t          j                            |           t          |           t          j        	                    |d          }t          j        	                    t                      ddd          }t          j                            |          s4t          j                            |          rt          j        ||           dD ]e}t          j        	                    ||          }		 t          |	           3# t          $ r&}
| j                            d|	|
           Y d }
~
^d }
~
ww xY w| j                            d|           d S d S )	NrM   rL   READMEr%   r$   )
extensionsnbextensionszcouldn't create path %s: %szIPYTHONDIR set to: %s)r   ra   r1   abspathr{   r\   add_ipython_dir_to_sys_pathr^   r   rb   r   existsshutilcopyOSErrorru   rv   r*   )r6   rQ   rM   rL   str_oldstr_pathreadme
readme_srcrh   r1   es              r:   rg   z+BaseIPythonApplication._ipython_dir_changed$  s   UmUmigooc**G#(""(((+ 	9ws++HHOOH%%%c"""W\\#x00F'))8Y J 7>>&)) 0bgnnZ.H.H 0J///3 K Kw||C++K%d++++ K K KHNN#@$JJJJJJJJK HNN2C88888#	9 	9s   F
GF<<Gc                    | j                             d| j                   d}| j                             d|z             	 |t          j        }| t          _        t          j        | || j                   n+# t          $ r | j                             d|           Y nw xY w||t          _        | j        D ]}|r||k    r| j                             d| j        z             	 t          j        | || j                   K# t          $ r1 || j	        v r| j         j
        }n| j         j        } |d|           Y t          $ r* |s | j         
                    d| j        z  d	
           Y w xY wdS )as  Load 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.

        `suppress_errors` default value is to be `None` in which case the
        behavior default to the one of `traitlets.Application`.

        The default value can be set :
           - to `False` by setting 'IPYTHON_SUPPRESS_CONFIG_ERRORS' environment variable to '0', or 'false' (case insensitive).
           - to `True` by setting 'IPYTHON_SUPPRESS_CONFIG_ERRORS' environment variable to '1' or 'true' (case insensitive).
           - to `None` by setting 'IPYTHON_SUPPRESS_CONFIG_ERRORS' environment variable to '' (empty string) or leaving it unset.

        Any other value are invalid, and will make IPython exit with a non-zero return code.
        z"Searching path %s for config fileszipython_config.pyz"Attempting to load config file: %sNr0   zConfig file %s not foundz#Config file not found, skipping: %szError loading config file: %sT)exc_info)ru   r*   rS   r   raise_config_file_errorsload_config_filer   r[   rC   rN   warning	Exception)r6   suppress_errorsbase_config	old_valuerC   msgs         r:   r   z'BaseIPythonApplication.load_config_file?  s#   & 	;T=STTT);"# 	$ 	$ 	$	*'@	;J7J4(+    
 " 	 	 	HNN5{CCCD	 &3<K0 $ 1 	D 	D# '7;'F'FHNN?01 2 2 2D,$/    
 & M M M#t'AAA(*CC(.C9;KLLLLL D D D&   !@"3"4>B ! D D D D D	D%	D 	Ds*   7A9 9%B! B!'D8E1>0E10E1c                    d| _         | j        dS d| j        vr2	 t          j        | j        | j        | j                  }| j                            d|j	                   nC# t          $ r | j        s| j        dk    r	 t          j        | j        | j        | j                  }| j                            d|j	        z             n~# t          $ r: | j                            d| j        z             |                     d           Y n;w xY w| j                            d	| j        z             |                     d           Y n]w xY w| j        j        j	        }	 t          j        || j                  }| j                            d|j	                   n# t          $ r | j        r{	 t          j        || j                  }| j                            d
|z             nt# t          $ r5 | j                            d|z             |                     d           Y n6w xY w| j                            d|z             |                     d           Y nw xY wt$          j                            |j	                  }|                    d          r|dd         | _        || _        | j                            |j	                   d| _         dS )zinitialize the profile dirTNr#   zUsing existing profile dir: %rr   zCreated profile dir: %rzCould not create profile: %rrr   zProfile %r not found.zCreating new profile dir: %rz&Could not create profile directory: %rzProfile directory %r not found.profile_   F)rl   r8   r%   r   r2   re   r$   ru   r*   r3   r   r)   create_profile_dir_by_nameinfofatalrw   find_profile_dircreate_profile_dirra   r1   basename
startswithrS   r^   )r6   pr3   dir_names       r:   rm   z'BaseIPythonApplication.init_profile_dir  s   $(!'F 33M78H$,X\Xcdd ?LLLL # ! ! !# 
!t|y'@'@L&A$BRTXT`bfbmnn
 &?
&JKKKK	 + % % %'Edl'RSSS		!% HNN#:4<#GHHHIIaLLL!  {-6HM/$+FF ?LLLL # ! ! !# 
!P&9(DKPP
 'Eh'NOOOO	 + % % %'OPX'XYYY		!% HNN#DX#MNNNIIaLLL!  w''
33H"":.. ,'|%%aj111$)!!!sl   %A# #E
 %C%#E
AD	E
D:E
	E
F I,G$I$<H# I"H##5IIc                    | j                             t                     | j                             t                     t	          | j                  }| j        r| j        }| j        }|rq||z  	                                rZ| j
                            d|d|d| j        j        d| j        d	           | j                            ||| j                   d
S |                                  d
S |                    d          }|D ]X}|j        }| j                            ||d          r2| j
                            d	|d| j        d| j        j                   Yd
S )z8[optionally] copy default config files into profile dir.zStaging z from z into z [overwrite=])r1   	overwritez*.pyFzStaging bundled N)rS   extendENV_CONFIG_DIRSSYSTEM_CONFIG_DIRSr   rc   r(   r$   rC   r   ru   r   r8   r3   r   copy_config_filestage_default_config_fileglobrG   )r6   r1   srccfgfilesfullpaths         r:   init_config_filesz(BaseIPythonApplication.init_config_files  s   %%o666%%&8999D,--! 	,C'C 1++-- 1   ssCCC!1!:!:!:DNNNL    11#DDN1[[[[[..00000
 IIf%%E!  m#44Stu4UU H$$$CCt/?/H/H&J   	 rA   c                    |                                  }t          | j        j                  | j        z  }| j        s|                                s4| j                            d|           |	                    |d           dS dS )zAauto generate default config file, and stage it into the profile.z"Generating default config file: %rzutf-8)encodingN)
generate_config_filer   r8   r3   rC   r   r   ru   r   
write_text)r6   sconfig_files      r:   r   z0BaseIPythonApplication.stage_default_config_file  s    %%''4+4558MM> 	8!3!3!5!5 	8HAKQQQ""1w"77777	8 	8rA   Nc                 4   |                      |           |                                  | j        d S t          | j                  }|                                  |                                  |                                  |                     |           d S rU   )	parse_command_liner   subappr   r%   rm   r   r   update_config)r6   argv	cl_configs      r:   
initializez!BaseIPythonApplication.initialize  s     	%%%!!!;"F T[))	   9%%%%%rA   rU   )Br;   r<   r=   rG   descriptionr   r	   versionbase_aliasesaliases
base_flagsflagsr   r   classesr.   python_config_loader_classr   rN   rC   r   rJ   r   rR   ra   r1   rb   r   rc   rS   rW   tagrY   r_   r$   rd   r   r   re   ri   rl   r   r8   rn   r   r)   r[   rp   r(   r   r   r
   CrashHandlerr   r   rs   r   r}   rg   r   r   rm   r   r   r   r?   r@   s   @r:   r'   r'   }   s       DBKggo&&GGEdJ<  G ":  CEEwyyW  : : ! :W  : : ! :
 "'
,,..	:zRR  WWYYW !!  "!  
	 	 	 
D			 
 W !!& & "!& gj.  	cc  WY
 
 

 #'$		# 	# 
cc   '   
cc  W]   !(:$777KW]      UJ  	cc  $uD  	cc  4		??LW^' ' ' U  
 SS  D    CtC,,  $|899    , , ,
F 
F 
F W]9 9 94 0N >D >D >D >D@4* 4* 4*l  @8 8 8 & & & & & & & &rA   )@r>   r   r   r   loggingra   r   r{   pathlibr   traitlets.config.applicationr   r   traitlets.config.loaderr   r   IPython.corer	   r
   IPython.core.profiledirr   r   IPython.pathsr   r   IPython.utils.pathr   	traitletsr   r   r   r   r   r   r   r   r   rG   environgetprogramdatastrr   r   r1   rb   prefix_env_config_dirr^   _envvarr   lowerrw   r   
isinstancer   dictupdater   r   DEBUGCRITICALr.   r'   rV   rA   r:   <module>r      s!            				  



       H H H H H H H H J J J J J J J J . . . . . . . . ? ? ? ? ? ? ? ? B B B B B B B B 0 0 0 0 0 0                     
 7d??*..55K!c$${"3"3i"?@@A 	! ',,sz5)<<,,,?+++ *..9
:
:
j%)""}},&&)-&&	M	)	)).&&  b  dk  k  	m  	m  	m :k!4(( -+,,,   ,3;,<    TVV
:k&& )k'((( 
  D['-89F

 ['*:;<I
 ))-#'+ +

    2V V V V V1 V V Vo& o& o& o& o&[ o& o& o& o& o&rA   