o
    ¯b„}  ã                   @   sb  d dl Z d dlmZmZ d dlmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZ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
„ Zdd„ Zdd„ Zdd„ Z e!ƒ Z"dd„ Z#dd„ Z$e$ddg d¢g d¢g d¢g d¢g d¢g d¢g d¢g d¢g d¢g d ¢g d!¢g d"¢g d#¢g d$¢g d%¢g d&¢ge  %d'¡d(Z&e$d)ddd*gdd+gd,d-gd.d/gdd0gd1d2gd3d4gd5d6gd7d8gd9dgd:d;gd<d=gd>d?gd@dAgdBdCgdDdEgge  %dF¡d(Z'G dGdH„ dHƒZ(G dIdJ„ dJƒZ)dKZ*G dLdM„ dMe)ƒZ+[*G dNdO„ dOe+ej,ƒZ-G dPdQ„ dQe+ej,ƒZ.G dRdS„ dSe+ej,ƒZ/G dTdU„ dUe+ej,ƒZ0G dVdW„ dWej,e)ƒZ1G dXdY„ dYej,ƒZ2dS )Zé    N)ÚOptionalÚType)ÚBLINKÚCS_ALTERNATEÚCS_ALTERNATE_SPECIALÚ
CS_DRAWINGÚCS_UKÚCS_USÚG0ÚG1Ú	UNDERLINEÚClientProtocolÚServerProtocolÚmodesÚprivateModes)ÚProtocol)Ú	iterbytes)ÚValueConstantÚValues)ÚStringTransport)Úunittestc                 C   s   t t| ƒ |¡S ©N)ÚsuperÚMockÚ__getattribute__)ÚmockÚname© r   úA/usr/lib/python3/dist-packages/twisted/conch/test/test_insults.pyÚ_getattr   s   r   c                 C   ó
   t | dƒS )NÚoccurrences©r   ©r   r   r   r   r!   "   ó   
r!   c                 C   r    )NÚmethodsr"   r#   r   r   r   r%   &   r$   r%   c                 C   s   t | ƒ |¡ d S r   )r!   Úappend)r   Úobjr   r   r   Ú_append*   s   r(   c                 C   s   t t| d> |B gƒƒS )a  
    Return the byte in 7- or 8-bit code table identified by C{column}
    and C{row}.

    "An 8-bit code table consists of 256 positions arranged in 16
    columns and 16 rows.  The columns and rows are numbered 00 to 15."

    "A 7-bit code table consists of 128 positions arranged in 8
    columns and 16 rows.  The columns are numbered 00 to 07 and the
    rows 00 to 15 (see figure 1)."

    p.5 of "Standard ECMA-35: Character Code Structure and Extension
    Techniques", 6th Edition (December 1994).
    é   )ÚbytesÚ	bytearray)ÚcolumnÚrowr   r   r   Ú_ecmaCodeTableCoordinate1   s   r.   c                    s,   ‡ fdd„t |ƒD ƒ}||d< t| tf|ƒS )Nc                    s:   i | ]\}}t |ƒD ]\}}|r
|tt|ˆ  |ƒƒ“q
qS r   )Ú	enumerater   r.   )Ú.0Újr-   Úir   ©Ú	colOffsetr   r   Ú
<dictcomp>J   s    ýüÿz/_makeControlFunctionSymbols.<locals>.<dictcomp>Ú__doc__)r/   Útyper   )r   r4   ÚnamesÚdocÚattrsr   r3   r   Ú_makeControlFunctionSymbolsE   s
   
þr;   ÚCSFinalByter)   )ÚICHÚDCHÚHPA)ÚCUUÚSSEÚHPR)ÚCUDÚCPRÚREP)ÚCUFÚSUÚDA)ÚCUBÚSDÚVPA)ÚCNLÚNPÚVPR)ÚCPLÚPPÚHVP)ÚCHAÚCTCÚTBC)ÚCUPÚECHÚSM)ÚCHTÚCVTÚMC)ÚEDÚCBTÚHPB)ÚELÚSRSÚVPB)ÚILÚPTXÚRM)ÚDLÚSDSÚSGR)ÚEFÚSIMDÚDSR)ÚEANÚDAQaW  
    Symbolic constants for all control sequence final bytes
    that do not imply intermediate bytes.  This happens to cover
    movement control sequences.

    See page 11 of "Standard ECMA 48: Control Functions for Coded
    Character Sets", 5th Edition (June 1991).

    Each L{ValueConstant} maps a control sequence name to L{bytes}
    )r4   r8   r9   Ú
C1SevenBitÚDCSÚPU1ÚBPHÚPU2ÚNBHÚSTSÚCCHÚNELÚMWÚSSAÚSPAÚESAÚEPAÚHTSÚSOSÚHTJÚVTSÚSCIÚPLDÚCSIÚPLUÚSTÚRIÚOSCÚSS2ÚPMÚSS3ÚAPCa   
    Symbolic constants for all 7 bit versions of the C1 control functions

    See page 9 "Standard ECMA 48: Control Functions for Coded
    Character Sets", 5th Edition (June 1991).

    Each L{ValueConstant} maps a control sequence name to L{bytes}
    c                   @   s.   e Zd ZeZdefdd„Zdd„ Zdd„ ZdS )r   Nc                 C   s.   g | _ |du r	i }|| _|tur|| _dS dS )z
        @param methods: Mapping of names to return values
        @param callReturnValue: object __call__ should return
        N)r!   r%   ÚdefaultÚcallReturnValue)Úselfr%   rŠ   r   r   r   Ú__init__ž   s   
ÿzMock.__init__c                 O   s.   t | dƒ}|tu rtƒ }t| d|||fƒ |S )NrŠ   Ú__call__)r   r‰   r   r(   )r‹   ÚaÚkwÚreturnValuer   r   r   r   ª   s
   
zMock.__call__c                 C   s:   t | dƒ}||v rt|| d}ntƒ }t| ||fƒ |S )Nr%   )rŠ   )r   r   r(   )r‹   r   r%   Ú	attrValuer   r   r   r   ²   s   
zMock.__getattribute__)Ú__name__Ú
__module__Ú__qualname__r‰   rŠ   rŒ   r   r   r   r   r   r   r   ›   s
    r   c                   @   s   e Zd Zdi fdd„ZdS )Ú	MockMixinr   c                 C   sb   |\}}|   ||¡ |   tt|ƒƒd¡ t|ƒ\\}}}	}
|   |d¡ |   |	|¡ |   |
|¡ |S )Né   r   )ÚassertEqualÚlenr!   )r‹   Ú
occurrenceÚ
methodNameÚexpectedPositionalArgsÚexpectedKeywordArgsÚattrr   ÚcallÚresultÚargsr   r   r   r   Ú
assertCall¾   s   zMockMixin.assertCallN)r’   r“   r”   r¡   r   r   r   r   r•   ½   s    ÿr•   a“  def testByte%(groupName)s(self):
    transport = StringTransport()
    proto = Mock()
    parser = self.protocolFactory(lambda: proto)
    parser.factory = self
    parser.makeConnection(transport)

    bytes = self.TEST_BYTES
    while bytes:
        chunk = bytes[:%(bytesPer)d]
        bytes = bytes[%(bytesPer)d:]
        parser.dataReceived(chunk)

    self.verifyResults(transport, proto, parser)
c                   @   sN   e Zd ZU dZeee  ed< dD ]\ZZ	e
eee	dœ ƒ q[[	dd„ ZdS )ÚByteGroupingsMixinNÚprotocolFactory))ÚPairsé   )ÚTriplesé   )ÚQuadsr)   )ÚQuintsé   )ÚSexesé   )Ú	groupNameÚbytesPerc                 C   s.   |   t|ƒ d¡d|f¡}|  t|ƒg ¡ d S )Nr   ÚmakeConnection)r¡   r!   Úpopr—   )r‹   Ú	transportÚprotoÚparserrŸ   r   r   r   ÚverifyResultsê   s   z ByteGroupingsMixin.verifyResults)r’   r“   r”   r£   r   r   r   Ú__annotations__ÚwordÚnÚexecÚ_byteGroupingTestTemplater´   r   r   r   r   r¢   Ý   s   
 r¢   c                   @   ó   e Zd ZeZdZdd„ ZdS )ÚServerArrowKeysTestss   [A[B[C[Dc                 C   sh   t  | |||¡ |j|j|j|jfD ]}|  t|ƒ d¡d|d f¡}|  	t|ƒg ¡ q|  
t|ƒ¡ d S )Nr   ÚkeystrokeReceived)r¢   r´   ÚUP_ARROWÚ
DOWN_ARROWÚRIGHT_ARROWÚ
LEFT_ARROWr¡   r!   r°   r—   ÚassertFalse)r‹   r±   r²   r³   ÚarrowrŸ   r   r   r   r´   ø   s   üÿz"ServerArrowKeysTests.verifyResultsN©r’   r“   r”   r   r£   Ú
TEST_BYTESr´   r   r   r   r   r»   ò   s    r»   c                   @   rº   )ÚPrintableCharactersTestss   abc123ABC!@#abc123c                 C   s¤   t  | |||¡ tdƒD ]}|  t|ƒ d¡d|d f¡}|  t|ƒg ¡ qtdƒD ]}|  t|ƒ d¡d||jf¡}|  t|ƒg ¡ q)t|ƒ}|  ||›d¡ d S )Ns   abc123ABC!@#r   r¼   s   abc123z should have been [])	r¢   r´   r   r¡   r!   r°   r—   ÚALTrÁ   )r‹   r±   r²   r³   ÚcharrŸ   Úoccsr   r   r   r´     s   ÿÿz&PrintableCharactersTests.verifyResultsNrÃ   r   r   r   r   rÅ     s    rÅ   c                   @   sF   e Zd ZdZeZg ZdD ]	Ze de ¡ qd 	e¡Z
[[dd„ ZdS )ÚServerFunctionKeysTestsz9Test for parsing and dispatching function keys (F1 - F12))s   OPs   OQs   ORs   OSs   15~s   17~s   18~s   19~s   20~s   21~s   23~s   24~ó   [ó    c                 C   sn   t  | |||¡ tddƒD ] }t|d|f ƒ}|  t|ƒ d¡d|d f¡}|  t|ƒg ¡ q|  t|ƒ¡ d S )Nr–   é   zF%dr   r¼   )	r¢   r´   ÚrangeÚgetattrr¡   r!   r°   r—   rÁ   )r‹   r±   r²   r³   ÚfuncNumÚfuncArgrŸ   r   r   r   r´   ;  s   ÿz%ServerFunctionKeysTests.verifyResultsN)r’   r“   r”   r6   r   r£   ÚbyteListÚ	byteCodesr&   ÚjoinrÄ   r´   r   r   r   r   rÉ   #  s    
rÉ   c                   @   sH   e Zd ZeZdZdZdZdZee e e e e Z	[[[[dd„ Z
dS )ÚClientCursorMovementTestss   [2Bs   [4Cs   [As   [2Dc                 C   s^   t  | |||¡ dD ]\}}|  t|ƒ d¡d| |f¡}|  t|ƒg ¡ q
|  t|ƒ¡ d S )N))ÚDownr¥   )ÚForwardr)   ©ÚUpr–   ©ÚBackwardr¥   r×   rÙ   r   Úcursor)r¢   r´   r¡   r!   r°   r—   rÁ   )r‹   r±   r²   r³   ÚmethodÚcountrŸ   r   r   r   r´   Q  s   ÿz'ClientCursorMovementTests.verifyResultsN)r’   r“   r”   r   r£   Úd2Úr4Úu1Úl2rÄ   r´   r   r   r   r   rÔ   F  s    rÔ   c                   @   s¼   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-S ).ÚClientControlSequencesTestsc                    sh   t ƒ ˆ _tƒ ˆ _t‡ fdd„ƒˆ _ˆ ˆ j_ˆ j ˆ j¡ ˆ  t	ˆ jƒ 
d¡dˆ jf¡}ˆ  t	|ƒ¡ d S )Nc                      s   ˆ j S r   )r²   r   ©r‹   r   r   Ú<lambda>g  s    z3ClientControlSequencesTests.setUp.<locals>.<lambda>r   r¯   )r   r±   r   r²   r   r³   Úfactoryr¯   r¡   r!   r°   rÁ   )r‹   rŸ   r   rã   r   ÚsetUpd  s   ÿz!ClientControlSequencesTests.setUpc                 C   st   | j  d dd„ tdƒD ƒ¡¡ t| jƒ}dD ]}dD ]}|  | d¡d| |f¡}|  t|ƒ¡ qq|  |¡ d S )	NrË   c                 s   s&    | ]}d D ]	}d| | V  qqdS ))rË   ó   2s   20s   200rÊ   Nr   )r0   Úchr·   r   r   r   Ú	<genexpr>q  s   € ý
þÿzBClientControlSequencesTests.testSimpleCardinals.<locals>.<genexpr>s   BACD)rÕ   rØ   rÖ   rÚ   )r–   r¥   é   éÈ   r   rÛ   )	r³   ÚdataReceivedrÓ   r   r!   r²   r¡   r°   rÁ   )r‹   rÈ   ÚmethrÝ   rŸ   r   r   r   ÚtestSimpleCardinalso  s   
þÿ
þz/ClientControlSequencesTests.testSimpleCardinalsc                 C   sh   | j  d¡ t| jƒ}|  | d¡dd¡}|  t|ƒ¡ |  | d¡dd¡}|  t|ƒ¡ |  |¡ d S )Ns
   [5;22r[rr   ÚsetScrollRegion)rª   é   )NN©r³   rì   r!   r²   r¡   r°   rÁ   ©r‹   rÈ   rŸ   r   r   r   ÚtestScrollRegion  s   
z,ClientControlSequencesTests.testScrollRegionc                 C   s¨   | j  d¡ t| jƒ}|  | d¡dd¡}|  t|ƒ¡ |  | d¡dd¡}|  t|ƒ¡ |  | d¡d¡}|  t|ƒ¡ |  | d¡d¡}|  t|ƒ¡ |  |¡ d S )Ns   #3#4#5#6r   ÚdoubleHeightLine)T)FÚsingleWidthLineÚdoubleWidthLinerñ   rò   r   r   r   ÚtestHeightAndWidthŠ  s   
z.ClientControlSequencesTests.testHeightAndWidthc                 C   s€   | j  d dd„ tdƒD ƒ¡¡ t| jƒ}ttfD ]}tt	t
ttfD ]}|  | d¡d||f¡}|  t|ƒ¡ q"q|  |¡ d S )NrË   c                    s(   g | ]‰ d   ‡ fdd„tdƒD ƒ¡‘qS )rË   c                    s   g | ]}d ˆ  | ‘qS )ó   r   )r0   r·   ©Úgr   r   Ú
<listcomp>Ÿ  s    zKClientControlSequencesTests.testCharacterSet.<locals>.<listcomp>.<listcomp>s   AB012)rÓ   r   )r0   r   rù   r   rû   ž  s    ÿÿz@ClientControlSequencesTests.testCharacterSet.<locals>.<listcomp>s   ()r   ÚselectCharacterSet)r³   rì   rÓ   r   r!   r²   r
   r   r   r	   r   r   r   r¡   r°   rÁ   )r‹   rÈ   ÚwhichÚcharsetrŸ   r   r   r   ÚtestCharacterSet›  s*   þÿÿ
ûÿöz,ClientControlSequencesTests.testCharacterSetc                 C   ód   | j  d¡ t| jƒ}|  | d¡d¡}|  t|ƒ¡ |  | d¡d¡}|  t|ƒ¡ |  |¡ d S )Ns   r   ÚshiftInÚshiftOutrñ   rò   r   r   r   ÚtestShifting´  ó   
z(ClientControlSequencesTests.testShiftingc                 C   r   )Ns   NOr   ÚsingleShift2ÚsingleShift3rñ   rò   r   r   r   ÚtestSingleShifts¿  r  z,ClientControlSequencesTests.testSingleShiftsc                 C   r   )Ns   =>r   ÚapplicationKeypadModeÚnumericKeypadModerñ   rò   r   r   r   ÚtestKeypadModeÊ  r  z*ClientControlSequencesTests.testKeypadModec                 C   r   )Ns   78r   Ú
saveCursorÚrestoreCursorrñ   rò   r   r   r   Ú
testCursorÕ  r  z&ClientControlSequencesTests.testCursorc                 C   sD   | j  d¡ t| jƒ}|  | d¡d¡}|  t|ƒ¡ |  |¡ d S )Ns   cr   Úresetrñ   rò   r   r   r   Ú	testResetà  s
   
z%ClientControlSequencesTests.testResetc                 C   s„   | j  d¡ t| jƒ}|  | d¡d¡}|  t|ƒ¡ |  | d¡d¡}|  t|ƒ¡ |  | d¡d¡}|  t|ƒ¡ |  |¡ d S )Ns   DMEr   ÚindexÚreverseIndexÚnextLinerñ   rò   r   r   r   Ú	testIndexè  s   
z%ClientControlSequencesTests.testIndexc              	   C   sØ   | j  dd dd„ tjtjtjfD ƒ¡ d ¡ | j  dd dd„ tjtjtjfD ƒ¡ d ¡ t| jƒ}|  	| 
d¡d	tjtjtjgf¡}|  t|ƒ¡ |  	| 
d¡d
tjtjtjgf¡}|  t|ƒ¡ |  |¡ d S )NrÊ   ó   ;c                 s   ó    | ]}d |f V  qdS ©s   %dNr   ©r0   Úmr   r   r   ré   ù  ó   € z8ClientControlSequencesTests.testModes.<locals>.<genexpr>ó   hc                 s   r  r  r   r  r   r   r   ré   þ  r  ó   lr   ÚsetModesÚ
resetModes)r³   rì   rÓ   r   ÚKAMÚIRMÚLNMr!   r²   r¡   r°   rÁ   rò   r   r   r   Ú	testModesö  s0   ÿþÿÿþÿ
ÿÿz%ClientControlSequencesTests.testModesc                 C   sp   | j  d¡ t| jƒ}dD ]}|  | d¡|¡}|  t|ƒ¡ q|  | d¡dd¡}|  t|ƒ¡ |  |¡ d S )Ns   [K[1K[2K[J[1J[2J[3P)ÚeraseToLineEndÚeraseToLineBeginningÚ	eraseLineÚeraseToDisplayEndÚeraseToDisplayBeginningÚeraseDisplayr   ÚdeleteCharacter)r§   rñ   )r‹   rÈ   rí   rŸ   r   r   r   ÚtestErasure  s   
z'ClientControlSequencesTests.testErasurec                 C   óR   | j  d¡ t| jƒ}dD ]}|  | d¡d|f¡}|  t|ƒ¡ q|  |¡ d S )Ns   [M[3M©r–   r§   r   Ú
deleteLinerñ   ©r‹   rÈ   ÚargrŸ   r   r   r   ÚtestLineDeletion!  ó   
z,ClientControlSequencesTests.testLineDeletionc                 C   r*  )Ns   [L[3Lr+  r   Ú
insertLinerñ   r-  r   r   r   ÚtestLineInsertion*  r0  z-ClientControlSequencesTests.testLineInsertionc                 C   sX   dt | jƒd< | j d¡ |  | j ¡ d¡ t| jƒ}|  | 	d¡d¡}|  |d¡ d S )N)r¬   é   ÚreportCursorPositions   [6ns   [7;8Rr   )
r%   r²   r³   rì   r—   r±   Úvaluer!   r¡   r°   rò   r   r   r   ÚtestCursorPosition3  s   
z.ClientControlSequencesTests.testCursorPositionc                 C   sN   t | jƒ}| j d¡ |  | d¡dd¡ | j d¡ |  | d¡dd¡ dS )z®
        Contiguous non-control bytes are passed to a single call to the
        C{write} method of the terminal to which the L{ClientProtocol} is
        connected.
        ó   ar   Úwrite)r7  ó   bc)r9  N)r!   r²   r³   rì   r¡   r°   )r‹   rÈ   r   r   r   Útest_applicationDataBytes>  s
   
z5ClientControlSequencesTests.test_applicationDataBytesc                 C   sR   t | jƒ}| j |¡ |r| j| d¡g| d¡¢R Ž  |s|  |d|›¡ d S )Nr   zNo other calls should happen: )r!   r²   r³   rì   r¡   r°   rÁ   )r‹   ÚdataÚcallsrÈ   r   r   r   Ú_applicationDataTestJ  s   
ÿz0ClientControlSequencesTests._applicationDataTestc                 C   ó   |   dddg¡ dS )z£
        Application data bytes followed by a shift-in command are passed to a
        call to C{write} before the terminal's C{shiftIn} method is called.
        s   ab©r8  )s   ab)r  N©r=  rã   r   r   r   Ú test_shiftInAfterApplicationDataQ  ó   z<ClientControlSequencesTests.test_shiftInAfterApplicationDatac                 C   r>  )z¥
        Application data bytes followed by a shift-out command are passed to a
        call to C{write} before the terminal's C{shiftOut} method is called.
        s   abr?  )r  Nr@  rã   r   r   r   Ú!test_shiftOutAfterApplicationDataX  rB  z=ClientControlSequencesTests.test_shiftOutAfterApplicationDatac                 C   r>  )z¹
        Application data bytes followed by a cursor-backward command are passed
        to a call to C{write} before the terminal's C{cursorBackward} method is
        called.
        s   abr?  )ÚcursorBackwardNr@  rã   r   r   r   Ú'test_cursorBackwardAfterApplicationData_  s   zCClientControlSequencesTests.test_cursorBackwardAfterApplicationDatac                 C   s,   |   dddg¡ |   ddddgffg¡ dS )z¸
        Application data bytes followed by an escape character are passed to a
        call to C{write} before the terminal's handler method for the escape is
        called.
        s   abDr?  )r  s   ab[4hr  r)   Nr@  rã   r   r   r   Útest_escapeAfterApplicationDatag  s   ÿz;ClientControlSequencesTests.test_escapeAfterApplicationDataN)r’   r“   r”   ræ   rî   ró   r÷   rÿ   r  r  r
  r  r  r  r!  r)  r/  r2  r6  r:  r=  rA  rC  rE  rF  r   r   r   r   râ   c  s.    		râ   c                   @   s   e Zd ZdZeddƒZeeddƒ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Z d9d:„ Z!d;d<„ Z"d=d>„ Z#d?d@„ Z$dAdB„ Z%dCS )DÚServerProtocolOutputTestszh
    Tests for the bytes L{ServerProtocol} writes to its transport when its
    methods are called.
    r–   é   rª   c                 C   s"   t ƒ | _tƒ | _| j | j¡ d S r   )r   Úprotocolr   r±   r¯   rã   r   r   r   ræ   …  s   zServerProtocolOutputTests.setUpc                 C   ó0   | j  d¡ |  | j ¡ | jd tjj ¡ dS )z
        L{ServerProtocol.cursorUp} writes the control sequence
        ending with L{CSFinalByte.CUU} to its transport.
        r–   ó   1N)rI  ÚcursorUpr—   r±   r5  r€   r<   r@   rã   r   r   r   Útest_cursorUpŠ  ó   ÿz'ServerProtocolOutputTests.test_cursorUpc                 C   rJ  )zƒ
        L{ServerProtocol.cursorDown} writes the control sequence
        ending with L{CSFinalByte.CUD} to its transport.
        r–   rK  N)rI  Ú
cursorDownr—   r±   r5  r€   r<   rC   rã   r   r   r   Útest_cursorDown”  rN  z)ServerProtocolOutputTests.test_cursorDownc                 C   rJ  )z†
        L{ServerProtocol.cursorForward} writes the control sequence
        ending with L{CSFinalByte.CUF} to its transport.
        r–   rK  N)rI  ÚcursorForwardr—   r±   r5  r€   r<   rF   rã   r   r   r   Útest_cursorForwardž  rN  z,ServerProtocolOutputTests.test_cursorForwardc                 C   rJ  )z‡
        L{ServerProtocol.cursorBackward} writes the control sequence
        ending with L{CSFinalByte.CUB} to its transport.
        r–   rK  N)rI  rD  r—   r±   r5  r€   r<   rI   rã   r   r   r   Útest_cursorBackward¨  rN  z-ServerProtocolOutputTests.test_cursorBackwardc                 C   s2   | j  dd¡ |  | j ¡ | jd tjj ¡ dS )zµ
        L{ServerProtocol.cursorPosition} writes a control sequence
        ending with L{CSFinalByte.CUP} and containing the expected
        coordinates to its transport.
        r   s   1;1N)rI  ÚcursorPositionr—   r±   r5  r€   r<   rU   rã   r   r   r   Útest_cursorPosition²  s   ÿz-ServerProtocolOutputTests.test_cursorPositionc                 C   ó*   | j  ¡  |  | j ¡ | jtjj ¡ dS )z±
        L{ServerProtocol.cursorHome} writes a control sequence ending
        with L{CSFinalByte.CUP} and no parameters, so that the client
        defaults to (1, 1).
        N)rI  Ú
cursorHomer—   r±   r5  r€   r<   rU   rã   r   r   r   Útest_cursorHome½  ó   
 z)ServerProtocolOutputTests.test_cursorHomec                 C   s,   | j  ¡  |  | j ¡ | jtddƒ ¡ dS )z´
        L{ServerProtocol.index} writes the control sequence ending in
        the 8-bit code table coordinates 4, 4.

        Note that ECMA48 5th Edition removes C{IND}.
        r)   N)rI  r  r—   r±   r5  ÚESCr.   rã   r   r   r   Ú
test_indexÆ  s   
ÿz$ServerProtocolOutputTests.test_indexc                 C   rV  )zt
        L{ServerProtocol.reverseIndex} writes the control sequence
        ending in the L{C1SevenBit.RI}.
        N)rI  r  r—   r±   r5  rZ  rl   rƒ   rã   r   r   r   Útest_reverseIndexÒ  ó   
 z+ServerProtocolOutputTests.test_reverseIndexc                 C   s    | j  ¡  |  | j ¡ d¡ dS )zM
        L{ServerProtocol.nextLine} writes C{"
"} to its transport.
        s   
N)rI  r  r—   r±   r5  rã   r   r   r   Útest_nextLineÚ  s   
z'ServerProtocolOutputTests.test_nextLinec                 C   óP   t jt jt jg}| j |¡ |  | j ¡ | j	d 
dd„ |D ƒ¡ tjj ¡ dS )zš
        L{ServerProtocol.setModes} writes a control sequence
        containing the requested modes and ending in the
        L{CSFinalByte.SM}.
        r  c                 s   r  r  r   r  r   r   r   ré   ï  r  z:ServerProtocolOutputTests.test_setModes.<locals>.<genexpr>N)r   r  r  r   rI  r  r—   r±   r5  r€   rÓ   r<   rW   ©r‹   Ú
modesToSetr   r   r   Útest_setModesä  s   ÿþþz'ServerProtocolOutputTests.test_setModesc                 C   r_  )zª
        L{ServerProtocol.setPrivatesModes} writes a control sequence
        containing the requested private modes and ending in the
        L{CSFinalByte.SM}.
        r  c                 s   r  r  r   r  r   r   r   ré     r  zAServerProtocolOutputTests.test_setPrivateModes.<locals>.<genexpr>N)r   ÚERRORÚCOLUMNÚORIGINrI  r  r—   r±   r5  r€   rÓ   r<   rW   )r‹   ÚprivateModesToSetr   r   r   Útest_setPrivateModesó  s   ýÿþþz.ServerProtocolOutputTests.test_setPrivateModesc                 C   r_  )zs
        L{ServerProtocol.resetModes} writes the control sequence
        ending in the L{CSFinalByte.RM}.
        r  c                 s   r  r  r   r  r   r   r   ré     r  z<ServerProtocolOutputTests.test_resetModes.<locals>.<genexpr>N)r   r  r  r   rI  r  r—   r±   r5  r€   rÓ   r<   rc   r`  r   r   r   Útest_resetModes  s   ÿþþz)ServerProtocolOutputTests.test_resetModesc                 C   rV  )zp
        L{ServerProtocol.singleShift2} writes an escape sequence
        followed by L{C1SevenBit.SS2}
        N)rI  r  r—   r±   r5  rZ  rl   r…   rã   r   r   r   Útest_singleShift2  r]  z+ServerProtocolOutputTests.test_singleShift2c                 C   rV  )zp
        L{ServerProtocol.singleShift3} writes an escape sequence
        followed by L{C1SevenBit.SS3}
        N)rI  r  r—   r±   r5  rZ  rl   r‡   rã   r   r   r   Útest_singleShift3  r]  z+ServerProtocolOutputTests.test_singleShift3c                 C   sB   | j  ttƒttƒ¡ |  | j ¡ | jdttf  t	j
j ¡ dS )z«
        L{ServerProtocol.selectGraphicRendition} writes a control
        sequence containing the requested attributes and ending with
        L{CSFinalByte.SGR}
        s   %d;%dN)rI  ÚselectGraphicRenditionÚstrr   r   r—   r±   r5  r€   r<   rf   rã   r   r   r   Útest_selectGraphicRendition$  s
   þz5ServerProtocolOutputTests.test_selectGraphicRenditionc                 C   rV  )zz
        L{ServerProtocol.horizontalTabulationSet} writes the escape
        sequence ending in L{C1SevenBit.HTS}
        N)rI  ÚhorizontalTabulationSetr—   r±   r5  rZ  rl   rz   rã   r   r   r   Útest_horizontalTabulationSet0  r]  z6ServerProtocolOutputTests.test_horizontalTabulationSetc                 C   rV  )a  
        L{ServerProtocol.eraseToLineEnd} writes the control sequence
        sequence ending in L{CSFinalByte.EL} and no parameters,
        forcing the client to default to 0 (from the active present
        position's current location to the end of the line.)
        N)rI  r"  r—   r±   r5  r€   r<   r^   rã   r   r   r   Útest_eraseToLineEnd8  ó   
 z-ServerProtocolOutputTests.test_eraseToLineEndc                 C   ó.   | j  ¡  |  | j ¡ | jd tjj ¡ dS )a	  
        L{ServerProtocol.eraseToLineBeginning} writes the control
        sequence sequence ending in L{CSFinalByte.EL} and a parameter
        of 1 (from the beginning of the line up to and include the
        active present position's current location.)
        rK  N)rI  r#  r—   r±   r5  r€   r<   r^   rã   r   r   r   Útest_eraseToLineBeginningB  ó   
$z3ServerProtocolOutputTests.test_eraseToLineBeginningc                 C   rr  )z¦
        L{ServerProtocol.eraseLine} writes the control
        sequence sequence ending in L{CSFinalByte.EL} and a parameter
        of 2 (the entire line.)
        rç   N)rI  r$  r—   r±   r5  r€   r<   r^   rã   r   r   r   Útest_eraseLineL  ó   
$z(ServerProtocolOutputTests.test_eraseLinec                 C   rV  )a  
        L{ServerProtocol.eraseToDisplayEnd} writes the control
        sequence sequence ending in L{CSFinalByte.ED} and no parameters,
        forcing the client to default to 0 (from the active present
        position's current location to the end of the page.)
        N)rI  r%  r—   r±   r5  r€   r<   r[   rã   r   r   r   Útest_eraseToDisplayEndU  rq  z0ServerProtocolOutputTests.test_eraseToDisplayEndc                 C   rr  )a  
        L{ServerProtocol.eraseToDisplayBeginning} writes the control
        sequence sequence ending in L{CSFinalByte.ED} a parameter of 1
        (from the beginning of the page up to and include the active
        present position's current location.)
        rK  N)rI  r&  r—   r±   r5  r€   r<   r[   rã   r   r   r   Útest_eraseToDisplayBeginning_  rt  z6ServerProtocolOutputTests.test_eraseToDisplayBeginningc                 C   rr  )z¤
        L{ServerProtocol.eraseDisplay} writes the control sequence
        sequence ending in L{CSFinalByte.ED} a parameter of 2 (the
        entire page)
        rç   N)rI  r'  r—   r±   r5  r€   r<   r[   rã   r   r   r   Útest_eraseToDisplayi  rv  z-ServerProtocolOutputTests.test_eraseToDisplayc                 C   rJ  )z®
        L{ServerProtocol.deleteCharacter} writes the control sequence
        containing the number of characters to delete and ending in
        L{CSFinalByte.DCH}
        r)   ó   4N)rI  r(  r—   r±   r5  r€   r<   r>   rã   r   r   r   Útest_deleteCharacterr  s   ÿz.ServerProtocolOutputTests.test_deleteCharacterc                 C   rJ  )z£
        L{ServerProtocol.insertLine} writes the control sequence
        containing the number of lines to insert and ending in
        L{CSFinalByte.IL}
        rª   ó   5N)rI  r1  r—   r±   r5  r€   r<   ra   rã   r   r   r   Útest_insertLine}  ó   $z)ServerProtocolOutputTests.test_insertLinec                 C   rJ  )z£
        L{ServerProtocol.deleteLine} writes the control sequence
        containing the number of lines to delete and ending in
        L{CSFinalByte.DL}
        r¬   ó   6N)rI  r,  r—   r±   r5  r€   r<   rd   rã   r   r   r   Útest_deleteLine†  r~  z)ServerProtocolOutputTests.test_deleteLinec                 C   s*   | j  ¡  |  | j ¡ | jd d ¡ dS )z¶
        With no arguments, L{ServerProtocol.setScrollRegion} writes a
        control sequence with no parameters, but a parameter
        separator, and ending in C{b'r'}.
        r  ó   rN©rI  rï   r—   r±   r5  r€   rã   r   r   r   Útest_setScrollRegionNoArgs  rY  z4ServerProtocolOutputTests.test_setScrollRegionNoArgsc                 C   ó.   | j jdd |  | j ¡ | jd d ¡ dS )zÍ
        With just a value for its C{first} argument,
        L{ServerProtocol.setScrollRegion} writes a control sequence with
        that parameter, a parameter separator, and finally a C{b'r'}.
        r–   )Úfirsts   1;r  Nr‚  rã   r   r   r   Útest_setScrollRegionJustFirst˜  ó    z7ServerProtocolOutputTests.test_setScrollRegionJustFirstc                 C   r„  )zÌ
        With just a value for its C{last} argument,
        L{ServerProtocol.setScrollRegion} writes a control sequence with
        a parameter separator, that parameter, and finally a C{b'r'}.
        r–   )Úlasts   ;1r  Nr‚  rã   r   r   r   Útest_setScrollRegionJustLast¡  r‡  z6ServerProtocolOutputTests.test_setScrollRegionJustLastc                 C   s0   | j jddd |  | j ¡ | jd d ¡ dS )zæ
        When given both C{first} and C{last}
        L{ServerProtocol.setScrollRegion} writes a control sequence with
        the first parameter, a parameter separator, the last
        parameter, and finally a C{b'r'}.
        r–   r¥   )r…  rˆ  s   1;2r  Nr‚  rã   r   r   r   Ú test_setScrollRegionFirstAndLastª  s    z:ServerProtocolOutputTests.test_setScrollRegionFirstAndLastc                 C   rr  )zÝ
        L{ServerProtocol.reportCursorPosition} writes a control
        sequence ending in L{CSFinalByte.DSR} with a parameter of 6
        (the Device Status Report returns the current active
        position.)
        r  N)rI  r4  r—   r±   r5  r€   r<   ri   rã   r   r   r   Útest_reportCursorPosition´  s   
ÿz3ServerProtocolOutputTests.test_reportCursorPositionN)&r’   r“   r”   r6   r.   rZ  r€   ræ   rM  rP  rR  rS  rU  rX  r[  r\  r^  rb  rg  rh  ri  rj  rm  ro  rp  rs  ru  rw  rx  ry  r{  r}  r€  rƒ  r†  r‰  rŠ  r‹  r   r   r   r   rG  y  sF    




	


	

						
rG  )3ÚtextwrapÚtypingr   r   Útwisted.conch.insults.insultsr   r   r   r   r   r	   r
   r   r   r   r   r   r   Útwisted.internet.protocolr   Útwisted.python.compatr   Útwisted.python.constantsr   r   Útwisted.test.proto_helpersr   Útwisted.trialr   r   r!   r%   r(   Úobjectr‰   r.   r;   Údedentr<   rl   r   r•   r¹   r¢   ÚTestCaser»   rÅ   rÉ   rÔ   râ   rG  r   r   r   r   Ú<module>   s˜   <ïÿê%ðÿë""#  