U
    
W[-ƒ  ã                   @   s¢  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	m
Z
mZmZmZmZmZ d dlmZmZ d dlmZmZ d dlmZmZ d d	lmZmZ d d
lZdd„ Zdd„ Zdd„ Zdd„ Zeƒ Z dd„ Z!dd„ Z"e"dddddgdddgdd d!gd"d#d$gd%d&d'gd(d)d*gd+d,d-gd.d/d0gd1d2d3gd4d5d6gd7d8d9gd:d;d<gd=d>d?gd@dAdBgdCdDdEgdFd
dGgge #dH¡dIZ$e"dJdd
dKgd
dLgdMdNgdOdPgd
dQgdRdSgdTdUgdVdWgdXdYgdZd
gd[d\gd]d^gd_d`gdadbgdcddgdedfgge #dg¡dIZ%G dhdi„ dieƒZ&G djdk„ dkƒZ'dlZ(G dmdn„ dne'ƒZ)[(G dodp„ dpe)ej*ƒZ+G dqdr„ dre)ej*ƒZ,G dsdt„ dte)ej*ƒZ-G dudv„ dve)ej*ƒZ.G dwdx„ dxej*e'ƒZ/G dydz„ dzej*ƒZ0G d{d|„ d|ej*ƒZ1d
S )}é    )ÚnamedAny)Úunittest)ÚStringTransport)ÚServerProtocolÚClientProtocol)ÚCS_UKÚCS_USÚ
CS_DRAWINGÚCS_ALTERNATEÚCS_ALTERNATE_SPECIALÚBLINKÚ	UNDERLINE)ÚG0ÚG1)ÚmodesÚprivateModes)Ú
intToBytesÚ	iterbytes)ÚValueConstantÚValuesNc                 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   s
   t | dƒS )NÚoccurrences©r   ©r   r   r   r   r      s    r   c                 C   s
   t | dƒS )NÚmethodsr    r!   r   r   r   r"      s    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   Ú_ecmaCodeTableCoordinate(   s    r+   c                    s,   ‡ fdd„t |ƒD ƒ}||d< t| tf|ƒS )Nc                    s:   i | ]2\}}t |ƒD ] \}}|r|tt|ˆ  |ƒƒ“qqS r   )Ú	enumerater   r+   )Ú.0Újr*   Úir   ©Ú	colOffsetr   r   Ú
<dictcomp>A   s   
 ý z/_makeControlFunctionSymbols.<locals>.<dictcomp>Ú__doc__)r,   Útyper   )r   r1   ÚnamesÚdocZattrsr   r0   r   Ú_makeControlFunctionSymbols<   s
    
ÿr7   ÚCSFinalByter&   ZICHÚDCHZHPAÚCUUZSSEZHPRÚCUDZCPRZREPÚCUFZSUZDAÚCUBZSDZVPAZCNLZNPZVPRZCPLZPPZHVPZCHAZCTCZTBCÚCUPZECHÚSMZCHTZCVTZMCÚEDZCBTZHPBÚELZSRSZVPBÚILZPTXÚRMÚDLZSDSÚSGRZEFZSIMDÚDSRZEAZ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}
    )r1   r5   r6   Ú
C1SevenBitZDCSZPU1ZBPHZPU2ZNBHZSTSZCCHZNELZMWZSSAZSPAZESAZEPAÚHTSZSOSZHTJZVTSZSCIZPLDÚCSIZPLUZSTÚRIZOSCÚSS2ZPMÚSS3Z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kri }|| _|tk	r&|| _dS )z
        @param methods: Mapping of names to return values
        @param callReturnValue: object __call__ should return
        N)r   r"   ÚdefaultÚcallReturnValue)Úselfr"   rN   r   r   r   Ú__init__Ž   s    zMock.__init__c                 O   s.   t | dƒ}|tkrtƒ }t| d|||fƒ |S )NrN   Ú__call__)r   rM   r   r%   )rO   ÚaÚkwZreturnValuer   r   r   rQ   ›   s
    
zMock.__call__c                 C   s:   t | dƒ}||kr"t|| d}ntƒ }t| ||fƒ |S )Nr"   )rN   )r   r   r%   )rO   r   r"   Z	attrValuer   r   r   r   ¤   s    
zMock.__getattribute__)Ú__name__Ú
__module__Ú__qualname__rM   rN   rP   rQ   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é   rQ   )ÚassertEqualÚlenr   )rO   Z
occurrenceZ
methodNameZexpectedPositionalArgsZexpectedKeywordArgsÚattrr   ÚcallÚresultÚargsrS   r   r   r   Ú
assertCall±   s    zMockMixin.assertCallN)rT   rU   rV   r_   r   r   r   r   rW   °   s   ÿrW   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                   @   s<   e Zd ZdZdD ]\ZZeeeedœ ƒ q[[dd„ ZdS )ÚByteGroupingsMixinN))ZPairsé   )ZTriplesé   )ZQuadsr&   )ZQuintsé   )ZSexesé   )Z	groupNameZbytesPerc                 C   s.   |   t|ƒ d¡d|f¡}|  t|ƒg ¡ d S )Nr   ÚmakeConnection)r_   r   ÚpoprY   )rO   Ú	transportÚprotoÚparserr]   r   r   r   ÚverifyResultsÔ   s    z ByteGroupingsMixin.verifyResults)	rT   rU   rV   ÚprotocolFactoryZwordÚnÚexecÚ_byteGroupingTestTemplaterj   r   r   r   r   r`   Í   s
   r`   c                   @   s   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 ]0}|  t|ƒ d¡d|d f¡}|  	t|ƒg ¡ q$|  
t|ƒ¡ d S )Nr   ÚkeystrokeReceived)r`   rj   ZUP_ARROWZ
DOWN_ARROWZRIGHT_ARROWZ
LEFT_ARROWr_   r   rf   rY   ÚassertFalse)rO   rg   rh   ri   Zarrowr]   r   r   r   rj   à   s     ÿz"ServerArrowKeysTests.verifyResultsN©rT   rU   rV   r   rk   Ú
TEST_BYTESrj   r   r   r   r   ro   Ú   s   ro   c                   @   s   e Zd ZeZdZdd„ ZdS )ÚPrintableCharactersTestss   abc123ABC!@#abc123c                 C   s¤   t  | |||¡ tdƒD ]0}|  t|ƒ d¡d|d f¡}|  t|ƒg ¡ qtdƒD ]2}|  t|ƒ d¡d||jf¡}|  t|ƒg ¡ qRt|ƒ}|  |d|f ¡ d S )Ns   abc123ABC!@#r   rp   s   abc123z%r should have been [])	r`   rj   r   r_   r   rf   rY   ZALTrq   )rO   rg   rh   ri   Úcharr]   Úoccsr   r   r   rj   ò   s    z&PrintableCharactersTests.verifyResultsNrr   r   r   r   r   rt   ê   s   rt   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 )ÚServerFunctionKeysTestsz>Test 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 )NrX   é   zF%dr   rp   )	r`   rj   ÚrangeÚgetattrr_   r   rf   rY   rq   )rO   rg   rh   ri   ZfuncNumZfuncArgr]   r   r   r   rj     s    z%ServerFunctionKeysTests.verifyResultsN)rT   rU   rV   r3   r   rk   ZbyteListZ	byteCodesr#   Újoinrs   rj   r   r   r   r   rw     s   
rw   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 ]6\}}|  t|ƒ d¡d| |f¡}|  t|ƒg ¡ q|  t|ƒ¡ d S )N))ÚDownra   )ÚForwardr&   ©ÚUprX   ©ÚBackwardra   r   rƒ   r   Úcursor)r`   rj   r_   r   rf   rY   rq   )rO   rg   rh   ri   ÚmethodÚcountr]   r   r   r   rj   $  s
    z'ClientCursorMovementTests.verifyResultsN)rT   rU   rV   r   rk   Zd2Zr4Zu1Úl2rs   rj   r   r   r   r   r~     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   )rh   r   ©rO   r   r   Ú<lambda>3  ry   z3ClientControlSequencesTests.setUp.<locals>.<lambda>r   re   )r   rg   r   rh   r   ri   Úfactoryre   r_   r   rf   rq   )rO   r]   r   rŠ   r   ÚsetUp0  s    z!ClientControlSequencesTests.setUpc                 C   st   | j  d dd„ tdƒD ƒ¡¡ t| jƒ}dD ]6}dD ],}|  | d¡d| |f¡}|  t|ƒ¡ q6q.|  |¡ d S )	Nry   c              
      s8   g | ]0‰ d   ‡ fdd„d tdƒtdƒtdƒfD ƒ¡‘qS )ry   c                    s   g | ]}d | ˆ  ‘qS )rx   r   ©r-   rl   ©Zchr   r   Ú
<listcomp><  s   ÿzNClientControlSequencesTests.testSimpleCardinals.<locals>.<listcomp>.<listcomp>ra   é   éÈ   )r}   r   ©r-   r   r   r   r   <  s   þÿzCClientControlSequencesTests.testSimpleCardinals.<locals>.<listcomp>s   BACD)r   r‚   r€   r„   )rX   ra   r‘   r’   r   r…   )	ri   ÚdataReceivedr}   r   r   rh   r_   rf   rq   )rO   rv   Úmethr‡   r]   r   r   r   ÚtestSimpleCardinals9  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)rc   é   )NN©ri   r”   r   rh   r_   rf   rq   ©rO   rv   r]   r   r   r   ÚtestScrollRegionH  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   ZdoubleHeightLine)T)FZsingleWidthLineZdoubleWidthLiner™   rš   r   r   r   ÚtestHeightAndWidthS  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|ƒ¡ qDq2|  |¡ d S )Nry   c                    s(   g | ] ‰ d   ‡ fdd„tdƒD ƒ¡‘qS )ry   c                    s   g | ]}d ˆ  | ‘qS )ó   r   rŽ   ©Úgr   r   r   g  s     zKClientControlSequencesTests.testCharacterSet.<locals>.<listcomp>.<listcomp>s   AB012)r}   r   r“   r   rž   r   r   g  s   ÿz@ClientControlSequencesTests.testCharacterSet.<locals>.<listcomp>s   ()r   ZselectCharacterSet)ri   r”   r}   r   r   rh   r   r   r   r   r	   r
   r   r_   rf   rq   )rO   rv   ZwhichÚcharsetr]   r   r   r   ÚtestCharacterSetd  s    ÿÿÿ
z,ClientControlSequencesTests.testCharacterSetc                 C   sd   | j  d¡ t| jƒ}|  | d¡d¡}|  t|ƒ¡ |  | d¡d¡}|  t|ƒ¡ |  |¡ d S )Ns   r   ÚshiftInÚshiftOutr™   rš   r   r   r   ÚtestShiftings  s    
z(ClientControlSequencesTests.testShiftingc                 C   sd   | j  d¡ t| jƒ}|  | d¡d¡}|  t|ƒ¡ |  | d¡d¡}|  t|ƒ¡ |  |¡ d S )Ns   NOr   ÚsingleShift2ÚsingleShift3r™   rš   r   r   r   ÚtestSingleShifts  s    
z,ClientControlSequencesTests.testSingleShiftsc                 C   sd   | j  d¡ t| jƒ}|  | d¡d¡}|  t|ƒ¡ |  | d¡d¡}|  t|ƒ¡ |  |¡ d S )Ns   =>r   ZapplicationKeypadModeZnumericKeypadModer™   rš   r   r   r   ÚtestKeypadMode‹  s    
z*ClientControlSequencesTests.testKeypadModec                 C   sd   | j  d¡ t| jƒ}|  | d¡d¡}|  t|ƒ¡ |  | d¡d¡}|  t|ƒ¡ |  |¡ d S )Ns   78r   Z
saveCursorZrestoreCursorr™   rš   r   r   r   Ú
testCursor—  s    
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 tttjtjtjgƒ¡ d ¡ | j  dd tttjtjtjgƒ¡ 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 )Nrx   ó   ;ó   hó   lr   ÚsetModesÚ
resetModes)ri   r”   r}   Úmapr   r   ÚKAMÚIRMÚLNMr   rh   r_   rf   rq   rš   r   r   r   Ú	testModes»  s    "ÿ"ÿ
""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)rb   r™   )rO   rv   r•   r]   r   r   r   ÚtestErasureÊ  s    ÿ
z'ClientControlSequencesTests.testErasurec                 C   sR   | j  d¡ t| jƒ}dD ](}|  | d¡d|f¡}|  t|ƒ¡ q|  |¡ d S )Ns   [M[3M©rX   rb   r   Ú
deleteLiner™   ©rO   rv   Úargr]   r   r   r   ÚtestLineDeletionÚ  s    
z,ClientControlSequencesTests.testLineDeletionc                 C   sR   | j  d¡ t| jƒ}dD ](}|  | d¡d|f¡}|  t|ƒ¡ q|  |¡ d S )Ns   [L[3LrÂ   r   Ú
insertLiner™   rÄ   r   r   r   ÚtestLineInsertionä  s    
z-ClientControlSequencesTests.testLineInsertionc                 C   sX   dt | jƒd< | j d¡ |  | j ¡ d¡ t| jƒ}|  | 	d¡d¡}|  |d¡ d S )N)rd   é   ÚreportCursorPositions   [6ns   [7;8Rr   )
r"   rh   ri   r”   rY   rg   Úvaluer   r_   rf   rš   r   r   r   ÚtestCursorPositionî  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)rÍ   ó   bc)rÏ   N)r   rh   ri   r”   r_   rf   )rO   rv   r   r   r   Útest_applicationDataBytesú  s
    
z5ClientControlSequencesTests.test_applicationDataBytesc                 C   sN   t | jƒ}| j |¡ |r8| j| d¡f| d¡žŽ  q|  |d|f ¡ d S )Nr   z No other calls should happen: %r)r   rh   ri   r”   r_   rf   rq   )rO   ÚdataZcallsrv   r   r   r   Ú_applicationDataTest  s
    
z0ClientControlSequencesTests._applicationDataTestc                 C   s   |   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©rÎ   )s   ab)r¢   N©rÒ   rŠ   r   r   r   Ú test_shiftInAfterApplicationData  s    þÿz<ClientControlSequencesTests.test_shiftInAfterApplicationDatac                 C   s   |   dddg¡ dS )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_shiftOutAfterApplicationData  s    þÿz=ClientControlSequencesTests.test_shiftOutAfterApplicationDatac                 C   s   |   dddg¡ dS )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_escapeAfterApplicationData1  s    þÿ
þÿz;ClientControlSequencesTests.test_escapeAfterApplicationDataN)rT   rU   rV   r   r–   r›   rœ   r¡   r¤   r§   r¨   r©   r«   r¯   r¹   rÁ   rÆ   rÈ   rÌ   rÐ   rÒ   rÕ   rÖ   rØ   rÙ   r   r   r   r   r‰   /  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.
    rX   é   rc   c                 C   s"   t ƒ | _tƒ | _| j | j¡ d S r   )r   Úprotocolr   rg   re   rŠ   r   r   r   r   S  s    zServerProtocolOutputTests.setUpc                 C   s0   | 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.
        rX   ó   1N)rÜ   ZcursorUprY   rg   rË   rI   r8   r:   rŠ   r   r   r   Útest_cursorUpY  s    ÿz'ServerProtocolOutputTests.test_cursorUpc                 C   s0   | j  d¡ |  | j ¡ | jd tjj ¡ dS )zƒ
        L{ServerProtocol.cursorDown} writes the control sequence
        ending with L{CSFinalByte.CUD} to its transport.
        rX   rÝ   N)rÜ   Z
cursorDownrY   rg   rË   rI   r8   r;   rŠ   r   r   r   Útest_cursorDownc  s    ÿz)ServerProtocolOutputTests.test_cursorDownc                 C   s0   | j  d¡ |  | j ¡ | jd tjj ¡ dS )z†
        L{ServerProtocol.cursorForward} writes the control sequence
        ending with L{CSFinalByte.CUF} to its transport.
        rX   rÝ   N)rÜ   ZcursorForwardrY   rg   rË   rI   r8   r<   rŠ   r   r   r   Útest_cursorForwardm  s    ÿz,ServerProtocolOutputTests.test_cursorForwardc                 C   s0   | j  d¡ |  | j ¡ | jd tjj ¡ dS )z‡
        L{ServerProtocol.cursorBackward} writes the control sequence
        ending with L{CSFinalByte.CUB} to its transport.
        rX   rÝ   N)rÜ   r×   rY   rg   rË   rI   r8   r=   rŠ   r   r   r   Útest_cursorBackwardw  s    ÿ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)rÜ   ZcursorPositionrY   rg   rË   rI   r8   r>   rŠ   r   r   r   Útest_cursorPosition  s    ÿz-ServerProtocolOutputTests.test_cursorPositionc                 C   s*   | 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)rÜ   Z
cursorHomerY   rg   rË   rI   r8   r>   rŠ   r   r   r   Útest_cursorHomeŒ  s    
ÿ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)rÜ   r¬   rY   rg   rË   ÚESCr+   rŠ   r   r   r   Ú
test_index—  s    
ÿz$ServerProtocolOutputTests.test_indexc                 C   s*   | j  ¡  |  | j ¡ | jtjj ¡ dS )zt
        L{ServerProtocol.reverseIndex} writes the control sequence
        ending in the L{C1SevenBit.RI}.
        N)rÜ   r­   rY   rg   rË   rä   rG   rJ   rŠ   r   r   r   Útest_reverseIndex£  s    
ÿz+ServerProtocolOutputTests.test_reverseIndexc                 C   s    | j  ¡  |  | j ¡ d¡ dS )zM
        L{ServerProtocol.nextLine} writes C{"
"} to its transport.
        s   
N)rÜ   r®   rY   rg   rË   rŠ   r   r   r   Útest_nextLine­  s    
z'ServerProtocolOutputTests.test_nextLinec              	   C   sL   t jt jt jg}| j |¡ |  | j ¡ | j	d 
tt|ƒ¡ 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°   N)r   r¶   r·   r¸   rÜ   r³   rY   rg   rË   rI   r}   rµ   r   r8   r?   ©rO   Z
modesToSetr   r   r   Útest_setModes¸  s    ÿþÿz'ServerProtocolOutputTests.test_setModesc              	   C   sL   t jt jt jg}| j |¡ |  | j ¡ | j	d 
tt|ƒ¡ tjj ¡ dS )zª
        L{ServerProtocol.setPrivatesModes} writes a control sequence
        containing the requested private modes and ending in the
        L{CSFinalByte.SM}.
        r°   N)r   ZERRORZCOLUMNZORIGINrÜ   r³   rY   rg   rË   rI   r}   rµ   r   r8   r?   )rO   ZprivateModesToSetr   r   r   Útest_setPrivateModesÆ  s    þÿþÿz.ServerProtocolOutputTests.test_setPrivateModesc              	   C   sL   t jt jt jg}| j |¡ |  | j ¡ | j	d 
tt|ƒ¡ tjj ¡ dS )zs
        L{ServerProtocol.resetModes} writes the control sequence
        ending in the L{CSFinalByte.RM}.
        r°   N)r   r¶   r·   r¸   rÜ   r´   rY   rg   rË   rI   r}   rµ   r   r8   rC   rè   r   r   r   Útest_resetModesÖ  s    ÿþÿz)ServerProtocolOutputTests.test_resetModesc                 C   s*   | j  ¡  |  | j ¡ | jtjj ¡ dS )zp
        L{ServerProtocol.singleShift2} writes an escape sequence
        followed by L{C1SevenBit.SS2}
        N)rÜ   r¥   rY   rg   rË   rä   rG   rK   rŠ   r   r   r   Útest_singleShift2ã  s    
ÿz+ServerProtocolOutputTests.test_singleShift2c                 C   s*   | j  ¡  |  | j ¡ | jtjj ¡ dS )zp
        L{ServerProtocol.singleShift3} writes an escape sequence
        followed by L{C1SevenBit.SS3}
        N)rÜ   r¦   rY   rg   rË   rä   rG   rL   rŠ   r   r   r   Útest_singleShift3í  s    
ÿz+ServerProtocolOutputTests.test_singleShift3c                 C   sJ   | j  ttƒttƒ¡ |  | j ¡ | jt	tƒ d t	tƒ t
jj ¡ dS )z«
        L{ServerProtocol.selectGraphicRendition} writes a control
        sequence containing the requested attributes and ending with
        L{CSFinalByte.SGR}
        r°   N)rÜ   ZselectGraphicRenditionÚstrr   r   rY   rg   rË   rI   r   r8   rE   rŠ   r   r   r   Útest_selectGraphicRendition÷  s    ÿÿÿþÿz5ServerProtocolOutputTests.test_selectGraphicRenditionc                 C   s*   | j  ¡  |  | j ¡ | jtjj ¡ dS )zz
        L{ServerProtocol.horizontalTabulationSet} writes the escape
        sequence ending in L{C1SevenBit.HTS}
        N)rÜ   ZhorizontalTabulationSetrY   rg   rË   rä   rG   rH   rŠ   r   r   r   Útest_horizontalTabulationSet  s    
ÿÿz6ServerProtocolOutputTests.test_horizontalTabulationSetc                 C   s*   | j  ¡  |  | j ¡ | jtjj ¡ dS )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)rÜ   rº   rY   rg   rË   rI   r8   rA   rŠ   r   r   r   Útest_eraseToLineEnd  s    
ÿz-ServerProtocolOutputTests.test_eraseToLineEndc                 C   s.   | 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.)
        rÝ   N)rÜ   r»   rY   rg   rË   rI   r8   rA   rŠ   r   r   r   Útest_eraseToLineBeginning  s    
ÿz3ServerProtocolOutputTests.test_eraseToLineBeginningc                 C   s.   | j  ¡  |  | j ¡ | jd tjj ¡ dS )z¦
        L{ServerProtocol.eraseLine} writes the control
        sequence sequence ending in L{CSFinalByte.EL} and a parameter
        of 2 (the entire line.)
        ó   2N)rÜ   r¼   rY   rg   rË   rI   r8   rA   rŠ   r   r   r   Útest_eraseLine'  s    
ÿz(ServerProtocolOutputTests.test_eraseLinec                 C   s*   | j  ¡  |  | j ¡ | jtjj ¡ dS )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)rÜ   r½   rY   rg   rË   rI   r8   r@   rŠ   r   r   r   Útest_eraseToDisplayEnd2  s    
ÿz0ServerProtocolOutputTests.test_eraseToDisplayEndc                 C   s.   | j  ¡  |  | j ¡ | jd tjj ¡ dS )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.)
        rÝ   N)rÜ   r¾   rY   rg   rË   rI   r8   r@   rŠ   r   r   r   Útest_eraseToDisplayBeginning>  s    
ÿz6ServerProtocolOutputTests.test_eraseToDisplayBeginningc                 C   s.   | j  ¡  |  | j ¡ | jd tjj ¡ dS )z¤
        L{ServerProtocol.eraseDisplay} writes the control sequence
        sequence ending in L{CSFinalByte.ED} a parameter of 2 (the
        entire page)
        ró   N)rÜ   r¿   rY   rg   rË   rI   r8   r@   rŠ   r   r   r   Útest_eraseToDisplayJ  s    
ÿz-ServerProtocolOutputTests.test_eraseToDisplayc                 C   s0   | j  d¡ |  | j ¡ | jd tjj ¡ dS )z®
        L{ServerProtocol.deleteCharacter} writes the control sequence
        containing the number of characters to delete and ending in
        L{CSFinalByte.DCH}
        r&   ó   4N)rÜ   rÀ   rY   rg   rË   rI   r8   r9   rŠ   r   r   r   Útest_deleteCharacterU  s    ÿz.ServerProtocolOutputTests.test_deleteCharacterc                 C   s0   | j  d¡ |  | j ¡ | jd tjj ¡ dS )z£
        L{ServerProtocol.insertLine} writes the control sequence
        containing the number of lines to insert and ending in
        L{CSFinalByte.IL}
        rc   ó   5N)rÜ   rÇ   rY   rg   rË   rI   r8   rB   rŠ   r   r   r   Útest_insertLine`  s    ÿz)ServerProtocolOutputTests.test_insertLinec                 C   s0   | j  d¡ |  | j ¡ | jd tjj ¡ dS )z£
        L{ServerProtocol.deleteLine} writes the control sequence
        containing the number of lines to delete and ending in
        L{CSFinalByte.DL}
        rd   ó   6N)rÜ   rÃ   rY   rg   rË   rI   r8   rD   rŠ   r   r   r   Útest_deleteLinek  s    ÿ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©rÜ   r—   rY   rg   rË   rI   rŠ   r   r   r   Útest_setScrollRegionNoArgsv  s    
z4ServerProtocolOutputTests.test_setScrollRegionNoArgsc                 C   s.   | 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'}.
        rX   )Úfirsts   1;rþ   Nrÿ   rŠ   r   r   r   Útest_setScrollRegionJustFirst€  s    z7ServerProtocolOutputTests.test_setScrollRegionJustFirstc                 C   s.   | j jdd |  | j ¡ | jd d ¡ dS )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'}.
        rX   )Úlasts   ;1rþ   Nrÿ   rŠ   r   r   r   Útest_setScrollRegionJustLastŠ  s    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'}.
        rX   ra   )r  r  s   1;2rþ   Nrÿ   rŠ   r   r   r   Ú test_setScrollRegionFirstAndLast”  s    z:ServerProtocolOutputTests.test_setScrollRegionFirstAndLastc                 C   s.   | j  ¡  |  | j ¡ | jd tjj ¡ dS )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)rÜ   rÊ   rY   rg   rË   rI   r8   rF   rŠ   r   r   r   Útest_reportCursorPositionŸ  s    
ÿz3ServerProtocolOutputTests.test_reportCursorPositionN)&rT   rU   rV   r3   r+   rä   rI   r   rÞ   rß   rà   rá   râ   rã   rå   ræ   rç   ré   rê   rë   rì   rí   rï   rð   rñ   rò   rô   rõ   rö   r÷   rù   rû   rý   r   r  r  r  r  r   r   r   r   rÚ   H  sD   










rÚ   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚDeprecationsTestszP
    Tests to ensure deprecation of L{insults.colors} and L{insults.client}
    c                 C   sD   |   ¡ }|  |d d t¡ |  |d d |¡ |  t|ƒd¡ dS )zJ
        Ensures that the correct deprecation warning was issued.
        r   ÚcategoryÚmessagerX   N)ZflushWarningsZassertIsÚDeprecationWarningrY   rZ   )rO   r	  Úwarningsr   r   r   ÚensureDeprecated²  s    z"DeprecationsTests.ensureDeprecatedc                 C   s   t dƒ |  d¡ dS )z<
        The L{insults.colors} module is deprecated
        ztwisted.conch.insults.colorszotwisted.conch.insults.colors was deprecated in Twisted 10.1.0: Please use twisted.conch.insults.helper instead.N©r   r  rŠ   r   r   r   Útest_colors¼  s    zDeprecationsTests.test_colorsc                 C   s   t dƒ |  d¡ dS )z<
        The L{insults.client} module is deprecated
        ztwisted.conch.insults.clientzptwisted.conch.insults.client was deprecated in Twisted 10.1.0: Please use twisted.conch.insults.insults instead.Nr  rŠ   r   r   r   Útest_clientÆ  s    zDeprecationsTests.test_clientN)rT   rU   rV   r3   r  r  r  r   r   r   r   r  ­  s   

r  )2Ztwisted.python.reflectr   Ztwisted.trialr   Ztwisted.test.proto_helpersr   Ztwisted.conch.insults.insultsr   r   r   r   r	   r
   r   r   r   r   r   r   r   Ztwisted.python.compatr   r   Ztwisted.python.constantsr   r   Útextwrapr   r   r"   r%   ÚobjectrM   r+   r7   Údedentr8   rG   r   rW   rn   r`   ZTestCasero   rt   rw   r~   r‰   rÚ   r  r   r   r   r   Ú<module>   s˜   $ïê"ðë %    g