U
    P|js}  ã                   @   s‚  d dl Z d dlmZ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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 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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-d.gd/d0d1gd2d3d4gd5d6d7gd8d9d:gd;d<d=gd>d?d@gdAdBdCgdDddEgge  %dF¡dG�Z&e$dHdddIgddJgdKdLgdMdNgddOgdPdQgdRdSgdTdUgdVdWgdXdgdYdZgd[d\gd]d^gd_d`gdadbgdcddgge  %de¡dG�Z'G dfdg„ dgƒZ(G dhdi„ diƒZ)djZ*G dkdl„ dle)ƒZ+[*G dmdn„ dne+ej,ƒZ-G dodp„ dpe+ej,ƒZ.G dqdr„ dre+ej,ƒZ/G dsdt„ dte+ej,ƒZ0G dudv„ dvej,e)ƒZ1G dwdx„ dxej,ƒZ2dS )yé    N)ÚOptionalÚType)ÚValueConstantÚValues)ÚBLINKÚCS_ALTERNATEÚCS_ALTERNATE_SPECIALÚ
CS_DRAWINGÚCS_UKÚCS_USÚG0ÚG1Ú	UNDERLINEÚClientProtocolÚServerProtocolÚmodesÚprivateModes)ÚProtocol)ÚStringTransport)Ú	iterbytes)Úunittestc                 C   s   t t| ƒ |¡S ©N)ÚsuperÚMockÚ__getattribute__)ÚmockÚname© r   úC/tmp/pip-unpacked-wheel-audpp6lv/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   Ú_ecmaCodeTableCoordinate2   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>K   s   
 ý z/_makeControlFunctionSymbols.<locals>.<dictcomp>Ú__doc__)r-   Útyper   )r   r2   ÚnamesÚdocÚattrsr   r1   r   Ú_makeControlFunctionSymbolsF   s
    
þr9   Ú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}
    )r2   r6   r7   Ú
C1SevenBitZDCSZPU1ZBPHZPU2ZNBHZSTSZCCHZNELZMWZSSAZSPAZESAZEPAÚHTSZSOSZHTJZVTSZSCIZPLDÚCSIZPLUZSTÚRIÚ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#   rQ   r   r   r   Ú__init__Ÿ   s    zMock.__init__c                 O   s.   t | dƒ}|tkrtƒ }t| d|||fƒ |S )NrQ   Ú__call__)r   rP   r   r&   )rR   ÚaÚkwZreturnValuer   r   r   rT   «   s
    
zMock.__call__c                 C   s:   t | dƒ}||kr"t|| d�}ntƒ }t| ||fƒ |S )Nr#   )rQ   )r   r   r&   )rR   r   r#   Ú	attrValuer   r   r   r   ³   s    
zMock.__getattribute__)Ú__name__Ú
__module__Ú__qualname__rP   rQ   rS   rT   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é   rT   )ÚassertEqualÚlenr    )rR   Z
occurrenceÚ
methodNameZexpectedPositionalArgsZexpectedKeywordArgsÚattrr   ÚcallÚresultÚargsrV   r   r   r   Ú
assertCall¿   s    zMockMixin.assertCallN)rX   rY   rZ   rd   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))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)rd   r    Úpopr]   )rR   Ú	transportÚprotoÚparserrb   r   r   r   ÚverifyResultsë   s    z ByteGroupingsMixin.verifyResults)rX   rY   rZ   rf   r   r   r   Ú__annotations__ÚwordÚnÚexecÚ_byteGroupingTestTemplaterp   r   r   r   r   re   Þ   s
   
re   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)re   rp   ZUP_ARROWZ
DOWN_ARROWZRIGHT_ARROWZ
LEFT_ARROWrd   r    rl   r]   ÚassertFalse)rR   rm   rn   ro   Zarrowrb   r   r   r   rp   ù   s    ü  ÿz"ServerArrowKeysTests.verifyResultsN©rX   rY   rZ   r   rf   Ú
TEST_BYTESrp   r   r   r   r   rv   ó   s   rv   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�¡ d S )Ns   abc123ABC!@#r   rw   s   abc123z should have been [])	re   rp   r   rd   r    rl   r]   ZALTrx   )rR   rm   rn   ro   Úcharrb   Úoccsr   r   r   rp     s"      ÿ  ÿz&PrintableCharactersTests.verifyResultsNry   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   rw   )	re   rp   ÚrangeÚgetattrrd   r    rl   r]   rx   )rR   rm   rn   ro   ZfuncNumZfuncArgrb   r   r   r   rp   <  s      ÿz%ServerFunctionKeysTests.verifyResultsN)rX   rY   rZ   r4   r   rf   ZbyteListZ	byteCodesr$   Újoinrz   rp   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 ]6\}}|  t|ƒ d¡d| |f¡}|  t|ƒg ¡ q|  t|ƒ¡ d S )N))ÚDownrg   )ÚForwardr'   ©ÚUpr\   ©ÚBackwardrg   rˆ   rŠ   r   Úcursor)re   rp   rd   r    rl   r]   rx   )rR   rm   rn   ro   ÚmethodÚcountrb   r   r   r   rp   R  s      ÿz'ClientCursorMovementTests.verifyResultsN)rX   rY   rZ   r   rf   Zd2Zr4Úu1Úl2rz   rp   r   r   r   r   r…   G  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   )rn   r   ©rR   r   r   Ú<lambda>h  r€   z3ClientControlSequencesTests.setUp.<locals>.<lambda>r   rk   )r   rm   r   rn   r   ro   Úfactoryrk   rd   r    rl   rx   )rR   rb   r   r’   r   ÚsetUpe  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 )	Nr€   c                 s   s$   | ]}d D ]}d| | V  q
qdS ))r€   ó   2s   20s   200r   Nr   )r.   Úchrs   r   r   r   Ú	<genexpr>r  s    þzBClientControlSequencesTests.testSimpleCardinals.<locals>.<genexpr>s   BACD)r†   r‰   r‡   r‹   )r\   rg   é   éÈ   r   rŒ   )	ro   ÚdataReceivedr„   r   r    rn   rd   rl   rx   )rR   r}   ÚmethrŽ   rb   r   r   r   ÚtestSimpleCardinalsp  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)ri   é   )NN©ro   r›   r    rn   rd   rl   rx   ©rR   r}   rb   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   ZdoubleHeightLine)T)FZsingleWidthLineZ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|ƒ¡ qDq2|  |¡ d S )Nr€   c                    s(   g | ] ‰ d   ‡ fdd„tdƒD ƒ¡‘qS )r€   c                    s   g | ]}d ˆ  | ‘qS )ó   r   )r.   rs   ©Úgr   r   Ú
<listcomp>   s     zKClientControlSequencesTests.testCharacterSet.<locals>.<listcomp>.<listcomp>s   AB012)r„   r   )r.   r   r¥   r   r§   Ÿ  s   ÿz@ClientControlSequencesTests.testCharacterSet.<locals>.<listcomp>s   ()r   ZselectCharacterSet)ro   r›   r„   r   r    rn   r   r   r
   r   r	   r   r   rd   rl   rx   )rR   r}   ÚwhichÚcharsetrb   r   r   r   ÚtestCharacterSetœ  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   ÚtestShiftingµ  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 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   s   | ]}d |f V  qdS ©s   %dNr   ©r.   Úmr   r   r   r˜   ú  s     z8ClientControlSequencesTests.testModes.<locals>.<genexpr>ó   hc                 s   s   | ]}d |f V  qdS rº   r   r»   r   r   r   r˜   ÿ  s     ó   lr   ÚsetModesÚ
resetModes)ro   r›   r„   r   ÚKAMÚIRMÚLNMr    rn   rd   rl   rx   r¡   r   r   r   Ú	testModes÷  s8    ÿþÿÿþÿ
  ÿ  ÿ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)rh   r    )rR   r}   rœ   rb   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©r\   rh   r   Ú
deleteLiner    ©rR   r}   Úargrb   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)rj   é   ÚreportCursorPositions   [6ns   [7;8Rr   )
r#   rn   ro   r›   r]   rm   Úvaluer    rd   rl   r¡   r   r   r   ÚtestCursorPosition4  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    rn   ro   r›   rd   rl   )rR   r}   r   r   r   Útest_applicationDataBytes?  s
    
z5ClientControlSequencesTests.test_applicationDataBytesc                 C   sN   t | jƒ}| j |¡ |r8| j| d¡f| d¡žŽ  q|  |d|›�¡ d S )Nr   zNo other calls should happen: )r    rn   ro   r›   rd   rl   rx   )rR   ÚdataZcallsr}   r   r   r   Ú_applicationDataTestK  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_shiftInAfterApplicationDataR  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_shiftOutAfterApplicationDataY  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_escapeAfterApplicationDatah  s
     ÿz;ClientControlSequencesTests.test_escapeAfterApplicationDataN)rX   rY   rZ   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‘   d  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\   é   ri   c                 C   s"   t ƒ | _tƒ | _| j | j¡ d S r   )r   Úprotocolr   rm   rk   r’   r   r   r   r•   †  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.
        r\   ó   1N)rç   ZcursorUpr]   rm   rÖ   rK   r:   r<   r’   r   r   r   Útest_cursorUp‹  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.
        r\   rè   N)rç   Z
cursorDownr]   rm   rÖ   rK   r:   r=   r’   r   r   r   Útest_cursorDown•  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.
        r\   rè   N)rç   ZcursorForwardr]   rm   rÖ   rK   r:   r>   r’   r   r   r   Útest_cursorForwardŸ  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.
        r\   rè   N)rç   râ   r]   rm   rÖ   rK   r:   r?   r’   r   r   r   Útest_cursorBackward©  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cursorPositionr]   rm   rÖ   rK   r:   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
cursorHomer]   rm   rÖ   rK   r:   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µ   r]   rm   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¶   r]   rm   rÖ   rï   rI   rL   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·   r]   rm   rÖ   r’   r   r   r   Útest_nextLineÛ  s    
z'ServerProtocolOutputTests.test_nextLinec                 C   sP   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   s   | ]}d |f V  qdS rº   r   r»   r   r   r   r˜   ð  s     z:ServerProtocolOutputTests.test_setModes.<locals>.<genexpr>N)r   rÁ   rÂ   rÃ   rç   r¿   r]   rm   rÖ   rK   r„   r:   rA   ©rR   Z
modesToSetr   r   r   Útest_setModeså  s    ÿþþz'ServerProtocolOutputTests.test_setModesc                 C   sP   t jt jt jg}| j |¡ |  | j ¡ | j	d 
dd„ |D ƒ¡ 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¹   c                 s   s   | ]}d |f V  qdS rº   r   r»   r   r   r   r˜     s     zAServerProtocolOutputTests.test_setPrivateModes.<locals>.<genexpr>N)r   ÚERRORZCOLUMNZORIGINrç   r¿   r]   rm   rÖ   rK   r„   r:   rA   )rR   ZprivateModesToSetr   r   r   Útest_setPrivateModesô  s    ýÿþþz.ServerProtocolOutputTests.test_setPrivateModesc                 C   sP   t jt jt jg}| j |¡ |  | j ¡ | j	d 
dd„ |D ƒ¡ tjj ¡ dS )zs
        L{ServerProtocol.resetModes} writes the control sequence
        ending in the L{CSFinalByte.RM}.
        r¹   c                 s   s   | ]}d |f V  qdS rº   r   r»   r   r   r   r˜     s     z<ServerProtocolOutputTests.test_resetModes.<locals>.<genexpr>N)r   rÁ   rÂ   rÃ   rç   rÀ   r]   rm   rÖ   rK   r„   r:   rE   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®   r]   rm   rÖ   rï   rI   rN   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¯   r]   rm   rÖ   rï   rI   rO   r’   r   r   r   Útest_singleShift3  s    
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)rç   ZselectGraphicRenditionÚstrr   r   r]   rm   rÖ   rK   r:   rG   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horizontalTabulationSetr]   rm   rÖ   rï   rI   rJ   r’   r   r   r   Útest_horizontalTabulationSet1  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Å   r]   rm   rÖ   rK   r:   rC   r’   r   r   r   Útest_eraseToLineEnd9  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Æ   r]   rm   rÖ   rK   r:   rC   r’   r   r   r   Útest_eraseToLineBeginningC  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.)
        r–   N)rç   rÇ   r]   rm   rÖ   rK   r:   rC   r’   r   r   r   Útest_eraseLineM  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È   r]   rm   rÖ   rK   r:   rB   r’   r   r   r   Útest_eraseToDisplayEndV  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É   r]   rm   rÖ   rK   r:   rB   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Ê   r]   rm   rÖ   rK   r:   rB   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Ë   r]   rm   rÖ   rK   r:   r;   r’   r   r   r   Útest_deleteCharacters  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}
        ri   ó   5N)rç   rÒ   r]   rm   rÖ   rK   r:   rD   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}
        rj   ó   6N)rç   rÎ   r]   rm   rÖ   rK   r:   rF   r’   r   r   r   Útest_deleteLine‡  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ž   r]   rm   rÖ   rK   r’   r   r   r   Útest_setScrollRegionNoArgs�  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'}.
        r\   )Ú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'}.
        r\   )Ú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'}.
        r\   rg   )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Õ   r]   rm   rÖ   rK   r:   rH   r’   r   r   r   Útest_reportCursorPositionµ  s
    
 ÿz3ServerProtocolOutputTests.test_reportCursorPositionN)&rX   rY   rZ   r4   r,   rï   rK   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å   z  sD   




	


	

						
rå   )3ÚtextwrapÚtypingr   r   Z
constantlyr   r   Ztwisted.conch.insults.insultsr   r   r   r	   r
   r   r   r   r   r   r   r   r   Ztwisted.internet.protocolr   Ztwisted.internet.testingr   Ztwisted.python.compatr   Ztwisted.trialr   r   r    r#   r&   ÚobjectrP   r,   r9   Údedentr:   rI   r   r[   ru   re   ZTestCaserv   r{   r~   r…   r‘   rå   r   r   r   r   Ú<module>   s–   <ïÿê%ðÿë""#  