
    ^hX                       % S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJrJr J!r"  SS	KJ#r#J$r$J%r%  SS
KJ&r&   SSK'J(r(  SSKJ*r*  SSK+J!r!J,r,J-r-JrJ.r.J/r/J0r0JrJ1r1J2r2J3r3J4r4J5r5  SSK6J7r7  SSK8J9r9  SSK:r;SSK<J=r=J>r>J?r?J@r@JArA  SSKBJCrCJDrD  SSKEJFrF  SSKGJHrH  SSKIJJrJ  SSKKJLrL  SSKMJNrN  SSKOJPrP  SSKQJRrR  SSKSJTrTJUrU  SSKVJWrWJXrX  SSKYJZrZ  SSK[J\r\  SSK]J^r^  SS K_J`r`Jara  SS!KbJcrc  SS"KdJere  SS#KfJgrg  SS$KhJiri  SS%KjJkrk  SS&KlJmrm  SS'KnJoro  SS(KpJqrq  SS)KrJsrs  SS*KtJuruJrJvrvJwrw  SS+KxJyry  SS,KzJ{r{  SS-K|J}r}  SS.K~JrJrJr  SS/KJrJr  SS0KJr  SS1KJr  SS2KJrJrJrJr  SS3KJr  \#\   \S4'    SSKJr  S5 r\GR*                  SS6 S7:  a  SS8KJr   " S9 S:\5      rSS;KJr  \GR6                  \GR8                  \GR:                  4r\GR6                  \GR8                  4rS<S=KJrJrJrJrJr  \
GRL                  " S>5      rS?\4S@ jr\ySA 5       r\ySB 5       r " SC SD\5      r " SE SF\25      r\y " SG SH\5      5       r " SI SJ\5      r " SK SL\5      r\GRf                  " \5      SM 5       r " SN SO\75      r " SP SQ\GRl                  SR9r\GRq                  \5        g! \) a     " S S5      r( GNqf = f! \ a    Sr GNLf = f)SzMain IPython class.    N)stmt)open)error)Path)Callable)ListDictAny)OptionalSequenceTuplewarn)PickleShareDBc                   *    \ rS rSrSrS rS rS rSrg)r   ,   Tc                     g N )selfpaths     W/home/james-whalen/.local/lib/python3.13/site-packages/IPython/core/interactiveshell.py__init__PickleShareDB.__init__/   s        c                 "    [        SU S3SS9  U$ Nzusing z3 requires you to install the `pickleshare` library.   
stacklevelr   )r   keydefaults      r   getPickleShareDB.get2   s!    PQ Nr   c                      [        SU S3SS9  g r   r   )r   r!   values      r   __setitem__PickleShareDB.__setitem__9   s    PQr   r   N)	__name__
__module____qualname____firstlineno___mockr   r#   r'   __static_attributes__r   r   r   r   r   ,   s    			r   r   )TemporaryDirectory)r
   BoolCaselessStrEnumr	   EnumInstanceIntegerr   TypeUnicoder"   observevalidate)SingletonConfigurableimport_item)magicoinspectpage	prefilterultratb)AliasAliasManagerExitAutocall)BuiltinTrap)CachingCompiler)InterruptiblePdb)DisplayTrap)DisplayHook)DisplayPublisher)InputRejected
UsageError)EventManageravailable_events)ExtensionManager)DisplayFormatter)HistoryManager)	ESC_MAGIC
ESC_MAGIC2)Logger)Macro)PayloadManager)PrefilterManager)
ProfileDir)default_banner)display)get_ipython_dir)skip_doctest)
PyColorizeioopenpy	py3compat)undoc)
ask_yes_no)Struct)ensure_dir_existsget_home_dirget_py_filename)	getoutputsystem)StrDispatch)prepended_to_syspath)DollarFormatterLSStringSListformat_screen)OInfo	sphinxifyc                 @   ^ [         R                  " U 5      mU4S jnU$ )Nc                    > [        5        n[        R                  " TU5      U S.sS S S 5        $ ! , (       d  f       g = f)N)z	text/html
text/plain)r/   sphxrp   )	docstringdirnamewrapped_docstrings     r   sphinxify_docstring&sphinxify.<locals>.sphinxify_docstring   s.    #%!%0A7!K"+ &%%s   0
>)rt   wrap_main_docstring)oinforx   rw   s     @r   rp   rp   }   s!     44U;	 #"r   r   )      )BaseExceptionGroupc                       \ rS rSrSrSrg)ProvisionalWarning   z%
Warning class for unstable features
r   Nr)   r*   r+   r,   __doc__r.   r   r   r   r   r      s     	r   r   )Module   )_asyncio_runner_curio_runner_pseudo_sync_runner_should_be_async_trio_runnerz^\s+raise|^\s+return|^\s+passsc                 <     [        U 5        g! [         a     gf = f)zI
Variant of "str.isnumeric()" that allow negative values and other ints.
TF)int
ValueError)r   s    r   is_integer_stringr      s#    A s    
c                     Sn U R                   n Xl         U$ ! [         a     Nf = f! [        [        4 a     U$ f = f)z-Copied from code.py, to remove the dependencyr   )	softspaceAttributeError	TypeError)filenewvalueoldvalues      r   r   r      sY     H>>! O   I& Os    ) 
&&==c                      g r   r   )akws     r   no_opr      s    r   c                       \ rS rSrSrg)SpaceInInput   r   N)r)   r*   r+   r,   r.   r   r   r   r   r      s    tr   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )SeparateUnicode   zA Unicode subclass to validate separate_in, separate_out, etc.

This is a Unicode based trait that converts '0'->'' and ``'\\n'->'\n'``.
c                 ^   > US:X  a  SnUR                  SS5      n[        [        U ]  X5      $ )N0 z\n
)replacesuperr   r8   )r   objr&   	__class__s      r   r8   SeparateUnicode.validate   s0    C<eD)_d4S@@r   r   )r)   r*   r+   r,   r   r8   r.   __classcell__r   s   @r   r   r      s    
A Ar   r   c                       \ rS rSrSrSrSrg)DummyMod   zpA dummy module used for IPython's interactive module when
a namespace must be assigned to the module's __dict__.Nr   )r)   r*   r+   r,   r   __spec__r.   r   r   r   r   r      s    >Hr   r   c                   8    \ rS rSrSrSrSrSrSrSr	S r
S rSrg)	ExecutionInfo   zvThe arguments used for a call to :meth:`InteractiveShell.run_cell`

Stores information about what is going to happen.
NFTc                 @    Xl         X l        X0l        X@l        XPl        g r   )raw_cellstore_historysilentshell_futurescell_id)r   r   r   r   r   r   s         r   r   ExecutionInfo.__init__   s     **r   c                    U R                   R                  n[        U R                  5      S:  a  U R                  S S S-   OU R                  nSU[	        U 5      UU R
                  U R                  U R                  U R                  4-  $ )N2   z..zW<%s object at %x, raw_cell="%s" store_history=%s silent=%s shell_futures=%s cell_id=%s>)	r   r+   lenr   idr   r   r   r   )r   namer   s      r   __repr__ExecutionInfo.__repr__   s    ~~**+.t}}+=+BT]]3B$& 	 f4""""		
r   )r   r   r   r   r   )r)   r*   r+   r,   r   r   r   r   r   r   r   r   r.   r   r   r   r   r      s,     HMFMG
r   r   c                   `    \ rS rSr% SrSrSrSr\\	   \
S'   SrSrS r\S 5       rS rS rS	rg)
ExecutionResulti  zeThe result of a call to :meth:`InteractiveShell.run_cell`

Stores information about what took place.
Nerror_in_execc                     Xl         g r   info)r   r   s     r   r   ExecutionResult.__init__  s    	r   c                 H    U R                   S L =(       a    U R                  S L $ r   error_before_execr   r   s    r   successExecutionResult.success  s#    &&$.PT5G5G45OPr   c                 h    U R                   b  U R                   eU R                  b  U R                  eg)z>Reraises error if `success` is `False`, otherwise does nothingNr   r   s    r   raise_errorExecutionResult.raise_error!  s7    !!-((()$$$ *r   c           
          U R                   R                  nSU[        U 5      U R                  U R                  U R
                  [        U R                  5      [        U R                  5      4-  $ )Nz]<%s object at %x, execution_count=%s error_before_exec=%s error_in_exec=%s info=%s result=%s>)	r   r+   r   execution_countr   r   reprr   resultr   r   s     r   r   ExecutionResult.__repr__(  sq    ~~**nr$x!5!5t7M7MtOaOacghlhqhqcrtxy}  zE  zE  uF  GG 	Gr   r   )r)   r*   r+   r,   r   r   r   r   r   BaseException__annotations__r   r   r   propertyr   r   r   r.   r   r   r   r   r     sS     O-1M8M*1DF Q Q%Gr   r   c                 J    U S;   a  [        SU  S35      e[        U /UQ70 UD6$ )N>   r   r   r   zIPython won't let you open fd=zi by default as it is likely to crash IPython. If you know what you are doing, you can use builtins' open.)r   io_open)r   argskwargss      r   _modified_openr   -  s?    y,TF 3* *
 	
 4)$)&))r   c                     ^  \ rS rSrSrSr\" / SS9R                  SS9r\	" SS	S
S9R                  SS9r
\" SSS9R                  SS9r\" SSS9R                  SS9r\S4\S4\S4\S4S.r\" SSSS9R                  SS9r\" S5      S 5       r\" S5      S 5       r\" SSS9R                  SS9r\" \SS9R                  SS9r\" SSS9R                  SS9r\" SSS9R                  SS9r\" SSS9R                  SS9r \!" SSSS9R                  SS9r"\" S5      R                  SS9r#\" SS S9R                  SS9r$\%" \&SS!9r'\(" \)5      r*\(" \+5      r,\(" \-5      r.\(" \/R`                  S"S9R                  SS9r1\" SS#S9R                  SS9r2\3" S$5      S% 5       r4\" SS&S9R                  SS9r5\3" S'5      S( 5       r6Sr7\" S5      r8\%" \95      r:\" S)5      S* 5       r;\" S+5      r<\" S,5      r=\" S5      R                  SS9r>\%" S-S.5      r?\@S/ 5       rA\" / S0S9rB\@S1 5       rC\" SS2S9R                  SS9rD\" SS3S9R                  SS9rE\" SS4S9R                  SS9rF\	" SS	S59R                  SS9rG\" SS6S9R                  SS9rH\" SS7S9R                  SS9rI\" SS8S9R                  SS9rJ\" S5      R                  SS9rK\" S9S:S9R                  SS9rL\" SS;S9R                  SS9rM\	" / S<QS=S>S9R                  SS9rN\" SS?S9R                  SS9rO\P" S@5      R                  SS9rQ\P" S5      R                  SS9rR\P" S5      R                  SS9rS\" S5      R                  SS9rT\!" SASBSCS9R                  SS9rU\%" SDSS!9rV\%" SESS!9rW\%" SFSS!9rX\%" SGSS!9rY\%" SHSS!9rZ\%" SISS!9r[\%" SJSS!9r\\%" SKSS!9r]\%" SLSS!9r^\@SM 5       r_\`" 5       raSrb\" SSNS9rc\%" SOSPSSQ9rd   SU 4SR jjreSS rf\3" ST5      SU 5       rgSSV jrhSW riSX rjSY rkSZ rlS[ rmS\ rn\3" S]5      SS^ j5       roS_ rpS` rqSa rrSb rsSc rt\3" S]5      SSd j5       ruSe rvSf rwSg rxSh rySi rzSj r{\|Sk\}4Sl j5       r~Sm rSn rSo r\@Sp 5       rSSq jrSr rSSs jrSt rSu rSv rSw rSx rSy rSz rS{ r\@" \\SS|5      rSS} jrSrSS~ jr\@S 5       rSS jrS rS r\@S 5       rSS jrSS jrSS jrSS jrS r\|S\S\\\\   4   4S j5       r SS\S\\\\\4         S\4S jjr\|S 5       rSS\4S jjrSS jrSS jrSS jrSS jrS r\rS rS rS rSS jrS rSS jr  SS jrS\4S jrSS jrS r\SS j5       rS rS r\SS j5       rSSS jjrSS jrS r\GR                  " \GR                  GR                  5      SS j5       rS\4S jrSS\4S jjrS rS rS rS rSS jrS rS rS rS r\rSS jrS rS rS rS rS rS rS rS rS rS rSSSS.S jrSS jrS r    SS jrS\S\S\S\S\S\4S jrSSS.S\S\4S jjr   SSSSS.S\S\\   S\\   S\4S jjjrS rS rS=\S4S\\   S\4S jjrSSS.S jjr\rS\S\\\4   4S jrSrSS jrSS jrSS jrS	\" 5       4S jrSS jrSS jrS rSS jrSS jrS rS rS rS rSrU =r$ )InteractiveShelli8  z*An enhanced, interactive shell for Python.Nz
        A list of ast.NodeTransformer subclass instances, which will be applied
        to user input before code is run.
        )helpT)config)r   r   r   r   a  
        Make IPython automatically call any callable object even if you didn't
        type explicit parentheses. For example, 'str 43' becomes 'str(43)'
        automatically. The value can be '0' to disable the feature, '1' for
        'smart' autocall, where it is not applied if there are no more
        arguments on the line, and '2' for 'full' autocall, where all callable
        objects are automatically called (even if no arguments are present).
        )default_valuer   z@
        Autoindent IPython code entered interactively.
        zJ
        Automatically run await statement in the top level repl.
        F)asynciocuriotriosync-IPython.core.interactiveshell._asyncio_runnerzOSelect the loop runner that will be used to execute top-level asynchronous code)r   
allow_noner   loop_runnerc                     [        S5      $ )Nr   r:   r   s    r   _default_loop_runner%InteractiveShell._default_loop_runnerg  s    JKKr   c                    [        UR                  [        5      (       ao  UR                  U R                  ;   a#  U R                  UR                     u  p#X0l        U$ [        UR                  5      n[        U5      (       d  [        S5      eU$ [        UR                  5      (       d  [        S5      eUR                  $ )Nzloop_runner must be callable)
isinstancer&   strloop_runner_map	autoawaitr;   callabler   )r   proposalrunnerr   s       r   _import_runnerInteractiveShell._import_runnerk  s    hnnc**~~!5!55$($8$8$H!!* 0FF## !?@@M'';<<~~r   zK
        Enable magic commands to be called without the leading %.
        z7The part of the banner to be printed before the profiler   z6The part of the banner to be printed after the profilei  a  
        Set the size of the output cache.  The default is 1000, you can
        change it permanently in your config file.  Setting it to 0 completely
        disables the caching system, and the minimum value accepted is 3 (if
        you provide a value less than 3, it is reset to 0 and a warning is
        issued).  This limit is defined because otherwise you'll spend more
        time re-flushing a too small cache than working
        z
        Use colors for displaying information about objects. Because this
        information is passed through a pager (like 'less'), and some pagers
        get confused with color codes, this capability can be turned off.
        )NeutralNoColorLightBGLinuxr   z;Set the color scheme (NoColor, Neutral, Linux, or LightBG).z?Don't call post-execute functions that have failed in the past.)r   z/Class to use to instantiate the shell inspectorzm
        Enables rich html representation of docstrings. (This requires the
        docrepr module).
        rx   c                 :    US   (       a  [        S[        5        g g )Nnewz[`sphinxify_docstring` is provisional since IPython 5.0 and might change in future versions.r   r   r   changes     r   _sphinxify_docstring_changed-InteractiveShell._sphinxify_docstring_changed  s!    %=n  rD  E r   zg
        (Provisional API) enables html representation in mime bundles sent
        to pagers.
        enable_html_pagerc                 :    US   (       a  [        S[        5        g g )Nr   zY`enable_html_pager` is provisional since IPython 5.0 and might change in future versions.r   r   s     r   _enable_html_pager_changed+InteractiveShell._enable_html_pager_changed  s!    %=l  oA  B r   exiterc                     [        U 5      $ r   rC   r   s    r   _exiter_default InteractiveShell._exiter_default  s    D!!r   r   z<ipython console>z1IPython.core.inputtransformer2.TransformerManagerr   c                 .    U R                   R                  $ r   )input_transformer_managercleanup_transformsr   s    r   input_transformers_cleanup+InteractiveShell.input_transformers_cleanup  s    --@@@r   z]A list of string input transformers, to be applied after IPython's own input transformations.c                 >    SSK Jn  U" S[        SS9  U R                  $ )zMake this available for backward compatibility (pre-7.0 release) with existing code.

For example, ipykernel ipykernel currently uses
`shell.input_splitter.check_complete`
r   r   zU`input_splitter` is deprecated since IPython 7.0, prefer `input_transformer_manager`.r   r   )warningsr   DeprecationWarningr  )r   r   s     r   input_splitterInteractiveShell.input_splitter  s%     	"dA	
 ---r   z
        Start logging to the default log file in overwrite mode.
        Use `logappend` to specify a log file to **append** logs to.
        z1
        The name of the logfile to use.
        z
        Start logging to the given file in append mode.
        Use `logfile` to specify a log file to **overwrite** logs to.
        )r   zL
        Automatically call the pdb debugger after every exception.
        zhIf True, anything that would be passed to the pager
        will be displayed as regular output instead.z(Show rewritten input, e.g. for autocall.i'  zTotal length of command historyzn
        The number of saved history entries to be loaded
        into the history buffer at startup.
        )alllast	last_exprnonelast_expr_or_assignr  z
        'all', 'last', 'last_expr' or 'none', 'last_expr_or_assign' specifying
        which nodes should be run interactively (displaying output from expressions).
        ztWarn if running in a virtual environment with no IPython installed (so IPython from the global environment is used).r   )ContextPlainVerboseMinimalr  z0Switch modes for the IPython exception handlers.zIPython.core.alias.AliasManagerz'IPython.core.prefilter.PrefilterManagerz%IPython.core.builtin_trap.BuiltinTrapz%IPython.core.display_trap.DisplayTrapz(IPython.core.extensions.ExtensionManagerz#IPython.core.payload.PayloadManagerz(IPython.core.history.HistoryAccessorBasez IPython.core.magic.MagicsManagerz#IPython.core.application.ProfileDirc                     U R                   bE  [        R                  R                  U R                   R                  5      nUR                  SS5      $ g )Nprofile_r   )profile_dirosr   basenamelocationr   r   s     r   profileInteractiveShell.profile6  sD    '77##D$4$4$=$=>D<<
2.. (r   z#Did last executed command succeededz-IPython.core.interactiveshell.ExecutionResultz$Result of executing the last command)r   r   c                   > [         [        U ]
  " S0 UD6  SU R                  ;   a  [	        S5        U /U l        U R                  U5        U R                  U5        U R                  5         U R                  5         U R                  5         U R                  X45        U R                  5         U R                  5         [        [        R                   R#                  U R$                  R&                  S5      5      U l        U R+                  5         U R-                  5         U R/                  5         U R1                  5         U R3                  5         U R5                  5         U R7                  5         U R9                  5         U R;                  5         U R=                  5         U R?                  5         [@        U l!        U RE                  5         U RG                  5         U RI                  U5        U RK                  5         U RM                  5         U RO                  5         U RQ                  5         U RS                  5         U RU                  5         U RW                  5         U RY                  5         U R[                  5         U R]                  5         U R_                  5         U R`                  Rc                  SU 5        [d        Rf                  " U Rh                  5        S U l5        g )NPromptManagerz|As of IPython 5.0 `PromptManager` config will have no effect and has been replaced by TerminalInteractiveShell.prompts_classdbshell_initializedr   )6r   r   r   r   r   configurablesinit_ipython_dirinit_profile_dirinit_instance_attrsinit_environmentinit_virtualenvinit_create_namespacessave_sys_module_stateinit_sys_modulesr   r!  r   joinr   r#  r(  init_historyinit_encodinginit_prefilterinit_syntax_highlighting
init_hooksinit_eventsinit_pushd_popd_magicinit_user_nsinit_loggerinit_builtinsinit_inspectorinputraw_input_originalinit_completerinit_ioinit_traceback_handlersinit_promptsinit_display_formatterinit_display_pubinit_data_pubinit_displayhookinit_magics
init_aliasinit_logstartinit_pdbinit_extension_managerinit_payloadeventstriggeratexitregisteratexit_operationstrio_runner)r   ipython_dirr   user_moduleuser_nscustom_exceptionsr   r   s          r   r   InteractiveShell.__init__G  s6   
 	.88dkk) T U"V 	k*k*  " 	 	##K9 	""$
  T-=-=-F-F MN%%'""$ 	"' 	$$%67##%##%/6../  r   c                     U $ )z.Return the currently running IPython instance.r   r   s    r   get_ipythonInteractiveShell.get_ipython  s    r   rU  c                      [        US   5        g )Nr   )rd   r   s     r   _ipython_dir_changed%InteractiveShell._ipython_dir_changed  s    &-(r   c                 D    Uc  U R                   (       + U l         gXl         g)zKSet the autoindent flag.

If called with no arguments, it acts as a toggle.N)
autoindent)r   r&   s     r   set_autoindentInteractiveShell.set_autoindent  s     ="&//1DO#Or   c                     Xl         g r   )rT  )r   trs     r   set_trio_runner InteractiveShell.set_trio_runner  s    r   c                 6    Ub  Xl         g [        5       U l         g r   )rU  r[   )r   rU  s     r   r+  !InteractiveShell.init_ipython_dir  s    "**,r   c                 d    Ub  Xl         g [        R                  " U R                  S5      U l         g )Nr"   )r   rX   create_profile_dir_by_namerU  )r   r   s     r   r,  !InteractiveShell.init_profile_dir  s/    "*%@@i
r   c                     SU l         U R                  5       U l        [        5       U l        / U l        / U l        [        R                  " 5       U l	        SU l
        0 U l        g )NFr   )morecompiler_classcompilerc   meta	tempfilestempdirsr!  getcwdstarting_dirindent_current_nsp_post_executer   s    r   r-  $InteractiveShell.init_instance_attrs  sZ    	 **, H	  IIK #$  r   c                     g)z6Any changes we need to make to the user's environment.Nr   r   s    r   r.  !InteractiveShell.init_environment      r   c                      [         R                  R                  =(       d    SU l        g ! [         a
    SU l         g f = f)Nascii)sysstdinencodingstdin_encodingr   r   s    r   r5  InteractiveShell.init_encoding  s5    	*"%))"4"4"?D 	*")D	*s   (+ ??colorsc                 n   ^ [         R                  " U R                  U S9R                  mU4S jU l        g )N)styleparentc                    > T" U S5      $ )Nr   r   )srcpyformats    r   <lambda>;InteractiveShell.init_syntax_highlighting.<locals>.<lambda>  s    hs5&9r   )r]   Parserr  format
pycolorize)r   changesr  s     @r   r7  )InteractiveShell.init_syntax_highlighting  s(     $$4;;tDKK9r   c                     g r   r   r   s    r   refresh_styleInteractiveShell.refresh_style  r{  r   c                 0    [        5       U l        / U l        g r   )re   home_dir	dir_stackr   s    r   r:  &InteractiveShell.init_pushd_popd_magic  s    $r   c                 8    [        U R                  SSS9U l        g )Nzipython_log.pyrotate)logfnamelogmode)rT   r  loggerr   s    r   r<  InteractiveShell.init_logger  s    T]]5E%-/r   c                 
   U R                   (       a  U R                  SU R                   -  5        gU R                  (       a  U R                  SU R                  -  5        gU R                  (       a  U R                  S5        gg)zIInitialize logging in case it was requested at the command line.
        zlogstart %s appendzlogstart %slogstartN)	logappendr<   logfiler  r   s    r   rK  InteractiveShell.init_logstart  sU     >>JJ+dnn<=\\JJ}t||34]]JJz" r   c                 t    S[         R                  S'   [        [         R                  S'   [        U S9U l        g )NT__IPYTHON__rZ   )shell)builtin_mod__dict__rZ   rE   builtin_trapr   s    r   r=  InteractiveShell.init_builtins  s1    
 /3]+*1Y''d3r   c                     U R                  [        R                  [        R                  U R
                  U R                  5      U l        g r   )inspector_classr=   InspectColorsr]   ANSICodeColorsr  object_info_string_level	inspector)r   r  s     r   r>  InteractiveShell.init_inspector  s8     --""%%KK))	
r   c                     g r   r   r   s    r   rB  InteractiveShell.init_io  s     	r   c                 F    S[         l        S[         l        S[         l        g )NzIn : z...: zOut: )r~  ps1ps2ps3r   s    r   rD  InteractiveShell.init_prompts!  s     r   c                 j    [        U S9U l        U R                  R                  U R                  5        g N)r  )rP   display_formatterr*  appendr   s    r   rE  'InteractiveShell.init_display_formatter(  s)    !1!>!!$"8"89r   c                 v    U R                  X S9U l        U R                  R                  U R                  5        g )N)r  r  )display_pub_classdisplay_pubr*  r  r   s    r   rF  !InteractiveShell.init_display_pub,  s2    111J!!$"2"23r   c                     U R                   (       d  S U l        g U R                  U S9U l        U R                  R                  U R                  5        g r  )data_pub_classdata_pubr*  r  r   s    r   rG  InteractiveShell.init_data_pub0  sB    "" DM++4+8!!$--0r   c                     U R                  U U U R                  S9U l        U R                  R	                  U R                  5        [        U R                  S9U l        g )N)r  r  
cache_size)hook)displayhook_classr  displayhookr*  r  rH   display_trapr   s    r   rH  !InteractiveShell.init_displayhook7  sX    11 2 

 	!!$"2"23 (T-=-=>r   pc                    U /nU R                  5       (       am  [        [        R                  " U 5      5      nUR	                  5       (       d  U R
                  U-  nUn UR                  U 5        U R                  5       (       a  Mm  U$ )a?  Gets path links including all symlinks

Examples
--------
In [1]: from IPython.core.interactiveshell import InteractiveShell

In [2]: import sys, pathlib

In [3]: paths = InteractiveShell.get_path_links(pathlib.Path(sys.executable))

In [4]: len(paths) == len(set(paths))
Out[4]: True

In [5]: bool(paths)
Out[5]: True
)
is_symlinkr   r!  readlinkis_absoluter  r  )r  pathsnew_paths      r   get_path_linksInteractiveShell.get_path_linksC  si    $ llnnBKKN+H''))88h.ALLO llnn r   c                 f  ^
 S[         R                  ;  a  g[         R                  S   S:X  a  [        S5        g[        [        R
                  5      n[        [         R                  S   5      m
U R                  U5      nT
R                  S   S:X  a*  T
R                  S   nUS-   [        T
R                  S	S 6 -  m
[        U
4S
 jU 5       5      (       a  g[        R                  S:X  a(  [        [        [         R                  S   SS5      5      nO[        [         R                  S   SSS5      n[        R                  SS n[        R                  " S[         R                  S   5      nU(       aT  [        [        U5      R                  " UR                  5       6 5      nUR!                  5       (       a  UR                  5       n[        U5      R                  " U6 nU R"                  (       a  [        S5        SSKn	[        R&                  R)                  SU5        U	R+                  U5        g)a  Add the current virtualenv to sys.path so the user can import modules from it.
This isn't perfect: it doesn't use the Python interpreter with which the
virtualenv was built, and it ignores the --no-site-packages option. A
warning will appear suggesting the user installs IPython in the
virtualenv, but for many cases, it probably works well enough.

Adapted from code snippets online.

http://blog.ufsoft.org/2009/1/29/ipython-and-virtualenv
VIRTUAL_ENVNr   z=Virtual env path set to '', please check if this is intended.r   cygdriver   z:/r|   c              3   H   >#    U  H  nTUR                   S    :H  v   M     g7f)r   N)parents).0r  p_venvs     r   	<genexpr>3InteractiveShell.init_virtualenv.<locals>.<genexpr>~  s     5u!v1%us   "win32Libzsite-packageslibzpython{}.{}z\bpy(?:thon)?([23])\.(\d+)\bzlAttempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.r   )r!  environr   r   r~  
executabler  partsanyplatformr   version_inforesearchr  groupsexists	warn_venvsiter   insert
addsitedir)r   r  r  
drive_namevirtual_envvirtual_env_pathp_verre_mpredicted_pathr  r  s             @r   r/   InteractiveShell.init_virtualenv^  s    

*ZZ&",PQ bjj/0 ##A& <<?j(aJ 4'4ab1A+BBF5u555<<7"d2::m#<e_UVK#

=)5-  $$Ra(E 99<bjj>WXD!%c*:&;&B&BDKKM&R!S!((** KKME./66>K>>@ 	;'$r   c                 2   [         R                  [         R                  [         R                  [         R                  S.U l        U R                  R                  U l        [         R                  R                  U R                  R                  5      U l        g)zeSave the state of hooks in the sys module.

This has to be called after self.user_module is created.
)r  stdoutstderr
excepthookN)r~  r  r  r  r  _orig_sys_module_staterV  r)   _orig_sys_modules_main_namemodulesr#   _orig_sys_modules_main_modr   s    r   r1  &InteractiveShell.save_sys_module_state  sb    
 14		141458^^'E# ,0+;+;+D+D(*-++//$:J:J:S:S*T'r   c                      U R                   R                  5        H  u  p[        [        X5        M     U R
                  b(  U R
                  [        R                  U R                  '   gg! [         a     NBf = f)z$Restore the state of the sys module.N)r  itemssetattrr~  r   r  r  r  )r   kvs      r   restore_sys_module_state)InteractiveShell.restore_sys_module_state  sm    	3399;Q" <
 **6<@<[<[CKK889 7  		s   3A+ +
A87A8c                     U R                   nU R                  (       a"  U R                  S:w  a  USU R                  -  -  nU R                  (       a  USU R                  -   -  nU$ )Nr"   z
IPython profile: %s
r   )banner1r$  banner2r   banners     r   r
  InteractiveShell.banner  sP    <<DLLI5/$,,>>F<<dT\\))Fr   c                 `    Uc  U R                   n[        R                  R                  U5        g r   )r
  r~  r  writer	  s     r   show_bannerInteractiveShell.show_banner  s"    >[[F

 r   c                 P   [        5       U l        0 U l        [        R                  R                  nUR
                   H  nU R                  U[        X5      S5        M!     U R                  (       a6  U R                  S[        R                  " [        R                  5      S5        g g )Nd   show_in_pagerZ   )rc   hooksstrdispatchersIPythoncore__all__set_hookgetattrdisplay_pager>   as_hook)r   r  	hook_names      r   r8  InteractiveShell.init_hooks  sx    X
  ""I MM)WU%>D '
 MM/4<<8I8I+JBO r   c                    [         R                  " X 5      nUbE  U R                  R                  U[	        5       5      nUR                  XFU5        XpR                  U'   gUbY  U R                  R                  U[	        5       5      nUR                  [        R                  " U5      Xc5        XpR                  U'   g[        U R                  US5      nU[        R                  R                  R                  ;  a5  [        SU< S[        R                  R                  R                  < 35        U[        R                  R                  R                  ;   aA  [        R                  R                  R                  U   n	[!        SR#                  X5      5      eU(       d(  [        R                  R                  R%                  5       n UR'                  Xc5        [+        U R                  X5        g! [(         a    Un N%f = f)zset_hook(name,hook) -> sets an internal IPython hook.

IPython exposes some of its internal API as user-modifiable hooks.  By
adding your function to one of these hooks, you can modify IPython's
behavior to call at runtime your own routines.NzWarning! Hook 'z' is not one of z>Hook {} has been deprecated since IPython 5.0. Use {} instead.)types
MethodTyper  r#   ri   add_sadd_rer  rp  r  r  r  r  r  print
deprecatedr   r  CommandChainDispatcheraddr   r  )
r   r   r  prioritystr_keyre_keyfsdpdpalternatives
             r   r  InteractiveShell.set_hook  s    T' %%))$>CIIg(,(+%%%))$>CJJrzz&)18(+%TZZt,w||))111++336 7 7<<%%000!,,,,77=KPWW  ##::<B	FF1
 	

4$	  	B	s   G0 0G?>G?c                 z    [        U [        5      U l        U R                  R                  SU R                  5        g )Npre_execute)rM   rN   rO  rR  _clear_warning_registryr   s    r   r9  InteractiveShell.init_events  s+    "4)9:]D,H,HIr   c                     [        S5      e)zqDEPRECATED: Use ip.events.register('post_run_cell', func)

Register a function for calling after code execution.
zpip.register_post_execute is deprecated since IPython 1.0, use ip.events.register('post_run_cell', func) instead.)r   )r   funcs     r   register_post_execute&InteractiveShell.register_post_execute  s    
 A
 	
r   c                 @    SU R                   ;   a  U R                   S	 g g )N__warningregistry__)user_global_nsr   s    r   r2  (InteractiveShell._clear_warning_registry   s&     !D$7$77##$9: 8r   c                 &   [         R                  R                  U5      n U R                  U   nUR                  R                  5         X#l        Xl
        S Ul        U$ ! [         a&    [        R                  " USS9=o0R                  U'    N?f = f)aH  Return a new 'main' module object for user code execution.

``filename`` should be the path of the script which will be run in the
module. Requests with the same filename will get the same module, with
its namespace cleared.

``modname`` should be the module name - normally either '__main__' or
the basename of the file without the extension.

When scripts are executed via %run, we must keep a reference to their
__main__ module around so that Python doesn't
clear it, rendering references to module globals useless.

This method keeps said reference in a private dict, keyed by the
absolute path of the script. This way, for multiple executions of the
same script we only keep one copy of the namespace (the last one),
thus preventing memory leaks from old references while allowing the
objects from the last execution to be accessible.
z(Module created for script run in IPythondocc                      gNTr   r   r   r   r  /InteractiveShell.new_main_mod.<locals>.<lambda>M  s    r   )r!  r   abspath_main_mod_cacher  clearr)   KeyErrorr   
ModuleType__file____nonzero__)r   filenamemodnamemain_mods       r   new_main_modInteractiveShell.new_main_mod+  s    ( 77??8,	(++H5H ##% '$  -  	H8=8H8HF9H HH++H5	Hs   A   -BBc                 8    U R                   R                  5         g)aB  Clear the cache of main modules.

Mainly for use by utilities like %reset.

Examples
--------
In [15]: import IPython

In [16]: m = _ip.new_main_mod(IPython.__file__, 'IPython')

In [17]: len(_ip._main_mod_cache) > 0
Out[17]: True

In [18]: _ip.clear_main_mod_cache()

In [19]: len(_ip._main_mod_cache) == 0
Out[19]: True
N)rC  rD  r   s    r   clear_main_mod_cache%InteractiveShell.clear_main_mod_cacheQ  s    & 	""$r   c                 &    U R                   U l        g r   )pdbcall_pdbr   s    r   rL  InteractiveShell.init_pdbj  s     r   c                     U R                   $ r   )	_call_pdbr   s    r   _get_call_pdbInteractiveShell._get_call_pdbo  s    ~~r   c                 R    US;  a  [        S5      eXl        XR                  l        g )N)r   r   FTz"new call_pdb value must be boolean)r   rV  InteractiveTBrS  )r   vals     r   _set_call_pdbInteractiveShell._set_call_pdbr  s,    &&ABB  '*#r   z,Control auto-activation of pdb at exceptionsc                     U(       d  U R                   (       d  g[        [        S5      (       d  [        S5        gU R                  R                  SS9  g)a
  Call the pdb debugger.

Keywords:

  - force(False): by default, this routine checks the instance call_pdb
    flag and does not actually invoke the debugger if the flag is false.
    The 'force' option forces the debugger to activate even if the flag
    is false.
Nlast_tracebackz1No traceback has been produced, nothing to debug.Tforce)rS  hasattrr~  r   rZ  debugger)r   ra  s     r   rc  InteractiveShell.debugger  sA     s+,,EF##$#/r   c                     Uc  Ub  SU l         U R                  X5      u  U l        U l        0 U l        0 U l        U R                  R                  U R                  [        R                  S.U l        g )NF)user_global
user_localbuiltin)	default_user_namespacesprepare_user_modulerV  rW  user_ns_hiddenrC  r  r  ns_tabler   rV  rW  s      r   r0  'InteractiveShell.init_create_namespaces  sp    J [%<+0D()-)A)A+)W&$, !4  " (,'7'7'@'@&*ll#.#7#7r   c                 .    U R                   R                  $ r   )rV  r  r   s    r   r:  InteractiveShell.user_global_ns  s    (((r   c                 &   Uc%  Ub"  UR                  SS5        [        5       nX!l        Uc  [        R                  " SSS9nUR                  R                  S[
        5        UR                  R                  S[
        5        Uc  UR                  nX4$ )a:  Prepare the module and namespace in which user code will be run.

When IPython is started normally, both parameters are None: a new module
is created automatically, and its __dict__ used as the namespace.

If only user_module is provided, its __dict__ is used as the namespace.
If only user_ns is provided, a dummy module is created, and user_ns
becomes the global namespace. If both are provided (as they may be
when embedding), user_ns is the local namespace, and user_module
provides the global namespace.

Parameters
----------
user_module : module, optional
    The current user module in which IPython is being run. If None,
    a clean module will be created.
user_ns : dict, optional
    A namespace in which to run interactive commands.

Returns
-------
A tuple of user_module and user_ns, each properly initialised.
r)   __main__z@Automatically created module for IPython interactive environmentr=  __builtin____builtins__)
setdefaultr   r  r   rF  r  rm  s      r   rj  $InteractiveShell.prepare_user_module  s    0 7#6z:6"*K#* **:VXK 	''{C''D?!**G##r   c                 j    U R                   R                  nU R                   [        R                  U'   g r   )rV  r)   r~  r  )r   	main_names     r   r2  !InteractiveShell.init_sys_modules  s)    " $$--	!%!1!1Ir   c                    0 nU R                   R                  US'   U R                   R                  US'   U R                   R                  US'   U R                   R                  US'   U R                   R                  US'   U R                  US'   U R
                  US'   U R
                  US'   [        US	'   U R                  R                  U5        U R                  R                  U5        g
)a@  Initialize all user-visible namespaces to their minimum defaults.

Certain history lists are also initialized here, as they effectively
act as user namespaces.

Notes
-----
All data structures here are only filled in, they are NOT reset by this
method.  If they were not empty before, data will simply be added to
them.
_ih_oh_dhInOutr[  exitquitr   N)
history_managerinput_hist_parsedoutput_histdir_histr[  r  r   rk  updaterW  )r   nss     r   r;  InteractiveShell.init_user_ns+  s    :  ((::5	((445	((115	 ((::4((445	 !,,=[[6
[[6
#6
 	""2& 	Br   c                     U R                   U R                  U R                  /U R                  R	                  5        Vs/ s H  oR
                  PM     sn-   $ s  snf )zGet a list of references to all the namespace dictionaries in which
IPython might store a user-created object.

Note that this does not include the displayhook, which also caches
objects from the output.)rW  r:  rk  rC  valuesr  )r   ms     r   all_ns_refsInteractiveShell.all_ns_refsf  sR     d1143F3FG$($8$8$?$?$AB$Aq

$ABC 	CBs   Ac                    U R                   R                  U5        U(       a  SU l        SU l        SU l        U R
                  R                  (       a  U R
                  R                  5         U R                  U R                  La  U R                  R                  5         U R                  n[        UR                  5       5      nUR                  S5        UR                  S5        UR                  S5        U H  nX5	 M     U R                  R                  5         U R                  5         U(       a  [!        U S5      (       d  [#        S5        OwU(       ap  [#        S	5        [        [$        R&                  R                  5       5      nX`R(                  -
   H,  nUR+                  S
5      (       a  M  [$        R&                  U	 M.     U R,                  R/                  5         U R,                  R1                  5         [2        R4                  S:X  aB  S H<  nXpR6                  R8                  S   ;  d  M!  U R,                  R;                  Xw5        M>     U R=                  5         g)zClear all internal namespaces, and attempt to release references to
user objects.

If new_session is True, a new history session will be opened.
r   TNrs  rt  r)   _sys_modules_keysz&Cannot restore sys.module, no snapshotzculling sys module...multiprocessingposix)rD  rn  lessmanline)r  resetr   last_execution_succeededlast_execution_resultr  do_full_cacheflushrW  r:  rD  setkeysdiscardrk  r;  rb  r$  r~  r  r  
startswithalias_managerclear_aliasesinit_aliasesr!  r   magics_managermagicssoft_define_aliasrO  )r   new_session
aggressiver  	drop_keysr  current_keyscmds           r   r  InteractiveShell.resetp  s    	"";/#$D  )-%%)" ))""$
 <<t222LL   	N	-(.)*%A  	!!# 	gd,?@@:;)*s{{//12L!$:$::<< 122KKN ; 	((*'')
 77g71188@@&&88B 8 	!!#r   c                 x   US;   a  [        SU-  5      eU R                  nU(       a  U H  n XA	 M     g U R                  U   nUR                  U R                  R                  5        U H8  nUR                  5        VVs/ s H  u  pxXL d  M  UPM     n	nnU	 H  n
XJ	 M     M:     U R                  R                  UL a  SU l	        S H5  n
[        U R                  U
5      UL d  M  [        U R                  U
S5        M7     g! [         a     M  f = f! [         a  n[	        SU-  5      UeSnAff = fs  snnf )a~  Delete a variable from the various namespaces, so that, as
far as possible, we're not keeping any hidden references to it.

Parameters
----------
varname : str
    The name of the variable to delete.
by_name : bool
    If True, delete variables with the given name in each
    namespace. If False (default), find the variable in the user
    namespace, and delete references to it.
)rs  rt  zRefusing to delete %szname '%s' is not definedN)______)r   r  rE  rW  	NameErrorr  r  r  r   r  r   r  r  r  )r   varnameby_namens_refsr  r   eno	to_deleter   s              r   del_varInteractiveShell.del_var  s7    554w>??"" Mll7+ NN4//;;<+-88:B:41Q:	B%D &  ))00C7-1* +4++T2c9D,,dD9 +'   
  M :W DE1LM
 Cs4   DD 
D6D6
DD
D3D..D3c                     UbN   [         R                  " U5      nU R                   H&  nU H  nUR	                  U5      (       d  M  XE	 M     M(     gg! [         a  n[        S5      UeSnAff = f)a  Clear selective variables from internal namespaces based on a
specified regular expression.

Parameters
----------
regex : string or compiled pattern, optional
    A regular expression pattern that will be used in searching
    variable names in the users namespaces.
Nz*regex must be a string or compiled pattern)r  rp  r   r  r  )r   regexr  r  r  vars         r   reset_selective InteractiveShell.reset_selective  st     UJJu%
 &&Cxx}}G  '   U LMSTTUs   A 
A.A))A.c                 |   Sn[        U[        5      (       a  UnO[        U[        [        [        45      (       am  [        U[        5      (       a  UR                  5       nOUn0 n[        R                  " S5      nU H&  n [        XeR                  UR                  5      X6'   M(     O[        S5      eU R                  R!                  U5        U R"                  nU(       a  U H  nUR%                  US5        M     gUR!                  U5        g!   [        SU< SUR                  R                  < 35         M  = f)aP  Inject a group of variables into the IPython user namespace.

Parameters
----------
variables : dict, str or list/tuple of str
    The variables to inject into the user's namespace.  If a dict, a
    simple update is done.  If a str, the string is assumed to have
    variable names separated by spaces.  A list/tuple of str can also
    be used to give the variable names.  If just the variable names are
    give (list/tuple/str) then the variable values looked up in the
    callers frame.
interactive : bool
    If True (default), the variables will be listed with the ``who``
    magic.
Nr   zCould not get variable z from z'variables must be a dict/str/list/tuple)r   dictr   listtuplesplitr~  	_getframeeval	f_globalsf_localsr$  f_codeco_namer   rW  r  rk  pop)r   	variablesinteractivevdictvlistcfr   rk  s           r   pushInteractiveShell.push  s      i&&E	Cu#566)S))!)!Eq!B5"&t\\2;;"GEK  FGG 	E" ,,""4.  !!%(5 !2!24 5s   "D)D;c                     UR                  5        HS  u  p#X R                  ;   d  M  U R                  U   UL d  M*  U R                  U	 U R                  R                  US5        MU     g)a{  Remove a dict of variables from the user namespace, if they are the
same as the values in the dictionary.

This is intended for use by extensions: variables that they've added can
be taken back out if they are unloaded, without removing any that the
user has overwritten.

Parameters
----------
variables : dict
    A dictionary mapping object names (as strings) to the objects.
N)r   rW  rk  r  )r   r  r   r   s       r   
drop_by_idInteractiveShell.drop_by_id"  sS     #*ID||#T(:c(ALL&##''d3 +r   onamereturnc                    U R                  S5      n/ nSnU H  nUR                  S5      (       a}  UR                  S5      tpVUR                  5       (       d  Sn  X24$ UR                  U5        U H7  nUS   S:w  a  [	        USS 5      (       d  Sn  OUR                  USS 5        M9     M  UR                  5       (       d  SnUR                  U5        M     X24$ )a]  
Given an object name, return a list of parts of this object name.

Basically split on docs when using attribute access,
and extract the value when using square bracket.


For example foo.bar[3].baz[x] -> foo, bar, 3, baz, x


Returns
-------
parts_ok: bool
    wether we were properly able to parse parts.
parts: list of str
    extracted parts



.T][FN)r  endswithisidentifierr  r   )r  	raw_partsr  parts_okr  r  indicesinds           r   _find_partsInteractiveShell._find_parts7  s    , KK$	Azz# !''))$H  S!"C2w#~.?CR.I.I#(LLSb*	 #
 >>## LLO! $ r   
namespacesc           	         UR                  5       nU R                  U5      u  p4UR                  [        5      (       d/  UR                  [        5      (       d  U(       d  [        SSSSSSS9$ Uc-  SU R                  4SU R                  4S[        R                  4/nSnSnSnSnSn	Sn
UnUS   USS pU Hx  u  p X   n
[        U5       H[  u  nn U
n	U[        U5      S-
  :X  a  U R                  U
U5      n
M/  [        U5      (       a  U
[        U5         n
MO  [        U
U5      n
M]     S	nUn  O   U(       d  Sn
UR                  [        5      (       a'  UR#                  [        5      nU R%                  U5      n
OfUR                  [        5      (       a'  UR#                  [        5      nU R'                  U5      n
O%U R'                  U5      n
U
c  U R%                  U5      n
U
b  S	nS
nS	n[)        U
[*        5      nU(       d  US;   a  [-        U5      n
S	nSn[        U
UU	UUUS9$ !      GMv  = f! [          a     GM  f = f)zFind an object in the available namespaces.


Returns
-------
OInfo with fields:
  - ismagic
  - isalias
  - found
  - obj
  - namespac
  - parent

Has special code to detect magic functions.
FN)ismagicisaliasfoundr   	namespacer  InteractivezInteractive (global)zPython builtinr   r   TzIPython internal)z''z""z[]z{}z())r   r  r  r  r  r  )stripr  r  rR   rS   ro   rW  r:  r  r  	enumerater   _getattr_propertyr   r   r  rE  lstripfind_cell_magicfind_line_magicr   rA   r  )r   r  r  r  r  r  r  r  ospacer  r   oname_parts
oname_head
oname_restnsnamer  idxparts                     r   _ofindInteractiveShell._ofindd  sv   $ **51   ++$$Z00   *4<<82D4G4GH,k.B.BCJ
  !,QABJ#IFn "+:!6IC!$ #j/A"55"&"8"8d"CC066&)#d)n&-c4&8 "7( !E#F9 $> C
++Z0**51!!),,Y/**51 **51;..u5C+$S%0 'AAz"CE"F
 	
K )  s*   <H/&H%:H%H%%H,/
H>=H>c                     [        U [        5      (       dM   [        U5      (       a  U [        U5         $ [	        [        U 5      U5      n [        U[
        5      (       a  U$  [	        X5      $ ! [         a     Nf = f)zProperty-aware getattr to use in object finding.

If attrname represents a property, return it unevaluated (in case it has
side effects or raises an error.

)r   typer   r   r  r   r   )r   attrnameattrs      r   r  "InteractiveShell._getattr_property  s|     #t$$  %X..s8}--"49h7D  dH--K . s%%' " s   A. A. .
A;:A;c                 $    U R                  X5      $ )z6Find an object and return a struct with info about it.)r  )r   r  r  s      r   _object_findInteractiveShell._object_find  s    {{5--r   c                 B   U R                  X#5      nU R                  (       a-  [        c  [        S5      e[        U R	                  U5      5      nOSnUR
                  (       d)  [        UR                  [        R                  5      (       a  [        U R                  U5      nUR                  (       a  [        OUnUS:X  a  U" UR                  X(5        gUS:X  a#  U" UR                  UUU4SU R                  0UD6  gU" UR                  U5        g[!        SU-  5        g)ziGeneric interface to the inspector system.

This function is meant to be called by pdef, pdoc & friends.
Nz'Module ``docrepr`` required but missingpdocpinfor  zObject `%s` not found.z	not found)r  rx   rp   ImportErrorobject_inspectr  rb  r  r=   	HOOK_NAMEr  r  r  rn   r   r  r$  )	r   methr  r  r   r   	docformatpmethod	formatters	            r   _inspectInteractiveShell._inspect  s    
 '':## !"KLL!$"5"5e"<=II::h.@.@AAdnnd3G *.9Iv~%3HH	
 '+&<&<  %(*U23r   c                    U R                      U R                  U5      nUR                  (       a.  U R                  R	                  UR
                  XUS9sSSS5        $ [        R                  " USS9sSSS5        $ ! , (       d  f       g= f)zGet object info about oname)r   detail_levelNF)r   r  )r  r  r  r  r   r   r=   object_info)r   r  r  r   s       r   r  InteractiveShell.object_inspect.  sj    $$U+Dzz~~**488U)5 +    ++eD s   AA<A<<
B
c                 *    U R                  X5      S   $ )z!Get object info as formatted textrs   )object_inspect_mime)r   r  r  s      r   object_inspect_text$InteractiveShell.object_inspect_text9  s    ''<\JJr   c           
      T   U R                      U R                  U5      nUR                  (       a^  U R                  (       a  [	        U R                  U5      5      OSnU R                  R                  UR                  UUUUUS9sSSS5        $ [        U5      e! , (       d  f       g= f)zGet object info as a mimebundle of formatted representations.

A mimebundle is a dictionary, keyed by mime-type.
It must always have the key `'text/plain'`.
N)r   r  r	  omit_sections)
r  r  r  rx   rp   r  r  	_get_infor   rE  )r   r  r  r  r   r  s         r   r  $InteractiveShell.object_inspect_mime=  s     $$U+Dzz // d11%89 
 ~~//HH!-'"/ 0  " uo%# s   A7BB
B'c                 j    [        X S9U l        U R                  R                  U R                  5        g)z:Sets up the command history, and starts regular autosaves.r  r  N)rQ   r  r*  r  r   s    r   r4  InteractiveShell.init_historyZ  s)    -DF!!$"6"67r   c                    [         R                  " SU S9U l        [         R                  " SSSU R                  U S9U l        [
        R                  U l        U R                  " U6   U R                  R                  U R                  S9  g )Nr   )color_schemer  r  r   )moder  	tb_offsetdebugger_clsr  )r  )r@   SyntaxTBAutoFormattedTBr  rZ  r~  r  sys_excepthookset_custom_excset_modexmode)r   rX  s     r   rC  (InteractiveShell.init_traceback_handlerse  s{    ((iM
 %44GBKAB040A0A$P "nn 	./ 	###4r   c                    ^^ [        U[        5      (       d  [        S5      eSS jnS mTc  UnO	SUU4S jjn[        R                  " X@5      U l        Xl        g)a  set_custom_exc(exc_tuple, handler)

Set a custom exception handler, which will be called if any of the
exceptions in exc_tuple occur in the mainloop (specifically, in the
run_code() method).

Parameters
----------
exc_tuple : tuple of exception classes
    A *tuple* of exception classes, for which to call the defined
    handler.  It is very important that you use a tuple, and NOT A
    LIST here, because of the way Python's except statement works.  If
    you only want to trap a single exception, use a singleton tuple::

        exc_tuple == (MyCustomException,)

handler : callable
    handler must have the following signature::

        def my_handler(self, etype, value, tb, tb_offset=None):
            ...
            return structured_traceback

    Your handler must return a structured traceback (a list of strings),
    or None.

    This will be made into an instance method (via types.MethodType)
    of IPython itself, and it will be called if any of the exceptions
    listed in the exc_tuple are caught. If the handler is None, an
    internal basic one is used, which just prints basic info.

    To protect IPython from crashes, if your handler ever raises an
    exception or returns an invalid result, it will be immediately
    disabled.

Notes
-----
WARNING: by putting in your own exception handler into IPython's main
execution loop, you run a very good chance of nasty crashes.  This
facility should only be used if you really know what you are doing.
z/The custom exceptions must be given as a tuple.Nc                 b    [        S5        [        SU5        [        SU5        [        SU5        g )Nz'*** Simple custom exception handler ***zException type :zException value:zTraceback      :)r$  )r   etyper&   tbr  s        r   dummy_handler6InteractiveShell.set_custom_exc.<locals>.dummy_handler  s,    ;<$e,$e,$b)r   c                     SU -  nU c  / $ [        U [        5      (       a  U /$ [        U [        5      (       d  [        U5      eU  H#  n[        U[        5      (       a  M  [        U5      e   U $ )a  validate structured traceback return type

return type of CustomTB *should* be a list of strings, but allow
single strings or None, which are harmless.

This function will *always* return a list of strings,
and will raise a TypeError if stb is inappropriate.
z,CustomTB must return list of strings, not %r)r   r   r  r   )stbmsgr  s      r   validate_stb5InteractiveShell.set_custom_exc.<locals>.validate_stb  sl     A3FC{	C%%uT**n$!$,,#C.(  Jr   c                 x  >  T" XX#US9nT" U5      $ !   U R                  SS5        [        S[        R                  S9  U R                  R
                  " [        R                  " 5       6 n[        U R                  R                  U5      5        [        S5        U R                  R                  XU4US9n U$ = f)zwrap CustomTB handler, to protect IPython from user code

This makes it harder (but not impossible) for custom exception
handlers to crash IPython.
r  r   Nz'Custom TB Handler failed, unregisteringr   zThe original exception:)r#  r$  r~  r  rZ  structured_tracebackexc_infostb2text)r   r)  r&   r*  r  r.  handlerr0  s         r   wrapped0InteractiveShell.set_custom_exc.<locals>.wrapped  s    !$U	JC',,
''D1C#**U,,AA3<<>RC$,,55c:;34,,AA-2,<	 B C 
s
    B#B9r   )r   r  r   r   r!  CustomTBrX  )r   	exc_tupler8  r+  r9  r0  s     `  @r   r#  InteractiveShell.set_custom_exc|  sY    V )U++MNN	*	. ?#G , ((6!*r   c                 (    U R                  XU4SS9  g)a  One more defense for GUI apps that call sys.excepthook.

GUI frameworks like wxPython trap exceptions and call
sys.excepthook themselves.  I guess this is a feature that
enables them to keep running after exceptions that would
otherwise kill their mainloop. This is a bother for IPython
which expects to catch all of the program exceptions with a try:
except: statement.

Normally, IPython sets sys.excepthook to a CrashHandler instance, so if
any app directly invokes sys.excepthook, it will look to the user like
IPython crashed.  In order to work around this, we can disable the
CrashHandler and replace it with this excepthook instead, which prints a
regular traceback using our InteractiveTB.  In this fashion, apps which
call sys.excepthook will generate a regular-looking exception from
IPython, and the CrashHandler will only be triggered by real IPython
crashes.

This hook should be used sparingly, only in places which are not likely
to be true IPython errors.
r   r3  N)showtraceback)r   r)  r&   r*  s       r   r  InteractiveShell.excepthook  s    , 	E"-;r   c                 8   Uc  [         R                  " 5       u  p#nOUu  p#nUcD  [        [         S5      (       a/  [         R                  [         R                  [         R
                  pCnUc  [        S5      eU[         l        U[         l        U[         l        X#U4$ )zget exc_info from a given tuple, sys.exc_info() or sys.last_type etc.

Ensures sys.last_type,value,traceback hold the exc_info we found,
from whichever source.

raises ValueError if none of these contain any information
	last_typezNo exception to find)r~  r6  rb  rB  
last_valuer_  r   )r   r<  r)  r&   r*  s        r   _get_exc_infoInteractiveShell._get_exc_info  s     "||~E"(E"=sK((#&==#..#&#5#5 ! =344 Rr   c                 :    [        SU-  [        R                  S9  g)zdShow a short message for UsageErrors

These are special exceptions that shouldn't show a traceback.
zUsageError: %sr4  N)r$  r~  r  )r   excs     r   show_usage_error!InteractiveShell.show_usage_error  s    
 	$3::6r   c                 x    U R                  U5      u  p#n[        R                  " X#5      nSR                  U5      $ )ze
Return as a string (ending with a newline) the exception that
just occurred, without any traceback.
r   )rD  	tracebackformat_exception_onlyr3  )r   r<  r)  r&   r*  r/  s         r   get_exception_only#InteractiveShell.get_exception_only"  s7    
  --i8b--e;wws|r   c                   ^
   U R                  U5      u  pgn[        U[        5      (       a  U R                  X%5        gU[        L a  U R                  U5        gU(       a/  S/n	U	R                  U R                  R                  UU5      5        OU
4S jm
T
" U5      (       a  [        R                  " 5         OP [        US5      (       a  UR!                  5       n	OU R                  R#                  XgXS9n	 U R'                  XgU	5        U R(                  (       a  U R+                  S	S
9  gU R'                  XgU	5        g! [         a    [        S[        R                  S9   gf = f! [$         a#    [        S5        [        R                  " 5          gf = f! [,         a,    [        SU R                  5       -   [        R                  S9   gf = f)a  Display the exception that just occurred.

If nothing is known about the exception, this is the method which
should be used throughout the code for presenting user tracebacks,
rather than directly invoking the InteractiveTB object.

A specific showsyntaxerror() also exists, but this method can take
care of calling it if needed, so unless you are explicitly catching a
SyntaxError exception, don't try to analyze the stack manually and
simply call this method.zNo traceback available to show.r4  Nz>An exception has occurred, use %tb to see the full traceback.
c                 ^   > U c  g[        U [        5      =(       d    T" U R                  5      $ NF)r   r~   __context__)r[  contains_exceptiongroups    r   rS  ?InteractiveShell.showtraceback.<locals>.contains_exceptiongroupM  s1    ;#()!3   F4S__EFr   _render_traceback_r3  zMUnexpected exception formatting exception. Falling back to standard exceptionTr`  r   )rD  r   r$  r~  r  
issubclassSyntaxErrorshowsyntaxerrorrL   rH  extendrZ  rM  rK  	print_excrb  rU  r5  	Exception_showtracebackrS  rc  KeyboardInterrupt)r   r<  rI  r  exception_onlyrunning_compiled_coder)  r&   r*  r.  rS  s             @r   r?  InteractiveShell.showtraceback+  s   =	E#'#5#5i#@ b
 %-- $$XE*$%%e,!3 4CJJt11DDUEJ L MF /u55 "++-(  'u.BCC&+&>&>&@&*&8&8&M&M$)" 'N '" ++E#>}}D1 ##E#6o  7cjjIR  ) (! o &//1#'(  ! 	E$0022D	Esp   D= &F F AF :!E% F E% 63F *F ="E"F !E""F %*FF FF 3G
Gr.  c                     U R                   R                  U5      n [        U5        g! [         a,    [        UR	                  SS5      R                  5       5         gf = f)zActually show a traceback.

Subclasses may override this method to put the traceback on a different
place, like a side channel.
utf-8backslashreplaceN)rZ  r7  r$  UnicodeEncodeErrorencodedecode)r   r)  evaluer.  r[  s        r   r\  InteractiveShell._showtracebackw  sU       ))#.	D#J! 	D#**W&89@@BC	Ds   ) 3AAc                    U R                  5       u  p4nU(       a  [        U[        5      (       a   Xl        U(       a  [        R
                  " U5      O/ nU R                  R                  X4U5      nU R                  X4U5        g!    NR= f)a  Display the syntax error that just occurred.

This doesn't display a stack trace because there isn't one.

If a filename is given, it is stuffed in the exception instead
of what was there before (because Python's parser always uses
"<string>" when reading from a string).

If the syntax error occurred when running a compiled code (i.e. running_compile_code=True),
longer stack trace will be displayed.
N)	rD  rV  rW  rI  rK  
extract_tbr   r5  r\  )r   rI  r_  r)  r&   r_  elistr.  s           r   rX   InteractiveShell.showsyntaxerror  sx     (,'9'9';$n
5+66!) 9N	$$^4SUmm00uEE#.s   B B	c                 $    U R                  5         g)zCalled by _run_cell when there's an IndentationError in code entered
at the prompt.

This is overridden in TerminalInteractiveShell to show a message about
the %paste magic.N)rX  r   s    r   showindentationerror%InteractiveShell.showindentationerror  s     	r   c                     Xl         g)zSets the 'default' input string for the next command line.

Example::

    In [1]: _ip.set_next_input("Hello Word")
    In [2]: Hello Word_  # cursor is here
N)rl_next_input)r   r   r   s      r   set_next_inputInteractiveShell.set_next_input  s
     r   c                 <    U R                   R                  5       S-  $ )z3return the current level of indentation as a string )r  get_indent_spacesr   s    r   _indent_current_str$InteractiveShell._indent_current_str  s    ""446<<r   c                    SSK Jn  SSKJnJnJnJn  U" U U R                  U R                  U S9U l	        U R                  R                  U R                  5        U R                  R                  S[        5       5      nX`R                  S'   X`R                  l        U R!                  SUSS9  U R!                  SUSS9  U R!                  SUS	S9  U R!                  SUS
S9  U R!                  SUSS9  U R!                  SUSS9  g)a&  Initialize the completion machinery.

This creates completion machinery that can be used by client code,
either interactively in-process (typically triggered by the readline
library), programmatically (such as in test suites) or out-of-process
(typically over the network by remote frontends).
r   )IPCompleter)cd_completermagic_run_completermodule_completerreset_completer)r  r  global_namespacer  complete_commandimport)r)  fromz%aimportz%runz%cdz%resetN)IPython.core.completerrz  IPython.core.completerlibr{  r|  r}  r~  rW  r:  	Completerr*  r  r  r#   ri   custom_completersr  )r   rz  r{  r|  r}  r~  sdisps          r   rA  InteractiveShell.init_completer  s     	7	
 	
 %4/3||6:6I6I,0'
 	!!$..1 ##''(:KMJ27./+0((*:hO(*:fM(*:jQ(*=P(,%H(/XNr   c                     U R                      U R                  R                  XU5      sSSS5        $ ! , (       d  f       g= f)a)  Return the completed text and a list of completions.

Parameters
----------
text : string
    A string of text to be completed on.  It can be given as empty and
    instead a line/position pair are given.  In this case, the
    completer itself will split the line like readline does.
line : string, optional
    The complete line that text is part of.
cursor_pos : int, optional
    The position of the cursor on the input line.

Returns
-------
text : string
    The actual text that was completed.
matches : list
    A sorted list with all possible completions.

Notes
-----
The optional arguments allow the completion to take more context into
account, and are part of the low-level completion API.

This is a wrapper around the completion mechanism, similar to what
readline does at the command line when the TAB key is hit.  By
exposing it as a method, it can be used by other non-readline
environments (such as GUIs) for text completion.

Examples
--------
In [1]: x = 'hello'

In [2]: _ip.complete('x.l')
Out[2]: ('x.l', ['x.ljust', 'x.lower', 'x.lstrip'])
N)r  r  complete)r   textr  
cursor_poss       r   r  InteractiveShell.complete  s.    R >>**4zB s	   3
Ac                     [         R                  " XR                  5      nU R                  R                  R	                  X#5        g)a  Adds a new custom completer function.

The position argument (defaults to 0) is the index in the completers
list where you want the completer to be inserted.

`completer` should have the following signature::

    def completion(self: Completer, text: string) -> List[str]:
        raise NotImplementedError

It will be bound to the current Completer instance and pass some text
and return a list with current completions to suggest to the user.
N)r   r!  r  custom_matchersr  )r   	completerposnewcomps       r   set_custom_completer%InteractiveShell.set_custom_completer		  s0     ""9nn=&&--c:r   c                     U(       a7  UR                   U R                  l        UR                  U R                  l        gU R
                  U R                  l        U R                  U R                  l        g)zSet the frame of the completer.N)r  r  r  r  r  rW  r:  )r   frames     r   set_completer_frame$InteractiveShell.set_completer_frame	  sG    ',~~DNN$.3ooDNN+'+||DNN$.2.A.ADNN+r   c                    SSK Jn  [        R                  " U U UR	                  U 5      S9U l        U R                  R                  U R
                  5        U R
                  R                  U l	        U R                  UR                  UR                  UR                  UR                  UR                  UR                  UR                   UR"                  UR$                  UR&                  UR(                  UR*                  UR,                  UR.                  5        U R                  UR0                  5        U R
                  nUR3                  SS5        UR3                  SS5        UR3                  SS	5        UR3                  S
SS5        UR3                  SSS5        UR3                  SSS5        U R5                  SU R6                  5        g )Nr   )r  )r  r  user_magicsededithisthistoryreprecallSVGsvgcellHTMLhtmlr   	writefiler  )IPython.corer  r<   MagicsManager
UserMagicsr  r*  r  rR  register_magics
AutoMagicsBasicMagics
CodeMagicsConfigMagicsDisplayMagicsExecutionMagicsExtensionMagicsHistoryMagicsLoggingMagicsNamespaceMagicsOSMagicsPackagingMagicsPylabMagicsScriptMagicsAsyncMagicsregister_aliasrun_line_magicr  )r   r  mmans      r   rI  InteractiveShell.init_magics(	  si   ,#11*./0||D/AC 	!!$"5"56  $22;;Q\\1==!,,NNAOOQ->->qqzz1+<+<MM1>>		
 	Q]]+ "" 	D&)FI.E8,E5&1FFF3FK8
 	Hdkk2r   c                 8    U R                   R                  XUS9  g )N)
magic_kind
magic_name)r  register_function)r   r5  r  r  s       r   register_magic_function(InteractiveShell.register_magic_functionK	  s     --J 	. 	
r   r  c                    U R                   U R                  S.U   nU" U5      nUb  U$ U R                  R                  R	                  U5      nUc  gU R                  SU5        U" U5      nU$ )a  
Try to find a magic potentially lazy-loading it.

Parameters
----------

type_: "line"|"cell"
    the type of magics we are trying to find/lazy load.
magic_name: str
    The name of the magic we are trying to find/lazy load


Note that this may have any side effects
)r  r  Nload_ext)r  r  r  lazy_magicsr#   r  )r   type_r  finderfnlazyress          r   _find_with_lazy_load%InteractiveShell._find_with_lazy_loadQ	  sv     ..8L8LMeTJ>I""..22:><J-Z 
r   c                    U R                  SU5      nUcO  U R                  R                  R                  U5      nU(       a#  U R	                  SU5        U R                  U5      nUc,  U R                  U5      nSnUc  SOSU-  n[        XqU4-  5      eUn	[        U[        R                  S5      (       a  Un
OU R                  X)5      n
U
/n0 n[        USS5      (       a  U R                  U	5      US	'   U R                     U" U0 UD6nSSS5        [        U[        R                  S5      (       a  [        R                   " U
5      (       a  gW$ ! , (       d  f       NL= f)
am  Execute the given line magic.

Parameters
----------
magic_name : str
    Name of the desired magic function, without '%' prefix.
line : str
    The rest of the input line as a single string.
_stack_depth : int
    If run_line_magic() is called from magic() then _stack_depth=2.
    This is added to ensure backward compatibility for use of 'get_ipython().magic()'
r  Nr  z'Line magic function `%%%s` not found%s.r   z= (But cell magic `%%%%%s` exists, did you mean that instead?)Fneeds_local_scopelocal_ns)r  r  r  r#   r  r  r  rL   r  r<   MAGIC_NO_VAR_EXPAND_ATTR
var_expandget_local_scoper  MAGIC_OUTPUT_CAN_BE_SILENCEDrI   semicolon_at_end_of_expression)r   r  r  _stack_depthr  r  cmetplextrastack_depthmagic_arg_sr   r   r   s                 r   r  InteractiveShell.run_line_magicl	  sU    &&vz::&&2266zBD##J5))*5:%%j1B<D*B ,BDN,OET$7788 'Kr5995AA""ood@=DFr.66%)%9%9+%Fz"""T,V, # r5==uEE==kJJM #"s   	E
Ec                 H    [         R                  " US-   5      R                  $ )zsGet local scope at given stack depth.

Parameters
----------
stack_depth : int
    Depth relative to calling frame
r   )r~  r  r  )r   r  s     r   r   InteractiveShell.get_local_scope	  s     }}[1_-666r   c                    U R                  SU5      nUcC  U R                  U5      nSnUc  SOSR                  U5      n[        UR                  X5      5      eUS:X  aB  SR                  U5      nU R                  U5      b  USR                  U5      -  n[        U5      eSn	[	        U[
        R                  S	5      (       a  Un
OU R                  X)5      n
0 n[	        US
S	5      (       a  U R                  US'   U R                     X4nU" U0 UD6nSSS5        [	        U[
        R                  S	5      (       a  [        R                  " U5      (       a  gW$ ! , (       d  f       NL= f)a  Execute the given cell magic.

Parameters
----------
magic_name : str
    Name of the desired magic function, without '%' prefix.
line : str
    The rest of the first input line as a single string.
cell : str
    The body of the cell as a (possibly multiline) string.
r  Nz Cell magic `%%{0}` not found{1}.r   z; (But line magic `%{0}` exists, did you mean that instead?)z2%%{0} is a cell magic, but the cell body is empty.z- Did you mean the line magic %{0} (single %)?r   Fr  r  )r  r  r  rL   r  r<   r  r  rW  r  r  rI   r  )r   r  r  r  r  lmr  r  messager  r  r   r   r   s                 r   run_cell_magicInteractiveShell.run_cell_magic	  sZ    &&vz::%%j1B5D*B ,::@&:L T[[;<<RZJQQR\]G##J/;JQQR\]]W%%
 Kr5995AA""ood@Fr.66%)\\z"""#*T,V, # r5==uEE==dCCM #"s   E
E&c                 R    U R                   R                  S   R                  U5      $ )zMFind and return a line magic by name.

Returns None if the magic isn't found.r  r  r  r#   r   r  s     r   r   InteractiveShell.find_line_magic	  &     ""))&155jAAr   c                 R    U R                   R                  S   R                  U5      $ )zMFind and return a cell magic by name.

Returns None if the magic isn't found.r  r  r  s     r   r   InteractiveShell.find_cell_magic	  r  r   c                 R    U R                   R                  U   R                  U5      $ )zZFind and return a magic of the given type by name.

Returns None if the magic isn't found.r  )r   r  r  s      r   
find_magicInteractiveShell.find_magic	  s&     ""))*599*EEr   c                     [         R                  " S[        SS9  UR                  S5      u  p#nUR	                  [
        R                  5      nU R                  X$SS9$ )aS  
DEPRECATED

Deprecated since IPython 0.13 (warning added in
8.1), use run_line_magic(magic_name, parameter_s).

Call a magic function by name.

Input: a string containing the name of the magic function to call and
any additional arguments to be passed to the magic.

magic('name -opt foo bar') is equivalent to typing at the ipython
prompt:

In[1]: %name -opt foo bar

To call a magic without arguments, simply use magic('name').

This provides a proper Python function to call IPython's magics in any
valid Python code you can type at the interpreter, including loops and
compound statements.
zr`magic(...)` is deprecated since IPython 0.13 (warning added in 8.1), use run_line_magic(magic_name, parameter_s).r   r   ru  )r  )r  r   r  	partitionr  r?   rR   r  )r   arg_sr  r  r  s        r   r<   InteractiveShell.magic	  s]    . 	A		
 &+__S%9"
{&&y':':;
"":"KKr   c                     SSK Jn  [        U[        5      (       a  UR	                  U5      n[        X#R                  5      (       d  [        S5      eX R                  U'   g)zDefine a new macro

Parameters
----------
name : str
    The name of the macro.
themacro : str or Macro
    The action to do upon invoking the macro.  If a string, a new
    Macro object is created by passing the string to it.
r   )macroz-A macro must be a string or a Macro instance.N)r  r  r   r   rU   r   rW  )r   r   themacror  s       r   define_macroInteractiveShell.define_macro
  sI     	'h$${{8,H(KK00LMM%Tr   c                     UR                  5       R                  S5      (       a  [        S5      e[        U R	                  USS95      U R
                  S'   g)zCall the given cmd in a subprocess, piping stdout/err

Parameters
----------
cmd : str
    Command to execute (can not end in '&', as background processes are
    not supported.  Should not be a command that expects input
    other than simple text.
&#Background processes not supported.r   depth
_exit_codeN)rstripr  OSErrorrh   r  rW  r   r  s     r   system_pipedInteractiveShell.system_piped0
  sK     ::<  %% ?@@
 &,DOOCqO,I%J\"r   c                    U R                  USS9nUR                  5       S   nSnX#;   a%  [        R                  " SR	                  U5      5        [
        R                  S:X  a;  SSKJn  U" 5        nUb
  S	U< S
U< 3n [        R                  " U5      nSSS5        OC[        R                  R!                  SS5      n ["        R$                  " USUS9nUS:  a  US-
  * nWU R&                  S'   g! [         a.    [        SU R                  5       -   [
        R                  S9  Sn Nf = f! , (       d  f       NY= f! [         a.    [        SU R                  5       -   [
        R                  S9  Sn Nf = f)zCall the given cmd in a subprocess using os.system on Windows or
subprocess.call using the system shell on other platforms.

Parameters
----------
cmd : str
    Command to execute.
r   r  r   )pipcondacdzhYou executed the system command !{0} which may not work as expected. Try the IPython magic %{0} instead.r  )AvoidUNCPathNz"pushd z &&"r   r4  SHELLT)r  r        r  )r  r  r  r   r  r~  r  IPython.utils._process_win32r  r!  rh   r]  r$  rM  r  r  r#   
subprocesscallrW  )r   r  main_cmdhas_magic_alternativesr  r   ecr  s           r   
system_rawInteractiveShell.system_rawG
  sJ    ooco+99;q>!7-MMG&"	 <<7"A4#/3S9C3B	  $ 6J__SL
 CxCx[ &(\"; ) $!8!8!::LB  , % dT4466SZZHs<   1D- C2 D> 25D*'D-)D**D--
D;>5E65E6c                     UR                  5       R                  S5      (       a  [        S5      e[        U R	                  XS-   S95      nU(       a  [        UR                  5       5      nU$ [        U5      nU$ )a  Get output (possibly including stderr) from a subprocess.

Parameters
----------
cmd : str
    Command to execute (can not end in '&', as background processes are
    not supported.
split : bool, optional
    If True, split the output into an IPython SList.  Otherwise, an
    IPython LSString is returned.  These are objects similar to normal
    lists and strings, with a few convenience attributes for easier
    manipulation of line-based output.  You can use '?' on them for
    details.
depth : int, optional
    How many frames above the caller are the local variables which should
    be expanded in the command string? The default (0) assumes that the
    expansion variables are in the stack frame calling this function.
r  r  r   r  )r  r  r  rg   r  rm   
splitlinesrl   )r   r  r  r  outs        r   rg   InteractiveShell.getoutput
  sk    & ::<  %%?@@7;<()C 
 3-C
r   c                 j    [        X S9U l        U R                  R                  U R                  5        g Nr  )rB   r  r*  r  r   s    r   rJ  InteractiveShell.init_alias
  s)    )B!!$"4"45r   c                 j    [        X S9U l        U R                  R                  U R                  5        g r  )rO   extension_managerr*  r  r   s    r   rM  'InteractiveShell.init_extension_manager
  s)    !1!J!!$"8"89r   c                 j    [        U S9U l        U R                  R                  U R                  5        g r  )rV   payload_managerr*  r  r   s    r   rN  InteractiveShell.init_payload
  s)    -T:!!$"6"67r   c                     [        X S9U l        U R                  R                  U R                  5        U R                  R                  U l        g r  )rW   prefilter_managerr*  r  prefilter_linesr?   r   s    r   r6  InteractiveShell.init_prefilter
  s>    !1!J!!$"8"89 //??r   c                 D    U R                   (       d  g[        SU-   5        g)aA  Print to the screen the rewritten form of the user's command.

This shows visual feedback by rewriting input lines that cause
automatic calling to kick in, like::

  /f x

into::

  ------> f(x)

after the user's input prompt.  This helps the user understand that the
input line was transformed automatically by IPython.
Nz------> )show_rewritten_inputr$  r  s     r   auto_rewrite_input#InteractiveShell.auto_rewrite_input
  s     (( 	j3r   c                     U R                  5       u  pnU R                  R                  X5      nSUUR                  [        R
                  " U5      S.nU$ )z:return simple exception dict

for use in user_expressions
r   )statusrK  enamerg  )rD  rZ  rM  r)   r`   safe_unicode)r   r)  rg  r*  r.  r6  s         r   _user_obj_error InteractiveShell._user_obj_error
  sX     !..0r  33EB ^^,,V4	
 r   c                 L    U R                   R                  U5      u  p#SUUS.nU$ )zBformat a user object to display dict

for use in user_expressions
ok)r)  datametadata)r  r  )r   r   r0  mdr&   s        r   _format_user_obj!InteractiveShell._format_user_obj
  s3     ))005

 r   c                     0 nU R                   nU R                  nUR                  5        H%  u  pV U R                  [	        XdU5      5      nXrU'   M'     U$ !   U R                  5       n N= f)a  Evaluate a dict of expressions in the user's namespace.

Parameters
----------
expressions : dict
    A dict with string keys and string values.  The expression values
    should be valid Python expressions, each of which will be evaluated
    in the user namespace.

Returns
-------
A dict, keyed like the input expressions dict, with the rich mime-typed
display_data of each value.
)rW  r:  r   r3  r  r,  )r   expressionsr  rW  	global_nsr!   exprr&   s           r   user_expressions!InteractiveShell.user_expressions  ss     ,,''	$**,IC/--d4G.LM H - 
/,,.s   AA*c                     U R                      [        XR                  U R                  5        SSS5        g! , (       d  f       g= f)z4Execute a normal python statement in user namespace.N)r  execr:  rW  r  s     r   exInteractiveShell.ex   s+    ))4<<8 s	   !7
Ac                     U R                      [        XR                  U R                  5      sSSS5        $ ! , (       d  f       g= f)zUEvaluate python expression expr in user namespace.

Returns the result of evaluation
N)r  r  r:  rW  )r   r8  s     r   evInteractiveShell.ev%  s-    
 114<<@ s	    7
A)exit_ignoreraise_exceptionsr   c                   [        U5      R                  5       R                  5       n UR                  S5          SSS5        [        UR                  5      n[        U5         U R                      US-   SS u  px[        R                  " XUU(       a  U R                  OS5        SSS5        SSS5        g! , (       d  f       N= f!   [	        SU-  5         g= f! [         a9  n	U	R                  (       a  U(       a  e U(       d  U R                  SS9   Sn	A	NuSn	A	f  U(       a  e U R                  SS9   N= f! , (       d  f       N= f! , (       d  f       g= f)	a  A safe version of the builtin execfile().

This version will never throw an exception, but instead print
helpful error messages to the screen.  This only works on pure
Python files with the .py extension.

Parameters
----------
fname : string
    The name of the file to be executed.
*where : tuple
    One or two namespaces, passed to execfile() as (globals,locals).
    If only one is given, it is passed as both.
exit_ignore : bool (False)
    If True, then silence SystemExit for non-zero status (it is always
    silenced for zero status, as it is so common).
raise_exceptions : bool (False)
    If True raise exceptions everywhere. Meant for testing.
shell_futures : bool (False)
    If True, the code will share future statements with the interactive
    shell. It will both be affected by previous __future__ imports, and
    any __future__ imports in the code will affect the shell. If False,
    __future__ imports are not shared in either direction.

rbN,Could not open file <%s> for safe execution.r   r   Tr^  r3  )r   
expanduserresolver   r   r   r  rj   r  r`   execfilerp  
SystemExitcoder?  )
r   fnamerB  rC  r   wherednamegloblocr)  s
             r   safe_execfileInteractiveShell.safe_execfile-  s   4 U&&(002	D! " ELL!!%($*;*;0"X-r2	""$1DLLt= +<(( "!	?%GH  @ ;;'&**$*?0#""Q"/3 +<*;((so   C
 B9C
 $E1D>35C(E9
CC
 C
 
C
D;)/DD>D;9D>>
E	E
Ec                 L  ^ [        T5      R                  5       R                  5       m TR                  S5          SSS5        [        TR                  5      nU4S jn[        U5          U" 5        H@  nU R                  USUS9nU(       a  UR                  5         M-  UR                  (       a  M@    O    SSS5        g! , (       d  f       N= f!   [	        ST-  5         g= f!   U(       a  e U R                  5         [	        ST-  5         NY= f! , (       d  f       g= f)aS  Like safe_execfile, but for .ipy or .ipynb files with IPython syntax.

Parameters
----------
fname : str
    The name of the file to execute.  The filename must have a
    .ipy or .ipynb extension.
shell_futures : bool (False)
    If True, the code will share future statements with the interactive
    shell. It will both be affected by previous __future__ imports, and
    any __future__ imports in the code will affect the shell. If False,
    __future__ imports are not shared in either direction.
raise_exceptions : bool (False)
    If True raise exceptions everywhere.  Meant for testing.
rE  NrF  c               3      >#    TR                   S:X  aS  SSKJn   U " TSS9nUR                  (       d  gUR                   H#  nUR                  S:X  d  M  UR
                  v   M%     gTR                  SS	9v   g7f)
z,generator for sequence of code blocks to runz.ipynbr   )read   )
as_versionNrL  rb  r  )suffixnbformatrV  cells	cell_typesource	read_text)rV  nbr  rM  s      r   	get_cells5InteractiveShell.safe_execfile_ipy.<locals>.get_cells  sb     ||x')%A.xxHHD~~/"kk) % oowo77s   AA9%A9T)r   r   z$Unknown failure executing file: <%s>)r   rH  rI  r   r   r   r  rj   run_cellr   r   r?  )r   rM  r   rC  rO  ra  r  r   s    `      r   safe_execfile_ipy"InteractiveShell.safe_execfile_ipyq  s      U&&(002	D! " ELL!	8 "%(E%KD!]]4M]ZF'**,#^^^ ( )(1 "!	?%GH8E#""$;eCD )(s^   C CC +D-AC(4C(5D6C(8D
CC C C%((DD
D#c                       UR                  [        R                  " [        U5      SSS95        g! [         a  nUR
                  (       a  e  SnAgSnAff = f!   U R                  5         [        SU-  5         g= f)aH  A safe version of runpy.run_module().

This version will never throw an exception, but instead print
helpful error messages to the screen.

`SystemExit` exceptions with status code 0 or None are ignored.

Parameters
----------
mod_name : string
    The name of the module to be executed.
where : dict
    The globals namespace.
rr  T)run_name	alter_sysNz&Unknown failure executing module: <%s>)r  runpy
run_moduler   rK  rL  r?  r   )r   mod_namerN  r)  s       r   safe_run_module InteractiveShell.safe_run_module  st    	F$$S]Z/35  ;; 	F 9HDEs&   .2 
AAA AA  A=c                 6   Sn U R                  XX4U5      nU R                  R                  S5        U(       d  U R                  R                  SU5        U$ ! U R                  R                  S5        U(       d  U R                  R                  SU5        f f = f)a-  Run a complete IPython cell.

Parameters
----------
raw_cell : str
    The code (including IPython code such as %magic functions) to run.
store_history : bool
    If True, the raw and translated cell will be stored in IPython's
    history. For user code calling back into IPython's machinery, this
    should be set to False.
silent : bool
    If True, avoid side-effects, such as implicit displayhooks and
    and logging.  silent=True forces store_history=False.
shell_futures : bool
    If True, the code will share future statements with the interactive
    shell. It will both be affected by previous __future__ imports, and
    any __future__ imports in the code will affect the shell. If False,
    __future__ imports are not shared in either direction.

Returns
-------
result : :class:`ExecutionResult`
Npost_executepost_run_cell)	_run_cellrO  rP  )r   r   r   r   r   r   r   s          r   rc  InteractiveShell.run_cell  s    > 	=^^F KK/##OV< KK/##OV< s   A ABr   r   r   r   r   c           
         Sn U R                  U5      nUc   eU R	                  UUUUUUUS9nU R
                  (       a  U R
                  n	O)U R                  UUUS9(       a  U R                  n	O[        n	 U	" U5      n
U
$ ! [         a    Un[        R                  " 5       n Nf = f! [         a8  n[        XX4U5      n[        U5      n
Xl        U R                  SS9   SnAU
$ SnAff = f! W
s  s $ = f)z/Internal method to run a complete IPython cell.N)r   r   r   transformed_cellpreprocessing_exc_tupler   rt  ru  Tr_  )transform_cellr[  r~  r6  run_cell_asyncrT  should_run_asyncr   r   r   r   r   r   r?  )r   r   r   r   r   r   ru  rt  coror   r   r  r   s                r   rq  InteractiveShell._run_cell  s(    #'	5#228<
  +++""''-$; # 
 %%F""-$; # 

 %%F(F
	D\F MQ  	5'&)lln#	5@  	; D %T*F#$ T:M	; Ms;   B 7B( !B%$B%(
C*2-C%C- %C**C- -C4rv  c                    U R                   (       d  gUb  gUb   eUc-  [        R                  " S[        SS9   U R	                  U5      nOUn[        U5      $ ! [
         a     gf = f)a  Return whether a cell should be run asynchronously via a coroutine runner

Parameters
----------
raw_cell : str
    The code to be executed

Returns
-------
result: bool
    Whether the code needs to be run with a coroutine runner or not
.. versionadded:: 7.0
Fz`should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.r   r   )r   r  r   r  rx  r[  r   )r   r   rt  ru  r  s        r   rz  !InteractiveShell.should_run_async*  s      ~~".&...#MM+ #	**84 $D%%   s   A 
A&%A&)rt  ru  r   rt  ru  c          
        ^ ^^#    [        UTX4U5      n[        U5      mU(       a  UR                  5       (       a  ST l        TT l        T$ U(       a  SmT(       a  T R
                  Tl        UU U4S jn	T R                  R                  S5        U(       d  T R                  R                  SU5        Uc/  [        R                  " S[        SS	9   T R                  U5      n
SnOUc  Un
OUn
S
U
;   a  SU
;   a  SmT(       a&  T R                  R!                  T R
                  X5        U(       d  T R"                  R%                  X5        Ub8  T R'                  U5        T(       a  T =R
                  S-  sl        U	" US   5      $ U(       a  T R(                  OT R+                  5       nSnT R,                     UR/                  U
T R
                  US9nT R0                      UR3                  XS9n T RI                  U5      nTT RL                  l'        U(       a  SOT RP                  nT RS                  URT                  UUUTS9I Sh  vN nU(       + T l        TT l        ST RL                  l'        SSS5        SSS5        T(       a:  T R                  RW                  T R
                  5        T =R
                  S-  sl        T$ ! [         a    [        R                  " 5       nUn
 GNf = f! T R4                   aP  n[        R                  " 5       u  nnnT R7                  UUU5        U	" U5      s SnAsSSS5        sSSS5        $ SnAf[8         a4  nT R;                  5         U	" U5      s SnAsSSS5        sSSS5        $ SnAf[<        [>        [@        [B        [D        4 a4  nT RG                  5         U	" U5      s SnAsSSS5        sSSS5        $ SnAff = f! [J         a4  nT R'                  5         U	" U5      s SnAsSSS5        sSSS5        $ SnAff = f GN! , (       d  f       GN= f! , (       d  f       GN= f7f)a  Run a complete IPython cell asynchronously.

Parameters
----------
raw_cell : str
  The code (including IPython code such as %magic functions) to run.
store_history : bool
  If True, the raw and translated cell will be stored in IPython's
  history. For user code calling back into IPython's machinery, this
  should be set to False.
silent : bool
  If True, avoid side-effects, such as implicit displayhooks and
  and logging.  silent=True forces store_history=False.
shell_futures : bool
  If True, the code will share future statements with the interactive
  shell. It will both be affected by previous __future__ imports, and
  any __future__ imports in the code will affect the shell. If False,
  __future__ imports are not shared in either direction.
transformed_cell: str
  cell that was passed through transformers
preprocessing_exc_tuple:
  trace if the transformation failed.

Returns
-------
result : :class:`ExecutionResult`

.. versionadded:: 7.0
TFc                 j   > T(       a  T=R                   S-  sl         U Tl        STl        TTl        T$ )Nr   F)r   r   r  r  )r&   r   r   r   s    r   r   :InteractiveShell.run_cell_async.<locals>.error_before_exec  s4    $$)$',F$,1D))/D&Mr   r1  pre_run_cellNz`run_cell_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.r   r   zget_ipython().run_line_magic(paster   )raw_code)rI  r  )interactivitycompilerr   ),r   r   isspacer  r  r   rO  rP  r  r   r  rx  r[  r~  r6  r  store_inputsr  logr?  rp  ro  r  cacher  	ast_parserX  r;  IndentationErrorrn  OverflowErrorrW  r   r   MemoryErrorrX  transform_astrK   r  exec_resultast_node_interactivityrun_ast_nodesbodystore_output)r   r   r   r   r   rt  ru  r   r   r   r  r  
_run_async	cell_namecode_astr  r)  r&   r*  r  
has_raisedr   s   ` `                  @r   ry  InteractiveShell.run_cell_asyncT  s    P X}fWU &X--//,0D))/D&M!M%)%9%9F"	 	M*KK5#MM+ #	/**84
 +/'&.' +d2w$!M   --d.B.BDSKKOOD+ #.67$$)$$%<Q%?@@
 $14<<d6I6I6K
 tT-A-AHUI""0'11$1KH0#11(;H 06  , +1d6Q6Q $(#5#5hmmY%2Xf $6 $V V
 5?--3* 04  ,O # X    --d.B.BC  A% m   *-,,.' T -- 0'*||~$E5"MM%3,Q// #"  ( 0--/,Q// #"  &{J	#% 0((*,Q// #" 0 % 0&&(,Q//+ #" ,0V? #" s#  C
QK !CQ5(P0PK*/O APP(P/P07AQ!K'#Q&K''Q*O:3M-O.P2	P0;
QON)O*P.	P07
Q"O#O:O;P?	P0
QOP
P$P;P<P 	P0	
QPP
P-	(P00
P?:Qc                 t   U R                   R                  U5      n[        UR                  5       5      S:X  a3  U R                     U R
                  R                  U5      S-   nSSS5        UR                  SS9nU R                   H  nU" U5      nM     SR                  U5      nU$ ! , (       d  f       NK= f)a  Transform an input cell before parsing it.

Static transformations, implemented in IPython.core.inputtransformer2,
deal with things like ``%magic`` and ``!system`` commands.
These run on all input.
Dynamic transformations, for things like unescaped magics and the exit
autocall, depend on the state of the interpreter.
These only apply to single line inputs.

These string-based transformations are followed by AST transformations;
see :meth:`transform_ast`.
r   r   NT)keependsr   )	r  rx  r   r  r  r!  r"  input_transformers_postr3  )r   r   r  lines	transforms        r   rx  InteractiveShell.transform_cell  s     --<<XFt !Q&"" --==dCdJ #
 .55Ie$E 6wwu~ #"s   B))
B7c                 >   U R                    H  n UR                  U5      nM     U R                   (       a  [        R                  " U5        U$ ! [         a    e [         a9  n[	        SU< SU< 35        U R                   R                  U5         SnAM  SnAff = f)az  Apply the AST transformations from self.ast_transformers

Parameters
----------
node : ast.Node
    The root node to be transformed. Typically called with the ast.Module
    produced by parsing user input.

Returns
-------
An ast.Node corresponding to the node it was called with. Note that it
may also modify the passed object, so don't rely on references to the
original AST.
zAST transformer z* threw an error. It will be unregistered. N)ast_transformersvisitrK   r[  r   removeastfix_missing_locations)r   nodetransformerr  s       r   r  InteractiveShell.transform_ast  s      00K:"((. 1   %%d+ !   :"A' %%,,[99:s   AB#.BBnodelistr  c                   #    U(       d  gUS:X  Ga  [        US   [        5      (       a  US   n[        U[        R                  5      (       a)  [	        UR
                  5      S:X  a  UR
                  S   nO$[        U[        5      (       a  UR                  nOSn[        U[        R                  5      (       ao  [        R                  " [        R                  " UR                  [        R                  " 5       5      5      n[        R                  " U5        UR                  U5        SnSn	US:X  a'  [        US   [        R                  5      (       a  SnOS	nUS	:X  a  U/ pO(US:X  a
  USS USS pOUS
:X  a  / UpO[        SU-  5      e S n/ nU
 H  nUR                  US45        M     U H  nUR                  US45        M     U H  u  pUS:X  a  [        U// 5      nOUS:X  a  [        R                   " U/5      nUR#                  U R$                  (       a  ['        [        SS5      OS5         U" WX/5      nU" U5      nSSS5        U R)                  WUWS9I Sh  vN (       d  M    g   [+        [,        R.                  S5      (       a
  [1        5         g! , (       d  f       N\= f NJ!   U(       a  [,        R2                  " 5       S   Ul        U R7                  5          g= f7f)aU  Run a sequence of AST nodes. The execution mode depends on the
interactivity parameter.

Parameters
----------
nodelist : list
  A sequence of AST nodes to run.
cell_name : str
  Will be passed to the compiler as the filename of the cell. Typically
  the value returned by ip.compile.cache(cell).
interactivity : str
  'all', 'last', 'last_expr' , 'last_expr_or_assign' or 'none',
  specifying which nodes should be run interactively (displaying output
  from expressions). 'last_expr' will run the last node interactively
  only if it is an expression (i.e. expressions in loops or other blocks
  are not displayed) 'last_expr_or_assign' will run the last expression
  or the last assignment. Other values for this parameter will raise a
  ValueError.

compiler : callable
  A function with the same interface as the built-in compile(), to turn
  the AST nodes into code objects. Default is the built-in compile().
result : ExecutionResult, optional
  An object to store exceptions that occur during execution.

Returns
-------
True if an exception occurred while running code, False if it finished
running.
Nr  r  r   r   r  Fr  r  r  zInteractivity was %rc                 b    [         R                  U R                  -  [         R                  :H  nU$ r   )inspectCO_COROUTINEco_flags)rL  is_asyncs     r   compare/InteractiveShell.run_ast_nodes.<locals>.compare  s&    "//$--?7CWCWWr   r<  singlePyCF_ALLOW_TOP_LEVEL_AWAITasync_T)r   _assign_nodesr  Assignr   targets_single_targets_nodestargetNameExprr   Loadr  r  r   r   r  extra_flagsr   r  run_coder   r~  r  r$  r6  r   r?  )r   r  r  r  r  r   asgr  nnode_asyncto_run_execto_run_interactiver  to_runr  r  modrL  asys                      r   r  InteractiveShell.run_ast_nodes?  s    L  11(2,66rlc3::..3s{{3Cq3H [[^F%:;; ZZF!Ffchh//HHSXXfii%DEE--e4OOE*'MK'(2,11 & &F".6+f$.6smXbc]+e#.0(+3mCDD.	 
 F#tVn- $ +tX./ + %
6> $,CX%//4&1C))~~ C!=sC
 $C9D!$-C tVC@@@ %  Q''" ;  A	 +.<<>!+<( sU   F
K+B(J0 5JJ0 #J.$J0 /J0 0K+1+J0 K+
J+	'J0 06K(&K+r  c                "  #    Sn[         R                  U R                  sn[         l        XPl        Sn  U(       a)  [        XR                  U R
                  5      I Sh  vN   O [        XR                  U R
                  5        U[         l         SnU$  N5! U[         l        f = f! [         a-  nUb  Xrl        U R                  SS9  [        SSS9   SnAU$ SnAf[        R                   a%    [         R                  " 5       u  pn
Ub  Xl         U$ U R                   a7    [         R                  " 5       u  pn
Ub  Xl        U R                  XU
5         U$   Ub  [         R                  " 5       S   Ul        U R                  SS	9   U$ = f7f)
a  Execute a code object.

When an exception occurs, self.showtraceback() is called to display a
traceback.

Parameters
----------
code_obj : code object
  A compiled code object, to be executed
result : ExecutionResult, optional
  An object to store exceptions that occur during execution.
async_ :  Bool (Experimental)
  Attempt to run top-level asynchronous code in a default loop.

Returns
-------
False : successful execution.
True : an error occurred.
__ipython_bottom__TNFrG  z'To exit: use 'exit', 'quit', or Ctrl-D.r   r   rw  )r~  r  r"  r  r:  rW  r<  rK  r   r?  r   bdbBdbQuitr6  rX  r;  )r   code_objr   r  __tracebackhide__old_excepthookoutflagr  r)  r&   r*  s              r   r  InteractiveShell.run_code  su    , 1 *-& -	0x)<)<dllKKK#6#6E "0* G7 L
 "0 	J!'($d3:qI" ! {{ 	-"||~E"!',$  %% 	,"||~E"!',$MM%+ 	;!'*||~a'8$T: sk   1F*B B %B B' FB B$$B' '
F1"CF8FFAFF0F	FrL  c                 \    U R                   R                  U5      u  p#USU=(       d    S-  4$ )a  Return whether a block of code is ready to execute, or should be continued

Parameters
----------
code : string
    Python input code, which can be multiline.

Returns
-------
status : str
    One of 'complete', 'incomplete', or 'invalid' if source is not a
    prefix of valid code.
indent : str
    When status is 'incomplete', this is some whitespace to insert on
    the next line of the prompt.
ru  r   )r  check_complete)r   rL  r)  nspacess       r   r  InteractiveShell.check_complete  s0    " 88GGMsgl+++r   c                     [        S5      e)Nz"Implement enable_gui in a subclass)NotImplementedError)r   guis     r   
enable_guiInteractiveShell.enable_gui  s    !"FGGr   c                    SSK Jn  SSKJn  UR	                  XR
                  5      u  pUS:w  a^  U R
                  c  Xl        OJXR
                  :w  a;  [        SU< SU R
                  < S35        UR	                  U R
                  5      u  pUR                  U5        U" X5        U R                  U5        UR                  U R                  5      U R                  R                  S   l        X4$ )	a  Enable interactive matplotlib and inline figure support.

This takes the following steps:

1. select the appropriate eventloop and matplotlib backend
2. set up matplotlib for interactive use with that backend
3. configure formatters for inline figure display
4. enable the selected gui eventloop

Parameters
----------
gui : optional, string
    If given, dictates the choice of matplotlib GUI backend to use
    (should be one of IPython's supported backends, 'qt', 'osx', 'tk',
    'gtk', 'wx' or 'inline'), otherwise we use the default chosen by
    matplotlib (as dictated by the matplotlib build-time options plus the
    user's matplotlibrc configuration file).  Note that not all backends
    make sense in all contexts, for example a terminal ipython can't
    display figures inline.
r   )configure_inline_support)
pylabtoolsinlinez3Warning: Cannot change to a different GUI toolkit: z. Using z	 instead.r  ) matplotlib_inline.backend_inliner  r  r  find_gui_and_backendpylab_gui_selectr$  activate_matplotlibr  
mpl_runnerrR  r  registrydefault_runner)r   r  r  ptbackends        r   enable_matplotlib"InteractiveShell.enable_matplotlib  s    * 	N1..s4I4IJ(?$$,(+%---03T5J5JL M!66t7L7LM
w' / 	MM$,,- 	$$%67F |r   c                    SSK Jn  U R                  U5      u  p0 nU" Xb5        S1n[        U5      R	                  U R
                  5      R                  U5      nU V	s/ s H  oR
                  U	   Xi   Ld  M  U	PM     n
n	U R
                  R                  U5        U R                  R                  U5        XU
4$ s  sn	f )ad  Activate pylab support at runtime.

This turns on support for matplotlib, preloads into the interactive
namespace all of numpy and pylab, and configures IPython to correctly
interact with the GUI event loop.  The GUI backend to be used can be
optionally selected with the optional ``gui`` argument.

This method only adds preloading the namespace to InteractiveShell.enable_matplotlib.

Parameters
----------
gui : optional, string
    If given, dictates the choice of matplotlib GUI backend to use
    (should be one of IPython's supported backends, 'qt', 'osx', 'tk',
    'gtk', 'wx' or 'inline'), otherwise we use the default chosen by
    matplotlib (as dictated by the matplotlib build-time options plus the
    user's matplotlibrc configuration file).  Note that not all backends
    make sense in all contexts, for example a terminal ipython can't
    display figures inline.
import_all : optional, bool, default: True
    Whether to do `from numpy import *` and `from pylab import *`
    in addition to module imports.
welcome_message : deprecated
    This argument is ignored, no welcome message will be displayed.
r   )import_pylabrt  )	IPython.core.pylabtoolsr  r  r  intersectionrW  
differencer  rk  )r   r  
import_allwelcome_messager  r  r  ignoredbothr   	clobbereds              r   enable_pylabInteractiveShell.enable_pylabH  s    4 	9--c2 R$!"2w##DLL1<<WE'+Stt||D/A/Qdt	SB""2&Y&& Ts   B;9B;c                 
   U R                   R                  5       n [        R                  " US-   5      nUR	                  UR
                  5         UR                  U/ US9nU$ ! [         a     N f = f! [         a     U$ f = f)a   Expand python variables in a string.

The depth argument indicates how many frames above the caller should
be walked to look for the local namespace where to expand variables.

The global namespace for expansion is always the user's interactive
namespace.
r   )r   r   )	rW  copyr~  r  r  r  r   vformatr[  )r   r  r  r	  r  r  s         r   r  InteractiveShell.var_expandx  s     \\ 	&MM%'*E IIenn%	 ##Cb#<C 
  	 	  	
	s#   A$ A4 $
A10A14
BBc                 ^   [        [        R                  " US95      nU R                  R	                  U5        [        R
                  " SU[        U5      S9u  pE[        R                  " U5        [        U5      nU R                  R	                  U5        U(       a  UR                  USS9  U$ )aT  Make a new tempfile and return its filename.

This makes a call to tempfile.mkstemp (created in a tempfile.mkdtemp),
but it registers the created filename internally so ipython cleans it up
at exit time.

Optional inputs:

  - data(None): if data is given, it gets written out to the temp file
    immediately, and the file is closed again.)prefixz.py)dirrb  rY  )r   tempfilemkdtemprs  r  mkstempr   r!  closerr  
write_text)r   r0  r  dir_pathhandlerI  	file_paths          r   
mktempfileInteractiveShell.mktempfile  s     ((78X&#++E6s8}M
N	i(   8r   c                 >    U R                   (       a  g[        XU5      $ r@  )quietrb   )r   promptr"   	interrupts       r   rb   InteractiveShell.ask_yes_no  s    ::&33r   c                 t    [         R                   " [        R                  R                  R                  5        g)zShow a usage messageN)r>   r  r  usageinteractive_usager   s    r   
show_usageInteractiveShell.show_usage  s    		',,$$667r   c                     U R                   R                  XS9nSR                  S U 5       5      nU(       d  SU;  a  SnU$ USUR                  S5       nU$ )a  Return as a string a set of input history slices.

Parameters
----------
range_str : str
    The set of slices is given as a string, like "~5/6-~4/2 4:8 9",
    since this function is for use by magic functions which get their
    arguments as strings. The number before the / is the session
    number: ~n goes n back from the current session.

    If empty string is given, returns history of current session
    without the last input.

raw : bool, optional
    By default, the processed input is used.  If this is true, the raw
    input history is used instead.

Notes
-----
Slices can be described with two notations:

* ``N:M`` -> standard python form, means including items N...(M-1).
* ``N-M`` -> include items N..M (closed endpoint).
rawr   c              3   ,   #    U  H
  u    pUv   M     g 7fr   r   )r  r  xs      r   r  7InteractiveShell.extract_input_lines.<locals>.<genexpr>  s     0%wq!%s   r   N)r  get_range_by_strr3  rfind)r   	range_strr  r  r  s        r   extract_input_lines$InteractiveShell.extract_input_lines  sg    2 $$55i5Iyy0%00 4  .djj./r   c                    U R                  XS9nU(       a  U$  UR                  S5      (       a  [        R                  " XS9$  U/n
 U
R                  S[        U5      5        U
 H  n[        R                  R                  U5      (       a   [        R                   " XS9s  $ [        R                  R%                  [        R                  R'                  U5      5      (       d  M  [        SU-  5      e   U(       a)  U R)                  USS9nUS   (       a  US   (       a  US   $  [+        XR,                  5      n[1        U[2        5      (       a  U$ [1        U[4        5      (       a  UR6                  $ [9        SU-  U5      e! [         aM  nU(       d2  SSKJn  U" U5      n	U	R                  5       R                  S5      s SnA$ [        SU-  5      UeSnAff = f! [         a     GNf = f! [         aX  nU(       d=  [#        US	SS
9 nUR                  5       sSSS5        s SnAs  $ ! , (       d  f       O= f[        SU-  5      UeSnAff = f! [.         a  n[        SU-  5      UeSnAff = f)a  Get a code string from history, file, url, or a string or macro.

This is mainly used by magic functions.

Parameters
----------
target : str
    A string specifying code to retrieve. This will be tried respectively
    as: ranges of input history (see %history for syntax), url,
    corresponding .py file, filename, or an expression evaluating to a
    string or Macro in the user namespace.

    If empty string is given, returns complete history of current
    session, without the last line.

raw : bool
    If true (default), retrieve raw history. Has no effect on the other
    retrieval mechanisms.

py_only : bool (default False)
    Only try to fetch python code, do not try alternative methods to decode file
    if unicode fails.

Returns
-------
A string of code.
ValueError is raised if nothing is found, and TypeError if it evaluates
to an object of another type. In each case, .args[0] is a printable
message.
r  )zhttp://zhttps://)skip_encoding_cookier   )urlopenlatin1Nz'%s' seem to be unreadable.rrY  z('%s' is a directory, not a regular file.r   )r  r  r^  zI'%s' was not found in history, as a file, url, nor in the user namespace.z#%s is neither a string nor a macro.)r  r  r_   read_py_urlUnicodeDecodeErrorurllib.requestr  rV  rf  r   r  rf   IOErrorr!  r   isfileread_py_filer   isdirrH  r  r  rW  r[  r   r   rU   r&   r   )r   r  r  py_onlyr  	search_nsrL  r  r  responsepotential_targettgtr+  r  codeobjs                  r   find_user_codeInteractiveShell.find_user_code  sL   > '''8K		N  !899))&\\ : #8	##Aof&=> $Cww~~c""V!..s^^ rww11#677 !Kf!TUU $ --f1-EK7#H(="8,,	O6<<0G
 gs##N''== =F! 	!W " 	N2"6?}}--h77;vEFAM	N  		 * V"$Sx@A#$668 A@@@$&Cv%MNTUU	V   	O =@FG HMNO	Os   )F 	G G/(I 
G3GGGG
G,+G,/
I9IH,	I$I,
H:6II
I2I--I2c                     [        U SS5      (       d8  SU l        U R                  SS9  U R                  R	                  5         SU l        gg)zt
At exist operation that need to be called at most once.
Second call to this function per instance will do nothing.
_atexit_once_calledFT)r  N)r  r1  r  r  end_sessionr   s    r   _atexit_onceInteractiveShell._atexit_once/  sK     t2E::'+D$JJ5J)   ,,.#'D  ;r   c                 8   U R                  5         U R                   H/  n UR                  5         U R                  R                  U5        M1     U ?U R
                   H5  n [        R                  " U5        U R
                  R                  U5        M7     U ?[        U S5      (       aO  U R                  S:X  a>  [        R                  R                  S5        [        R                  R                  5         ggg! [         a     M  f = f! [         a     M  f = f)ax  This will be executed at the time of exit.

Cleanup operations and saving of persistent data that is done
unconditionally by IPython should be performed here.

For things that may depend on startup flags or platform specifics (such
as having readline or not), register a separate atexit function in the
code that has the appropriate information, rather than trying to
clutter
editing_modeviz[0 qN)r3  rr  unlinkr  FileNotFoundErrorrs  shutilrmtreerb  r6  r~  r  r  r  )r   tfiletdirs      r   rS  "InteractiveShell.atexit_operationsB  s     	 ^^E%%e, $ NMMDd#$$T* " M 4((T->->$-FJJZ(JJ .G( %  % s#   +C:"1D:
DD
DDc                 $    U R                  5         g r   )r  r   s    r   cleanupInteractiveShell.cleanupd  s    %%'r   c                     g r   r   )r   r  s     r   switch_doctest_mode$InteractiveShell.switch_doctest_modei  s    r   )>r  r;  rZ  r   r1  rV  rC  r  r  r  rw  r  r   ra  r  rS  rp  r*  rX  r  r(  ri  r  r  r  r  r  rO  r   r  r  r  r  rv  r  rU  r  r  r  r  rq  rn  rl  r  r?   r!  r   r  r  r@  r  rq  ru  r  r  r"  rs  rr  rT  rV  rW  rk  )NNNN)r   Nr   )r   NN)F)NN)TF)T)r   )r   r   )NNNFFrQ  )r  N)r  N)r   )r  )Tr   )FF)FFTN)FFT)NTF)Nipython_edit_)TFTF)r)   r*   r+   r,   r   	_instancer   tagr  r2   autocallr0   ra  r   r   r   r   r   r   r
   r   r"   r   r8   r   	automagicr6   rY   r  r  r4   r  
color_infor1   r  debugdisable_failing_post_executer3   rP   r  r5   rI   r  rJ   r  rF   ro  r=   	Inspectorr  rx   r7   r  r  r  r  exit_nowrD   r  r	  r   rI  rU  r  r   r  r  r  r  r  r  r  rR  r  r%  r  history_lengthhistory_load_lengthr  r  r   separate_inseparate_outseparate_out2wildcards_case_sensitiver%  r  r!  r  r  r  r  r  r  r   r$  r	   rw  r  r  r  r   r[  r^  rb  rf  r+  r,  r-  r.  r5  r7  r  r:  r<  rK  r=  r>  rB  rD  rE  rF  rG  rH  staticmethodr   r  r/  r1  r  r
  r  r8  r  r9  r6  r2  rL  rO  rL  rW  r\  rS  rc  ri  r0  r:  rj  r2  r;  r  r  r  r  r  r  r   r   boolListTyper  r   r   AnyTypero   r  r  r  r
  r  r  r  r4  rG   r  rC  r#  r  rD  rH  rM  r?  r\  rX  rn  r\   rr  rw  rA  r  r  r  rI  	functoolswrapsr<   r  r  r  r  r  r  r  r  r  r  r  r   r  rh   rg   rJ  rM  rN  r6  r&  r,  r3  r9  r=  r@  rR  rd  rl  rc  r   rq  rz  ry  rx  r  rp  r   r  r  runcoder  active_eventloopr  r  r  rk   r  r  rb   r  r  r.  r3  rS  r@  rC  r.   r   r   s   @r   r   r   8  s   4IB	
 
cc  G1		 
cc  d	 
cc	  T	 
cc	  #D)%d#$e,	O $Sb 
cc 
 ]L L m  T	 
cc	  nJ	cc  bI	cc  		 
cc  d	 
cc  E+4J 
cc  KOO4O(E#'N$	cc ! !!1dC[)-./*N!R	cc  u	 SS	  "#E $E U	 SS	   !B "B NE{Hl#FX" " ajO*+H-K !))\)+!- A A #2*
 
. 
. E	
 
cc  b	 
cc	 
 	
 
cc   $G1  	cc 
u	 
cc	 
 8 
cc   7	cc  KOO4O(EU.	cc  "$	
 
cc  ""]0;( 
cc   D 
cc  "$'++4+8K"2&**$*7L#B'++4+8M#Dz~~T~:F*3!S "cc. 
 >4PM !JW[\CPTULCPTUL !KX\]DQUVOIVZ[O@TRN@TRK/ / FM #D/TU$%T  \B  OS  T59+/#-L \ ]) )$-
 8* X: :
/#4 X
 

:41
? $  4;%B
U	\  !P /%jJ

;$L%2!
	* mDFHH0. #L\ ) )*$X2(9 v C C=$~+:Z$,.)`4* *3 *5x})<#= * *Z QUx
x
&.xc7l8K/L&Mx
	x
t '& '&R.e . D	EK&:8 $L5.e+N<0 @7 FJBGJEX
D 
D/8  =!OF )C )CV;$B 3F __U((::;
 <

 65 5n71fBBF LL&0K.;(| FB6:8@ 2$>9
A 8=udi B0H8EtF> (T77 7 	7
 7 7 
7t 26t(&(&	(&Z i +/59ii #3-i "*'!2i 
iV< L "y4.y yv=e =@ G,3 ,5c? ,0 H-^*'` %&1B :24
8#JQ!f(& D(
 r   r   c                       \ rS rSrSrSrg)InteractiveShellABCim  z,An abstract base class for InteractiveShell.r   Nr   r   r   r   r^  r^  m  s    6r   r^  )	metaclass)r   abcr  rQ  r  builtinsr  rY  r  r!  r  ri  r:  r  r~  r  rK  r   r  r   r^   r   r   loggingr   pathlibr   typingr   r   rW  r	   DictTyper
   rX  r   r   r   r   picklesharer   ModuleNotFoundErrorr/   	traitletsr0   r1   r2   r3   r4   r5   r6   r"   r7   r8   traitlets.config.configurabler9   traitlets.utils.importstringr;   IPython.core.hooksr  r  r<   r=   r>   r?   r@   IPython.core.aliasrA   rB   IPython.core.autocallrD   IPython.core.builtin_traprE   IPython.core.compileroprF   IPython.core.debuggerrG   IPython.core.display_traprH   IPython.core.displayhookrI   IPython.core.displaypubrJ   IPython.core.errorrK   rL   IPython.core.eventsrM   rN   IPython.core.extensionsrO   IPython.core.formattersrP   IPython.core.historyrQ   IPython.core.inputtransformer2rR   rS   IPython.core.loggerrT   IPython.core.macrorU   IPython.core.payloadrV   IPython.core.prefilterrW   IPython.core.profiledirrX   IPython.core.usagerY   IPython.displayrZ   IPython.pathsr[   IPython.testing.skipdoctestr\   IPython.utilsr]   r_   r`   IPython.utils.decoratorsra   IPython.utils.iorb   IPython.utils.ipstructrc   IPython.utils.pathrd   re   rf   IPython.utils.processrg   rh   IPython.utils.strdispatchri   IPython.utils.syspathcontextrj   IPython.utils.textrk   rl   rm   rn   IPython.core.oinspectro   r   docrepr.sphinxifyrp   rt   r  r  exceptiongroupr~   r  r   r   	AugAssign	AnnAssignr  r  r  async_helpersr   r   r   r   r   rp  	dedent_rer   r   r   r   r[  r   r   objectr   r   r   rZ  r   r   ABCMetar^  rR  r   r   r   <module>r     s     
  
    	 	    
          E E , , ). (    @ 4  B B 2 . 1 3 2 1 0 4 8 > 4 4 / @ & $ / 3 . - # ) 4 ; ; * ' ) O O 3 1 = N N ' H $
# BQ'!1	+ 	 szz:6   JJ78		) 	)   	 	 $9 #	Ag 	A v  "
F "
JGf G< * *r8, r8jq7CKK 7   - .Mz   |  Is$   K% 2	K< %K98K9<LL