HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberPanel/lib64/python3.10/site-packages/asyncssh/__pycache__/editor.cpython-310.pyc
o

�h�v�@sdZddlZddlmZddlmZmZmZmZddlm	Z	m
Z
mZmZm
Z
ddlmZddlmZer@dd	lmZdd
lmZeeefZedgdfZeeegeeeeefffZdZd
Zdedefdd�ZGdd�d�ZGdd�d�Z Gdd�d�Z!dS)�Input line editor�N)�partial)�
TYPE_CHECKING�Callable�Dict�List)�Optional�Set�Tuple�Union�cast��east_asian_width�)�DataType)�SSHServerChannel)�SSHServerSession�
SSHLineEditor�P)�ansi�cygwin�linux�putty�screen�teraterm�cit80�vt100�vt102�vt220�vt320�xtermzxterm-colorz
xterm-16colorzxterm-256color�rxvtz
rxvt-color�ch�returncCst|�dvS)z!Return display width of character�WFr
�r"�r&�E/usr/local/CyberPanel/lib/python3.10/site-packages/asyncssh/editor.py�_is_wide4�r(c@seZdZdZdddddededed	ed
efdd�Zd
ededdfdd�Z	d
eddfdd�Z
d~dd�Zdedefdd�Z	ddedede
edeeeffdd�Zddede
eddfdd�Zd~d d!�Zd"edefd#d$�Zdeddfd%d&�Zdeddfd'd(�Zd~d)d*�Zd~d+d,�Zd~d-d.�Zd"ed/eddfd0d1�Zdeded"eddfd2d3�Zd~d4d5�Zd~d6d7�Zdeddfd8d9�Zd~d:d;�Zd~d<d=�Zd~d>d?�Zd~d@dA�Z d~dBdC�Z!d~dDdE�Z"d
edFe#ddfdGdH�Z$d~dIdJ�Z%d~dKdL�Z&d~dMdN�Z'd~dOdP�Z(d~dQdR�Z)d~dSdT�Z*d~dUdV�Z+d~dWdX�Z,d~dYdZ�Z-ed[fed\fed]fe d^fe!d_fe"d`fe%dafe&dbfe'dcfe(ddfe)defe*dffe+dgfe,dhfe-diffZ.d
edFe#ddfdjdk�Z/d
eddfdldm�Z0dnededdfdodp�Z1dqeddfdrds�Z2dteddfdudv�Z3d
eddfdwdx�Z4dedye5ddfdzd{�Z6deddfd|d}�Z7dS)�rr�chan�SSHServerChannel[str]�session�SSHServerSession[str]�	line_echo�history_size�max_line_length�	term_type�widthcCs�||_||_||_d|_|dkr|nd|_||_|tv|_|p t|_	d|_
d|_d|_d|_
d|_d|_d|_d|_d|_d|_t�|_g|_i|_|j|_d|_g|_d|_|jD]\}}	|	D]}
|�|
|�q`qZ|��dS)NFrT�)�_chan�_session�
_line_echo�
_line_pending�
_history_size�_max_line_length�_ansi_terminals�_wrap�_DEFAULT_WIDTH�_width�
_line_mode�_echo�
_start_column�_end_column�_cursor�	_left_pos�
_right_pos�_pos�_line�
_bell_rung�set�_early_wrap�_outbuf�_keymap�
_key_state�_erased�_history�_history_index�_keylist�_add_key�_build_printable)�selfr*r,r.r/r0r1r2�func�keys�keyr&r&r'�__init__=s<

�zSSHLineEditor.__init__rVrTr#NcCsF|j}|dd�D]}||vri||<tt||�}q	|||d<dS)zAdd a key to the keymapN���)rKr�	_CharDict)rSrVrT�keymapr"r&r&r'rQaszSSHLineEditor._add_keycCsH|j}|dd�D]}||vrdStt||�}q	|�|dd�dS)zDelete a key from the keymapNrX)rKrrY�pop)rSrVrZr"r&r&r'�_del_keynszSSHLineEditor._del_keycs�dtdtfdd�}dtdtf�fdd�}g}|j���td�}d	}||kro||kr=|t|��s=|d
7}||kr=|t|��r/|}|t|��rO|d
7}|t|��sE|�||��||d
krg|�d||d
��|d
}||ks%t�	dd
�
|�d�|_dS)z4Build a regex of printable ASCII non-registered keys�cr#cSs t|�}|dvrd|Sd|S)z<Backslash escape special characters in regex character rangez-&|[]\^~�\r3)�chr)r]r"r&r&r'�_escape~sz/SSHLineEditor._build_printable.<locals>._escaper"cs|��o|�vS)z3Return if character is printable and has no handler)�isprintabler%�rUr&r'�
_is_printable��z5SSHLineEditor._build_printable.<locals>._is_printable� ir�-�[r3z]*N)�int�str�boolrKrU�ordr_�append�re�compile�join�
_printable)rSr`rc�pat�start�limit�endr&rbr'rR{s(
���zSSHLineEditor._build_printable�poscCs dt|j|�|d|jvS)z/Return width of character at specified positionr)r(rFrI�rSrur&r&r'�_char_width�s zSSHLineEditor._char_width�data�columnc	Cs<d}|}|}g}|D]m}|dkr|d8}nZ|dkrd}nS|r%|dkr$d}nJt|�r]||j|jdkr]|d7}|dur\|dusAJ�|dusGJ�|�|||||��|}|j�|�n
|durg|j�|�|dt|�7}|durw|d7}q
|dur�|dus�J�|dus�J�|�|||d��d�|�|fS||fS)	z/Determine new output column after output occursF�r�T�mNre)r(r=rlrI�add�discardro)	rSrxryru�escaped�offset�
last_wrap_pos�wrapped_datar"r&r&r'�_determine_column�sH
����zSSHLineEditor._determine_columncCs�|�d�}|dkr!|j�|d|d��||dd�}d|_n|}|�||j|�\}|_|j�|�|jrG|j|jdkrI|j�d�dSdSdS)z/Generate output and calculate new output column�
rNr� )�rfindrJrlrBr�r=)rSrxru�idx�tailr&r&r'�_output�s
�zSSHLineEditor._outputcCs |js|j�d�d|_dSdS)zRing the terminal bell�TN)rGrJrl�rSr&r&r'�
_ring_bell�s
�zSSHLineEditor._ring_bell�new_poscCs:t|j�}||jkr||_n`||kr|d7}|j}|j}||kr/||�|�7}|d7}||ks ||jkrN||jkrM||�|j�8}|jd7_||jks9n |jdkrn||�|j�7}||jkrh|jd8_nn|jdksS|j}|j|_|j|kr�|�|j�}|||jkr�|jd7_||7}n	|S|j|ksz|S)zAUpdate visible input window when not wrapping onto multiple linesrr)	�lenrFrCrErBrwr=r@rD)rSr��line_lenrury�ch_widthr&r&r'�_update_input_window�sD

�


��


�


�	z"SSHLineEditor._update_input_windowcCs�|j|j}|j|j}||j}||j}||kr)|j�dt||�d�n||kr;|j�dt||�d�||krN|j�dt||�d�n||kr`|j�dt||�d�||_dS)z2Move the cursor to selected position in input linez[�A�B�C�DN)rBr=rJrlri)rSry�	start_row�	start_col�end_row�end_colr&r&r'�_move_cursors


zSSHLineEditor._move_cursorcCs4|jr
|�|�dS|j�d|j|�||_dS)z;Move the cursor backward to selected position in input linerzN)r;r�rJrlrB�rSryr&r&r'�
_move_back1s
zSSHLineEditor._move_backcCs`|j}|j|}|dkr&|j�d|�|j|_|j|jdkr&|j�d�|�|�||_dS)z7Clear any remaining characters from previous input linerrer�N)rBrArJrlr=r�)rSry�	remainingr&r&r'�
_clear_to_end:s


zSSHLineEditor._clear_to_endcCs"|�|j�|��|j��dS)zErase current input lineN)r�r@r�rI�clearr�r&r&r'�_erase_inputJszSSHLineEditor._erase_inputcCs�|jrR|jrT|jr&|�|jd|j�d�|j}|�|j|jd�|j�n!|�|j�|�|j|j|j��|j}|�|j|j|j��|j|_	|�
|�dSdSdS)zDraw current input lineNr)rFr?r;r�rErBr�rCrDrAr�r�r&r&r'�_draw_inputQs�zSSHLineEditor._draw_input�
new_columncCs4|jr|jr|�|�n	|�|j|j|�||_dS)z3Reposition the cursor to selected position in inputN)r?r;r��
_update_inputrErB)rSr�r�r&r&r'�_repositionbs

zSSHLineEditor._repositioncCs�|jri|jr<||jvr|d8}|�|�||jv}|�|j||�|�|j}|�|j|d�|�|||jv|7}n$|�|�|�|j	�|�|j|j
|��|j}|�|j||j��|��|�|�||_
dS)z-Update selected portion of current input linerN)r?r;rIr�r�rFrBr�r�r@rCrDr�rE)rSruryr��	prev_wrapr&r&r'r�ms$





zSSHLineEditor._update_inputcCs,d|_d|_d|_d|_|j|_|j|_dS)zReset input line to emptyr3rN)rFrCrDrErBr@rAr�r&r&r'�_reset_line�szSSHLineEditor._reset_linecCs$|jr|��|��d|_dSdS)z"Reset a pending echoed line if anyFN)r7r�r�r�r&r&r'�_reset_pending�s

�zSSHLineEditor._reset_pendingcCs�t|j�}t|�}|jr"|||jkr"|��|j|}|d|�}|rF|j}||}|jd|�||j|d�|_|�||j|�dSdS)zInsert data into the input lineN)r�rFr9r�rEr�rB)rSrxr��data_lenrur�r&r&r'�_insert_printable�s

"�zSSHLineEditor._insert_printablecCs�|j}|jo|jo|jdkp|jt|�k}|js|r9|r+|�d|j|j	|�n|�
�|�d�|��n|�
�d|_|jrX|j
rX|rX|j�|�|j|j
d�|_t|j�|_|j�|dd�dS)z5End the current input line and send it to the sessionrrz�
TNr�)rFr?r;rCrDr�r6r�rBr@�_move_to_endr�r7r8rNrlrOr5�
data_received)rS�line�	need_wrapr&r&r'�	_end_line�s"�


zSSHLineEditor._end_linecCs |js
|j��dS|��dS)z@Erase character to the right, or send EOF if input line is emptyN)rFr5�soft_eof_received�_erase_rightr�r&r&r'�_eof_or_delete�szSSHLineEditor._eof_or_deletecCsd|jdkr,|jd}|j|�|�}|jd|�|j|dd�|_|�|||�dS|��dS)zErase character to the leftrrN)rErBrwrFr�r��rSruryr&r&r'�_erase_left�s

"zSSHLineEditor._erase_leftcCsX|jt|j�kr&|j}|jd|�|j|dd�|_|�||j|�dS|��dS)zErase character to the rightNr)rEr�rFr�rBr�rvr&r&r'r��s
"zSSHLineEditor._erase_rightcCs"|j|_d|_|�d|jd�dS)zErase entire input liner3rN)rFrMr�r@r�r&r&r'�_erase_line�szSSHLineEditor._erase_linecCs:|j}|j|d�|_|jd|�|_|�||j|�dS)zErase to end of input lineN)rErFrMr�rBrvr&r&r'�
_erase_to_end�szSSHLineEditor._erase_to_end�handlercCs�||j|j�}|dur|��r|�|�dS|��dS|dur&|��dSttttf|�\}}|dkr=|j	�
|�dS||_|�d|j|�dS)zCall an external key handlerTFrN)
rFrErar�r�rr
rirhr5�signal_receivedr�r@)rSrVr��resultr�r�r&r&r'�_handle_key�szSSHLineEditor._handle_keycCsL|jdkr |jd8_|j|j|_|�d|jt|j��dS|��dS)z+Replace input with previous line in historyrrN)rOrNrFr�r@r�r�r�r&r&r'�
_history_prev	s

zSSHLineEditor._history_prevcCsj|jt|j�kr/|jd7_|jt|j�kr|j|j|_nd|_|�d|jt|j��dS|��dS)z'Replace input with next line in historyrr3rN)rOr�rNrFr�r@r�r�r&r&r'�
_history_nextszSSHLineEditor._history_nextcCs@|jdkr|jd}|j|�|�}|�||�dS|��dS)zMove left in input linerrN)rErBrwr�r�r�r&r&r'�
_move_left"s


zSSHLineEditor._move_leftcCsF|jt|j�kr|j}|j|�|�}|�|d|�dS|��dS)zMove right in input linerN)rEr�rFrBrwr�r�r�r&r&r'�_move_right,s
zSSHLineEditor._move_rightcCs|�d|j�dS)zMove to start of input linerN)r�r@r�r&r&r'�_move_to_start6szSSHLineEditor._move_to_startcCs|�t|j�|j�dS)zMove to end of input lineN)r�r�rFrAr�r&r&r'r�;szSSHLineEditor._move_to_endcCs|��|��dS)zRedraw input lineN)r�r�r�r&r&r'�_redraw@szSSHLineEditor._redrawcCs|�|j�dS)zInsert previously erased inputN)r�rMr�r&r&r'�_insert_erasedFrdzSSHLineEditor._insert_erasedcCs|j�d�dS)zSend break to sessionrN)r5�break_receivedr�r&r&r'�_send_breakKrdzSSHLineEditor._send_break)r��
zOM)�)rz�)z[3~)�)�)�zzOA)�zzOB)�zzOD)�zzOC)�zz[1~)�zz[4~)�)�)�z[33~cCs$|�|ttj||d��|��dS)z5Register a handler to be called when a key is pressed)rVr�N)rQrrr�rR�rSrVr�r&r&r'�register_key`s�zSSHLineEditor.register_keycCs|�|�|��dS)z(Remove the handler associated with a keyN)r\rR�rSrVr&r&r'�unregister_keygs
zSSHLineEditor.unregister_keyr�cCs"|��||_|�d|j|�dS)z"Set input line and cursor positionrN)r�rFr�r@�rSr�rur&r&r'�	set_inputmszSSHLineEditor.set_input�	line_modecCs>|��|jr|s|j}|��d|_|j�|d�||_dS)z!Enable/disable input line editingr3N)r�rFr�r5r�r>)rSr�rxr&r&r'�
set_line_modeus

zSSHLineEditor.set_line_mode�echocCsH|��|jr|s|��d|_dS|r |js"d|_|��dSdSdS)z,Enable/disable echoing of input in line modeFTN)r�r?r�r��rSr�r&r&r'�set_echo�s


�zSSHLineEditor.set_echocCs<|��|pt|_|jr|�|j|jd�\}|_|��dS)zSet terminal line widthrN)	r�r<r=r;r�rFr@rBr�)rSr2�_r&r&r'�	set_width�s

�zSSHLineEditor.set_width�datatypecCsD|jr�t|�}d}||kr�|��||}|d7}||jvrA|j|}t|�r:z
tt|�|�W|j|_nG|j|_wtt|�|_n;|j|jkrt|�	�rt|j
�||d�}|dusZJ�|d}|rn|�|�|t|�d7}n|�|�n|j|_|�
�||ks
d|_|jr�|j�d�|j��|j��dSdS|j�||�dS)zProcess input from channelrrNFr3)r>r�r�rL�callabler�_CharHandlerrKrYrarp�matchr�r�rGrJr4�writeror�r5r�)rSrxr�r�r�r"�	key_stater�r&r&r'�
process_input�s>


��zSSHLineEditor.process_inputcCs�|jr"|�|j�r|j|_|t|j�d�}n|��|��d|_|�dd�}|��|�	|�|j
s<|j|j;_|j|_|j|_|�
�|j�d�|j��|j��dS)zProcess output to channelNFr�r�r3)r7�
startswithrFrBr@r�r�r��replacer�r;r=rAr�r4r�rorJr�)rSrxr&r&r'�process_output�s"
zSSHLineEditor.process_output�r#N�N)8�__name__�
__module__�__qualname__�__doc__rjrhrirWr�rQr\rRrwrr
r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��_KeyHandlerr�r�r�r�r�r�r�r�r�r�rPr�r�r�r�r�r�rr�r�r&r&r&r'r:s������
�$

%��

�0
-
	























�
.c
@s�eZdZdZdddddededef
d	d
�Zdefdd
�Zde	e
fdd�Zdededdfdd�Z
deddfdd�Zd(dd�Zdededdfdd�Zdeddfdd �Zd!eddfd"d#�Zd)d$ed%eddfd&d'�ZdS)*�SSHLineEditorChannela�Input line editor channel wrapper

       When creating server channels with `line_editor` set to `True`,
       this class is wrapped around the channel, providing the caller with
       the ability to enable and disable input line editing and echoing.

       .. note:: Line editing is only available when a pseudo-terminal
                 is requested on the server channel and the character
                 encoding on the channel is not set to `None`.

    �	orig_chanr+�orig_sessionr-r.r/r0cCs(||_||_||_||_||_d|_dSr�)�
_orig_chan�
_orig_sessionr6r8r9�_editor)rSr�r�r.r/r0r&r&r'rW�s
zSSHLineEditorChannel.__init__�attrcC�t|j|�S)z3Delegate most channel functions to original channel)�getattrr��rSr�r&r&r'�__getattr__�r)z SSHLineEditorChannel.__getattr__r#cCsT|j��\}}|j��}|j��d}|r'|r't|j|j|j|j|j||�|_	|j	S)z>Create input line editor if encoding and terminal type are setr)
r��get_encoding�get_terminal_type�get_terminal_sizerr�r6r8r9r�)rS�encodingr�r1r2r&r&r'�
create_editors
�z"SSHLineEditorChannel.create_editorrVr�NcC� |jdusJ�|j�||�dS)aRegister a handler to be called when a key is pressed

           This method registers a handler function which will be called
           when a user presses the specified key while inputting a line.

           The handler will be called with arguments of the current
           input line and cursor position, and updated versions of these
           two values should be returned as a tuple.

           The handler can also return a tuple of a signal name and
           negative cursor position to cause a signal to be delivered
           on the channel. In this case, the current input line is left
           unchanged but the signal is delivered before processing any
           additional input. This can be used to define "hot keys" that
           trigger actions unrelated to editing the input.

           If the registered key is printable text, returning `True` will
           insert that text at the current cursor position, acting as if
           no handler was registered for that key. This is useful if you
           want to perform a special action in some cases but not others,
           such as based on the current cursor position.

           Returning `False` will ring the bell and leave the input
           unchanged, indicating the requested action could not be
           performed.

           :param key:
               The key sequence to look for
           :param handler:
               The handler function to call when the key is pressed
           :type key: `str`
           :type handler: `callable`

        N)r�r�r�r&r&r'r�s$z!SSHLineEditorChannel.register_keycCs|jdusJ�|j�|�dS)a�Remove the handler associated with a key

           This method removes a handler function associated with
           the specified key. If the key sequence is printable,
           this will cause it to return to being inserted at the
           current position when pressed. Otherwise, it will cause
           the bell to ring to signal the key is not understood.

           :param key:
               The key sequence to look for
           :type key: `str`

        N)r�r�r�r&r&r'r�8sz#SSHLineEditorChannel.unregister_keycCs |jdusJ�|j�dd�dS)zQClear input line

           This method clears the current input line.

        Nr3r�r�r�r�r&r&r'�clear_inputJsz SSHLineEditorChannel.clear_inputr�rucCr)a+Clear input line

           This method sets the current input line and cursor position.

           :param line:
               The new input line
           :param pos:
               The new cursor position within the input line
           :type line: `str`
           :type pos: `int`

        Nrr�r&r&r'r�TszSSHLineEditorChannel.set_inputr�cC�6|jj�d|r	dnd�|jdusJ�|j�|�dS)avEnable/disable input line editing

           This method enabled or disables input line editing. When set,
           only full lines of input are sent to the session, and each
           line of input can be edited before it is sent.

           :param line_mode:
               Whether or not to process input a line at a time
           :type line_mode: `bool`

        z%s line editor�Enabling�	DisablingN)r��logger�infor�r�)rSr�r&r&r'r�es


�z"SSHLineEditorChannel.set_line_moder�cCr)a!Enable/disable echoing of input in line mode

           This method enables or disables echoing of input data when
           input line editing is enabled.

           :param echo:
               Whether or not input to echo input as it is entered
           :type echo: `bool`

        z%s echorrN)r�rrr�r�r�r&r&r'r�xs


�zSSHLineEditorChannel.set_echorxr�cCs0|jr|dur|j�|�dS|j�||�dS)z#Process data written to the channelN)r�r�r�r��rSrxr�r&r&r'r��szSSHLineEditorChannel.writer�r�)r�r�r�r�rjrhrWrir�rrr�r�r�r�rr�r�r�rr�r&r&r&r'r��s(���
�
'

r�c
@s�eZdZdZdeddfdd�Zdefdd	�Zddd
�Zde	de	de	de	d
df
dd�Z
deded
dfdd�Zd
e
efdd�ZdS)�SSHLineEditorSessionz!Input line editor session wrapperr*r�r-cCs||_||_d|_dSr�)r4r�r�)rSr*r�r&r&r'rW�s
zSSHLineEditorSession.__init__r�cCr�)z3Delegate most channel functions to original session)r�r�r�r&r&r'r��r)z SSHLineEditorSession.__getattr__r#NcCs|j��|_|j��dS)z4Start a session for this newly opened server channelN)r4r�r�r��session_startedr�r&r&r'r
�sz$SSHLineEditorSession.session_startedr2�height�pixwidth�	pixheightcCs(|jr	|j�|�|j�||||�dS)zThe terminal size has changedN)r�r�r��terminal_size_changed)rSr2rrr
r&r&r'r�s

�z*SSHLineEditorSession.terminal_size_changedrxr�cCs*|jr|j�||�dS|j�||�dS)z&Process data received from the channelN)r�r�r�r�rr&r&r'r��sz"SSHLineEditorSession.data_receivedcCs|jr	|j�d�|j��S)z%Process EOF received from the channelF)r�r�r��eof_receivedr�r&r&r'r�s
z!SSHLineEditorSession.eof_receivedr�)r�r�r�r�r�rWrir�r
rhrrr�rrjrr&r&r&r'r	�s 
�

��
�
r	)"r�rm�	functoolsr�typingrrrrrr	r
rr�unicodedatarr,r�channelrrri�objectrYr�rhrjr�r<r:r(rr�r	r&r&r&r'�<module>s2 2-