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e\dygdzƒe+e]d{gdzƒe+e^d|gd}ƒe+e_d~gdƒe+e`d~gd€ƒe+ead�gd‚ƒe+ecdƒgd„ƒe+edd…gd†ƒe+eed‡gdƒge6¢eE¢e+edˆgd‰ƒ‘e+emdŠgd‹ƒ‘eL¢eU¢Zne!joejpejqejrejsejtgZudS )�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 Zd ZU eegef ed< ee ed< dS )ÚBaseBindingÚcommandÚkeysN)	Ú__name__Ú
__module__Ú__qualname__r   r	   r   Ú__annotations__r   Ústr© r   r   úYc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/terminal/shortcuts/__init__.pyr   %   s   
 r   c                   @   s   e Zd ZU eed< dS )ÚRuntimeBindingÚfilterN)r   r   r   r   r   r   r   r   r    r!   +   s   
 r!   c                   @   s&   e Zd ZU dZee ed< dd„ ZdS )ÚBindingNÚ	conditionc                 C   s    | j rt| j ƒ| _d S d | _d S ©N)r$   r   r"   )Úselfr   r   r    Ú__post_init__8   s   
zBinding.__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|ƒdkr!|d }|› d|› d|› �S |› d|› �S )NÚ.r   r   éÿÿÿÿú:)r   Úsplitr   Úlen)r(   ÚpartsÚnameÚpackageZfinal_moduler   r   r    Úcreate_identifier?   s   r1   c                 C   ó   g | ]\}}t ||gd ƒ‘qS )z>focused_insert & auto_match & followed_by_closing_paren_or_end©r#   ©Ú.0ÚkeyÚcmdr   r   r    Ú
<listcomp>K   s    ýÿÿr8   c                 C   r2   )z8focused_insert & auto_match & preceded_by_raw_str_prefixr3   r4   r   r   r    r8   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_quoteZ	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-ezc-fÚrightz_has_suggestion & default_buffer_focused & emacs_like_insert_mode & is_cursor_at_the_end_of_lineÚescapeÚfzc-rightz;has_suggestion & default_buffer_focused & emacs_insert_modeÚdeletezc-upzQnavigable_suggestions & ~has_line_above & has_suggestion & default_buffer_focusedzc-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_focusedzc-leftZdownz/default_buffer_focused & emacs_like_insert_modez]is_cursor_at_the_end_of_line & default_buffer_focused & emacs_like_insert_mode & pass_throughc                 C   r2   ©z0vi_insert_mode & default_buffer_focused & ebivimr3   r4   r   r   r    r8      s    ÿÿ)zc-azc-bzc-kzc-wzc-yzc-_c                 C   s    g | ]\}}t |t|ƒd ƒ‘qS rD   )r#   Úlist)r5   r   r7   r   r   r    r8   -  s    ÿÿ)
)úc-xr?   )rF   Úe)rA   Úb)rA   Úc)rA   Úd)rA   Úh)rA   Úl)rA   Úu)rA   Úy)rA   r)   ÚbindingsÚbindingc                 C   s0   | j |ji |jd urd|jini ¤Ž|jƒ d S )Nr"   )Úaddr   r"   r   )rO   rP   r   r   r    Úadd_binding@  s   ÿþýrR   Úreturnc                    sž   t ƒ }|pg }tD ]'}d}|D ]}|j|jkr'|j|jkr'|j|jkr'd} nq|r+q	t||ƒ q	‡ fdd„}dd„ }ˆ jdkrMˆ jrMtj	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|_| jS r%   )r   ZttimeoutlenZ
timeoutlenÚ_input_mode)r&   Úapp©Úshellr   r    Úget_input_modeg  s   z0create_ipython_shortcuts.<locals>.get_input_modec                 S   sB   t jdt jdi |d¡}d |¡}tj |¡ tj ¡  || _	d S )Né   é   é   z[{} q)
r   Z
NAVIGATIONZREPLACEÚgetÚformatÚsysÚstdoutÚwriteÚflushrT   )r&   ÚmodeÚshapeÚcursorr   r   r    Úset_input_moden  s
   


z0create_ipython_shortcuts.<locals>.set_input_modeÚvi)r   ÚKEY_BINDINGSr   r"   r   rR   Zediting_modeZmodal_cursorr   ZINSERTr   rT   ÚpropertyZ
input_mode)rW   ÚskipÚkbrP   Zskip_this_oneZto_skiprX   re   r   rV   r    r   G  s(   €	c                 C   s&   t ƒ }t| j| jj|ƒ | j ¡  dS )zReformat code and execute itN)r   Úreformat_text_before_cursorÚcurrent_bufferÚdocumentÚvalidate_and_handle©ÚeventrW   r   r   r    Úreformat_and_execute~  s
   ÿrq   c              
   C   sf   |   t|jd |j… ƒ¡}z| |¡}|  |¡ W d S  ty2 } z|  |¡ W Y d }~d S d }~ww r%   )Zdelete_before_cursorr-   ÚtextÚcursor_positionZreformat_handlerÚinsert_textÚ	Exception)Úbufferrm   rW   rr   Zformatted_textrG   r   r   r    rk   ‡  s   
€ÿrk   c                 C   s,   t ƒ }t|dd ƒr| |¡| ƒS t|ƒ| ƒS )NÚhandle_return)r   Úgetattrrw   Únewline_or_execute_outerro   r   r   r    Ú#handle_return_or_newline_or_execute�  s   rz   c                    s   ‡ fdd„}|S )Nc           	         s$  | j }|j}|jr|jj}|r| |¡ dS | ¡  dS |jdkr%|j}n|jd|j… }ˆ  	|¡\}}|j|jd… }d}| 
¡ sJt||ˆ ƒ d}|jsj|j|j| ¡  ksjˆ jrc| d| ¡ dS | d¡ dS |dkr|jr|syt||ˆ ƒ | ¡  dS ˆ jr‹| d| ¡ dS | d¡ dS )zCWhen the user presses return, insert a newline or execute the code.Nr   FTÚ
Ú
incomplete)rl   rm   Úcomplete_stateZcurrent_completionZapply_completionÚcancel_completionÚ
line_countrr   rs   Úcheck_completeÚstriprk   Zon_last_lineZcursor_position_rowZempty_line_count_at_the_endZ
autoindentrt   Zaccept_handlerrn   )	rp   rH   rJ   ÚccÚ
check_textÚstatusÚindentZafter_cursorZreformattedrV   r   r    Únewline_or_execute™  sB   
ÿ
ÿ
ÿz4newline_or_execute_outer.<locals>.newline_or_executer   )rW   r†   r   rV   r    ry   ˜  s   0ry   c                 C   ó   | j  ¡  dS )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)rl   Zauto_up©rp   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)rl   Z	auto_downrˆ   r   r   r    Únext_history_or_next_completionÕ  rŠ   r‹   c                 C   s   | j }|jr| ¡  dS dS )zDismiss completionN)rl   r}   r~   ©rp   rH   r   r   r    Údismiss_completionÞ  s   ÿr�   c                 C   s$   | j }|jr| ¡  dS | ¡  dS )zReset bufferN)rl   r}   r~   ÚresetrŒ   r   r   r    Úreset_bufferå  s   r�   c                 C   s*   | j jjr| j  ¡  dS | jj t¡ dS )zReset search bufferN)rl   rm   rr   rŽ   rU   ZlayoutZfocusr   rˆ   r   r   r    Úreset_search_bufferî  s   
r�   c                 C   r‡   )zSuspend to backgroundN)rU   Zsuspend_to_backgroundrˆ   r   r   r    Úsuspend_to_bgö  s   r‘   c                 C   s4   t tddƒ}|durt dtj¡ dS t d¡ dS )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   ZQuit)rx   ÚsignalÚosÚkillr’   r^   Úexit)rp   Zsigquitr   r   r    Úquitû  s   r—   c                 C   s   | j  d¡ dS )zIndent bufferú    N)rl   rt   rˆ   r   r   r    Úindent_buffer	  ó   r™   c                 C   sf   t ƒ }|j}| j}|j}|jr| ¡  |jd|j… d }| |¡\}}|j	dd|p+d  dd� dS )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)Zmove_cursor)
r   Zinput_transformer_managerrl   rm   r}   r~   rr   rs   r€   rt   )rp   rW   ZinputsplitterrH   rJ   rr   Ú_r…   r   r   r    Únewline_autoindent  s   r�   c                 C   s   | j j ¡  dS )z'Open code from input in external editorN)rU   rl   Zopen_in_editorrˆ   r   r   r    Úopen_input_in_editor"  rš   rž   Úwin32)ÚTryNext)ÚClipboardEmptyÚtkinter_clipboard_getÚwin32_clipboard_getc                 C   sn   zt ƒ }W n% ty!   ztƒ }W n ttfy   Y Y d S w Y n
 ty*   Y d S w | j | dd¡¡ d S )Nú	r˜   )r£   r    r¢   r¡   rl   rt   Úreplace)rp   rr   r   r   r    Ú	win_paste/  s   

ÿÿÿr¦   c                 C   s   dS )zStub used on other platformsNr   rˆ   r   r   r    r¦   >  s   Zenterz5default_buffer_focused & ~has_selection & insert_modez>default_buffer_focused & ~has_selection & insert_mode & ebivimzc-\zc-pz'vi_insert_mode & default_buffer_focusedzc-nzc-gz(default_buffer_focused & has_completionszc-cZdefault_buffer_focusedZsearch_buffer_focusedzc-zZsupports_suspendÚtabzLdefault_buffer_focused & ~has_selection & insert_mode & cursor_in_leading_wszc-oz*default_buffer_focused & emacs_insert_modeÚf2zc-izireadline_like_completions & default_buffer_focused & ~has_selection & insert_mode & ~cursor_in_leading_wszc-vz1default_buffer_focused & ~vi_mode & is_windows_osr%   )vÚ__doc__r”   r“   r^   ÚwarningsÚdataclassesr   Útypingr   r   r   r   Z"prompt_toolkit.application.currentr   Zprompt_toolkit.key_bindingr   Z(prompt_toolkit.key_binding.key_processorr	   Z#prompt_toolkit.key_binding.bindingsr
   ÚncZ.prompt_toolkit.key_binding.bindings.completionr   Z#prompt_toolkit.key_binding.vi_stater   r   Zprompt_toolkit.filtersr   ZIPython.core.getipythonr   Ú r   Úmatchr   Úfiltersr   ZIPython.utils.decoratorsr   Zprompt_toolkit.enumsr   Ú__all__r   r!   r#   r1   Zauto_match_parensÚitemsZauto_match_parens_raw_stringZdouble_quoteZsingle_quoteZdocstring_double_quotesZdocstring_single_quotesZ	skip_overZdelete_pairZAUTO_MATCH_BINDINGSZaccept_or_jump_to_endÚacceptZaccept_wordZaccept_tokenÚdiscardZswap_autosuggestion_upZswap_autosuggestion_downZup_and_update_hintZdown_and_update_hintZaccept_characterZaccept_and_move_cursor_leftZaccept_and_keep_cursorZbackspace_and_resume_hintZresume_hintingZAUTO_SUGGEST_BINDINGSZbeginning_of_lineZbackward_charZ	kill_lineZbackward_kill_wordZyankZundoZSIMPLE_CONTROL_BINDINGSZedit_and_executeZbackward_wordZcapitalize_wordZ	kill_wordZdowncase_wordZuppercase_wordZyank_popZyank_last_argZALT_AND_COMOBO_CONTROL_BINDINGSrR   r   rq   rk   rz   ry   r‰   r‹   r�   r�   r�   r‘   r—   r™   r�   rž   ÚplatformZIPython.core.errorr    ZIPython.lib.clipboardr¡   r¢   r£   r¦   rg   Zllm_autosuggestionZbeginning_of_bufferZend_of_bufferÚend_of_lineZforward_wordZunix_line_discardZUNASSIGNED_ALLOWED_COMMANDSr   r   r   r    Ú<module>   sd   üÿýùýôýëýâ&ýÚ.ýÒ3ýÍ8ýÈ=
ÿÃ@
ÿÀCý½KýµSý­[ý¥cý�rýýýýýýûýýýýýýýýüý¢iú÷ôñ7		4			
ýý
ýýýÝ$Ü%Û&ýÚ/Ñ0Ð1Ï5ú