HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/conch/insults/__pycache__/insults.cpython-38.pyc
U


W[��@s�dZddlmZmZddlmZmZmZddl	m
Z
mZmZGdd�de�Z
ee
�Gdd�de��ZGd	d
�d
ej�ZdZdd
iZGdd�d�ZGdd�d�ZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#Gdd �d �Z$d!d"�Z%d#Z&Gd$d%�d%e�Z'd&d'�e&D�Z(ee�Gd(d)�d)ej)��Z*e+e&e(�D]\Z,Z-e.e*e,e-��q2Gd*d+�d+ej)�Z/dd
ddd,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d)d+gZ0d;S)<z?
VT102 and VT220 terminal manipulation.

@author: Jp Calderone
�)�implementer�	Interface)�protocol�defer�
interfaces)�
intToBytes�	iterbytes�
networkStringc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ITerminalProtocolcCsdS)zX
        Called with an L{ITerminalTransport} when a connection is established.
        N�)�	transportrr�?/usr/lib/python3/dist-packages/twisted/conch/insults/insults.py�makeConnectionsz ITerminalProtocol.makeConnectioncCsdS)a`
        A keystroke was received.

        Each keystroke corresponds to one invocation of this method.
        keyID is a string identifier for that key.  Printable characters
        are represented by themselves.  Control keys, such as arrows and
        function keys, are represented with symbolic constants on
        L{ServerProtocol}.
        Nr)�keyID�modifierrrr
�keystrokeReceivedsz#ITerminalProtocol.keystrokeReceivedcCsdS)z�
        Called to indicate the size of the terminal.

        A terminal of 80x24 should be assumed if this method is not
        called.  This method might not be called for real terminals.
        Nr)�width�heightrrr
�terminalSize#szITerminalProtocol.terminalSizecCsdS�z�
        Called when an unsupported control sequence is received.

        @type seq: L{str}
        @param seq: The whole control sequence which could not be interpreted.
        Nr��seqrrr
�unhandledControlSequence+sz*ITerminalProtocol.unhandledControlSequencecCsdS)zh
        Called when the connection has been lost.

        reason is a Failure describing why.
        Nr)�reasonrrr
�connectionLost3sz ITerminalProtocol.connectionLostN)�__name__�
__module__�__qualname__rrrrrrrrr
r
s
r
c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TerminalProtocolcCs||_|��dS�N)�terminal�connectionMade)�selfr rrr
r>szTerminalProtocol.makeConnectioncCsdS)zA
        Called after a connection has been established.
        Nr�r"rrr
r!DszTerminalProtocol.connectionMadecCsdSrr)r"rrrrr
rJsz"TerminalProtocol.keystrokeReceivedcCsdSrr)r"rrrrr
rNszTerminalProtocol.terminalSizecCsdSrr)r"rrrr
rRsz)TerminalProtocol.unhandledControlSequencecCsdSrr�r"rrrr
rVszTerminalProtocol.connectionLostN)	rrrrr!rrrrrrrr
r<src@sdeZdZdVdd�ZdWdd�ZdXdd�ZdYdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�ZdZd7d8�Zd9d:�Zd;d<�Zd=d>�Z d?d@�Z!dAdB�Z"dCdD�Z#dEdF�Z$dGdH�Z%d[dIdJ�Z&d\dKdL�Z'd]dMdN�Z(dOdP�Z)dQdR�Z*dSdT�Z+dUS)^�ITerminalTransport�cCsdS)z-
        Move the cursor up n lines.
        Nr��nrrr
�cursorUp\szITerminalTransport.cursorUpcCsdS)z/
        Move the cursor down n lines.
        Nrr'rrr
�
cursorDownbszITerminalTransport.cursorDowncCsdS)z2
        Move the cursor right n columns.
        Nrr'rrr
�
cursorForwardhsz ITerminalTransport.cursorForwardcCsdS)z1
        Move the cursor left n columns.
        Nrr'rrr
�cursorBackwardnsz!ITerminalTransport.cursorBackwardcCsdS)z?
        Move the cursor to the given line and column.
        Nr)�column�linerrr
�cursorPositiontsz!ITerminalTransport.cursorPositioncCsdS)z'
        Move the cursor home.
        Nrrrrr
�
cursorHomezszITerminalTransport.cursorHomecCsdS)zS
        Move the cursor down one line, performing scrolling if necessary.
        Nrrrrr
�index�szITerminalTransport.indexcCsdS)zQ
        Move the cursor up one line, performing scrolling if necessary.
        Nrrrrr
�reverseIndex�szITerminalTransport.reverseIndexcCsdS)zl
        Move the cursor to the first position on the next line, performing scrolling if necessary.
        Nrrrrr
�nextLine�szITerminalTransport.nextLinecCsdS)zj
        Save the cursor position, character attribute, character set, and origin mode selection.
        Nrrrrr
�
saveCursor�szITerminalTransport.saveCursorcCsdS)z�
        Restore the previously saved cursor position, character attribute, character set, and origin mode selection.

        If no cursor state was previously saved, move the cursor to the home position.
        Nrrrrr
�
restoreCursor�sz ITerminalTransport.restoreCursorcCsdS)z6
        Set the given modes on the terminal.
        Nr��modesrrr
�setModes�szITerminalTransport.setModescCsdS)z8
        Reset the given modes on the terminal.
        Nr)�moderrr
�
resetModes�szITerminalTransport.resetModescCsdS)zB
        Set the given DEC private modes on the terminal.
        Nrr6rrr
�setPrivateModes�sz"ITerminalTransport.setPrivateModescCsdS)zD
        Reset the given DEC private modes on the terminal.
        Nrr6rrr
�resetPrivateModes�sz$ITerminalTransport.resetPrivateModescCsdS)z�
        Cause keypad to generate control functions.

        Cursor key mode selects the type of characters generated by cursor keys.
        Nrrrrr
�applicationKeypadMode�sz(ITerminalTransport.applicationKeypadModecCsdS)z=
        Cause keypad to generate normal characters.
        Nrrrrr
�numericKeypadMode�sz$ITerminalTransport.numericKeypadModecCsdS)z�
        Select a character set.

        charSet should be one of CS_US, CS_UK, CS_DRAWING, CS_ALTERNATE, or
        CS_ALTERNATE_SPECIAL.

        which should be one of G0 or G1.
        Nr)�charSet�whichrrr
�selectCharacterSet�sz%ITerminalTransport.selectCharacterSetcCsdS)z0
        Activate the G0 character set.
        Nrrrrr
�shiftIn�szITerminalTransport.shiftIncCsdS)z0
        Activate the G1 character set.
        Nrrrrr
�shiftOut�szITerminalTransport.shiftOutcCsdS)zG
        Shift to the G2 character set for a single character.
        Nrrrrr
�singleShift2�szITerminalTransport.singleShift2cCsdS)zG
        Shift to the G3 character set for a single character.
        Nrrrrr
�singleShift3�szITerminalTransport.singleShift3cGsdS)z�
        Enabled one or more character attributes.

        Arguments should be one or more of UNDERLINE, REVERSE_VIDEO, BLINK, or BOLD.
        NORMAL may also be specified to disable all character attributes.
        Nr)�
attributesrrr
�selectGraphicRendition�sz)ITerminalTransport.selectGraphicRenditioncCsdS)z@
        Set a tab stop at the current cursor position.
        Nrrrrr
�horizontalTabulationSet�sz*ITerminalTransport.horizontalTabulationSetcCsdS)zD
        Clear the tab stop at the current cursor position.
        Nrrrrr
�tabulationClear�sz"ITerminalTransport.tabulationClearcCsdS)z&
        Clear all tab stops.
        Nrrrrr
�tabulationClearAll�sz%ITerminalTransport.tabulationClearAllTcCsdS)z�
        Make the current line the top or bottom half of a double-height, double-width line.

        If top is True, the current line is the top half.  Otherwise, it is the bottom half.
        Nr)�toprrr
�doubleHeightLinesz#ITerminalTransport.doubleHeightLinecCsdS)zK
        Make the current line a single-width, single-height line.
        Nrrrrr
�singleWidthLinesz"ITerminalTransport.singleWidthLinecCsdS)z<
        Make the current line a double-width line.
        Nrrrrr
�doubleWidthLinesz"ITerminalTransport.doubleWidthLinecCsdS)zV
        Erase from the cursor to the end of line, including cursor position.
        Nrrrrr
�eraseToLineEndsz!ITerminalTransport.eraseToLineEndcCsdS)zd
        Erase from the cursor to the beginning of the line, including the cursor position.
        Nrrrrr
�eraseToLineBeginningsz'ITerminalTransport.eraseToLineBeginningcCsdS)z/
        Erase the entire cursor line.
        Nrrrrr
�	eraseLine#szITerminalTransport.eraseLinecCsdS)za
        Erase from the cursor to the end of the display, including the cursor position.
        Nrrrrr
�eraseToDisplayEnd)sz$ITerminalTransport.eraseToDisplayEndcCsdS)zg
        Erase from the cursor to the beginning of the display, including the cursor position.
        Nrrrrr
�eraseToDisplayBeginning/sz*ITerminalTransport.eraseToDisplayBeginningcCsdS)z+
        Erase the entire display.
        Nrrrrr
�eraseDisplay5szITerminalTransport.eraseDisplaycCsdS)z�
        Delete n characters starting at the cursor position.

        Characters to the right of deleted characters are shifted to the left.
        Nrr'rrr
�deleteCharacter;sz"ITerminalTransport.deleteCharactercCsdS)z�
        Insert n lines at the cursor position.

        Lines below the cursor are shifted down.  Lines moved past the bottom margin are lost.
        This command is ignored when the cursor is outside the scroll region.
        Nrr'rrr
�
insertLineCszITerminalTransport.insertLinecCsdS)z�
        Delete n lines starting at the cursor position.

        Lines below the cursor are shifted up.  This command is ignored when the cursor is outside
        the scroll region.
        Nrr'rrr
�
deleteLineLszITerminalTransport.deleteLinecCsdS)zi
        Return a Deferred that fires with a two-tuple of (x, y) indicating the cursor position.
        Nrrrrr
�reportCursorPositionUsz'ITerminalTransport.reportCursorPositioncCsdS)z:
        Reset the terminal to its initial state.
        Nrrrrr
�reset[szITerminalTransport.resetcCsdSrrrrrr
rasz+ITerminalTransport.unhandledControlSequenceN)r&)r&)r&)r&)T)r&)r&)r&),rrrr)r*r+r,r/r0r1r2r3r4r5r8r:r;r<r=r>rArBrCrDrErGrHrIrJrLrMrNrOrPrQrRrSrTrUrVrWrXrYrrrrr
r%[sR



	


	
	r%��~stildec@s(eZdZdZdZZdZZdZZ	dS)r7z$
    ECMA 48 standardized modes
    ���N)
rrr�__doc__ZKEYBOARD_ACTIONZKAMZINSERTION_REPLACEMENTZIRMZLINEFEED_NEWLINEZLNMrrrr
r7ms	
r7c@s@eZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdS)�privateModesz'
    ANSI-Compatible Private Modes
    rr&r\�r]�������N)rrrr_ZERRORZ
CURSOR_KEYZ	ANSI_VT52ZCOLUMNZSCROLLZSCREENZORIGINZ	AUTO_WRAPZAUTO_REPEATZPRINTER_FORM_FEEDZPRINTER_EXTENTZCURSOR_MODErrrr
r`�sr`sCS_USsCS_UKs
CS_DRAWINGsCS_ALTERNATEsCS_ALTERNATE_SPECIALsG0sG1sG2sG3r&r]rbrdc@seZdZdd�ZdS)�VectorcCs||_||_dSr)�x�y)r"rjrkrrr
�__init__�szVector.__init__N)rrrrlrrrr
ri�sric	Cs,tdd��}|�t|�d�W5QRXdS)N�log�a�
)�open�write�str)�s�frrr
rm�srm)�UP_ARROW�
DOWN_ARROW�RIGHT_ARROW�
LEFT_ARROW�HOME�INSERT�DELETE�END�PGUP�PGDN�
NUMPAD_MIDDLE�F1�F2�F3�F4�F5�F6�F7�F8�F9�F10�F11�F12�ALT�SHIFTZCONTROLc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�_constz3
    @ivar name: A string naming this constant
    cCs
||_dSr��name)r"r�rrr
rl�sz_const.__init__cCsd|jdS)N�[�]r�r#rrr
�__repr__�sz_const.__repr__cCsd|jd�d�S)Nr�r��ascii)r��encoder#rrr
�	__bytes__�sz_const.__bytes__N)rrrr_rlr�r�rrrr
r��sr�cCsg|]}t|����qSr)r�r�)�.0�_namerrr
�
<listcomp>�sr�c@seZdZdZdZdZdZdZdZe	dd�Z
e	dd�ZdZdZ
dwd	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Zdd�ZGdd�d�Ze�Zdxdd�Zdydd�Zdzdd�Zd{d d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Z d.d/�Z!d0d1�Z"d2d3�Z#d4d5�Z$d6d7�Z%d8d9�Z&d:d;�Z'd<d=�Z(d>d?�Z)d@dA�Z*dBdC�Z+dDdE�Z,dFdG�Z-dHdI�Z.dJdK�Z/dLdM�Z0d|dOdP�Z1dQdR�Z2dSdT�Z3dUdV�Z4dWdX�Z5dYdZ�Z6d[d\�Z7d]d^�Z8d_d`�Z9d}dadb�Z:d~dcdd�Z;ddedf�Z<d�dgdh�Z=didj�Z>dkdl�Z?dmdn�Z@dodp�ZAdqdr�ZBdsdt�ZCdudv�ZDdS)��ServerProtocolN�	���data�P�rcOs$|dk	r||_||_||_g|_dS)a
        @param protocolFactory: A callable which will be invoked with
        *a, **kw and should return an ITerminalProtocol implementor.
        This will be invoked when a connection to this ServerProtocol
        is established.

        @param a: Any positional arguments to pass to protocolFactory.
        @param kw: Any keyword arguments to pass to protocolFactory.
        N)�protocolFactory�protocolArgs�protocolKwArgs�_cursorReports)r"r�rn�kwrrr
rl�s
zServerProtocol.__init__cCsT|jdk	rP|j|j|j�|_z
|j}Wntk
r:Yn
X||j_|j�|�dSr)r�r�r��terminalProtocol�factory�AttributeErrorr)r"r�rrr
r!s

zServerProtocol.connectionMadecCs�t|�D]�}|jdkr6|dkr&d|_q�|j�|d�q|jdkrx|dkrVd|_g|_q�|dkrfd|_q�d|_|�|�q|jdkr�|dkr�d|_q�|��s�|dkr�|�d	�|j�|�|`d|_q�|j�	|�q|jdkr�|�
|�d|_qtd
��qdS)Nr�rZ�escaped�[sbracket-escaped�Oslow-function-escapedr[r��
Illegal state)r�stater�rZescBuf�_handleShortControlSequence�isalpha�_handleControlSequence�join�append�!_handleLowFunctionControlSequence�
ValueError)r"�data�chrrr
�dataReceiveds2




zServerProtocol.dataReceivedcCs|j�||j�dSr)r�rr�)r"r�rrr
r�3sz*ServerProtocol._handleShortControlSequencecCsbd|}t|jt�|dd�|dd���d�d�}|dkrH|�|�n|||j|dd��dS)N�[���r�)�getattr�controlSequenceParser�CST�get�decoderr�)r"�bufrtrrr
r�7s �z%ServerProtocol._handleControlSequencecCs|j�|�dSr)r�r)r"r�rrr
rBsz'ServerProtocol.unhandledControlSequencecCsL|j|j|j|jd�}|�|�}|dk	r8|j�|d�n|j�d|�dS)N)�P�Q�R�Ss)r�r�r�r�r�r�rr)r"r�ZfunctionKeysrrrr
r�Fs�
z0ServerProtocol._handleLowFunctionControlSequencec@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)z$ServerProtocol.ControlSequenceParsercCs*|dkr|�|jd�n|�|d�dS)Nr��A)rrur�r"�proto�handlerr�rrr
�AQsz&ServerProtocol.ControlSequenceParser.AcCs*|dkr|�|jd�n|�|d�dS)Nr��B)rrvrr�rrr
�BXsz&ServerProtocol.ControlSequenceParser.BcCs*|dkr|�|jd�n|�|d�dS)Nr��C)rrwrr�rrr
�C_sz&ServerProtocol.ControlSequenceParser.CcCs*|dkr|�|jd�n|�|d�dS)Nr��D)rrxrr�rrr
�Dfsz&ServerProtocol.ControlSequenceParser.DcCs*|dkr|�|jd�n|�|d�dS)Nr��E)rrrr�rrr
�Emsz&ServerProtocol.ControlSequenceParser.EcCs*|dkr|�|jd�n|�|d�dS)Nr��F)rr|rr�rrr
�Ftsz&ServerProtocol.ControlSequenceParser.FcCs*|dkr|�|jd�n|�|d�dS)Nr��H)rryrr�rrr
�H{sz&ServerProtocol.ControlSequenceParser.Hc	Cs�|js|�|d�n�|�d�r�|dd�}|�d�}t|�dkrR|�|d�q�|\}}zt|�t|�}}Wn"tk
r�|�|d�Yq�X|j�d�}|�|d|df�n|�|d�dS)Nr�r�r\�;rr&)	r�r�
startswith�split�len�intr��pop�callback)	r"r�r�r��report�partsZPlZPc�drrr
�R�s

z&ServerProtocol.ControlSequenceParser.RcCs,|dkr|�|j|j�n|�|d�dS)Nr��Z)r�TABr�rr�rrr
�Z�sz&ServerProtocol.ControlSequenceParser.ZcCs�|j|j|j|j|j|j|j|j|j|j	|j
|j|j|j
d�}|�d�r�|dd�}zt|�}Wn"tk
r�|�|d�Yq�X|�|�}|dk	r�|�||d�q�|�|d�n|�|d�dS)N)r&r\rar]rbrc��rfrgr^��r�r�r\r[)ryrzr{r|r}r~r�r�r�r�r�r�r�r�r�r�r�rr�r)r"r�r�r��mapr��vZsymbolicrrr
�tilde�s0�

z*ServerProtocol.ControlSequenceParser.tildeN)
rrrr�r�r�r�r�r�r�r�r�r�rrrr
�ControlSequenceParserPsr�r&cCs<|dkst�t|jj|d�|j_|�dt|�d�dS)Nr&rr�r�)�AssertionError�max�	cursorPosrkrqr�r"r(rrr
r)�szServerProtocol.cursorUpcCsD|dkst�t|jj||jjd�|j_|�dt|�d�dS)Nr&r�r�)r��minr�rk�termSizerqrr�rrr
r*�szServerProtocol.cursorDowncCsD|dkst�t|jj||jjd�|j_|�dt|�d�dS)Nr&r�r�)r�r�r�rjr�rqrr�rrr
r+�szServerProtocol.cursorForwardcCs<|dkst�t|jj|d�|j_|�dt|�d�dS)Nr&rr�r�)r�r�r�rjrqrr�rrr
r,�szServerProtocol.cursorBackwardcCs.|�dt|d�dt|d�d�dS)Nr�r&r�r��rqr)r"r-r.rrr
r/�s
��
��zServerProtocol.cursorPositioncCsd|j_|j_|�d�dS)Nrs)r�rjrkrqr#rrr
r0�szServerProtocol.cursorHomecCs,t|jjd|jjd�|j_|�d�dS)Nr&sD)r�r�rkr�rqr#rrr
r1�szServerProtocol.indexcCs$t|jjdd�|j_|�d�dS)Nr&rsM)r�r�rkrqr#rrr
r2�szServerProtocol.reverseIndexcCs4d|j_t|jjd|jjd�|j_|�d�dS)Nrr&�
)r�rjr�rkr�rqr#rrr
r3�szServerProtocol.nextLinecCs"t|jj|jj�|_|�d�dS)Ns7)rir�rjrk�_savedCursorPosrqr#rrr
r4�szServerProtocol.saveCursorcCs|j|_|`|�d�dS)Ns8)r�r�rqr#rrr
r5�szServerProtocol.restoreCursorcCs*d�dd�|D��}|�d|d�dS)Nr�cSsg|]}t|��qSr�r�r�r9rrr
r��sz+ServerProtocol.setModes.<locals>.<listcomp>r��h�r�rq�r"r7Z
modesBytesrrr
r8�szServerProtocol.setModescCs*d�dd�|D��}|�d|d�dS)Nr�cSsg|]}t|��qSrr�r�rrr
r�sz2ServerProtocol.setPrivateModes.<locals>.<listcomp>�[?r�r�r�rrr
r;szServerProtocol.setPrivateModescCs*d�dd�|D��}|�d|d�dS)Nr�cSsg|]}t|��qSrr�r�rrr
r�sz-ServerProtocol.resetModes.<locals>.<listcomp>r��lr�r�rrr
r:szServerProtocol.resetModescCs*d�dd�|D��}|�d|d�dS)Nr�cSsg|]}t|��qSrr�r�rrr
r�sz4ServerProtocol.resetPrivateModes.<locals>.<listcomp>r�r�r�r�rrr
r<sz ServerProtocol.resetPrivateModescCs|�d�dS)Ns=�rqr#rrr
r=sz$ServerProtocol.applicationKeypadModecCs|�d�dS)Ns>r�r#rrr
r>sz ServerProtocol.numericKeypadModecCs�|tkrd}n|tkrd}ntd��|tkr2d}n@|tkr@d}n2|tkrNd}n$|tkr\d}n|tkrjd}ntd	��|�d
||�dS)N�(�)z7`which' argument to selectCharacterSet must be G0 or G1r�r��0�1�2z0Invalid `charSet' argument to selectCharacterSetrZ)	�G0�G1r��CS_UK�CS_US�
CS_DRAWING�CS_ALTERNATE�CS_ALTERNATE_SPECIALrq)r"r?r@rrr
rAs"z!ServerProtocol.selectCharacterSetcCs|�d�dS)N�r�r#rrr
rB/szServerProtocol.shiftIncCs|�d�dS)N�r�r#rrr
rC3szServerProtocol.shiftOutcCs|�d�dS)NsNr�r#rrr
rD7szServerProtocol.singleShift2cCs|�d�dS)NsOr�r#rrr
rE;szServerProtocol.singleShift3cGs8g}|D]}|�t|��q|�dd�|�d�dS)Nr�r��m)r�r	rqr�)r"rF�attrsrnrrr
rG?s��z%ServerProtocol.selectGraphicRenditioncCs|�d�dS)NsHr�r#rrr
rHIsz&ServerProtocol.horizontalTabulationSetcCs|�d�dS)Nsr�r#rrr
rIMszServerProtocol.tabulationClearcCs|�d�dS)Nsr�r#rrr
rJQsz!ServerProtocol.tabulationClearAllTcCs|r|�d�n
|�d�dS)Ns#3s#4r�)r"rKrrr
rLUszServerProtocol.doubleHeightLinecCs|�d�dS)Ns#5r�r#rrr
rM\szServerProtocol.singleWidthLinecCs|�d�dS)Ns#6r�r#rrr
rN`szServerProtocol.doubleWidthLinecCs|�d�dS)Nsr�r#rrr
rOdszServerProtocol.eraseToLineEndcCs|�d�dS)Nsr�r#rrr
rPhsz#ServerProtocol.eraseToLineBeginningcCs|�d�dS)Nsr�r#rrr
rQlszServerProtocol.eraseLinecCs|�d�dS)Nsr�r#rrr
rRpsz ServerProtocol.eraseToDisplayEndcCs|�d�dS)Nsr�r#rrr
rStsz&ServerProtocol.eraseToDisplayBeginningcCs|�d�dS)Nsr�r#rrr
rTxszServerProtocol.eraseDisplaycCs|�dt|�d�dS)Nr�r�r�r�rrr
rU|szServerProtocol.deleteCharactercCs|�dt|�d�dS)Nr��Lr�r�rrr
rV�szServerProtocol.insertLinecCs|�dt|�d�dS)Nr��Mr�r�rrr
rW�szServerProtocol.deleteLinecCsJ|dk	rt|�}nd}|dk	r(t|�}nd}|�d|d|d�dS)Nr�r�r��r)rrq)r"�firstZlastrrr
�setScrollRegion�s

zServerProtocol.setScrollRegioncCs|��dSr)rr#rrr
�resetScrollRegion�sz ServerProtocol.resetScrollRegioncCs"t��}|j�|�|�d�|S)Ns)rZDeferredr�r�rq)r"r�rrr
rX�s
z#ServerProtocol.reportCursorPositioncCs<d|j_|j_z|`Wntk
r,YnX|�d�dS)Nrsc)r�rjrkr�r�rqr#rrr
rY�szServerProtocol.resetcCs:|r6t|t�s|�d�}||_|j�d�|�d���dS)Nzutf-8s
r�)�
isinstance�bytesr��	lastWriterrqr�r��r"r�rrr
rq�s


zServerProtocol.writecCs|�d�|��dS)Nr�)rqr�rrrr
�
writeSequence�szServerProtocol.writeSequencecCs|��|j��dSr)rYr�loseConnectionr#rrr
r�szServerProtocol.loseConnectioncCs(|jdk	r$z|j�|�W5d|_XdSr)r�rr$rrr
r�s
zServerProtocol.connectionLost)N)r&)r&)r&)r&)T)r&)r&)r&)NN)Errrr�r�r�Z	BACKSPACErr�rir�r�ZscrollRegionr�rlr!r�r�r�rr�r�r�r)r*r+r,r/r0r1r2r3r4r5r8r;r:r<r=r>rArBrCrDrErGrHrIrJrLrMrNrOrPrQrRrSrTrUrVrWrrrXrYrqrrrrrrr
r��s�


 
e










r�c@s�eZdZdZdZdZdZddddddd	d
ddd
d�Zddddd�Ze	e
eee
d�ZdZd#dd�Zdd�Zdd�Zdd�Zdd�ZGdd �d �Ze�Zd!d"�ZdS)$�ClientProtocolNr�sindexsreverseIndexsnextLines
saveCursors
restoreCursorsapplicationKeypadModesnumericKeypadModessingleShift2ssingleShift3shorizontalTabulationSetsreset)r�r
r��7�8�=�>�Nr�r��c�bracket-escape�	select-g0�	select-g1�select-height-width)r�r�r��#)r�r�r�r�rcOs|dk	r||_||_||_dS)aw
        @param terminalFactory: A callable which will be invoked with
        *a, **kw and should return an ITerminalTransport provider.
        This will be invoked when this ClientProtocol establishes a
        connection.

        @param a: Any positional arguments to pass to terminalFactory.
        @param kw: Any keyword arguments to pass to terminalFactory.
        N)�terminalFactory�terminalArgs�terminalKwArgs)r"r$rnr�rrr
rl�szClientProtocol.__init__cCs6|jdk	r2|j|j|j�|_|j|j_|j�|�dSr)r$r%r&r r�rr#rrr
r!�s

zClientProtocol.connectionMadecCs&|jdk	r"z|j�|�W5|`XdSr)r rr$rrr
rs
zClientProtocol.connectionLostcCsdg}t|�D�]8}|jdkr�|dkrL|rD|j�d�|��|dd�=d|_n�|dkr�|rt|j�d�|��|dd�=|j��nr|dkr�|r�|j�d�|��|dd�=|j��n>|dkr�|r�|j�d�|��|dd�=|j��n
|�|�q|jdk�rh|j	�
|�}|dk	�r2d|_t|j|�d	���n4|j
�
|�}|dk	�rP||_n|j�d|�d|_q|jd
k�r�|jdk�r�g|_|���s�|dk�r�|�d�|j�|�|`d|_n|j�|�q|jdk�r�|j�|j�
||�t�d|_q|jd
k�r |j�|j�
||�t�d|_q|jdk�r>|�|�d|_qtd��q|�r`|j�d�|��dS)z�
        Parse the given data from a terminal server, dispatching to event
        handlers defined by C{self.terminal}.
        r�rZr�Nr�r	r�r�rr[r r!r"r�)rr�r rqr�rCrBr,r��_shortsr�r�r��_longsr�_escBufr�r�rA�	_charsetsrr�_handleHeightWidthr�)r"r�ZtoWrite�b�fNamer�rrr
r�sl








zClientProtocol.dataReceivedcCsLt|jt�||��d�d�}|dkr:|j�d||�n|||j|�dS)Nr�r�)r�r�r�r�r�r r)r"r�r rtrrr
r�Nsz%ClientProtocol._handleControlSequencec@s�eZdZdd�ZdD]\ZZeed�q[dd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)z$ClientProtocol.ControlSequenceParsercsd|���fdd�}|S)NZcursorcsZ|st|��d�nBzt|�}Wn&tk
rF|�d|��YnXt|��|�dS)Nr&r�)r�r�r�r)r"r�r�r��m�r�r(rr
�simpleYsz@ClientProtocol.ControlSequenceParser._makeSimple.<locals>.simpler)r�r.r1rr0r
�_makeSimpleWs
z0ClientProtocol.ControlSequenceParser._makeSimple))r�ZUp)r�ZDown)r�ZForward)r�ZBackwardz = _makeSimple(ch, fName)cCsNzdd�|�d�D�}Wn&tk
r>|�d|d�YnX|�|�dS)NcSsg|]}t|��qSr�r�r�rrr
r�psz:ClientProtocol.ControlSequenceParser.h.<locals>.<listcomp>r�r�r�)r�r�rr8�r"r�r�r�r7rrr
�hms
z&ClientProtocol.ControlSequenceParser.hcCsNzdd�|�d�D�}Wn&tk
r>|�d|d�YnX|�|�dS)NcSsg|]}t|��qSrr3r�rrr
r�zsz:ClientProtocol.ControlSequenceParser.l.<locals>.<listcomp>r�r��l)r�r�rr:r4rrr
r6ws
z&ClientProtocol.ControlSequenceParser.lcCs�|�d�}t|�dkr$|�dd�n�t|�dkr�z8|drHt|d�}nd}|drbt|d�}nd}Wn&tk
r�|�d|d�Yq�X|�||�n|�d|d�dS)Nr�r&r\rr�r)r�r�rr�r�r)r"r�r�r�r�ZptZpbrrr
�r�s
z&ClientProtocol.ControlSequenceParser.rcCsH|s|��n6|dkr |��n$|dkr2|��n|�d|d�dS)Nr�rr��K)rOrPrQrr�rrr
�K�s


z&ClientProtocol.ControlSequenceParser.KcCs|��dSr)r0r�rrr
r��sz&ClientProtocol.ControlSequenceParser.HcCsH|s|��n6|dkr |��n$|dkr2|��n|�d|d�dS)Nr�rr��J)rRrSrTrr�rrr
�J�s


z&ClientProtocol.ControlSequenceParser.JcCsR|s|�d�n>zt|�}Wn&tk
rB|�d|d�YnX|�|�dS)Nr&r�r�)rUr�r�r�r"r�r�r�r(rrr
�P�sz&ClientProtocol.ControlSequenceParser.PcCsR|s|�d�n>zt|�}Wn&tk
rB|�d|d�YnX|�|�dS)Nr&r�r)rVr�r�rr<rrr
�L�sz&ClientProtocol.ControlSequenceParser.LcCsR|s|�d�n>zt|�}Wn&tk
rB|�d|d�YnX|�|�dS)Nr&r�r
)rWr�r�rr<rrr
�M�sz&ClientProtocol.ControlSequenceParser.McCsX|dkrB|��\}}|j�dt|d�dt|d�d�n|�d|d�dS)N�6r�r&r�r��n)rXrrqrr)r"r�r�r�rjrkrrr
r(�s
��
��z&ClientProtocol.ControlSequenceParser.nc	Cs^|s|�t�nJg}|�d�D]0}zt|�}Wntk
rBYnX|�|�q|j|�dS)Nr�)rG�NORMALr�r�r�r�)r"r�r�r�rrnrrr
r/�sz&ClientProtocol.ControlSequenceParser.mN)rrrr2r�r.�execr5r6r7r9r�r;r=r>r?r(r/rrrr
r�Vs

r�cCsh|dkr|j�d�nN|dkr,|j�d�n8|dkr@|j��n$|dkrT|j��n|j�d|�dS)N�3T�4F�5r@s#)r rLrMrNr)r"r-rrr
r,�sz!ClientProtocol._handleHeightWidth)N)rrrr$r r�r*r(r)rrrrrr+r�rlr!rr�r�r�r�r,rrrr
r�sJ���
Br�
FUNCTION_KEYSrrrrrrr�G2�G3�	UNDERLINE�
REVERSE_VIDEO�BLINK�BOLDrBN)1r_Zzope.interfacerrZtwisted.internetrrrZ	iinternetZtwisted.python.compatrrr	r
�objectrZ
ITransportr%ZCSIr�r7r`rrrrrrrrHrIrBrMrJrLrKrirmZ
_KEY_NAMESr�rGZProtocolr��zipr�Zconst�setattrr�__all__rrrr
�<module>s�*�e:�