
    XhH                        d Z ddlZddlZddlZddlZddlmZ ddlmZm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZ ddlmZ ddlmZ  ddlm!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z' dgZ(e G d d             Z)e G d de)             Z*e G d de)             Z+defdZ,g e jZ                  j]                         D  cg c]  \  } } e+|| gd       c}} e j^                  j]                         D  cg c]  \  } } e+|| gd       c}}  e+e j`                  dgd       e+e jb                  d gd!       e+e jd                  dgd"       e+e jf                  d gd#       e+e jh                  d$gd%       e+e jh                  d&gd'       e+e jh                  d(gd)       e+e jh                  dgd*       e+e jh                  d gd+       e+e jj                  d,gd-       e+e jj                  d,gd.       e+e jj                  d,gd/       e+e jj                  d,gd0       e+e jj                  d,gd1      Z6 e+e!jn                  d2gd3       e+e!jn                  d4gd3       e+e!jp                  d5gd3       e+e!jp                  d6gd7       e+e!jr                  d8d9gd3       e+e!jt                  d:gd3       e+e!jv                  d8gd;       e+e!jv                  d<gd;       e+e!jx                  d=gd>       e+e!jz                  d?gd@       e+e!j|                  d=gdA       e+e!j~                  d?gdB       e+e!j                  d8d6gd3       e+e!j                  dCgd3       e+e!j                  d8dDgd;       e+e!j                  d,gdE       e+e!j                  d6gdF      gZEej                  ej                  ej                  ej                  ej                  ej                  dGj]                         D  cg c]  \  } } e+|| gdH       c}} ZLej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  dI
j]                         D cg c]  \  }} e+| eU|      dH       c}}ZVdJedKe+fdLZWdydMefdNZXdO ZYdP ZZdQ Z[dR Z\dS Z]dT Z^dU Z_dV Z`dW ZadX ZbdY ZcdZ Zdd[ Zed\ Zfej                  d]k(  rdd^lhmiZi dd_ljmkZkmlZlmmZm e%d`        Znne%da        Zn e+e[dbgdc       e+eYd8dbgdd       e+ecdeg       e+e]dfgdg       e+e^dhgdg       e+e_digdj       e+e`dkgdl       e+eadkgdm       e+ebdngdo       e+eddpgdq       e+eedrgds       e+efdtgdl      ge6eE e+edugdv       e+endwgdx      eLeVZoe!j                  ej                  ej                  ej                  ej                  ej                  gZvyc c}} w c c}} w c c}} w c c}}w )zzU
Module to define and register Terminal IPython shortcuts with
:mod:`prompt_toolkit`
    N)	dataclass)CallableAnyOptionalList)get_app)KeyBindings)KeyPressEvent)named_commands)!display_completions_like_readline)	InputModeViState)	Condition)get_ipython   )
auto_match)auto_suggest)filter_from_string)undoc)DEFAULT_BUFFERcreate_ipython_shortcutsc                   4    e Zd ZU eegef   ed<   ee   ed<   y)BaseBindingcommandkeysN)	__name__
__module____qualname__r   r
   r   __annotations__r   str     W/var/www/html/myenv/lib/python3.12/site-packages/IPython/terminal/shortcuts/__init__.pyr   r   %   s    }os*++
s)Or"   r   c                       e Zd ZU eed<   y)RuntimeBindingfilterN)r   r   r   r   r   r!   r"   r#   r%   r%   +   s    r"   r%   c                   (    e Zd ZU dZee   ed<   d Zy)BindingN	conditionc                 `    | j                   rt        | j                         | _        y d | _        y N)r)   r   r&   )selfs    r#   __post_init__zBinding.__post_init__8   s     >>,T^^<DKDKr"   )r   r   r   r)   r   r    r   r-   r!   r"   r#   r(   r(   0   s      $Ix}#r"   r(   handlerc                     | j                   j                  d      }| j                  }|d   }t        |      dkD  r|d   }| d| d| S | d| S )N.r   r   :)r   splitr   len)r.   partsnamepackagefinal_modules        r#   create_identifierr9   ?   sh    $$S)EDAhG
5zA~Ry!L>4&11!D6""r"   z>focused_insert & auto_match & followed_by_closing_paren_or_endz8focused_insert & auto_match & preceded_by_raw_str_prefix"z~focused_insert & auto_match & not_inside_unclosed_string & preceded_by_paired_double_quotes & followed_by_closing_paren_or_end'z~focused_insert & auto_match & not_inside_unclosed_string & preceded_by_paired_single_quotes & followed_by_closing_paren_or_endzXfocused_insert & auto_match & not_inside_unclosed_string & preceded_by_two_double_quoteszXfocused_insert & auto_match & not_inside_unclosed_string & preceded_by_two_single_quotes)z=focused_insert & auto_match & followed_by_closing_round_paren]z9focused_insert & auto_match & followed_by_closing_bracket}z7focused_insert & auto_match & followed_by_closing_bracez6focused_insert & auto_match & followed_by_double_quotez6focused_insert & auto_match & followed_by_single_quote	backspacez_focused_insert & preceded_by_opening_round_paren & auto_match & followed_by_closing_round_parenzWfocused_insert & preceded_by_opening_bracket & auto_match & followed_by_closing_bracketzSfocused_insert & preceded_by_opening_brace & auto_match & followed_by_closing_bracezQfocused_insert & preceded_by_double_quote & auto_match & followed_by_double_quotezQfocused_insert & preceded_by_single_quote & auto_match & followed_by_single_quoteendz@has_suggestion & default_buffer_focused & emacs_like_insert_modec-ezc-frightz_has_suggestion & default_buffer_focused & emacs_like_insert_mode & is_cursor_at_the_end_of_lineescapefzc-rightz;has_suggestion & default_buffer_focused & emacs_insert_modedeletezc-upzQnavigable_suggestions & ~has_line_above & has_suggestion & default_buffer_focusedzc-downzQnavigable_suggestions & ~has_line_below & has_suggestion & default_buffer_focusedz?has_line_above & navigable_suggestions & default_buffer_focusedz?has_line_below & navigable_suggestions & default_buffer_focusedzc-leftdownz/default_buffer_focused & emacs_like_insert_modez]is_cursor_at_the_end_of_line & default_buffer_focused & emacs_like_insert_mode & pass_through)zc-azc-bzc-kzc-wzc-yzc-_z0vi_insert_mode & default_buffer_focused & ebivim)
)c-xrA   )rG   e)rC   b)rC   c)rC   d)rC   h)rC   l)rC   u)rC   y)rC   r0   bindingsbindingc                       | j                   |j                  i |j                  d|j                  ini |j                         y )Nr&   )addr   r&   r   )rP   rQ   s     r#   add_bindingrT   @  sE    LHLL	)0)CHgnn% oor"   returnc                     t               }|xs g }t        D ]k  }d}|D ]S  }|j                  |j                  k(  s|j                  |j                  k(  s7|j                  |j                  k(  sQd} n |r`t        ||       m  fd}d } j                  dk(  r: j                  r.t        j                  t        _        t        ||      t        _        |S )a4  Set up the prompt_toolkit keyboard shortcuts for IPython.

    Parameters
    ----------
    shell: InteractiveShell
        The current IPython shell Instance
    skip: List[Binding]
        Bindings to skip.

    Returns
    -------
    KeyBindings
        the keybinding instance for prompt toolkit.

    FTc                 t    t               }j                  |_        j                  |_        | j                  S r+   )r   ttimeoutlen
timeoutlen_input_mode)r,   appshells     r#   get_input_modez0create_ipython_shortcuts.<locals>.get_input_modeg  s0    i++))r"   c                    t         j                  dt         j                  dij                  |d      }dj	                  |      }t
        j                  j                  |       t
        j                  j                          || _	        y )N         z[{} q)
r   
NAVIGATIONREPLACEgetformatsysstdoutwriteflushrZ   )r,   modeshapecursors       r#   set_input_modez0create_ipython_shortcuts.<locals>.set_input_moden  sc    %%q)*;*;Q?CCD!L##E*

 

r"   vi)r	   KEY_BINDINGSr   r&   r   rT   editing_modemodal_cursorr   INSERTr   rZ   property
input_mode)r\   skipkbrQ   skip_this_oneto_skipr]   rm   s   `       r#   r   r   G  s      
B:2D ! 	G7??2NNgnn4LLGLL0 $	 B !   T!e&8&8'..%nnEIr"   c                     t               }t        | j                  | j                  j                  |       | j                  j	                          y)zReformat code and execute itN)r   reformat_text_before_cursorcurrent_bufferdocumentvalidate_and_handleeventr\   s     r#   reformat_and_executer   ~  s>    MEe22;;U 
,,.r"   c                     | j                  t        |j                  d |j                               }	 |j	                  |      }| j                  |       y # t        $ r}| j                  |       Y d }~y d }~ww xY wr+   )delete_before_cursorr4   textcursor_positionreformat_handlerinsert_text	Exception)bufferr|   r\   r   formatted_textrH   s         r#   rz   rz     sm    &&s8==9S8;S;S+T'UVD!//5>* !4  !s   "A 	A:A55A:c                     t               }t        |dd       r |j                  |      |       S  t        |      |       S )Nhandle_return)r   getattrr   newline_or_execute_outerr~   s     r#   #handle_return_or_newline_or_executer     s@    MEuot,)u""5)%00.'.u55r"   c                       fd}|S )Nc                 b   | j                   }|j                  }|j                  r;|j                  j                  }|r|j	                  |       y|j                          y|j                  dk(  r|j                  }n|j                  d|j                   }	j                  |      \  }}|j                  |j                  d }d}|j                         st        ||	       d}|j                  s]|j                  |j                  |j                         z
  k\  s3	j                  r|j!                  d|z          y|j!                  d       y|dk7  r,|j"                  r |st        ||	       |j%                          y	j                  r|j!                  d|z          y|j!                  d       y)zCWhen the user presses return, insert a newline or execute the code.Nr   FT

incomplete)r{   r|   complete_statecurrent_completionapply_completioncancel_completion
line_countr   r   check_completestriprz   on_last_linecursor_position_rowempty_line_count_at_the_end
autoindentr   accept_handlerr}   )
r   rI   rK   cc
check_textstatusindentafter_cursorreformattedr\   s
            r#   newline_or_executez4newline_or_execute_outer.<locals>.newline_or_execute  s{     JJ!!44B""2&  ##% <<1J 3!"3"34J--j9 vva//12!!#'1e4KNN$$q7T7T7V(VVdVm,  d#l"(8(8+Aq%8!!#dVm,d#r"   r!   )r\   r   s   ` r#   r   r     s    .$` r"   c                 8    | j                   j                          y)z
    Control-P in vi edit mode on readline is history next, unlike default prompt toolkit.

    If completer is open this still select previous completion.
    N)r{   auto_upr   s    r#   'previous_history_or_previous_completionr     s     
  "r"   c                 8    | j                   j                          y)z
    Control-N in vi edit mode on readline is history previous, unlike default prompt toolkit.

    If completer is open this still select next completion.
    N)r{   	auto_downr   s    r#   next_history_or_next_completionr     s     
""$r"   c                 V    | j                   }|j                  r|j                          yy)zDismiss completionN)r{   r   r   r   rI   s     r#   dismiss_completionr     s'    A	 r"   c                 v    | j                   }|j                  r|j                          y|j                          y)zReset bufferN)r{   r   r   resetr   s     r#   reset_bufferr     s+    A			r"   c                     | j                   j                  j                  r| j                   j                          y| j                  j
                  j                  t               y)zReset search bufferN)r{   r|   r   r   r[   layoutfocusr   r   s    r#   reset_search_bufferr     sA    $$))""$		~.r"   c                 8    | j                   j                          y)zSuspend to backgroundN)r[   suspend_to_backgroundr   s    r#   suspend_to_bgr     s    	II##%r"   c                     t        t        dd      }|%t        j                  dt        j                         yt        j                  d       y)z
    Quit application with ``SIGQUIT`` if supported or ``sys.exit`` otherwise.

    On platforms that support SIGQUIT, send SIGQUIT to the current process.
    On other platforms, just exit the process with a message.
    SIGQUITNr   Quit)r   signaloskillr   rf   exit)r   sigquits     r#   quitr     s6     fi.G
6>>"r"   c                 :    | j                   j                  d       y)zIndent buffer    N)r{   r   r   s    r#   indent_bufferr   	  s    	$$W-r"   c                 2   t               }|j                  }| j                  }|j                  }|j                  r|j                          |j                  d|j                   dz   }|j                  |      \  }}|j                  dd|xs dz  z   d       y)at  Insert a newline after the cursor indented appropriately.

    Fancier version of former ``newline_with_copy_margin`` which should
    compute the correct indentation of the inserted line. That is to say, indent
    by 4 extra space after a function definition, class definition, context
    manager... And dedent by 4 space after ``pass``, ``return``, ``raise ...``.
    Nr    r   F)move_cursor)
r   input_transformer_managerr{   r|   r   r   r   r   r   r   )r   r\   inputsplitterrI   rK   r   _r   s           r#   newline_autoindentr     s     ME33MA	

A	66%A%%&-D,,T2IAvMM$#1-.EMBr"   c                 L    | j                   j                  j                          y)z'Open code from input in external editorN)r[   r{   open_in_editorr   s    r#   open_input_in_editorr   "  s    	II++-r"   win32)TryNext)ClipboardEmptytkinter_clipboard_getwin32_clipboard_getc                     	 t               }| j                  j                  |j                  dd             y # t        $ r% 	 t               }n# t        t        f$ r Y Y y w xY wY Yt        $ r Y y w xY w)N	r   )r   r   r   r   r{   r   replace)r   r   s     r#   	win_paster   /  sw    	&(D 	((dG)DE  	,.^,    		s9   
8 	A0
AA0A A0A  A0%A0/A0c                      y)zStub used on other platformsNr!   r   s    r#   r   r   >  s     	r"   enterz5default_buffer_focused & ~has_selection & insert_modez>default_buffer_focused & ~has_selection & insert_mode & ebivimzc-\zc-pz'vi_insert_mode & default_buffer_focusedzc-nzc-gz(default_buffer_focused & has_completionszc-cdefault_buffer_focusedsearch_buffer_focusedzc-zsupports_suspendtabzLdefault_buffer_focused & ~has_selection & insert_mode & cursor_in_leading_wszc-oz*default_buffer_focused & emacs_insert_modef2zc-izireadline_like_completions & default_buffer_focused & ~has_selection & insert_mode & ~cursor_in_leading_wszc-vz1default_buffer_focused & ~vi_mode & is_windows_osr+   )w__doc__r   r   rf   warningsdataclassesr   typingr   r   r   r   "prompt_toolkit.application.currentr   prompt_toolkit.key_bindingr	   (prompt_toolkit.key_binding.key_processorr
   #prompt_toolkit.key_binding.bindingsr   nc.prompt_toolkit.key_binding.bindings.completionr   #prompt_toolkit.key_binding.vi_stater   r   prompt_toolkit.filtersr   IPython.core.getipythonr    r   matchr   filtersr   IPython.utils.decoratorsr   prompt_toolkit.enumsr   __all__r   r%   r(   r9   auto_match_parensitemsauto_match_parens_raw_stringdouble_quotesingle_quotedocstring_double_quotesdocstring_single_quotes	skip_overdelete_pairAUTO_MATCH_BINDINGSaccept_or_jump_to_endacceptaccept_wordaccept_tokendiscardswap_autosuggestion_upswap_autosuggestion_downup_and_update_hintdown_and_update_hintaccept_characteraccept_and_move_cursor_leftaccept_and_keep_cursorbackspace_and_resume_hintresume_hintingAUTO_SUGGEST_BINDINGSbeginning_of_linebackward_char	kill_linebackward_kill_wordyankundoSIMPLE_CONTROL_BINDINGSedit_and_executebackward_wordcapitalize_word	kill_worddowncase_worduppercase_wordyank_popyank_last_arglistALT_AND_COMOBO_CONTROL_BINDINGSrT   r   r   rz   r   r   r   r   r   r   r   r   r   r   r   r   platformIPython.core.errorr   IPython.lib.clipboardr   r   r   r   ro   llm_autosuggestionbeginning_of_bufferend_of_bufferend_of_lineforward_wordunix_line_discardUNASSIGNED_ALLOWED_COMMANDS)keycmdr   s   000r#   <module>r)     sF   
  
  ! 0 0 6 2 B D C , / !  ' * /%
&   
 [   k  #x #k
 //557	 C 	#X	
k ::@@B C 	cUVWk 		.k* 		.+k< %%		+=kL %%		+Mk\ 	G]kf 	Cgkp 	Aqkz # X{k@ # XAkF 		-GkV 		)Wkf 		'gkv 		&wkF 		&Gk d **	J
 **	J
 	J
 		i
   	3J
 !!	J
 	
 	F 	
E
 ++		$ --	
	$ ''	I
 ))	
I
 %%	7J
 00	
J
 ++	6E
 ..	9	 ##			}f X ##||$$wwww eg
S C#JK
 " ++))))++..))**)) eg#c CdOP# &+  4+ 4n/!61h#%/&
.
C(.
 <<7*  
F 
F   +		?
 	7H
 D6(/	1
 '	1
 )STL5'#;<%*ABME7$67	V
 )UV 4&*BCA/B C/D E/F )		#G/X Iw STY/Z [/\ %]/d ##NNOO U^
#s   W/W50W;X