
    &e*0                        d 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 ddl
mZ ddlm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 ddlmZmZ ddlm Z m!Z!m"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-m.Z. dZ/ G d de          Z0 e1e          Z2e23                    e!           i Z4d Z5 e5dddd            e5dddd            e5d d!d"d#            e5d$d%d&d'            e5d(d)d*d+            e            Z6de6j7        _8        d,e6j        _9        d-e6j&        _:        d.e6j7        _;        d.e6j7        _<        d.e6j7        _=        d/e6j7        _>        d0e6j7        _?        e6d1fe4d2<   d3d4d5iid6fe4d4<   d3d7d5iid8fe4d9<   e23                    e4            e1e          Z@e@3                    e"            G d: d;e          ZA G d< d3ee           ZBd>d=ZCeBjD        ZEdS )?zp
The :class:`~traitlets.config.application.Application` object for the command
line :command:`ipython` program.
    N)Config)boolean_flagcatch_config_error)release)usage)IPCompleter)CrashHandler)PlainTextFormatter)HistoryManager)
ProfileDirBaseIPythonApplication
base_flagsbase_aliases)MagicsManager)ScriptMagicsLoggingMagics)InteractiveShellAppshell_flagsshell_aliases)StoreMagics   )TerminalInteractiveShell)get_ipython_dir)BoolListdefaultobserveTypea  
ipython --matplotlib       # enable matplotlib integration
ipython --matplotlib=qt    # enable matplotlib integration with qt4 backend

ipython --log-level=DEBUG  # set logging to DEBUG
ipython --profile=foo      # start with profile foo

ipython profile create foo # create profile foo w/ default config files
ipython help profile       # show the help for the profile subcmd

ipython locate             # print the path to the IPython directory
ipython locate profile foo # print the path to the directory for profile `foo`
c                   ,     e Zd ZdZ fdZ fdZ xZS )IPAppCrashHandlerzDsys.excepthook for IPython itself, leaves a detailed report on disk.c                     t           j        }t           j        }d}t          t          |                               ||||           d S )Nz)https://github.com/ipython/ipython/issues)r   authorauthor_emailsuperr    __init__)selfappcontact_namecontact_emailbug_tracker	__class__s        6lib/python3.11/site-packages/IPython/terminal/ipapp.pyr%   zIPAppCrashHandler.__init__B   sM    ~,A%%..}k	
 	
 	
 	
 	
    c                 d   | j         }t          t          |                               |          g}|j        }	  ||dz              | j        j        j        d         D ]} ||            |d            || j        j        j        dz              n#  Y nxY wd	                    |          S )z*Return a string containing a crash report.zHistory of session input:_ihz7
*** Last line of input (may not be in above history):

 )
section_sepr$   r    make_reportappendr'   shelluser_ns_last_input_linejoin)r&   	tracebacksec_sepreportrpt_addliner+   s         r,   r3   zIPAppCrashHandler.make_reportJ   s     ")400<<YGGH-	GG77888.u5  GOPPPGDHN3D89999	Dwwvs   AB B)__name__
__module____qualname____doc__r%   r3   __classcell__r+   s   @r,   r    r    ?   sW        NN
 
 
 
 
        r-   r    c                  D    t                               t          |            S N)frontend_flagsupdater   )argss    r,   <lambda>rI   c   s    --lD.ABB r-   zautoedit-syntaxz(TerminalInteractiveShell.autoedit_syntaxz1Turn on auto editing of files with syntax errors.z2Turn off auto editing of files with syntax errors.zsimple-promptz&TerminalInteractiveShell.simple_promptz-Force simple minimal prompt using `raw_input`z1Use a rich interactive prompt with prompt_toolkitbannerz!TerminalIPythonApp.display_bannerz'Display a banner upon starting IPython.z-Don't display a banner upon starting IPython.zconfirm-exitz%TerminalInteractiveShell.confirm_exitzSet to confirm when you try to exit IPython with an EOF (Control-D
    in Unix, Control-Z/Enter in Windows). By typing 'exit' or 'quit',
    you can force a direct exit without any confirmation.z#Don't prompt the user when exiting.z
term-titlez#TerminalInteractiveShell.term_titlez'Enable auto setting the terminal title.z(Disable auto setting the terminal title.Fz'IPython.terminal.prompts.ClassicPromptsr1   NoColorPlainz:Gives IPython a similar feel to the classic Python prompt.classicTerminalIPythonAppquickTz*Enable quick startup with no config files.force_interactzIf running code from the command line, become interactive afterwards.
    It is often useful to follow this with `--` to treat remaining flags as
    script arguments.
    ic                   0    e Zd ZdZ ed          Zd ZdS )LocateIPythonAppz!print the path to the IPython dir)z%IPython.core.profileapp.ProfileLocatez.print the path to an IPython profile directory)profilec                 n    | j         | j                                         S t          | j                   d S rE   )subappstartprintipython_dirr&   s    r,   rW   zLocateIPythonApp.start   s5    ;";$$&&&$"#####r-   N)r>   r?   r@   descriptiondictsubcommandsrW    r-   r,   rS   rS      sC        9K$
  K
$ $ $ $ $r-   rS   c                       e Zd ZdZej        ZeZe	Z
eZeZ e            Z eeed                              d          Z ed          d             Z edd	d
ej        fd          Z ed          Z edd                              d          Z ed          d             Z edd                              d          Z edd                              d          Z ed          d             Z  eddd          d             Z! ed          Z"e#d  fd	            Z$d Z%d Z&d Z'd Z( xZ)S )!rN   ipythonz\Class to use to instantiate the TerminalInteractiveShell object. Useful for custom Frontends)klassdefault_valuehelpT)configclassesc                     t           | j        t          t          t          t
          t          t          t          t          t          gS )zCThis has to be in a method, for TerminalIPythonApp to be available.)r   r+   r   r   r   r   r
   r   r   r   r   rZ   s    r,   _classes_defaultz#TerminalIPythonApp._classes_default   s1      N$
 	
r-   )z"IPython.core.profileapp.ProfileAppz#Create and manage IPython profiles.)zipykernel.kernelapp.IPKernelAppz,Start a kernel without an attached frontend.z'IPython.terminal.ipapp.LocateIPythonApp)z"IPython.core.historyapp.HistoryAppz$Manage the IPython history database.)rT   kernellocatehistoryFz>Start IPython quickly by skipping the loading of config files.)rc   rO   c                 *    |d         r
d | _         d S d S )Nnewc                      d S rE   r^   )akws     r,   rI   z3TerminalIPythonApp._quick_changed.<locals>.<lambda>   s    T r-   )load_config_filer&   changes     r,   _quick_changedz!TerminalIPythonApp._quick_changed   s)    %= 	:$9$9D!!!	: 	:r-   z2Whether to display a banner upon starting IPython.zIf a command or file is given via the command-line,
        e.g. 'ipython foo.py', start an interactive shell after executing the
        file or command.rP   c                 (    |d         r	d| _         d S d S )Nrl   T)interactrq   s     r,   _force_interact_changedz*TerminalIPythonApp._force_interact_changed   s#    %= 	! DMMM	! 	!r-   file_to_runcode_to_runmodule_to_runc                 P    |d         }|rd| _         |r| j        sd| _        d S d S d S )Nrl   TF)something_to_runrP   ru   )r&   rr   rl   s      r,   _file_to_run_changedz'TerminalIPythonApp._file_to_run_changed   sL    Um 	)$(D! 	&t* 	& %	& 	& 	& 	&r-   Nc                    t          t          |                               |           | j        dS | j        r| j        s| j        d         | _        |                                  |                                  | 	                                 | 
                                 |                                  |                                  dS )z8Do actions after construct, but before starting the app.Nr   )r$   rN   
initializerV   
extra_argsr{   rw   	init_path
init_shellinit_bannerinit_gui_pylabinit_extensions	init_code)r&   argvr+   s     r,   r~   zTerminalIPythonApp.initialize
  s     	 $''224888;"F? 	24#8 	2#q1Dr-   c                     | j                             | | j        | j        | j                  | _        | j        j                            |            dS )z(initialize the InteractiveShell instance)parentprofile_dirrY   r6   N)interactive_shell_classinstancer   rY   r6   r5   configurablesr4   rZ   s    r,   r   zTerminalIPythonApp.init_shell  sX     1::$$($4$($4dl ; L L
 	
 ''-----r-   c                     | j         r | j        r| j                                         | j        t
          j        k    rt                       dS dS )zoptionally display the bannerN)display_bannerru   r5   show_banner	log_levelloggingINFOrX   rZ   s    r,   r   zTerminalIPythonApp.init_banner)  sK     	%4= 	%J""$$$>W\))577777))r-   c                 L    |dk    rt          j        d           d| _        dS dS )z,Replace --pylab='inline' with --pylab='auto'inlinez>'inline' not available as pylab backend, using 'auto' instead.autoN)warningswarnpylab)r&   nameoldrl   s       r,   _pylab_changedz!TerminalIPythonApp._pylab_changed0  s6    (??M . / / /DJJJ ?r-   c                 h   | j         | j                                         S | j        r5| j                            d           | j                                         d S | j                            d           | j                                         | j        j        st          j
        d           d S d S )NzStarting IPython's mainloop...zIPython not interactive...r   )rV   rW   ru   logdebugr5   mainlooprestore_term_titlelast_execution_succeededsysexitrZ   s    r,   rW   zTerminalIPythonApp.start7  s    ;";$$&&&= 	HNN;<<<J!!!!!HNN7888J))+++:6  r-   rE   )*r>   r?   r@   r   r   cl_usager[   r    crash_handler_class	_examplesexamplesflagsaliasesr   re   r   objectr   tagr   r   rg   r\   rS   r]   r   auto_createrO   r   rs   r   rP   rv   r|   r{   r   r~   r   r   r   rW   rB   rC   s   @r,   rN   rN      se       D.K+HEGdffG"d.k   
cc	  WY
 
 
  $

 :(

  K" T

KDQ  	cc 
 WW: : : T$A  	cc  T%   
cc	 
 W! ! ! W]M?;;& & <;& T%[[     &	. 	. 	.3 3 3           r-   c                     | t                      } t          j                            | d          }t	                      }|j                            |           |                                 |j        S )zhLoad the default config file from the default ipython_dir.

    This is useful for embedded shells.
    Nprofile_default)	r   ospathr8   rN   config_file_pathsr4   rp   rd   )rY   r   r'   s      r,   load_default_configr   D  sg    
 %''',,{,=>>K


C  ---:r-   rE   )FrA   r   r   r   r   traitlets.config.loaderr   traitlets.config.applicationr   r   IPython.corer   r   IPython.core.completerr   IPython.core.crashhandlerr	   IPython.core.formattersr
   IPython.core.historyr   IPython.core.applicationr   r   r   r   IPython.core.magicr   IPython.core.magicsr   r   IPython.core.shellappr   r   r   IPython.extensions.storemagicr   interactiveshellr   IPython.pathsr   	traitletsr   r   r   r   r   r   r    r\   r   rG   rF   addflagclassic_configInteractiveShell
cache_sizepprintprompts_classseparate_inseparate_outseparate_out2colorsxmoder   rS   rN   r   launch_instancelaunch_new_instancer^   r-   r,   <module>r      sq     				 



  * * * * * * I I I I I I I I                   . . . . . . 2 2 2 2 2 2 6 6 6 6 6 6 / / / / / /            - , , , , ,                 6 5 5 5 5 5 6 6 6 6 6 6 ) ) ) ) ) )             	$       B 	Z [   
B
B E;<   A7;  
 517   ?= *	   ;-.   -.  *+0 ! (6_ ' 5.0  +/1  ,02  -)2  &(/  % @y  Wt,-0w  -56s  ^   
$|

 }   $ $ $ $ $- $ $ $O O O O O/1D O O Ob    )8   r-   