o
    ˷e0                     @   sh  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 deZ0e1eZ2e23e! i Z4dd Z5e5dddd e5dddd  e5d!d"d#d$ e5d%d&d'd( e5d)d*d+d, e Z6de6j7_8d-e6j_9d.e6j&_:d/e6j7_;d/e6j7_<d/e6j7_=d0e6j7_>d1e6j7_?e6d2fe4d3< d4d5d6iid7fe4d5< d4d8d6iid9fe4d:< e23e4 e1eZ@e@3e" G d;d< d<eZAG d=d4 d4ee ZBdAd>d?ZCeBjDZEeFd@kr2eE  dS dS )Bzp
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                       s,   e Zd ZdZ fddZ fddZ  ZS )IPAppCrashHandlerzDsys.excepthook for IPython itself, leaves a detailed report on disk.c                    s*   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__ M/var/www/ideatree/venv/lib/python3.10/site-packages/IPython/terminal/ipapp.pyr"   C   s   
zIPAppCrashHandler.__init__c                    sx   | j }tt| |g}|j}z#||d  | jjjd D ]}|| q|d || jjjd  W n   Y 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(   r*   r+   r0   K   s   

zIPAppCrashHandler.make_report)__name__
__module____qualname____doc__r"   r0   __classcell__r*   r*   r(   r+   r   @   s    r   c                  G   s   t t|  S N)frontend_flagsupdater   )argsr*   r*   r+   <lambda>d   s    rD   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.ClassicPromptsr.   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                   @   s"   e Zd ZdZeddZd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                 C   s"   | j d ur
| j  S t| j d S r@   )subappstartprintipython_dirr#   r*   r*   r+   rP      s   

zLocateIPythonApp.startN)r;   r<   r=   descriptiondictsubcommandsrP   r*   r*   r*   r+   rM      s    rM   c                       s  e Zd ZdZejZeZe	Z
eZeZe ZeeeddjddZeddd Zed	d
dejfddZedZedddjddZeddd ZedddjddZedddjddZeddd Z eddddd Z!edZ"e#d) fdd 	Z$d!d" Z%d#d$ Z&d%d& Z'd'd( Z(  Z)S )*rI   ipythonz\Class to use to instantiate the TerminalInteractiveShell object. Useful for custom Frontends)klassdefault_valuehelpT)configclassesc                 C   s   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   rS   r*   r*   r+   _classes_default   s   z#TerminalIPythonApp._classes_default)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.)rN   kernellocatehistoryFz>Start IPython quickly by skipping the loading of config files.)rZ   rJ   c                 C   s   |d rdd | _ d S d S )Nnewc                  _   s   d S r@   r*   )akwr*   r*   r+   rD      s    z3TerminalIPythonApp._quick_changed.<locals>.<lambda>)load_config_filer#   changer*   r*   r+   _quick_changed   s   z!TerminalIPythonApp._quick_changedz2Whether 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.rK   c                 C   s   |d r	d| _ d S d S )Nra   T)interactre   r*   r*   r+   _force_interact_changed   s   
z*TerminalIPythonApp._force_interact_changedfile_to_runcode_to_runmodule_to_runc                 C   s.   |d }|r	d| _ |r| jsd| _d S d S d S )Nra   TF)something_to_runrK   rh   )r#   rf   ra   r*   r*   r+   _file_to_run_changed   s   

z'TerminalIPythonApp._file_to_run_changedNc                    sj   t t| | | jdurdS | jr| js| jd | _|   |   | 	  | 
  |   |   dS )z8Do actions after construct, but before starting the app.Nr   )r!   rI   
initializerO   
extra_argsrm   rj   	init_path
init_shellinit_bannerinit_gui_pylabinit_extensions	init_code)r#   argvr(   r*   r+   ro     s   
zTerminalIPythonApp.initializec                 C   s.   | j j| | j| j| jd| _| jj|  dS )z(initialize the InteractiveShell instance)parentprofile_dirrR   r3   N)interactive_shell_classinstancery   rR   r3   r2   configurablesr1   rS   r*   r*   r+   rr     s
   zTerminalIPythonApp.init_shellc                 C   s0   | j r| jr| j  | jtjkrt  dS dS )zoptionally display the bannerN)display_bannerrh   r2   show_banner	log_levelloggingINFOrQ   rS   r*   r*   r+   rs   *  s   
zTerminalIPythonApp.init_bannerc                 C   s    |dkrt 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oldra   r*   r*   r+   _pylab_changed1  s   

z!TerminalIPythonApp._pylab_changedc                 C   sZ   | j d ur
| j  S | jr| jd | j  d S | jd | jjs+t	d d S d S )NzStarting IPython's mainloop...zIPython not interactive...r   )
rO   rP   rh   logdebugr2   mainlooplast_execution_succeededsysexitrS   r*   r*   r+   rP   8  s   

zTerminalIPythonApp.startr@   )*r;   r<   r=   r   r   cl_usagerT   r   crash_handler_class	_examplesexamplesflagsaliasesr   r\   r   objectr   tagrz   r   r]   rU   rM   rV   r   auto_createrJ   r   rg   r}   rK   ri   rn   rm   r   ro   rr   rs   r   rP   r?   r*   r*   r(   r+   rI      sl    




c                 C   s<   | du r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pathr5   rI   config_file_pathsr1   rd   r[   )rR   ry   r$   r*   r*   r+   load_default_configD  s   r   __main__r@   )Gr>   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   rU   r   rB   rA   addflagclassic_configInteractiveShell
cache_sizepprintprompts_classseparate_inseparate_outseparate_out2colorsxmoder   rM   rI   r   launch_instancelaunch_new_instancer;   r*   r*   r*   r+   <module>   s   	!




 


