
    MhǛ                        d Z ddlZddlZddlZddlmZ ddlmZm	Z	 ddl
mZ ddlmZmZ ddlmZ ddlmZ dd	lmZmZmZ dd
lmZ ddlmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#mZm$Z$m%Z%m&Z&m'Z' ddl(m)Z) ddl*m+Z+ ddl,m-Z-m.Z. ddl/m0Z0m1Z1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z?m@Z@mAZA ddlBmCZCmDZD ddlEmFZFmGZG ddlHmIZI ddlJmKZK ddlLmMZMmNZN ddlOmPZP ddlQmRZR ddlSmTZTmUZUmVZV ddlWmXZXmYZY dd lZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z` dd!lambZbmcZc dd"ldmeZemfZf  G d# d$eK          Zgd%ehd&ehd'ehfd(Zid) Zjd*D ]CZk eleek          Zm	 emr  enemd+          remo                                sd,Zp n6# eq$ r d,ZpY  nw xY wd-Zpd.ejr        v pep Zsd/ Ztd0 Zu G d1 d2e6          Zv G d3 d4e          Zw ejx        ew           eyd5k    r(ewz                                {                                 dS dS )6z/IPython terminal interface using prompt_toolkit    N)warn)UnionOptional)get_asyncio_loop)InteractiveShellInteractiveShellABC)input)theme_table)toggle_set_term_titleset_term_titlerestore_term_title)
abbrev_cwd)AnyBoolDictEnumFloatInstanceIntegerListTypeUnicoder   defaultobservevalidateDottedObjectName)import_item)AutoSuggestFromHistory)DEFAULT_BUFFEREditingMode)HasFocus	ConditionIsDone)PygmentsTokens)History)ConditionalProcessor!HighlightMatchingBracketProcessor)
ColorDepth)patch_stdout)PromptSessionCompleteStyleprint_formatted_text)DynamicStylemerge_styles)style_from_pygments_clsstyle_from_pygments_dict)get_style_by_name)Style   )TerminalPdbPdb)TerminalMagics)get_inputhook_name_and_func)PromptsClassicPromptsRichPromptDisplayHook)IPythonPTCompleterIPythonPTLexer)KEY_BINDINGSUNASSIGNED_ALLOWED_COMMANDScreate_ipython_shortcutscreate_identifierRuntimeBindingadd_binding)KEYBINDING_FILTERSfilter_from_string)NavigableAutoSuggestFromHistoryAppendAutoSuggestionInAnyLinec                       e Zd ZdS )_NoStyleN)__name__
__module____qualname__     a/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/IPython/terminal/interactiveshell.pyrH   rH   E   s        DrM   rH   widthlineno
wrap_countc                R   t          j        |           }i }t          j        |           j        }dt          j        |           j        v s0t          d |j                                        D                       r||d<   dt          j        |           j        v s0t          d |j                                        D                       r||d<   dt          j        |           j        v s0t          d |j                                        D                       r||d<    | |fi |S )z~
    Sagemath use custom prompt and we broke them in 8.19.

    make sure to pass only width if method only support width
    rP   c                 .    g | ]}|j         |j        k    S rL   kindVAR_KEYWORD.0ps     rN   
<listcomp>z?_backward_compat_continuation_prompt_tokens.<locals>.<listcomp>V   !    BBBQ1=	 BBBrM   line_numberc                 .    g | ]}|j         |j        k    S rL   rT   rW   s     rN   rZ   z?_backward_compat_continuation_prompt_tokens.<locals>.<listcomp>Z   r[   rM   rQ   c                 .    g | ]}|j         |j        k    S rL   rT   rW   s     rN   rZ   z?_backward_compat_continuation_prompt_tokens.<locals>.<listcomp>_   r[   rM   )inspect	signature
parametersanyvalues)methodrO   rP   rQ   sigextraparamss          rN   +_backward_compat_continuation_prompt_tokensrh   J   s@    
F
#
#CEv&&1F7$V,,7773BB#.*?*?*A*ABBB< <7 !h)&11<<<BB#.*?*?*A*ABBBA A<  &mw(00;;;sBB#.*?*?*A*ABBB@ @; )l6%!!5!!!rM   c                      	 t           j        d         S # t          $ r Y nt          $ r t	          d           Y nw xY wt           j        dk    rdS dS )NEDITORzN$EDITOR environment variable is not pure ASCII. Using platform default editor.posixvinotepad)osenvironKeyErrorUnicodeErrorr   namerL   rM   rN   get_default_editorrs   e   s     z(##           	  	  	  	  	   
w'tys    
;;;)stdinstdoutstderrisattyFTIPY_TEST_SIMPLE_PROMPTc                     ddl }|                    | |                                          }|                     d          s|                    d          r
|dd         }|S )z
    We do not need to protect against error,
    this is taken care at a higher level where any reformat error is ignored.
    Indeed we may call reformatting on incomplete code.
    r   N)mode
)black
format_strFileModeendswith)text_before_cursorr}   formatted_texts      rN   black_reformat_handlerr      so     LLL%%&8u~~?O?O%PPN&&t,, -1H1H1N1N -',rM   c                    ddl m} ddl m} |                    t	          j                              }|                    | |          \  }}|r6|                     d          s|                    d          r
|d d         }|S | S )Nr   )file_resources)yapf_api)style_configr{   r|   )yapf.yapflibr   r   GetDefaultStyleForDirrn   getcwd
FormatCoder   )r   r   r   r   r   was_formatteds         rN   yapf_reformat_handlerr      s    ++++++%%%%%%!77	DDL$,$7$7 %8 % %!NM  "!**400 	1^5L5LT5R5R 	1+CRC0N!!rM   c                   D     e Zd ZdZ fdZd Zd Zd Zdeddfd	Z	 xZ
S )
PtkHistoryAdapterzs
    Prompt toolkit has it's own way of handling history, Where it assumes it can
    Push/pull from history.

    c                 ~    t                                                       || _        |                                  d S N)super__init__shell_refresh)selfr   	__class__s     rN   r   zPtkHistoryAdapter.__init__   s1    
rM   c                 <    d| _         |                                  d S NF)_loadedr   r   strings     rN   append_stringzPtkHistoryAdapter.append_string   s    rM   c                 d    | j         s(t          |                                           | _        d S d S r   )r   listload_history_strings_loaded_stringsr   s    rN   r   zPtkHistoryAdapter._refresh   s;    | 	E#'(A(A(C(C#D#DD   	E 	ErM   c              #      K   d}g }| j         j                            | j         j        d          D ]9\  }}}|                                }|r||k    r|                    |           |}:|d d d         E d {V  d S )N T)include_latestr|   )r   history_managerget_tailhistory_load_lengthrstripappend)r   	last_cellres_____cells         rN   r   z&PtkHistoryAdapter.load_history_strings   s      	!Z7@@J*4 A 
 
 	! 	!MBT ;;==D !**

4    	ttt9rM   r   returnNc                     d S r   rL   r   s     rN   store_stringzPtkHistoryAdapter.store_string   s    rM   )rI   rJ   rK   __doc__r   r   r   r   strr   __classcell__r   s   @rN   r   r      s             
  
E E E  3 4        rM   r   c                   ~    e Zd ZU  e                                d          Z edd                              d          Z edd                              d          ZdZ	e
edf         ed	<   dZe
eedf         ed
<   dZ edd                              d          Z eed                              d          Zed             Z edd                              d          Z edd                              d          Z edd                              d          Z edd                              d          Z edd                              d          Z edd                              d          Z eddd                              d          Z edd                              d          Z  edd                              d          Z! e" ed           e#e$          gd                              d          Z% e&d           d!             Z' e(d           d"             Z)d# Z* e(d$          d%             Z+ e(d&           e(d'          d(                         Z,d) Z- ed*                              d          Z. edd+                              d          Z/ e e0            d,                              d          Z1 e#e2d-                              d          Z3 e4e2          Z5 e6d.          d/             Z7 e6d0          d1             Z8 edd2                              d          Z9 ed3d4                              d          Z: e;d5d6d78                              d          Z< edd9                              d          Z= edd:                              d          Z> e?dd;                              d          Z@ edd<                              d          ZA ed=d>d                              d          ZBe?ed?<    ei d@                              d          ZC eDdAdB                              d          ZEe?edC<    e(dD          dE             ZF eDdddFG                              d          ZGdZHe?edH<    e(dI          dJ             ZIdwdKZJ e(dL          dM             ZK eL e e;g dN           e             eL e                       e             eL e                       e             ed          dNO          dPM                    dQN                    dR eOD                       S          T                              d          ZP e(dU          dV             ZQdW ZR eddX                              d          ZS edYdZ                              d          ZT e(d[          dwd\            ZUd] ZV fd^ZWd_ ZXd` ZYeda             ZZedb             Z[dce\dde\dee\fdfZ]dg Z^dh Z_di Z` fdjZa fdkZbdx fdmZcdn ZddZedo Zfdp ZgdZhdq ZidZjekel         edr<   dwdsekel         dldfdtZmenjo        Zpdu ZqdZrdv Zs xZtS )yTerminalInteractiveShellT)config   z@minimum characters for filling with ellipsis in file completions)help   zNumber of line at the bottom of the screen to reserve for the tab completion menu, search history, ...etc, the height of these menus will at most this value. Increase it is you prefer long and skinny menus, decrease for short and wide.Npt_appauto_suggestz~/.pdbhistoryz'File in which to store and read historya  Use `raw_input` for the REPL, without completion and prompt colors.

            Useful when controlling IPython as a subprocess, and piping
            STDIN/OUT/ERR. Known usage are: IPython's own testing machinery,
            and emacs' inferior-python subprocess (assuming you have set
            `python-shell-interpreter` to "ipython") available through the
            built-in `M-x run-python` and third party packages such as elpy.

            This mode default to `True` if the `IPY_TEST_SIMPLE_PROMPT`
            environment variable is set, or the current terminal is not a tty.
            Thus the Default value reported in --help-all, or config will often
            be incorrectly reported.
            c                 ,    | j         rt          nt          S r   )simple_promptr5   r4   r   s    rN   debugger_clsz%TerminalInteractiveShell.debugger_cls   s    (9ssk9rM   z
        Set to confirm when you try to exit IPython with an EOF (Control-D
        in Unix, Control-Z/Enter in Windows). By typing 'exit' or 'quit',
        you can force a direct exit without any confirmation.emacsz5Shortcut style to use at the prompt. 'vi' or 'emacs'.z;Add shortcuts from 'emacs' insert mode to 'vi' insert mode.z
       Cursor shape changes depending on vi mode: beam in vi insert mode,
       block in nav mode, underscore in replace mode.g{Gz?zJThe time in milliseconds that is waited for a key code
       to complete.g      ?zUThe time in milliseconds that is waited for a mapped key
       sequence to complete.zMAutoformatter to reformat Terminal code. Can be `'black'`, `'yapf'` or `None`)r   
allow_noneFz
        Automatically add/delete closing bracket or quote when opening bracket or quote is entered/deleted.
        Brackets: (), [], {}
        Quotes: '', ""
        zQEnable mouse support in the prompt
(Note: prevents selecting text with the mouse)legacy)klasszDeprecated, and has not effect, use IPython themes

        The name or class of a Pygments style to use for syntax
        highlighting. To see available styles, run `pygmentize -L styles`.editing_modec                 ,   |d                                          dk    rd|d<   n#|d                                          dk    rd|d<   t          t          |d                                                   r|d                                          S | j        S )Nvaluevimrl   r   r   )lowerhasattrr    upperr   )r   proposals     rN   _validate_editing_modez/TerminalInteractiveShell._validate_editing_mode;  s    G""$$--#HWg$$&&)33&HW; 1 7 7 9 9:: 	-G$**,,,  rM   c                     | j         r8t          t          |j                                                  | j         _        d S d S r   )r   getattrr    newr   r   r   changes     rN   _editing_modez&TerminalInteractiveShell._editing_modeG  sA    ; 	P'.{FJ<L<L<N<N'O'ODK$$$	P 	PrM   c                 x    |
d | _         d S |dk    rt          | _         d S |dk    rt          | _         d S t          )Nc                     | S r   rL   )xs    rN   <lambda>z9TerminalInteractiveShell._set_formatter.<locals>.<lambda>N  s    Q rM   r}   yapf)reformat_handlerr   r   
ValueError)r   	formatters     rN   _set_formatterz'TerminalInteractiveShell._set_formatterL  sP    $.JD!!!'!!$:D!!!&  $9D!!!rM   autoformatterc                 >    |j         }|                     |           d S r   )r   r   )r   r   r   s      rN   _autoformatter_changedz/TerminalInteractiveShell._autoformatter_changedV  s#    J	I&&&&&rM   highlighting_stylecolorsc                     |j         |j                                         k    sJ |j         dk    rt          d           d S d S )Nr   zLhighlighting_style is deprecated since 9.0 and have no effect, use themeing.)r   r   r   r   s     rN   _highlighting_style_changedz4TerminalInteractiveShell._highlighting_style_changed[  sV     zVZ--//////:!!^   F	 "!rM   c                 :    |                      d          | _        d S )Nr   )_make_style_from_name_or_cls_styler   s    rN   refresh_stylez&TerminalInteractiveShell.refresh_stylee  s    77AArM   z0Override highlighting format for specific tokenszUse 24bit colors instead of 256 colors in prompt highlighting.
        If your terminal supports true color, the following command should
        print ``TRUECOLOR`` in orange::

            printf "\x1b[38;2;255;100;0mTRUECOLOR\x1b[0m\n"
        z?Set the editor used by IPython (default to $EDITOR/vi/notepad).z6Class used to generate Prompt token for prompt_toolkitpromptsc                 ,    |                      |           S r   )prompts_classr   s    rN   _prompts_defaultz)TerminalInteractiveShell._prompts_default~  s    !!$'''rM   displayhook_classc                     t           S r   )r:   r   s    rN   _displayhook_class_defaultz3TerminalInteractiveShell._displayhook_class_default  s    $$rM   z$Automatically set the terminal titlezIPython: {cwd}ziCustomize the terminal title format.  This is a python format string. Available substitutions are: {cwd}.)columnmulticolumnreadlinelikezOptions for displaying tab completions, 'column', 'multicolumn', and 'readlinelike'. These options are for `prompt_toolkit`, see `prompt_toolkit` documentation for more information.r   )r   default_valuezHighlight matching brackets.zEnable vi (v) or Emacs (C-X C-E) shortcuts to open an external editor. This is in addition to the F2 binding, which is always enabled.zProvide an alternative handler to be called when the user presses Return. This is an advanced option intended for debugging, which may be changed or removed in later releases.z:Allows to enable/disable the prompt toolkit history searchrE   a  Specifies from which source automatic suggestions are provided. Can be set to ``'NavigableAutoSuggestFromHistory'`` (:kbd:`up` and :kbd:`down` swap suggestions), ``'AutoSuggestFromHistory'``,  or ``None`` to disable automatic suggestions. Default is `'NavigableAutoSuggestFromHistory`'._autosuggestions_provideru   
        Extra arguments to pass to `llm_provider_class` constructor.

        This is used to – for example – set the `model_id`input_historyaX      Fully Qualifed name of a function that takes an IPython history manager and
    return a prefix to pass the llm provider in addition to the current buffer
    text.

    You can use:

     - no_prefix
     - input_history

    As default value. `input_history` (default),  will use all the input history
    of current IPython session

    _llm_prefix_from_historyllm_prefix_from_historyc                 J    |j         }|| _        |                                  d S r   )r   r   _set_autosuggestions)r   r   rr   s      rN    _llm_prefix_from_history_changedz9TerminalInteractiveShell._llm_prefix_from_history_changed  s)    z(,%!!#####rM   ax          Provisional:
            This is a provisional API in IPython 8.32, before stabilisation
            in 9.0, it may change without warnings.

        class to use for the `NavigableAutoSuggestFromHistory` to request
        completions from a LLM, this should inherit from
        `jupyter_ai_magics:BaseProvider` and implement
        `stream_inline_completions`
    )r   r   _llm_provider_classllm_provider_classc                 J    |j         }|| _        |                                  d S r   )r   r   r   )r   r   provider_classs      rN   _llm_provider_class_changedz4TerminalInteractiveShell._llm_provider_class_changed  s)    #1 !!#####rM   c                     | j         } j        r3t           j        t                    r j                                         |d  _        n|dk    rt                       _        n~|dk    ri j        r fd}nd }t                       _        | j        _         j        }|dk    rd }|}n|dk    rd }|}nt          |          }| j        _
        nt          d           j        r j         j        _        d S d S )	Nr   rE   c                  F    t          j                  }  | di j        S )NrL   )r   r   llm_constructor_kwargs)llm_provider_constructorr   s    rN   init_llm_providerzHTerminalInteractiveShell._set_autosuggestions.<locals>.init_llm_provider  s.    /:4;S/T/T,33RRd6QRRRrM   	no_prefixc                     dS )Nr   rL   r   s    rN   r  z@TerminalInteractiveShell._set_autosuggestions.<locals>.no_prefix  s    2rM   r   c                 j    d                     d |                                 D                       dz   S )Nr{   c                     g | ]
}|d          S )   rL   )rX   ss     rN   rZ   zXTerminalInteractiveShell._set_autosuggestions.<locals>.input_history.<locals>.<listcomp>  s    %P%P%Pqad%P%P%PrM   )join	get_ranger  s    rN   r   zDTerminalInteractiveShell._set_autosuggestions.<locals>.input_history  s5    99%P%PO4M4M4O4O%P%P%PQQTXXXrM   zNo valid provider.)autosuggestions_providerr   
isinstancerE   
disconnectr   r   _init_llm_providerr   r   _llm_prefixerr   r   )r   providerr  rr   r  funr   s   `      rN   r   z-TerminalInteractiveShell._set_autosuggestions  s{   4H 	+>"
 "
 	+ ((*** $D111 6 8 8D:::' )S S S S S S
 %)! ? A AD3DD0/D{""    ((Y Y Y $ "$''.1D++1222; 	9'+'8DK$$$	9 	9rM   r  c                 >    |j         }|                     |           d S r   )r   r   )r   r   r  s      rN   !_autosuggestions_provider_changedz:TerminalInteractiveShell._autosuggestions_provider_changed!  s#    :!!(+++++rM   )command
match_keysmatch_filternew_keys
new_filtercreate)	key_traitper_key_traitsa  
        Add, disable or modifying shortcuts.

        Each entry on the list should be a dictionary with ``command`` key
        identifying the target function executed by the shortcut and at least
        one of the following:

          - ``match_keys``: list of keys used to match an existing shortcut,
          - ``match_filter``: shortcut filter used to match an existing shortcut,
          - ``new_keys``: list of keys to set,
          - ``new_filter``: a new shortcut filter to set

        The filters have to be composed of pre-defined verbs and joined by one
        of the following conjunctions: ``&`` (and), ``|`` (or), ``~`` (not).
        The pre-defined verbs are:

        {filters}

        To disable a shortcut set ``new_keys`` to an empty list.
        To add a shortcut add key ``create`` with value ``True``.

        When modifying/disabling shortcuts, ``match_keys``/``match_filter`` can
        be omitted if the provided specification uniquely identifies a shortcut
        to be modified/disabled. When modifying a shortcut ``new_filter`` or
        ``new_keys`` can be omitted which will result in reuse of the existing
        filter/keys.

        Only shortcuts defined in IPython (and not default prompt-toolkit
        shortcuts) can be modified or disabled. The full list of shortcuts,
        command identifiers and filters is available under
        :ref:`terminal-shortcuts-list`.

        Here is an example:

        .. code::

            c.TerminalInteractiveShell.shortcuts = [
               {{
                   "new_keys": ["c-q"],
                   "command": "prompt_toolkit:named_commands.capitalize_word",
                   "create": True,
               }},
               {{
                   "new_keys": ["c-j"],
                   "command": "prompt_toolkit:named_commands.beginning_of_line",
                   "create": True,
               }},
            ]


        z	
        c                     g | ]}d | d	S )z  - ``z``rL   rX   ks     rN   rZ   z#TerminalInteractiveShell.<listcomp>n  s     &R&R&R!~~~~&R&R&RrM   )filters)traitr   	shortcutsc                 b    | j         r'|                     |j                  | j         _        d S d S )Nuser_shortcuts)r   _merge_shortcutsr   key_bindingsr   s     rN   _shortcuts_changedz+TerminalInteractiveShell._shortcuts_changedr  s<    ; 	X'+'<'<FJ'<'W'WDK$$$	X 	XrM   c           
         t          |           }d t          D             }|                    d t          D                        g }g }|D ]d         |vr)d                    |          }t           d|                               dd           dv rt          d                   nd fdt          D             }                    d	d           }                    d
d           }|         }	                    dd          }
|
 o|d up|}|
r|g k    rt          d          |rfddD             }t          |          dk    rt          d| dt                     t          |          dk    rt          d| d|           |d         }|j	        t          |j                  |                    t          |	                     |g k    rI|                    t          |	|p|t          |          nnt          d                               t          | |          }|D ]}t          ||           |S )Nc                 B    i | ]}t          |j                  |j        S rL   )r@   r  )rX   bindings     rN   
<dictcomp>z=TerminalInteractiveShell._merge_shortcuts.<locals>.<dictcomp>}  s6     
 
 
 go..
 
 
rM   c                 .    i | ]}t          |          |S rL   )r@   )rX   r  s     rN   r.  z=TerminalInteractiveShell._merge_shortcuts.<locals>.<dictcomp>  s2        "'**G  rM   r  z
 - z< is not a known shortcut command. Allowed commands are: 
 - r  r  c                     g | ]@}|j         k    r1d |j        D             k    rt          |j                  k    >|AS )Nc                     g | ]}|S rL   rL   r   s     rN   rZ   zHTerminalInteractiveShell._merge_shortcuts.<locals>.<listcomp>.<listcomp>  s    -F-F-FAa-F-F-FrM   )filterkeysr@   r  )rX   r-  
command_id
old_filterold_keyss     rN   rZ   z=TerminalInteractiveShell._merge_shortcuts.<locals>.<listcomp>  sn       '7>Z+G+G!)-F-F-F-F-F(-R-R)'/::jHH 
 IHHrM   r  r  r  Fz"Cannot add a shortcut without keysc                 *    i | ]}|v ||         S rL   rL   )rX   keyshortcuts     rN   r.  z=TerminalInteractiveShell._merge_shortcuts.<locals>.<dictcomp>  s0     ! ! !h #&rM   )r  r2  r   zNo shortcuts matching z
 found in r3   zMultiple shortcuts matching z1 found, please add keys/filter to select one of: )r3  r2  always)skip)r?   r=   updater>   r  r   getrD   lenr2  r   r3  r   rA   rB   )r   r'  r)  allowed_commandsshortcuts_to_skipshortcuts_to_addmatchingr  r  r  creating_newmodifying_existingspecificationmatchedr-  r4  r5  r6  r9  s                  @@@@rN   r(  z)TerminalInteractiveShell._merge_shortcutsw  s   /55
 
'
 
 
 	 :  	
 	
 	
 & O	 O	H!),J!111#*<<0@#A#A  ! F F3CF F    ||L$77H "X-- #8N#;<<< 
     +  H  ||J55H!lD99J&z2G#<<%88L%1!1 "$2
   GB !EFFF! ! ! ! !4! ! !
 x==A%%$XXX,XX   ]]Q&&$P} P PEMP P  
 #1+$^
--!(("%)     2~~ ''"%1  *5 /z::: $.#9 !+
%7%A%A    " 0;LMMM' 	/ 	/Gg....rM   z9Display the current vi mode (when using vi editing mode).r   a  The format for line numbering, will be passed `line` (int, 1 based) the current line number and `rel_line` the relative line number. for example to display both you can use the following template string : c.TerminalInteractiveShell.prompt_line_number_format='{line: 4d}/{rel_line:+03d} | ' This will display the current line number, with leading space and a width of at least 4 character, as well as the relative line number 0 padded and always with a + or - sign. Note that when using Emacs mode the prompt of the first line may not update.
term_titlec                     | j         rLt          rEt          d           t          | j                            t                                           d S t          d           d S )NT)cwdF)rG  _is_ttyr   r   term_title_formatformatr   r   s     rN   init_term_titlez(TerminalInteractiveShell.init_term_title  sc     ? 	)w 	)!$'''4188Z\\8JJKKKKK!%(((((rM   c                 F    | j         rt          rt                       d S d S d S r   )rG  rJ  r   r   s    rN   r   z+TerminalInteractiveShell.restore_term_title  s9    ? 	!w 	!     	! 	! 	! 	!rM   c                 p    t          t          |                                            dg| j        _        d S )Nz
text/plain)r   r   init_display_formatterdisplay_formatteractive_typesr   r   s    rN   rP  z/TerminalInteractiveShell.init_display_formatter  s3    &--DDFFF/;n+++rM   c                 \     j         r fd}| _        d S                       j                  }t	                     }                                  t           fd          }t          t           j	        
                                          }d _        t          d j        |||t                      j        |d j         j         j        dd                                  _        t+           j        t,                    r! j                             j                   d S d S )	Nc                  2   d                     d j                                        D                       } t          |           g}d                     d j                                        D                       }                    d                     |                    d         dk    rT|                    t          |                                         d                     |                    d         dk    Td                     |          S )Nr   c              3   &   K   | ]}|d          V  dS r3   NrL   rX   r   s     rN   	<genexpr>zSTerminalInteractiveShell.init_prompt_toolkit_cli.<locals>.prompt.<locals>.<genexpr>  s&      %T%Tqad%T%T%T%T%T%TrM   c              3   &   K   | ]}|d          V  dS rW  rL   rX  s     rN   rY  zSTerminalInteractiveShell.init_prompt_toolkit_cli.<locals>.prompt.<locals>.<genexpr>
  s7       . .AaD. . . . . .rM   r{   r   
incomplete)r  r   in_prompt_tokensr	   continuation_prompt_tokenscheck_completer   )prompt_textlinesprompt_continuationr   s      rN   promptz@TerminalInteractiveShell.init_prompt_toolkit_cli.<locals>.prompt  s    gg%T%TDL4Q4Q4S4S%T%T%TTT{++,&(gg . ."&,"I"I"K"K. . . ' '# ))$))E*:*:;;A>,NNLL':!;!;<<< ))$))E*:*:;;A>,NNyy'''rM   r&  c                       j         S r   )r   r   s   rN   r   zBTerminalInteractiveShell.init_prompt_toolkit_cli.<locals>.<lambda>  s	    T[ rM   F)r   z.py)r   r   r)  history	completerenable_history_searchstyleinclude_default_pygments_stylemouse_supportenable_open_in_editorcolor_depthtempfile_suffixrL   )r   prompt_for_coder(  r$  r   r   r-   r   r    r   r   _use_asyncio_inputhookr*   r   r;   rf  ri  extra_open_editor_shortcutsrk  _extra_prompt_optionsr   r  rE   connect)r   rb  r)  rd  ptk_sr   s   `     rN   init_prompt_toolkit_cliz0TerminalInteractiveShell.init_prompt_toolkit_cli  s^    	( ( ( ( ( $*D F ,,DN,KK $D))000011{D,=,C,C,E,EFF&+## 
*%%(t444"&"<+0,"&"B(!
 
 ((**
 
 d')HII 	3%%dk22222	3 	3rM   c                 f   |dk    sJ | j                                         }t          j        |d          }|
J |            |dk    r
i }t          }n3i |j        | j        }|j        t          |j                  }nt          }t          t          |          t          |          g          }|S )z
        Small wrapper that make an IPython compatible style from a style name

        We need that to add style for prompt ... etc.
        r   Nnocolor)r   r   r
   r=  rH   extra_stylehighlighting_style_overridesbaser1   r.   r/   r0   )r   name_or_clsr   themestyle_overrides	style_clsrg  s          rN   r   z5TerminalInteractiveShell._make_style_from_name_or_cls2  s     h&&&&""$$--  &   Y O IIX!2Xd6WXOz%-ej99		$	'	22(99
 
 rM   c                 `    t           j        t           j        t           j        d| j                 S )N)r   r   r   )r+   MULTI_COLUMNCOLUMNREADLINE_LIKEdisplay_completionsr   s    rN   pt_complete_stylez*TerminalInteractiveShell.pt_complete_styleQ  s2     )5#*)7
 
 
"	$ 	$rM   c                 ,    | j         rt          j        nd S r   )
true_colorr(   
TRUE_COLORr   s    rN   rk  z$TerminalInteractiveShell.color_depthY  s    )-B
%%dCrM   rO   r\   rQ   c                 V    t          t          | j        j        |||                    S )N)rP   rQ   )r$   rh   r   r]  )r   rO   r\   rQ   s       rN   _ptk_prompt_contz)TerminalInteractiveShell._ptk_prompt_cont]  s7    77"%	  
 
 	
rM   c                      fd} j         dk    r j        dk    r
 |            }dt                       j        | j        d j        t          t          d          t          t                    t                       z  t           fd          z  	          t          t                      t          t                    t                       z  t           fd
          z  	          gd}|S )z\
        Return the current layout option for the current Terminal InteractiveShell
        c                  P    t           j                                                  S r   )r$   r   r\  r   s   rN   get_messagezCTerminalInteractiveShell._extra_prompt_options.<locals>.get_messagek  s    !$,"?"?"A"ABBBrM   r   r   FTz[](){})charsc                       j         S r   )highlight_matching_bracketsr   s   rN   r   z@TerminalInteractiveShell._extra_prompt_options.<locals>.<lambda>  s
    (H rM   )	processorr2  c                  8    t           j        t                    S r   )r  r   rE   r   s   rN   r   z@TerminalInteractiveShell._extra_prompt_options.<locals>.<lambda>  s    
 -;! ! rM   )complete_in_threadlexerreserve_space_for_menumessagera  	multilinecomplete_styleinput_processors)r   prompt_line_number_formatr<   space_for_menur  r  r&   r'   r!   r   r#   r"   rF   )r   r  optionss   `  rN   rp  z.TerminalInteractiveShell._extra_prompt_optionsg  s<   	C 	C 	C 	C 	C ''D,Jb,P,P &+--K #(#%%&*&9"#'#8"4 %?hOOO#N33xxi  H H H HIIJ   %;==#N33xxi     
 
 
!
 
@ rM   c           	      |   | j         r| j         }d | _         nd}t          d          5  | j        rHt                      }|                     | j        j        dd|i|                                           }n, | j        j        d|| j	        d|                                 }d d d            n# 1 swxY w Y   |S )Nr   T)rawr   )r   	inputhookrL   )
rl_next_inputr)   rn  r   run_until_completer   prompt_asyncrp  rb  
_inputhook)r   r   asyncio_looptexts       rN   rm  z(TerminalInteractiveShell.prompt_for_code  s8    	(G!%DG d### 	 	*   011#66,DK,   '+/+E+E+G+G   *t{) #"o  0022 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	$ s   A<B11B58B5c                 V    t           j        dvrd S dd l}|                                 d S )N>   cliwin32r   )sysplatformcoloramainit)r   r  s     rN   init_ioz TerminalInteractiveShell.init_io  s/    <///FrM   c                     t          t          |                                            |                     t                     d S r   )r   r   init_magicsregister_magicsr6   rS  s    rN   r  z$TerminalInteractiveShell.init_magics  s:    &--99;;;^,,,,,rM   c                     t          t          |                                            t          j        dk    r dD ]}| j                            ||           d S d S )Nrk   )clearmorelessman)r   r   
init_aliasrn   rr   alias_managersoft_define_alias)r   cmdr   s     rN   r  z#TerminalInteractiveShell.init_alias  sn     	&--88:::
 7g7 ? ?"44S#>>>> ? ?rM   r   c                      t                      j        |i | |                     | j                   |                                  |                                  d| _        |                     | j                   d S )NT)	r   r   r   r  rs  rM  keep_runningr   r   )r   argskwargsr   s      rN   r   z!TerminalInteractiveShell.__init__  s    $)&)))!!$"?@@@$$&&& D./////rM   c                     d| _         d S r   )r  r   s    rN   ask_exitz!TerminalInteractiveShell.ask_exit  s    !rM   c                 B   d| _         | j         rt          | j        d           	 |                                 }|r|                     |d           nB# t
          $ r5 | j        r|                     ddd          r|                                  Y nw xY w| j         d S d S )NTr   )end)store_historyz#Do you really want to exit ([y]/n)?yn)	r  printseparate_inrm  run_cellEOFErrorconfirm_exit
ask_yes_nor  )r   codes     rN   interactz!TerminalInteractiveShell.interact  s      	<$"++++	<++--  <MM$dM;;;  $ $ $) $??+PQTUXYY$MMOOO$  	< 	< 	< 	< 	<s   A <BBc                 T   	 	 |                                   	 t          | d          r| j                                         |                                  n# t
          $ r.}t          dt          |          j        z             Y d }~nd }~ww xY w	 t          | d          r| j                                         |                                  nB# t          | d          r| j                                         |                                  w xY w| 	                                 d S )NT
_eventloopz
%s escaped interact()
)
r  r   r  stopr   KeyboardInterruptr  typerI   _atexit_once)r   es     rN   mainloopz!TerminalInteractiveShell.mainloop  sJ   	** 4.. +O((***'')))) % F F F1DGG4DDEEEEEEEEFE 4.. +O((***'')))) 4.. +O((***''))))	** 	s)   A 
B $B	C 	BC ?Dc                 p    t          dt          d           | j        |                     |           d S d S )Nzvinputkook seem unused, and marked for deprecation/Removal as of IPython 9.0. Please open an issue if you are using it.r
  )category
stacklevel)r   PendingDeprecationWarningr  )r   contexts     rN   r  z"TerminalInteractiveShell.inputhook
  sN    8.		
 	
 	
 	
 ?&OOG$$$$$ '&rM   active_eventloopguic                 D   |rddl m}  ||          }| j        du r&|$t          d| d           t          d           d S | j        |t          d           d S | j        i|gt          |          \  }}| j        |k    r%| j                            d| j         d	           d S | j        	                    d
| j         d           d S | j        |d x| _        | _        |r!|dvrt          |          \  | _        | _        nd x| _        | _        |dk    | _
        d S )Nr
  )_convert_gui_from_matplotlibTz$Cannot install event loop hook for "z&" when running with `--simple-prompt`.zSNOTE: Tk is supported natively; use Tk apps and Tk backends with `--simple-prompt`.zNo event loop hook running.zShell is already running the z eventloop. Doing nothingz8Shell is already running a different gui event loop for z5. Call with no arguments to disable the current loop.>   Nwebaggasyncio)core.pylabtoolsr  r   r  r  r7   loginfor  warningrn  )r   r  r  newev	newinhooks        rN   
enable_guiz#TerminalInteractiveShell.enable_gui  s    	4FFFFFF..s33C%%#/bsbbb   e   F?"s{/000F?&3?:3??E9)++dD4Iddd   HF4K` F F F   F?&3;6::D!DO 	;C///5PQT5U5U2D!4??6::D!DO&)Y&6###rM   c                 8   | j         sdS | j                                        }| j        r?t	          t          |          d| j        j        j                   t          |           dS d	                    d |D                       }t          ||d           dS )z>Overridden from the parent class to use fancy rewriting promptNr   )r  rg  c              3       K   | ]	\  }}|V  
d S r   rL   )rX   tr  s      rN   rY  z>TerminalInteractiveShell.auto_rewrite_input.<locals>.<genexpr>P  s&      2241aQ222222rM   )sep)
show_rewritten_inputr   rewrite_prompt_tokensr   r,   r$   apprg  r  r  )r   r  tokensrb  s       rN   auto_rewrite_inputz+TerminalInteractiveShell.auto_rewrite_inputE  s    ( 	F3355; 	' !7!7R'+{'<> > > >#JJJJJWW22622222F&#2&&&&&&rM   c                     |r"| j         | _        t          |           | _         dS | j        r| j        | _         d| _        dS dS )z+Switch prompts to classic for %doctest_modeN)r   _prompts_beforer9   )r   rz   s     rN   switch_doctest_modez,TerminalInteractiveShell.switch_doctest_modeT  sT     	(#'<D )$//DLLL! 	(/DL#'D   	( 	(rM   r   )r   N)urI   rJ   rK   r   tagmime_renderersr   	min_elider  r   	UnionTyper*   __annotations__r   r   rE   debugger_historyr   debugger_history_filer   _use_simple_promptr   propertyr   r  r    emacs_bindings_in_vi_insert_modemodal_cursorr   ttimeoutlen
timeoutlenr   
auto_matchri  r   r   r2   r   r   r   r   r   r   r   r   r   rw  r  rs   editorr8   r   r   r   r   r   r   rG  rK  r   r  r  ro  r   handle_returnrf  r  r  r   r   r   r   r   r   r   r  r   rL  r  rC   r$  r*  r(  prompt_includes_vi_moder  rM  r   rP  rs  r   r  rk  intr  rp  rm  r  r  r  r   r  r  r  r  r  r  r  r   r   r  r   
system_rawsystemr  r  r  r   r   s   @rN   r   r      s        TVVZZtZ,,N
S  	cc  W	.   
cc  .2FImT)*111
 		 )'	   
 #GG  	cc  D+   
cc   : : X: 4A  
 
cc  77D  	cc  (,tJ( ( ( 
cc %
 49  
 
cc  %   
cc	      
cc	  G\   
cc	     
cc  Da  	cc  			DDu---.N   
cc  Xn	! 	! 	! W^P P P   W_' ' ' W!""WX   #"B B B $(4?$ $ $	cc ! e   
cc  W''))N  	cc  D'_```ddlpdqqMhwGWY( ( ( W !!% % "!% d3  	cc    03   
cc 
 $GG $% % %
 &)SS%5%5  #'$t+# # #	cc   #'$uO# # # 
cc  
 C<   
cc	  !DI  	cc   'w):
       
cc   #"""!T
B   
cc  /.    
cc! " "!!!W&''$ $ ('$
 *)	   
cc   $###W!""$ $ #"$
09 09 09 09d W'((, , )(, dd  	 	 #799"d7799oo '		 DOO%gii$u++ 
 
 
(2d F %%&R&R?Q&R&R&RSS  
 
OJ J JT 
ccU X W[X X Xi i iV #d4H  	cc  !(
X	! 	! 	! 
cc  W\) ) ) )! ! != = = = =
-3 -3 -3^  > $ $ X$ D D XD
c 
 
 
 
 
 
1 1 1f  B  - - - - -
? 
? 
? 
? 
?0 0 0 0 0 0" " " M< < <   4 J% % % '+hsm***)7 )7hsm )7t )7 )7 )7 )7Z (F' ' ' O( ( ( ( ( ( (rM   r   __main__)|r   rn   r  r_   warningsr   typingr   r  r   IPython.core.async_helpersr   IPython.core.interactiveshellr   r   IPython.utils.py3compatr	   IPython.utils.PyColorizer
   IPython.utils.terminalr   r   r   IPython.utils.processr   	traitletsr   r   r   r   r   r   r   r   r   r   r   r   r   r   traitlets.utils.importstringr   prompt_toolkit.auto_suggestr   prompt_toolkit.enumsr   r    prompt_toolkit.filtersr!   r"   r#   prompt_toolkit.formatted_textr$   prompt_toolkit.historyr%    prompt_toolkit.layout.processorsr&   r'   prompt_toolkit.outputr(   prompt_toolkit.patch_stdoutr)   prompt_toolkit.shortcutsr*   r+   r,   prompt_toolkit.stylesr-   r.   prompt_toolkit.styles.pygmentsr/   r0   pygments.stylesr1   pygments.styler2   debuggerr4   r5   magicsr6   pt_inputhooksr7   r   r8   r9   r:   ptutilsr;   r<   r$  r=   r>   r?   r@   rA   rB   shortcuts.filtersrC   rD   shortcuts.auto_suggestrE   rF   rH   r  rh   rs   _namer   _streamr   rw   rJ  r   ro   r  r   r   r   r   registerrI   instancer  rL   rM   rN   <module>r&     s   5 5 				 



        / / / / / / / / 7 7 7 7 7 7 O O O O O O O O ) ) ) ) ) ) 0 0 0 0 0 0 \ \ \ \ \ \ \ \ \ \ , , , , , ,                                 " 5 4 4 4 4 4 ? > > > > > < < < < < < < < > > > > > > > > > > 8 8 8 8 8 8 * * * * * * d d d d d d d d , , , , , , 4 4 4 4 4 4 W W W W W W W W W W < < < < < < < < \ \ \ \ \ \ \ \ - - - - - -             & & & & & & & & " " " " " " 6 6 6 6 6 6 C C C C C C C C C C 7 7 7 7 7 7 7 7                F E E E E E E E       	 	 	 	 	u 	 	 	
""#&"47" " " "6  & +  Egc5!!G 	gggx88 	@P@P 	GE	    
 G /"*<Ng+   " " " # # # # # # # #JP( P( P( P( P(/ P( P( P(h   5 6 6 6z%%''0022222 s   ?$E&&E10E1