o
    voiH                     @   sZ  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 dZ)eG dd de)Z*eG dd de)Z+defddZ,g dd e j-. D dd e j/. D e+e j0d gd!e+e j1d"gd#e+e j2d gd$e+e j3d"gd%e+e j4d&gd'e+e j4d(gd)e+e j4d*gd+e+e j4d gd,e+e j4d"gd-e+e j5d.gd/e+e j5d.gd0e+e j5d.gd1e+e j5d.gd2e+e j5d.gd3Z6e+e!j7d4gd5e+e!j7d6gd5e+e!j8d7gd5e+e!j8d8gd9e+e!j9d:d;gd5e+e!j:d<gd5e+e!j;d:gd=e+e!j;d>gd=e+e!j<d?gd@e+e!j=dAgdBe+e!j>d?gdCe+e!j?dAgdDe+e!j@d:d8gd5e+e!jAdEgd5e+e!jBd:dFgd=e+e!jCd.gdGe+e!jDd8gdHgZEdId ejFejGejHejIejJejKdJ. D ZLdKd ejMejMejNejOejPejIejQejRejSejTdL
. D ZUdMedNe+fdOdPZVddQefdRdZWdSdT ZXdUdV ZYdWdX ZZdYdZ Z[d[d\ Z\d]d^ Z]d_d` Z^dadb Z_dcdd Z`dedf Zadgdh Zbdidj Zcdkdl Zddmdn Zeejfdokr7ddplgmhZh ddqlimjZjmkZkmlZl e%drds Zmne%dtds Zme+eZdugdve+eXd:dugdwe+ebdxge+e\dygdze+e]d{gdze+e^d|gd}e+e_d~gde+e`d~gde+eadgde+ecdgde+eddgde+eedgdge6eEe+edgde+emdgdeLeUZne!joejpejqejrejsejtgZudS )zU
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                   @   s,   e Zd ZU eegef ed< ee ed< dS )BaseBindingcommandkeysN)	__name__
__module____qualname__r   r	   r   __annotations__r   str r   r   W/home/ubuntu/.local/lib/python3.10/site-packages/IPython/terminal/shortcuts/__init__.pyr   %   s   
 r   c                   @   s   e Zd ZU eed< dS )RuntimeBindingfilterN)r   r   r   r   r   r   r   r   r    r!   +   s   
 r!   c                   @   s&   e Zd ZU dZee ed< dd ZdS )BindingN	conditionc                 C   s    | j rt| j | _d S d | _d S N)r$   r   r"   )selfr   r   r    __post_init__8   s   
zBinding.__post_init__)r   r   r   r$   r   r   r   r'   r   r   r   r    r#   0   s   
 r#   handlerc                 C   sP   | j d}| j}|d }t|dkr!|d }| d| d| S | d| S )N.r   r   :)r   splitr   len)r(   partsnamepackagefinal_moduler   r   r    create_identifier?   s   r2   c                 C      g | ]\}}t ||gd qS )z>focused_insert & auto_match & followed_by_closing_paren_or_endr#   .0keycmdr   r   r    
<listcomp>K   s    r9   c                 C   r3   )z8focused_insert & auto_match & preceded_by_raw_str_prefixr4   r5   r   r   r    r9   Q   s    "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_throughc                 C   r3   z0vi_insert_mode & default_buffer_focused & ebivimr4   r5   r   r   r    r9      s    )zc-azc-bzc-kzc-wzc-yzc-_c                 C   s    g | ]\}}t |t|d qS rG   )r#   list)r6   r   r8   r   r   r    r9   -  s    )
)c-xrA   )rI   e)rC   b)rC   c)rC   d)rC   h)rC   l)rC   u)rC   y)rC   r)   bindingsbindingc                 C   s0   | j |ji |jd urd|jini |j d S )Nr"   )addr   r"   r   )rR   rS   r   r   r    add_binding@  s   rU   returnc                    s   t  }|pg }tD ]'}d}|D ]}|j|jkr'|j|jkr'|j|jkr'd} nq|r+q	t|| q	 fdd}dd } jdkrM jrMt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                    s   t  } j|_ j|_| jS r%   )r   ttimeoutlen
timeoutlen_input_mode)r&   appshellr   r    get_input_modeg  s   z0create_ipython_shortcuts.<locals>.get_input_modec                 S   sB   t jdt jdi|d}d|}tj| tj  || _	d S )N         z[{} q)
r   
NAVIGATIONREPLACEgetformatsysstdoutwriteflushrY   )r&   modeshapecursorr   r   r    set_input_moden  s
   


z0create_ipython_shortcuts.<locals>.set_input_modevi)r   KEY_BINDINGSr   r"   r   rU   editing_modemodal_cursorr   INSERTr   rY   property
input_mode)r\   skipkbrS   skip_this_oneto_skipr]   rl   r   r[   r    r   G  s(   	c                 C   s&   t  }t| j| jj| | j  dS )zReformat code and execute itN)r   reformat_text_before_cursorcurrent_bufferdocumentvalidate_and_handleeventr\   r   r   r    reformat_and_execute~  s
   r~   c              
   C   sf   |  t|jd |j }z||}| | W d S  ty2 } z| | W Y d }~d S d }~ww r%   )delete_before_cursorr-   textcursor_positionreformat_handlerinsert_text	Exception)bufferrz   r\   r   formatted_textrJ   r   r   r    rx     s   
rx   c                 C   s,   t  }t|dd r||| S t|| S )Nhandle_return)r   getattrr   newline_or_execute_outerr|   r   r   r    #handle_return_or_newline_or_execute  s   r   c                    s    fdd}|S )Nc           	         s$  | j }|j}|jr|jj}|r|| dS |  dS |jdkr%|j}n|jd|j } 	|\}}|j|jd }d}|
 sJt||  d}|jsj|j|j|  ksj jrc|d|  dS |d dS |dkr|jr|syt||  |  dS  jr|d|  dS |d dS )zCWhen the user presses return, insert a newline or execute the code.Nr   FT

incomplete)ry   rz   complete_statecurrent_completionapply_completioncancel_completion
line_countr   r   check_completestriprx   on_last_linecursor_position_rowempty_line_count_at_the_end
autoindentr   accept_handlerr{   )	r}   rK   rM   cc
check_textstatusindentafter_cursorreformattedr[   r   r    newline_or_execute  sB   


z4newline_or_execute_outer.<locals>.newline_or_executer   )r\   r   r   r[   r    r     s   0r   c                 C      | j   dS )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)ry   auto_upr}   r   r   r    'previous_history_or_previous_completion     r   c                 C   r   )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)ry   	auto_downr   r   r   r    next_history_or_next_completion  r   r   c                 C   s   | j }|jr|  dS dS )zDismiss completionN)ry   r   r   r}   rK   r   r   r    dismiss_completion  s   r   c                 C   s$   | j }|jr|  dS |  dS )zReset bufferN)ry   r   r   resetr   r   r   r    reset_buffer  s   r   c                 C   s*   | j jjr| j   dS | jjt dS )zReset search bufferN)ry   rz   r   r   rZ   layoutfocusr   r   r   r   r    reset_search_buffer  s   
r   c                 C   r   )zSuspend to backgroundN)rZ   suspend_to_backgroundr   r   r   r    suspend_to_bg  s   r   c                 C   s4   t tdd}|durtdtj dS td dS )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   re   exit)r}   sigquitr   r   r    quit  s   r   c                 C   s   | j d dS )zIndent buffer    N)ry   r   r   r   r   r    indent_buffer	     r   c                 C   sf   t  }|j}| j}|j}|jr|  |jd|j d }||\}}|j	dd|p+d  dd dS )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_managerry   rz   r   r   r   r   r   r   )r}   r\   inputsplitterrK   rM   r   _r   r   r   r    newline_autoindent  s   r   c                 C   s   | j j  dS )z'Open code from input in external editorN)rZ   ry   open_in_editorr   r   r   r    open_input_in_editor"  r   r   win32)TryNext)ClipboardEmptytkinter_clipboard_getwin32_clipboard_getc                 C   sn   zt  }W n% ty!   zt }W n ttfy   Y Y d S w Y n
 ty*   Y d S w | j|dd d S )N	r   )r   r   r   r   ry   r   replace)r}   r   r   r   r    	win_paste/  s   

r   c                 C   s   dS )zStub used on other platformsNr   r   r   r   r    r   >  s   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%   )v__doc__r   r   re   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#   r2   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ALT_AND_COMOBO_CONTROL_BINDINGSrU   r   r~   rx   r   r   r   r   r   r   r   r   r   r   r   r   platformIPython.core.errorr   IPython.lib.clipboardr   r   r   r   rn   llm_autosuggestionbeginning_of_bufferend_of_bufferend_of_lineforward_wordunix_line_discardUNASSIGNED_ALLOWED_COMMANDSr   r   r   r    <module>   sd   &.38=
@
CKS[cri7		4			

$%&/015