
    f̏                     n   d Z ddlZddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZmZ ddlmZ ddlmZ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# ddl$m%Z% ddl&m'Z'm(Z( ddl)m*Z*m+Z+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9m:Z:m;Z; ddl<m=Z=m>Z> ddl?m@Z@mAZA ddlBmCZD ddlEmFZF ddlGmHZH ddlImJZJ ddlKmLZLmMZM ddlNmOZO ddlPmQZQ ddlRmSZSmTZTmUZU ddlVmWZWmXZX dd lYmZZZm[Z[m\Z\m]Z]m^Z^ dd!l_m`Z`maZa dd"lbmcZcmdZd  eDj                  d#      Zf G d$ d%eH      ZgeJj                  d&eJj                  d'eJj                  d(eJj                  d)iZleJj                  d*eJj                  d+eJj                  d(eJj                  d)iZmd, Znd-D ]+  Zo epeeo      Zq	 eqr ereqd.      reqj                         sd/Zt n- d0Ztd1ej                  v xs et Zwd2 Zxd3 Zy G d4 d5e0      Zz G d6 d7e      Z{ ej                  e{       e}d8k(  re{j                         j                          yy# eu$ r d/ZtY  pw xY w)9z/IPython terminal interface using prompt_toolkit    N)warn)Union)get_asyncio_loop)InteractiveShellInteractiveShellABC)input)toggle_set_term_titleset_term_titlerestore_term_title)
abbrev_cwd)BoolUnicodeDictIntegerListobserveInstanceTypedefaultEnumr   AnyvalidateFloat)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)__version__)get_style_by_name)Style)Token   )TerminalPdbPdb)TerminalMagics)get_inputhook_name_and_func)PromptsClassicPromptsRichPromptDisplayHook)IPythonPTCompleterIPythonPTLexer)KEY_BINDINGScreate_ipython_shortcutscreate_identifierRuntimeBindingadd_binding)KEYBINDING_FILTERSfilter_from_string)NavigableAutoSuggestFromHistoryAppendAutoSuggestionInAnyLinez3.c                       e Zd Zy)_NoStyleN)__name__
__module____qualname__     \/var/www/cvtools/html/venv/lib/python3.12/site-packages/IPython/terminal/interactiveshell.pyrE   rE   E   s    rJ   rE   z#ansibrightbluez#ansiblue boldz#ansibrightred#ansired boldz#ansibrightgreen#ansigreen boldc                      	 t         j                  d   S # t        $ r Y nt        $ r t	        d       Y nw xY wt         j
                  dk(  ryy)NEDITORzN$EDITOR environment variable is not pure ASCII. Using platform default editor.posixvinotepad)osenvironKeyErrorUnicodeErrorr   namerI   rJ   rK   get_default_editorrX   W   sQ     zz(##     	   
ww's    	666)stdinstdoutstderrisattyFTIPY_TEST_SIMPLE_PROMPTc                     ddl }|j                  | |j                               }| j                  d      s|j                  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_cursorrb   formatted_texts      rK   black_reformat_handlerrh   y   sQ     %%&8u~~?O%PN&&t,1H1H1N',rJ   c                     ddl m} ddl m} |j                  t	        j
                               }|j                  | |      \  }}|r)| j                  d      s|j                  d      r|d d }|S | S )Nr   )file_resources)yapf_api)style_configr`   ra   )yapf.yapflibrj   rk   GetDefaultStyleForDirrS   getcwd
FormatCodere   )rf   rj   rk   rl   rg   was_formatteds         rK   yapf_reformat_handlerrr      su    +%!77		DL$,$7$7 %8 %!NM !**40^5L5LT5R+CR0N!!rJ   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                 P    t         |           || _        | j                          y N)super__init__shell_refresh)selfry   	__class__s     rK   rx   zPtkHistoryAdapter.__init__   s    
rJ   c                 2    d| _         | j                          y NF)_loadedrz   r{   strings     rK   append_stringzPtkHistoryAdapter.append_string   s    rJ   c                 Z    | j                   st        | j                               | _        y y rv   )r   listload_history_strings_loaded_stringsr{   s    rK   rz   zPtkHistoryAdapter._refresh   s$    ||#'(A(A(C#DD  rJ   c              #     K   d}g }| j                   j                  j                  | j                   j                  d      D ]2  \  }}}|j	                         }|s||k7  s |j                  |       |}4 |d d d   E d {    y 7 w)N T)include_latestra   )ry   history_managerget_tailhistory_load_lengthrstripappend)r{   	last_cellres_____cells         rK   r   z&PtkHistoryAdapter.load_history_strings   s     	!ZZ77@@JJ**4 A 
 	!MBT ;;=D*

4  		! tt9s   AB
B
" B
BB
r   returnNc                      y rv   rI   r   s     rK   store_stringzPtkHistoryAdapter.store_string   s    rJ   )rF   rG   rH   __doc__rx   r   rz   r   strr   __classcell__)r|   s   @rK   rt   rt      s0    

E3 4 rJ   rt   c                   *	   e Zd ZU  e       j	                  d      Z edd      j	                  d      ZdZe	e
df   ed<   dZe	eedf   ed<   dZ ed	d
      j	                  d      Z eed      j	                  d      Zed        Z edd      j	                  d      Z edd      j	                  d      Z edd      j	                  d      Z edd      j	                  d      Z edd      j	                  d      Z edd      j	                  d      Z eddd      j	                  d      Z edd      j	                  d      Z edd      j	                  d      Z  e! ed       e"e#      gd      j	                  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(      j	                  d      Z- edd)      j	                  d      Z. e e/       d*      j	                  d      Z0 e"e1d+      j	                  d      Z2 e3e1      Z4 e5d,      d-        Z6 e5d.      d/        Z7 edd0      j	                  d      Z8 ed1d2      j	                  d      Z9 e:d3d4d56      j	                  d      Z; edd7      j	                  d      Z< edd8      j	                  d      Z= e>dd9      j	                  d      Z? edd:      j	                  d      Z@ ed;d<d      j	                  d      ZAd= ZB e'd>      d?        ZC eD e e:g d@       e        eD e              e        eD e              e        ed      d@A      dBj                  dCj                  eGD  cg c]  }dD| dE
 c}}             F      j	                  d      ZH e'dG      dH        ZIdI ZJ eddJ      j	                  d      ZK e'dK      dadL       ZLdM ZMfdNZNdO ZOdP ZPedQ        ZQedR        ZRdS ZSdT ZTdU ZUdV ZVfdWZWfdXZXdbfdYZYdZ ZZdZ[d[ Z\d\ Z]dZ^d] Z_dZ`dad^Zaebj                  Zdd_ ZedZfd` ZgxZhS c c}} w )cTerminalInteractiveShellT)config   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.)helpN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 own testing machinery, and emacs inferior-shell integration through elpy.

            This mode default to `True` if the `IPY_TEST_SIMPLE_PROMPT`
            environment variable is set, or the current terminal is not a tty.c                 2    | j                   rt        S t        S rv   )simple_promptr3   r2   r   s    rK   debugger_clsz%TerminalInteractiveShell.debugger_cls   s    ((s9k9rJ   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)klasszThe name or class of a Pygments style to use for syntax
        highlighting. To see available styles, run `pygmentize -L styles`.editing_modec                     |d   j                         dk(  rd|d<   n|d   j                         dk(  rd|d<   t        t        |d   j                               r|d   j                         S | j                  S )NvaluevimrQ   r   r   )lowerhasattrr   upperr   )r{   proposals     rK   _validate_editing_modez/TerminalInteractiveShell._validate_editing_mode  sz    G""$-#HWg$$&)3&HW; 1 7 7 9:G$**,,   rJ   c                     | j                   r8t        t        |j                  j	                               | j                   _        y y rv   )r   getattrr   newr   r   r{   changes     rK   _editing_modez&TerminalInteractiveShell._editing_mode)  s.    ;;'.{FJJ<L<L<N'ODKK$ rJ   c                 h    |	d | _         y |dk(  rt        | _         y |dk(  rt        | _         y t        )Nc                     | S rv   rI   )xs    rK   <lambda>z9TerminalInteractiveShell._set_formatter.<locals>.<lambda>0  s    Q rJ   rb   yapf)reformat_handlerrh   rr   
ValueError)r{   	formatters     rK   _set_formatterz'TerminalInteractiveShell._set_formatter.  s6    $.D!'!$:D!& $9D!rJ   autoformatterc                 >    |j                   }| j                  |       y rv   )r   r   )r{   r   r   s      rK   _autoformatter_changedz/TerminalInteractiveShell._autoformatter_changed8  s    JJ	I&rJ   highlighting_stylecolorsc                 $    | j                          y rv   )refresh_styler   s     rK   _highlighting_style_changedz4TerminalInteractiveShell._highlighting_style_changed=  s     	rJ   c                 D    | j                  | j                        | _        y rv   )_make_style_from_name_or_clsr   _styler   s    rK   r   z&TerminalInteractiveShell.refresh_styleB  s    778O8OPrJ   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                 $    | j                  |       S rv   )prompts_classr   s    rK   _prompts_defaultz)TerminalInteractiveShell._prompts_default[  s    !!$''rJ   displayhook_classc                     t         S rv   )r8   r   s    rK   _displayhook_class_defaultz3TerminalInteractiveShell._displayhook_class_defaultc  s    $$rJ   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 searchrB   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`'.c                 R   | j                   r4t        | j                   t              r| j                   j                          |d | _         n5|dk(  rt	               | _         n |dk(  rt               | _         nt        d      | j                  r| j                   | j                  _         y y )Nr   rB   zNo valid provider.)r   
isinstancerB   
disconnectr   r   r   )r{   providers     rK   _set_autosuggestionsz-TerminalInteractiveShell._set_autosuggestions  s    >"
 ((* $D11 6 8D:: ? AD122;;'+'8'8DKK$ rJ   autosuggestions_providerc                 >    |j                   }| j                  |       y rv   )r   r   )r{   r   r   s      rK   !_autosuggestions_provider_changedz:TerminalInteractiveShell._autosuggestions_provider_changed  s    ::!!(+rJ   )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:

        {}


        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`.
        z	
        z- ``)traitr   	shortcutsc                 t    | j                   r,| j                  |j                        | j                   _        y y )Nuser_shortcuts)r   _merge_shortcutsr   key_bindingsr   s     rK   _shortcuts_changedz+TerminalInteractiveShell._shortcuts_changed  s,    ;;'+'<'<FJJ'<'WDKK$ rJ   c           
         t        |       }t        D ci c]"  }t        |j                        |j                  $ }}g }g }|D ]  }|d   }||vr!dj	                  |      }	t        | d|	       |j                  dd       }
d|v rt        |d         nd }t        D cg c]L  }||j                  |k(  r9|
|j                  D cg c]  }| c}|
k(  rt        |j                        |k(  r|N }}}|j                  dd       }|j                  dd       }||   }|j                  dd	      }| xr |d uxs |}|r|g k(  rt        d
      |rdD ci c]  }||v r|||    }}t        |      dk(  rt        d| dt               t        |      dkD  rt        d| d|       |d   }|j                  }t        |j                        }
|j                  t        ||
|             |g k7  s|j                  t        ||xs |
|t        |      n||n
t        d                    t        | |      }|D ]  }t        ||        |S c c}w c c}w c c}}w c c}w )Nr   z
 - z< is not a known shortcut command. Allowed commands are: 
 - r   r   r   r   r   Fz"Cannot add a shortcut without keys)r   filterr   zNo shortcuts matching z
 found in r1   zMultiple shortcuts matching z1 found, please add keys/filter to select one of: )keysr   always)skip)r<   r;   r=   r   joinr   getrA   r   r   lenr   r   r>   r?   )r{   r   r   bindingknown_commandsshortcuts_to_skipshortcuts_to_addshortcut
command_idallowed_commandsold_keys
old_filterkmatchingr   r   r   creating_newmodifying_existingkeyspecificationmatcheds                         rK   r   z)TerminalInteractiveShell._merge_shortcuts  s	   /5 (
 goo.?
 
 & M	H!),J/#*<<#?  !l #33C2DF   ||L$7H "X- #8N#;<   ,'7>>Z+G!)-FAa-F(-R)'//:jH H   ||J5H!lD9J$Z0G#<<%8L%1!1 "$2
  B !EFF!  5!h #&! !
 x=A%$0z,X  ]Q&$6}o FEEMJP 
 #1+$^^
-!(("%) 2~ ''"%1%1  2*=  *5 '!3H!=
CM	` 0;LM' 	/Gg.	/ w
4 .G0!s#   'I &I	I"II#Iz9Display the current vi mode (when using vi editing mode).
term_titlec                     | j                   r?t        r9t        d       t        | j                  j                  t                            y t        d       y )NT)cwdF)r  _is_ttyr	   r
   term_title_formatformatr   r   s     rK   init_term_titlez(TerminalInteractiveShell.init_term_titleO  s;     ??w!$'41188Z\8JK!%(rJ   c                 @    | j                   rt        rt                y y y rv   )r  r  r   r   s    rK   r   z+TerminalInteractiveShell.restore_term_titleX  s    ??w   '?rJ   c                 N    t         t        |           dg| j                  _        y )Nz
text/plain)rw   r   init_display_formatterdisplay_formatteractive_typesr{   r|   s    rK   r  z/TerminalInteractiveShell.init_display_formatter\  s!    &DF/;n+rJ   c                      j                   r fd}| _        y  j                   j                        }t	               } j                   j                         _        t         fd       _	        t        t         j                  j                               }t        j                          _        t#        d j$                  |||t'                j(                   j                  d j*                   j,                   j.                  dd j1                          _        t5         j$                  t6              r& j$                  j9                   j2                         y y )	Nc                     dj                  d j                  j                         D              } t        |       g}dj                  d j                  j	                         D              }j                  dj                  |            d   dk(  rA|j                  t        |             j                  dj                  |            d   dk(  rAdj                  |      S )Nr   c              3   &   K   | ]	  }|d      ywr1   NrI   .0r   s     rK   	<genexpr>zSTerminalInteractiveShell.init_prompt_toolkit_cli.<locals>.prompt.<locals>.<genexpr>f  s     %Tqad%T   c              3   &   K   | ]	  }|d      ywr  rI   r  s     rK   r  zSTerminalInteractiveShell.init_prompt_toolkit_cli.<locals>.prompt.<locals>.<genexpr>h  s     -fqad-fr  r`   r   
incomplete)r   r   in_prompt_tokensr   continuation_prompt_tokenscheck_completer   )prompt_textlinesprompt_continuationr{   s      rK   promptz@TerminalInteractiveShell.init_prompt_toolkit_cli.<locals>.prompte  s     gg%TDLL4Q4Q4S%TT{+,&(gg-fDLL<c<c<e-f&f#))$))E*:;A>,NLL%(;"<> ))$))E*:;A>,Nyy''rJ   r   c                       j                   S rv   )r   r   s   rK   r   zBTerminalInteractiveShell.init_prompt_toolkit_cli.<locals>.<lambda>v  s    $++ rJ   )ry   Fz.py)r   r   r   history	completerenable_history_searchstyleinclude_default_pygments_stylemouse_supportenable_open_in_editorcolor_depthtempfile_suffixrI   )r   prompt_for_coder   r   rt   r   r   r   r)   r*  r   r   r   r   asyncionew_event_looppt_loopr&   r   r9   r)  r,  extra_open_editor_shortcutsr.  _extra_prompt_optionsr   r   rB   connect)r{   r%  r   r'  r   s   `    rK   init_prompt_toolkit_cliz0TerminalInteractiveShell.init_prompt_toolkit_clia  s3   ( $*D  ,,DNN,K $D)778O8OP!"56
{D,=,=,C,C,EF--/# 
**%%(t4"&"<"<**+0,,"&"B"B((!
 ((*
 d'')HI%%dkk2 JrJ   c                    i }|dk(  r| j                   j                         }|dk(  rt        d      }t        }n|dk(  rt        }t        d      }n|dk(  rct        d      }|j                  t        j                  dt        j                  d	t        j                  d
t        j                  j                  dt        j                  j                  dt        j                  j                  dt        j                  j                  j                  dt        j                   dt        j"                  dt        j$                  dt        j&                  di       t(        j*                  dk(  r|j                  t        j                   dt        j"                  dt        j$                  dt        j&                  di       nz|dk(  r	t,        }i }nlt/        d|      t1        |t2              rt        |      }n|}t        j                   dt        j"                  dt        j$                  dt        j&                  di}|j                  | j4                         t7        t9        |      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   linuxmonokailightbgpastieneutralr   z
#ansigreen	noinheritz#ansiyellowz	#ansibluezbold #ansibluez#ansibrightgreen boldz#ansiredz#ansibrightred boldntz#ansidarkgreenrM   z#ansidarkredrL   nocolorzGot unknown colors: )r   r   r.   _style_overrides_linux_style_overrides_light_bgupdater0   NumberOperatorStringNameFunctionClass	NamespaceVariableMagicPrompt	PromptNum	OutPromptOutPromptNumrS   rW   rE   r   r   r   highlighting_style_overridesr*   r+   r,   )r{   name_or_clsstyle_overridesr   	style_clsr*  s         rK   r   z5TerminalInteractiveShell._make_style_from_name_or_cls  s    ("[[&&(F -i8	"89$";-h7	9$ .i8	&&LL,NNKLL-JJ''JJ$$&6JJ((*:JJ''--{LL,OO%<OOZ&&(=(   77d?#**&6):**O	,  )#"	"$ !7@@+s+-k:	'	l!8""$9	O 	t@@A#I.$_5
 
 rJ   c                 |    t         j                  t         j                  t         j                  d| j                     S )N)r   r   r   )r'   MULTI_COLUMNCOLUMNREADLINE_LIKEdisplay_completionsr   s    rK   pt_complete_stylez*TerminalInteractiveShell.pt_complete_style  s9     )55#**)77
 
"
"	$ 	$rJ   c                 >    | j                   rt        j                  S d S rv   )
true_colorr$   
TRUE_COLORr   s    rK   r.  z$TerminalInteractiveShell.color_depth  s    )-
%%CdCrJ   c                      fd} j                   dk(  r |       }dt                j                  | fd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}t        s j                  |d<   |S )z\
        Return the current layout option for the current Terminal InteractiveShell
        c                  J    t         j                  j                               S rv   )r    r   r  r   s   rK   get_messagezCTerminalInteractiveShell._extra_prompt_options.<locals>.get_message  s    !$,,"?"?"ABBrJ   r   Fc                 L    t        j                  j                  |             S rv   )r    r   r   )widthlinenois_soft_wrapr{   s      rK   r   z@TerminalInteractiveShell._extra_prompt_options.<locals>.<lambda>  s    NLL;;EB5 rJ   Tz[](){})charsc                       j                   S rv   )highlight_matching_bracketsr   s   rK   r   z@TerminalInteractiveShell._extra_prompt_options.<locals>.<lambda>   s    (H(H rJ   )	processorr   c                  8    t         j                  t              S rv   )r   r   rB   r   s   rK   r   z@TerminalInteractiveShell._extra_prompt_options.<locals>.<lambda>  s    
 --/N! rJ   )complete_in_threadlexerreserve_space_for_menumessager$  	multilinecomplete_styleinput_processors	inputhook)r   r:   space_for_menurZ  r"   r#   r   r   r   r   rC   PTK3rq  )r{   r`  optionss   `  rK   r5  z.TerminalInteractiveShell._extra_prompt_options  s    	C ' &-K #(#%&*&9&9" "44 %?hO#N3xi  HIJ %;=#N3xi 	!!
D #'>>GK rJ   c                    | j                   r| j                   }d | _         nd}t        j                         }t               }|| j                  ur|j                  | j                         	 t        d      5   | j                  j                  dd|i| j                         }d d d        ||| j                  ur|j                  |       S # 1 sw Y   ,xY w# |!|| j                  ur|j                  |       w w w xY w)Nr   T)rawr   rI   )
rl_next_inputr1  get_event_loop_policyr   r3  set_event_loopr%   r   r%  r5  )r{   r   policyold_looptexts        rK   r0  z(TerminalInteractiveShell.prompt_for_code  s    ((G!%DG ..0#% 4<<'!!$,,/	0$' 4)t{{)) 4#400244 #(D%%h/4 4 #(D%%h/ )E#s$   +C 7-C$C CC %D c                 (    t        dt        d       y )Nzu`enable_win_unicode_console` is deprecated since IPython 7.10, does not do anything and will be removed in the future   )
stacklevel)r   DeprecationWarningr   s    rK   enable_win_unicode_consolez3TerminalInteractiveShell.enable_win_unicode_console6  s     	  E	rJ   c                 R    t         j                  dvry dd l}|j                          y )N>   cliwin32r   )sysplatformcoloramainit)r{   r  s     rK   init_ioz TerminalInteractiveShell.init_io=  s    <<//rJ   c                 T    t         t        |           | j                  t               y rv   )rw   r   init_magicsregister_magicsr4   r  s    rK   r  z$TerminalInteractiveShell.init_magicsD  s    &9;^,rJ   c                     t         t        |           t        j                  dk(  r$dD ]  }| j
                  j                  ||         y y )NrP   )clearmorelessman)rw   r   
init_aliasrS   rW   alias_managersoft_define_alias)r{   cmdr|   s     rK   r  z#TerminalInteractiveShell.init_aliasH  sK     	&8:
 77g7 ?""44S#>? rJ   c                     t        t        | 
  |i | | j                  | j                         | j                          | j                          d| _        | j                  | j                         y )NT)
rw   r   rx   r   r   r7  r  keep_runningr   r   )r{   argskwargsr|   s      rK   rx   z!TerminalInteractiveShell.__init__U  s`    &6GG!!$"?"?@$$& D../rJ   c                     d| _         y r~   )r  r   s    rK   ask_exitz!TerminalInteractiveShell.ask_exit^  s
    !rJ   c                 >   d| _         | j                   rLt        | j                  d       	 | j                         }|r| j	                  |d       	 | j                   rKy y # t
        $ r2 | j                  r| j                  ddd      r| j                          Y Iw xY w)NTr   )end)store_historyz#Do you really want to exit ([y]/n)?yn)	r  printseparate_inr0  run_cellEOFErrorconfirm_exit
ask_yes_nor  )r{   codes     rK   interactz!TerminalInteractiveShell.interactc  s     $""+	<++- MM$dM; 
  $))??+PQTUXYMMO$s   A! !8BBc                    	 	 | j                          	 t        | d      r| j                  j                          | j	                          | j                          y # t
        $ r+}t        dt        |      j                  z         Y d }~nd }~ww xY w	 t        | d      r| j                  j                          | j	                          n;# t        | d      r| j                  j                          | j	                          w xY w)N
_eventloopz
%s escaped interact()
)
r  r   r  stopr   KeyboardInterruptr  typerF   _atexit_once)r{   es     rK   mainloopz!TerminalInteractiveShell.mainloops  s     * 4.OO((*'') 	# % F1DG4D4DDEEFE 4.OO((*'') 4.OO((*'') s)   A 	B$!B
C
 
BC
 
8Dc                 @    | j                   | j                  |       y y rv   )
_inputhook)r{   contexts     rK   rq  z"TerminalInteractiveShell.inputhook  s    ??&OOG$ 'rJ   c                 8   | j                   |t        d       y | j                   |t        d| j                   d       y | j                   |d x| _        | _         |r|dvrt        |      \  | _        | _         nd x| _        | _         t        rdd l}ddlm} |dk(  rt               | _	        t        d       y | j                   r1 || j                         | _	        t        d	| j                   d
       y  |j                         | _	        t        d       y y )NzNo event loop hook running.z.Shell is already running a gui event loop for z5. Call with no arguments to disable the current loop.>   inlinewebaggr   )new_eventloop_with_inputhookr1  z"Installed asyncio event loop hook.z
Installed z event loop hook.zGUI event loop hook disabled.)r  r  active_eventloopr5   rs  r1  prompt_toolkit.eventloopr  r   r3  r2  )r{   guir1  r  s       rK   
enable_guiz#TerminalInteractiveShell.enable_gui  s   ??"s{/0??&3?@AVAV@W XF F ??&3;6::D!DOC335PQT5U2D!4?6::D!DO Mi  01:;  <DOOL
4#8#8"99JKL  6w55756) rJ   c                 8   | j                   sy| j                  j                         }| j                  rAt	        t        |      d| j                  j                  j                         t        |       ydj                  d |D              }t        ||d       y)z>Overridden from the parent class to use fancy rewriting promptNr   )r  r*  c              3   &   K   | ]	  \  }}|  y wrv   rI   )r  tss      rK   r  z>TerminalInteractiveShell.auto_rewrite_input.<locals>.<genexpr>  s     241aQ2r  )sep)
show_rewritten_inputr   rewrite_prompt_tokensr   r(   r    appr*  r  r   )r{   r  tokensr%  s       rK   auto_rewrite_inputz+TerminalInteractiveShell.auto_rewrite_input  sp    ((335;; !7R'+{{'<'<>#JWW2622F&#2&rJ   c                     |r"| j                   | _        t        |       | _         y| j                  r| j                  | _         d| _        yy)z+Switch prompts to classic for %doctest_modeN)r   _prompts_beforer7   )r{   r_   s     rK   switch_doctest_modez,TerminalInteractiveShell.switch_doctest_mode  s@    #'<<D )$/DL!!//DL#'D  "rJ   rv   )r   N)irF   rG   rH   r   tagmime_renderersr   rr  r   	UnionTyper&   __annotations__r   r   rB   debugger_historyr   debugger_history_filer   _use_simple_promptr   propertyr   r  r    emacs_bindings_in_vi_insert_modemodal_cursorr   ttimeoutlen
timeoutlenr   
auto_matchr,  r   r   r/   r   r   r   r   r   r   r   r   r   rQ  r\  rX   editorr6   r   r   r   r   r   r   r  r  r   rY  rg  r4  r   handle_returnr)  r   r   r   r   r  r   r@   r   r   r   prompt_includes_vi_moder  r   r  r7  r   rZ  r.  r5  r0  r  r  r  r  rx   r  rw  r  r  r  rq  r  r  r   
system_rawsystemr  r  r  r   )r  r  r|   s   00@rK   r   r      st   VZZtZ,NQ &K  "cc.  .2FImT)*1 	 ) ?E  #G	cc  +R cc  : : A
 
cc  7D	cc  (,J( 
cc %
 9
 
cc   
cc	    
cc	  \ 
cc	   
cc  a	cc   14e3DEN 
cc 
 n	! 	! ^P P _' ' !"X  #Q $(?$	cc ! e 
cc  ')N	cc  '_`ddlpdqMwGY( (  !% "% d3	cc    03 
cc 
 GG $%
 &)SS%5  #'t+#	cc   #'uO# 
cc  
 < 
cc	  !I	cc   '):
   
cc 9" '(, ), 	 #9"79o '	 O%iu+
(> F3EFaQCqzFG
i7n 
cco r [X XaF #4H	cc  \) )!=
*3XAF $ $ D D6p D-
?0" M< 6 J% *7\ ((F' O(i Gs   ?Rr   __main__)r   r1  rS   r  warningsr   typingr   r  IPython.core.async_helpersr   IPython.core.interactiveshellr   r   IPython.utils.py3compatr   IPython.utils.terminalr	   r
   r   IPython.utils.processr   	traitletsr   r   r   r   r   r   r   r   r   r   r   r   r   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+   r,   prompt_toolkitr-   ptk_versionpygments.stylesr.   pygments.styler/   pygments.tokenr0   debuggerr2   r3   magicsr4   pt_inputhooksr5   r   r6   r7   r8   ptutilsr9   r:   r   r;   r<   r=   r>   r?   shortcuts.filtersr@   rA   shortcuts.auto_suggestrB   rC   
startswithrs  rE   rM  rN  rO  rP  rB  rA  rX   _namer   _streamr   r\   r  r   rT   r  rh   rr   rt   r   registerrF   instancer  rI   rJ   rK   <module>r     s   5  	 
  % 7 O ) \ \ ,   " ? < > > 8 * d , 4 W W < \ 5 -     & " 6 C C 7  F
 {d# u 
 LL+OO-OO-	  LL,OO.OO-	 $ + Ec5!Gggx8@PG AQ G /"**<Ng+ " # #J^(/ ^(D    5 6z%%'002 c  s    H))H43H4