U
    -eE                     @   s  d Z ddlZddlm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 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mZmZ ddlmZ ee ej!e ej" Z#e ej!$ Z%e%&dd i Z'dd Z(e(dddd e(dddd e(dddd e(dddd e(d d!d"d# e(d$d%d&d' e Z)d(e)j*_+d(e)j*_,d(e)j*_-e)d)fe'd*< d+d,diid-fe'd,< d+d.diid/fe'd.< e.d0d1d2d3d4d5d6d7d8d9d:
Z/d;e/d<< G d=d+ d+e	Z0dS )>z
A mixin for :class:`~IPython.core.application.Application` classes that
launch InteractiveShell instances, load extensions, etc.
    N)chain)boolean_flag)Configurable)Config)SYSTEM_CONFIG_DIRSENV_CONFIG_DIRS)
pylabtools)preserve_keys)filefind)UnicodeInstanceListBoolCaselessStrEnumobserveDottedObjectName)pt_inputhooksautoc                  G   s   t t|  S )N)shell_flagsupdater   )args r   V/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/IPython/core/shellapp.py<lambda>'       r   Z
autoindentzInteractiveShell.autoindentzTurn on autoindenting.zTurn off autoindenting.Z	automagiczInteractiveShell.automagiczoTurn on the auto calling of magic commands. Type %%magic at the
        IPython  prompt  for  more information.z,Turn off the auto calling of magic commands.pdbzInteractiveShell.pdbz;Enable auto calling the pdb debugger after every exception.z<Disable auto calling the pdb debugger after every exception.pprintzPlainTextFormatter.pprintz'Enable auto pretty printing of results.z(Disable auto pretty printing of results.z
color-infozInteractiveShell.color_infoa0  IPython can display information about objects via a set of functions,
    and optionally can use colors for this, syntax highlighting
    source code and various other elements. This is on by default, but can cause
    problems with some pagers. If you see such problems, you can disable the
    colours.z-Disable using colors for info related things.z
ignore-cwdzInteractiveShellApp.ignore_cwdz3Exclude the current working directory from sys.pathz1Include the current working directory in sys.path z&Eliminate all spacing between prompts.ZnosepInteractiveShellApppylabzZPre-load matplotlib and numpy for interactive use with
    the default matplotlib backend.
matplotlibzQConfigure matplotlib for interactive use with
    the default matplotlib backend.zInteractiveShell.autocallzInteractiveShell.colorszInteractiveShell.logfilezInteractiveShell.logappendzInteractiveShellApp.code_to_runz!InteractiveShellApp.module_to_runz$InteractiveShellApp.extra_extensionszInteractiveShellApp.guizInteractiveShellApp.pylabzInteractiveShellApp.matplotlib)
ZautocallcolorsZlogfileZ	logappendcmextguir   r    zInteractiveShell.cache_sizez
cache-sizec                   @   s  e Zd ZdZee ddjddZee ddjddZ	e
dddjddZee d	gjddZe
dd
djddZee ddjddZe
dddjddZedddjddZee ddjddZedddjddZedddjddZeeddedjddZeedddjddZeedddj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Zee dddZ!e"ddd Z#dd  Z$d!d" Z%d#d$ Z&d%d& Z'd'd( Z(d)d* Z)d5d+d,Z*d-d. Z+d/d0 Z,d1d2 Z-d3d4 Z.dS )6r   a  A Mixin for applications that start InteractiveShell instances.

    Provides configurables for loading extensions and executing files
    as part of configuring a Shell environment.

    The following methods should be called by the :meth:`initialize` method
    of the subclass:

      - :meth:`init_path`
      - :meth:`init_shell` (to be implemented by the subclass)
      - :meth:`init_gui_pylab`
      - :meth:`init_extensions`
      - :meth:`init_code`
    z<A list of dotted module names of IPython extensions to load.)helpT)configz
        Dotted module name(s) of one or more IPython extensions to load.

        For specifying extra extensions to load on the command-line.

        .. versionadded:: 7.10
        Fz:Reraise exceptions encountered loading IPython extensions?Z
storemagiczoShould variables loaded at startup (by startup files, exec_lines, etc.)
        be hidden from tools like %who?z(List of files to run at IPython startup.z]Run the file referenced by the PYTHONSTARTUP environment
        variable at IPython startup.r   zA file to be runz(lines of code to run at IPython startup.z!Execute the given command string.zRun the module as a script.z2Enable GUI event loop integration with any of {0}.)
allow_noner&   zUConfigure matplotlib for interactive use with
        the default matplotlib backend.zPre-load matplotlib and numpy for interactive use,
        selecting a particular matplotlib backend and loop integration.
        zIf true, IPython will populate the user namespace with numpy, pylab, etc.
        and an ``import *`` is done from numpy and pylab, when using pylab mode.

        When False, pylab mode should not import any names into the user namespace.
        zIf True, IPython will not add the current working directory to sys.path.
        When False, the current working directory is added to sys.path, allowing imports
        of modules defined in the current directory.z1IPython.core.interactiveshell.InteractiveShellABC)r(   N)r   r(   user_nsc                 C   s$   | j d k	r |d | j _| j   d S )Nnew)shellr)   Zinit_user_ns)selfZchanger   r   r   _user_ns_changed   s    
z$InteractiveShellApp._user_ns_changedc                 C   sZ   dt jks| jrdS tt jD ]$\}}tj|\}}|dkr qHqd}t j|d dS )a  Add current working directory, '', to sys.path

        Unlike Python's default, we insert before the first `site-packages`
        or `dist-packages` directory,
        so that it is after the standard library.

        .. versionchanged:: 7.2
            Try to insert after the standard library, instead of first.
        .. versionchanged:: 8.0
            Allow optionally not including the current directory in sys.path
        r   N>   dist-packagessite-packagesr   )syspath
ignore_cwd	enumerateossplitinsert)r,   idxr1   parentZ	last_partr   r   r   	init_path   s    zInteractiveShellApp.init_pathc                 C   s   t dd S )NzOverride in subclasses)NotImplementedErrorr,   r   r   r   
init_shell   s    zInteractiveShellApp.init_shellc                    s  d} j  jr& fdd} j}n& jr:j} j}n jrLj} j}|sTdS z||}W nV tk
r    jd  j 	  Y dS  t
k
r    jd  j 	  Y dS X t|t r|dd \}} jd|| |d	krtd
|  n|} jd| dS )z=Enable GUI event loop integration, taking pylab into account.Fc                    s   j |  jdS )N)Z
import_all)Zenable_pylabpylab_import_all)keyr,   r+   r   r   r      r   z4InteractiveShellApp.init_gui_pylab.<locals>.<lambda>NzDEventloop or matplotlib integration failed. Is matplotlib installed?z-GUI event loop or pylab initialization failed   z@Enabling GUI event loop integration, eventloop=%s, matplotlib=%sr   zUsing matplotlib backend: %sz1Enabling GUI event loop integration, eventloop=%s)r+   r   r    Zenable_matplotlibr%   Z
enable_guiImportErrorlogwarningshowtraceback	Exception
isinstancetupleinfoprint)r,   enabler>   rr%   backendr   r?   r   init_gui_pylab   sF    

 
z"InteractiveShellApp.init_gui_pylabc                 C   s   z| j d | j| j | j }|D ]\}z | j d| | jj| W q$   | j	rX dj
|| jjd}| j j|dd Y q$X q$W n$   | j	r | j jddd Y nX dS )	zLoad all IPython extensions in IPythonApp.extensions.

        This uses the :meth:`ExtensionManager.load_extensions` to load all
        the extensions listed in ``self.extensions``.
        zLoading IPython extensions...zLoading IPython extension: %szGError in loading extension: {ext}
Check your config files in {location})r$   locationT)exc_infoz$Unknown error in loading extensions:N)rB   debugdefault_extensions
extensionsextra_extensionsrH   r+   Zextension_managerZload_extension"reraise_ipython_extension_failuresformatprofile_dirrN   rC   )r,   rR   r$   msgr   r   r   init_extensions  s(    z#InteractiveShellApp.init_extensionsc                 C   sj   |    |   |   | jr0| jj| jj |   | 	  t
j  t
j  tt
j | j_dS )z1run the pre-flight code, specified via exec_linesN)_run_startup_files_run_exec_lines_run_exec_fileshide_initial_nsr+   Zuser_ns_hiddenr   r)   _run_cmd_line_code_run_moduler0   stdoutflushstderrsetmoduleskeysZ_sys_modules_keysr;   r   r   r   	init_code)  s    

zInteractiveShellApp.init_codec                 C   s   | j s
dS zh| jd | j D ]P}z$| jd|  | jj|dd W q   | jd|  | j  Y qX qW n"   | jd | j  Y nX dS )zCRun lines of code in IPythonApp.exec_lines in the user's namespace.Nz*Running code from IPythonApp.exec_lines...z"Running code in user namespace: %sFZstore_history-Error in executing line in user namespace: %sz0Unknown error in handling IPythonApp.exec_lines:)
exec_linesrB   rP   rH   r+   run_cellrC   rD   )r,   liner   r   r   rZ   =  s$    
z#InteractiveShellApp._run_exec_linesc              	   C   s   zt |d| jg}W n& tk
r:   | jd|  Y d S X tj}|g| jdd   t_ztj	
|r| jd|  t| jjdP || jjd< |ds|dr| jj||d n| jj|| jj|d	d
 W 5 Q R X W 5 |t_X d S )N.zFile not found: %r   z"Running file in user namespace: %s__file__z.ipyz.ipynbshell_futuresT)ro   Zraise_exceptions)r
   Zipython_dirIOErrorrB   rC   r0   argv
extra_argsr4   r1   isfilerH   r	   r+   r)   endswithZsafe_execfile_ipyZsafe_execfile)r,   fnamero   Zfull_filename	save_argvr   r   r   
_exec_fileP  s0    zInteractiveShellApp._exec_filec                 C   s2  | j jgdd tttD  }g }| jrtjddr| j	s| j
s| jstjd }| jd| z| | W n$   | jd| | j  Y nX |ddd D ]4}|ttj|d	7 }|ttj|d
7 }q|sdS | jd| zt|D ]}| | qW n"   | jd | j  Y nX dS )z(Run files from profile startup directoryc                 S   s   g | ]}t j|d qS )Zstartup)r4   r1   join).0pr   r   r   
<listcomp>p  s    z:InteractiveShellApp._run_startup_files.<locals>.<listcomp>ZPYTHONSTARTUPFz Running PYTHONSTARTUP file %s...z0Unknown error in handling PYTHONSTARTUP file %s:Nz*.pyz*.ipyz Running startup files from %s...z(Unknown error in handling startup files:)rV   startup_dirr   r   r   exec_PYTHONSTARTUPr4   environgetfile_to_runcode_to_runmodule_to_runrB   rP   rw   rC   r+   rD   globr1   rx   sorted)r,   Zstartup_dirsZstartup_filesZpython_startupr}   ru   r   r   r   rY   n  s<    
z&InteractiveShellApp._run_startup_filesc                 C   sX   | j s
dS | jd z| j D ]}| | qW n"   | jd | j  Y nX dS )z$Run files from IPythonApp.exec_filesNz)Running files in IPythonApp.exec_files...z0Unknown error in handling IPythonApp.exec_files:)
exec_filesrB   rP   rw   rC   r+   rD   )r,   ru   r   r   r   r[     s    
z#InteractiveShellApp._run_exec_filesc                 C   s   | j rj| j }z$| jd|  | jj|dd W q   | jd|  | j  | jsb| d Y qX n| j	r| j	}t
j|rt
j|d}t
j|s| jd| | js| d z| j|d	d
 W n*   | jjdd | js| d Y nX dS )z.Run code or file specified at the command-linez+Running code given at command line (c=): %sFrf   rg   rl   z__main__.pyzFile '%s' doesn't existr@   Trn      )	tb_offsetN)r   rB   rH   r+   ri   rC   rD   interactexitr   r4   r1   isdirrx   existsrw   )r,   rj   ru   r   r   r   r]     s8    

z&InteractiveShellApp._run_cmd_line_codec                 C   sB   | j r>tj}tjg| j t_z| j| j | jj W 5 |t_X dS )z)Run module specified at the command-line.N)r   r0   rq   
executablerr   r+   Zsafe_run_moduler)   )r,   rv   r   r   r   r^     s    
zInteractiveShellApp._run_module)F)/__name__
__module____qualname____doc__r   r   tagrR   r   rS   r   rT   rQ   r\   r   r~   r   rh   r   r   r   gui_keysrU   r%   backend_keysr    r   r=   r2   r   r+   r   dictr)   r   r-   r9   r<   rM   rX   re   rZ   rw   rY   r[   r]   r^   r   r   r   r   r   h   s   	
'
)1r   r   	itertoolsr   r4   r0   Ztraitlets.config.applicationr   Ztraitlets.config.configurabler   Ztraitlets.config.loaderr   ZIPython.core.applicationr   r   ZIPython.corer   ZIPython.utils.contextsr	   ZIPython.utils.pathr
   Z	traitletsr   r   r   r   r   r   r   ZIPython.terminalr   rG   r   backendsaliasesr   rd   r   r6   r   ZaddflagZnosep_configZInteractiveShellZseparate_inZseparate_outZseparate_out2r   Zshell_aliasesr   r   r   r   r   <module>   s   $ 

