
    Vhh                     B   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ  eej                         G d	 d
             Z G d dej"                        Z G d dej"                        Z G d dej(                        Z G d dej"                        Zy)z$
Tests for L{twisted.conch.telnet}.
    )implementer)verifyObject)telnet)defer)	iterbytes)proto_helpers)unittestc                   \    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zy)TestProtocol c                 f    d| _         g | _        g | _        g | _        g | _        g | _        g | _        y )N    )datasubcmdcallsenabledLocalenabledRemotedisabledLocaldisabledRemoteselfs    N/home/dcms/DCMS/lib/python3.12/site-packages/twisted/conch/test/test_telnet.py__init__zTestProtocol.__init__   s7    	
 r   c                      i x}|_          j                  |d<   |j                  j                         x}|_        dD ]  }|f fd	|t	        t
        |      <    y )N   )
EORNOPDMBRKIPAOAYTECELGAc                 :    j                   j                  |      S N)r   append)argcmdr   s     r   <lambda>z-TestProtocol.makeConnection.<locals>.<lambda>)   s    4::;L;LS;Q r   )negotiationMapneg_TEST_COMMAND
commandMapcopygetattrr   )r   	transportdr*   s   `   r   makeConnectionzTestProtocol.makeConnection#   s`    '))I$**'
#,#7#7#<#<#>>I S 	RC69&QAgfc"#	Rr   c                 .    | xj                   |z  c_         y r'   )r   r   r   s     r   dataReceivedzTestProtocol.dataReceived+   s    		T	r   c                      y r'   r   )r   reasons     r   connectionLostzTestProtocol.connectionLost.   s    r   c                     || _         y r'   )r   )r   payloads     r   r-   zTestProtocol.neg_TEST_COMMAND1   s	    r   c                 X    || j                   v r| j                  j                  |       yyNTF)localEnableabler   r(   r   options     r   enableLocalzTestProtocol.enableLocal4   s*    T)))$$V,r   c                 :    | j                   j                  |       y r'   )r   r(   r?   s     r   disableLocalzTestProtocol.disableLocal:   s    !!&)r   c                 X    || j                   v r| j                  j                  |       yyr=   )remoteEnableabler   r(   r?   s     r   enableRemotezTestProtocol.enableRemote=   s*    T***%%f-r   c                 :    | j                   j                  |       y r'   )r   r(   r?   s     r   disableRemotezTestProtocol.disableRemoteC   s    ""6*r   c                      y r'   r   r   s    r   connectionMadezTestProtocol.connectionMadeF       r   c                      y r'   r   )r   commandarguments      r   unhandledCommandzTestProtocol.unhandledCommandJ   rK   r   c                      y r'   r   r   rM   r   s      r   unhandledSubnegotiationz$TestProtocol.unhandledSubnegotiationN   rK   r   N)__name__
__module____qualname__r>   rE   r   r3   r6   r9   r-   rA   rC   rF   rH   rJ   rO   rR   r   r   r   r   r      sJ    O!R*+r   r   c                       e Zd Zd Zy)InterfacesTestsc                 `    t        j                         }t        t         j                  |       y)zO
        L{telnet.TelnetProtocol} implements L{telnet.ITelnetProtocol}
        N)r   TelnetProtocolr   ITelnetProtocol)r   ps     r   test_interfacezInterfacesTests.test_interfaceT   s"     !!#V++Q/r   N)rS   rT   rU   r\   r   r   r   rW   rW   S   s    0r   rW   c                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zg g g g fdZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(y')(TelnetTransportTestsz.
    Tests for L{telnet.TelnetTransport}.
    c                     t        j                  t              | _        t	        j
                         | _        | j                  j                  | j                         y r'   )r   TelnetTransportr   r[   r   StringTransporttr3   r   s    r   setUpzTelnetTransportTests.setUpa   s:    ''5..0dff%r   c                     | j                   j                  }g d}|D ]  }| j                   j                  |        | j                  |j                  dj                  |             y )N)s   here are some bytes la la las   some more arrive heres   lots of bytes to play withs   la la las   ta de das   dumr   )r[   protocolr6   assertEqualr   joinr   hLbs       r   testRegularBytesz%TelnetTransportTests.testRegularBytesf   sY     FFOO
  	#AFF"	# 	!-r   c                    | j                   j                  }g d}|D ]  }| j                   j                  |        | j                  |j                  |d   d d dz   |d   d d z   dz   |d   d d z   dz   |d   d d z   dz          y )	N)s   here is the first line
s   here is the second line s   here is the third line
s   here is the last line r      
            )r[   re   r6   rf   r   rh   s       r   testNewlineHandlingz(TelnetTransportTests.testNewlineHandlingy   s     FFOO
  	#AFF"	# 	FFaD"Id3Bi  d3Bi	
  d3Bi 
	
r   c                     | j                   j                  }g d}|D ]  }| j                   j                  |        | j                  |j                  dj                  |      j                  dd             y )N)s*   here are some bytes with an embedded IACs&   and here is a test of a border escapes    did you get that IAC?r   s      )r[   re   r6   rf   r   rg   replacerh   s       r   testIACEscapez"TelnetTransportTests.testIACEscape   sf     FFOO
  	#AFF"	# 	!!4!4['!JKr   c                 z   | j                   j                  }t        j                  t	        t        |      z   }dd|z   dz   g}|D ]  }| j                   j                  |        | j                  |j                  |g       | j                  |j                  dj                  |      j                  |d             y )Ns   Here's some bytes, tra la las   But ono!s    an interruptr   )r[   re   r   IACr0   r6   rf   r   r   rg   rw   )r   cmdNameri   r*   rj   rk   s         r   _simpleCommandTestz'TelnetTransportTests._simpleCommandTest   s     FFOOjj76733,kC.?BR.RS 	#AFF"	# 	7),!!4!4S#!>?r   c                 &    | j                  d       y )Nr    r|   r   s    r   testInterruptz"TelnetTransportTests.testInterrupt       %r   c                 &    | j                  d       y )Nr   r~   r   s    r   testEndOfRecordz$TelnetTransportTests.testEndOfRecord       &r   c                 &    | j                  d       y )Nr   r~   r   s    r   testNoOperationz$TelnetTransportTests.testNoOperation   r   r   c                 &    | j                  d       y )Nr   r~   r   s    r   testDataMarkz!TelnetTransportTests.testDataMark   r   r   c                 &    | j                  d       y )Nr   r~   r   s    r   	testBreakzTelnetTransportTests.testBreak   r   r   c                 &    | j                  d       y )Nr!   r~   r   s    r   testAbortOutputz$TelnetTransportTests.testAbortOutput   r   r   c                 &    | j                  d       y )Nr"   r~   r   s    r   testAreYouTherez$TelnetTransportTests.testAreYouThere   r   r   c                 &    | j                  d       y )Nr#   r~   r   s    r   testEraseCharacterz'TelnetTransportTests.testEraseCharacter   r   r   c                 &    | j                  d       y )Nr$   r~   r   s    r   testEraseLinez"TelnetTransportTests.testEraseLine   r   r   c                 &    | j                  d       y )Nr%   r~   r   s    r   testGoAheadz TelnetTransportTests.testGoAhead   r   r   c                    | j                   j                  }t        j                  t        j                  z   dz   t        j                  z   t        j
                  z   }d|z   dg}|D ]  }| j                   j                  |        | j                  |j                  dj                  |      j                  |d             | j                  |j                  t        t        d                   y )Ns   hello worlds   These are some bytes but soons   there will be some morer   s   hello world)r[   re   r   rz   SBSEr6   rf   r   rg   rw   r   listr   r   ri   r*   rj   rk   s        r   testSubnegotiationz'TelnetTransportTests.testSubnegotiation   s     FFOOjj699$'99FJJFR-35OP 	#AFF"	# 	!!4!4S#!>?4	.(A#BCr   c                    | j                   j                  }t        j                  t        j                  z   dz   t        j
                  z   t        j                  z   t        j
                  z   }d|z   dz   dg}|D ]  }| j                   j                  |        | j                  |j                  dj                  |      j                  |d             | j                  |j                  t        j
                  g       y )Nr   s   Some bytes are heres   and herer   )r[   re   r   rz   r   r   r6   rf   r   rg   rw   r   r   s        r    testSubnegotiationWithEmbeddedSEz5TelnetTransportTests.testSubnegotiationWithEmbeddedSE   s     FFOOjj699$w.:VZZG&))S#c)K7E 	#AFF"	# 	!!4!4S#!>?FII;/r   c           
         t         j                  t         j                  z   dz   t         j                  z   dz   t         j                  z   t         j                  z   }t	        t        |            D ]  }t               x}| j                  _        |j                  | j                         |d | ||d  }}d|z   |dz   g}|D ]  }| j                  j                  |        | j                  |j                  dj                  |      j                  |d             | j                  |j                  t         j                  gt!        t#        d            z           y )Nr   s   hellos
   first parts	   last partr   )r   rz   r   r   rangelenr   r[   re   r3   r6   rf   r   rg   rw   r   r   r   )r   r*   iri   ark   rj   r   s           r   testBoundarySubnegotiationz/TelnetTransportTests.testBoundarySubnegotiation   s5   
 JJii ii 	
 jj ii 	 s3x 	PA"..0ATVV$r7CGqA"A$45A *##D)* QVVSXXa[%8%8c%BCQXX		{T)H:M5N'NO	Pr   c                     | j                  |j                  |       | j                  |j                  |       | j                  |j                  |       | j                  |j                  |       y r'   )rf   r   r   r   r   )r   oeLeRdLdRs         r   _enabledHelperz#TelnetTransportTests._enabledHelper
  sT    ,"-"-))2.r   c                    t         j                  t         j                  z   dz   }d|z   dz   }| j                  j	                  |       | j                  | j                  j                  j                  |j                  |d             | j                  | j                  j                         t         j                  t         j                  z   dz          | j                  | j                  j                         y Nr   s   surrounding bytess   to spice things upr   )r   rz   WILLr[   r6   rf   re   r   rw   rb   valueDONTr   r   r*   r   s      r   testRefuseWillz#TelnetTransportTests.testRefuseWill  s    jj6;;&0#c),AAD!--t||C/EFfkk)AG)KLDFFOO,r   c                    t         j                  t         j                  z   dz   }d|z   dz   }| j                  j	                  |       | j                  | j                  j                  j                  |j                  |d             | j                  | j                  j                         t         j                  t         j                  z   dz          | j                  | j                  j                         y r   )r   rz   DOr[   r6   rf   re   r   rw   rb   r   WONTr   r   s      r   testRefuseDoz!TelnetTransportTests.testRefuseDo  s    jj699$w.#c),AAD!--t||C/EFfkk)AG)KLDFFOO,r   c                    t         j                  t         j                  z   dz   }d|z   dz   }| j                  j                  }d|_        | j                  j                  |       | j                  | j                  j                         t         j                  t         j                  z   dz          | j                  |dg       y )N      paddings   trailer)r   )r   )r   rz   r   r[   re   r>   r6   rf   rb   r   r   r   r   r*   r   ri   s       r   testAcceptDoz!TelnetTransportTests.testAcceptDo&  s     jj699$w.C*,FFOO&D!fkk)AG)KLA7),r   c                    t         j                  t         j                  z   dz   }d|z   dz   }| j                  j                  }d|_        | j                  j                  |       | j                  | j                  j                         t         j                  t         j                  z   dz          | j                  |dg       y )N   s   headerr   )r   r   )r   rz   r   r[   re   rE   r6   rf   rb   r   r   r   r   s       r   testAcceptWillz#TelnetTransportTests.testAcceptWill3  s    jj6;;&03+FFOO'D!fii)?')IJA7),r   c                    t         j                  t         j                  z   dz   }| j                  j	                  d      }d|j
                  _        d|z   }| j                  j                  |       | j                  | j                  j                  j                  |j                  |d             | j                  | j                  j                         t         j                  t         j                  z   dz          | j                  |j
                  j                  d       | j                  | j                  j                  dg       y )N   )yess
   fiddle deer   nor   )r   rz   r   r[   getOptionStatehimstater6   rf   re   r   rw   rb   r   r   r   r   r*   sr   s       r   testAcceptWontz#TelnetTransportTests.testAcceptWont?  s     jj6;;&0
 FF!!'*s"D!--t||C/EFfkk)AG)KLd+DFFOO	:r   c                    t         j                  t         j                  z   dz   }| j                  j	                  d      }d|j
                  _        d|z   }| j                  j                  |       | j                  | j                  j                  j                  |j                  |d             | j                  | j                  j                         t         j                  t         j                  z   dz          | j                  |j
                  j                  d       | j                  | j                  j                  dg       y )Nr   r   s   fiddle dum r   r   )r   )r   rz   r   r[   r   usr   r6   rf   re   r   rw   rb   r   r   r   r   s       r   testAcceptDontz#TelnetTransportTests.testAcceptDontS  s     jj6;;&0
 FF!!'*
#D!--t||C/EFfkk)AG)KLT*DFFOO	:r   c                    t         j                  t         j                  z   dz   }d|z   dz   }| j                  j	                  |       | j                  | j                  j                  j                  |j                  |d             | j                  | j                  j                         d       | j                  | j                  j                         y N   G
   dum de dum	   tra la lar   )r   rz   r   r[   r6   rf   re   r   rw   rb   r   r   r   s      r   testIgnoreWontz#TelnetTransportTests.testIgnoreWontg  s     jj6;;&0s"\1D!--t||C/EF-DFFOO,r   c                    t         j                  t         j                  z   dz   }d|z   dz   }| j                  j	                  |       | j                  | j                  j                  j                  |j                  |d             | j                  | j                  j                         d       | j                  | j                  j                         y r   )r   rz   r   r[   r6   rf   re   r   rw   rb   r   r   r   s      r   testIgnoreDontz#TelnetTransportTests.testIgnoreDonts  s     jj6;;&0s"\1D!--t||C/EF-DFFOO,r   c                    t         j                  t         j                  z   dz   }| j                  j	                  d      }d|j
                  _        d|z   dz   }| j                  j                  |       | j                  | j                  j                  j                  |j                  |d             | j                  | j                  j                         d       | j                  | j                  j                         y N   Vr   r   r   r   )r   rz   r   r[   r   r   r   r6   rf   re   r   rw   rb   r   r   r   s       r   testIgnoreWillz#TelnetTransportTests.testIgnoreWill  s     jj6;;&0
 FF!!'*c!M1D!--t||C/EF-DFFOO,r   c                    t         j                  t         j                  z   dz   }| j                  j	                  d      }d|j
                  _        d|z   dz   }| j                  j                  |       | j                  | j                  j                  j                  |j                  |d             | j                  | j                  j                         d       | j                  | j                  j                         y r   )r   rz   r   r[   r   r   r   r6   rf   re   r   rw   rb   r   r   r   s       r   testIgnoreDoz!TelnetTransportTests.testIgnoreDo  s     jj699$w.
 FF!!'*
c!M1D!--t||C/EF-DFFOO,r   c                      j                   j                  d      } j                   j                  d_         j	                   j
                  j                         t        j                  t        j                  z   dz           j                   j                  t        j                  t        j                  z   dz          |j                   j                  d       |j                   fd       |S )N   Br   Tc                 ,    j                  dg      S )Nr   r   )r   )_ri   r   s    r   r+   z@TelnetTransportTests.testAcceptedEnableRequest.<locals>.<lambda>  s     3 3A7) 3 D r   )r[   dore   rE   rf   rb   r   r   rz   r   r6   r   addCallback)r   r2   ri   s   ` @r   testAcceptedEnableRequestz.TelnetTransportTests.testAcceptedEnableRequest  s    
 FFIIgFFOO'fii)?')IJFJJ4w>?	d&&-	DEr   c                 |    d j                   j                  _         j                   j                  d      } j	                   j
                  j                         t        j                  t        j                  z   dz           j                   j                  d       j	                  j                  j                  d        j	                  j                  j                  d        j                  j                  j                          j!                  j                  j                          j                   j#                  t        j                  t        j$                  z   dz           j'                  |t        j(                        }|j+                   fd       |j+                   fd       |S )z
        If the peer refuses to enable an option we request it to enable, the
        L{Deferred} returned by L{TelnetProtocol.do} fires with an
        L{OptionRefused} L{Failure}.
        r   r   r   c                 N    j                  j                  j                        S r'   r   r[   re   ignoredr   s    r   r+   z@TelnetTransportTests.test_refusedEnableRequest.<locals>.<lambda>      d&9&9$&&//&J r   c                 N    j                  j                  j                        S r'   )assertFalser   negotiatingr   r   r   s    r   r+   z@TelnetTransportTests.test_refusedEnableRequest.<locals>.<lambda>  s    d&6&6quu7H7H&I r   )r[   re   rE   r   rf   rb   r   r   rz   r   r   r   r   r   
assertTruer   r   r6   r   assertFailureOptionRefusedr   r   r2   r   s   ` @r   test_refusedEnableRequestz.TelnetTransportTests.test_refusedEnableRequest  s     ,6(FFIIgfii)?')IJFF!!'*d+T*))*))*FJJ4w>?q&"6"67	JK	IJr   c                 |    d j                   j                  _         j                   j                  d      } j	                   j
                  j                         t        j                  t        j                  z   dz           j                   j                  d       j	                  j                  j                  d        j	                  j                  j                  d        j                  j                  j                          j!                  j                  j                          j                   j#                  t        j                  t        j$                  z   dz           j'                  |t        j(                        }|j+                   fd       |j+                   fd       |S )z
        If the peer refuses to allow us to enable an option, the L{Deferred}
        returned by L{TelnetProtocol.will} fires with an L{OptionRefused}
        L{Failure}.
        r   r   r   c                 N    j                  j                  j                        S r'   r   r   s    r   r+   z>TelnetTransportTests.test_refusedEnableOffer.<locals>.<lambda>  r   r   c                 N    j                  j                  j                        S r'   )r   r   r   r   s    r   r+   z>TelnetTransportTests.test_refusedEnableOffer.<locals>.<lambda>  s    d&6&6qtt7G7G&H r   )r[   re   r>   willrf   rb   r   r   rz   r   r   r   r   r   r   r   r   r6   r   r   r   r   r   s   ` @r   test_refusedEnableOfferz,TelnetTransportTests.test_refusedEnableOffer  s     +5'FFKK fkk)AG)KLFF!!'*d+T***+(()FJJ4w>?q&"6"67	JK	HIr   c                      j                   j                  d      }d|j                  _         j                   j	                  d      } j                   j                  j                         t        j                  t        j                  z   dz           j                   j                  t        j                  t        j                  z   dz          |j                   j
                  d       |j                   fd       |S )Nr   r   Tc                 T    j                  j                  j                  dg      S )Nr   r   r   r   r   s    r   r+   zATelnetTransportTests.testAcceptedDisableRequest.<locals>.<lambda>  s!     3 3DFFOO	 3 R r   )r[   r   r   r   dontrf   rb   r   r   rz   r   r6   r   r   r   r   r2   s   `  r   testAcceptedDisableRequestz/TelnetTransportTests.testAcceptedDisableRequest  s    
 FF!!'*FFKK fkk)AG)KLFJJ4w>?	d&&-	RSr   c                      j                   j                  d      }d|j                  _         j                   j	                  d        fd} fd} fd} |d       }|j                  |       |j                  |       |S )N   $r   c                 z    j                   j                  d      }j                  |t        j                        S Nr   )r[   r   r   r   AlreadyNegotiatingxr2   r   s     r   _dozITelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._do
  s.    		'"A%%a)B)BCCr   c                 z    j                   j                  d      }j                  |t        j                        S r   )r[   r   r   r   r   r   s     r   _dontzKTelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._dont  s.    G$A%%a)B)BCCr   c                    j                   j                  t        j                  t        j                  z   dz          j                  j                   j                  dg       dj                   j                  _        j                   j                  d      }j                   j                  t        j                  t        j                  z   dz          |j                  j                  d       |j                  fd       |S )Nr   r   )r   Tc                 X    j                  j                  j                  dgdg      S )Nr   )r   r   r   r   s    r   r+   z^TelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._final.<locals>.<lambda>  s*    $--FFOO	wi .  r   )r[   r6   r   rz   r   r   re   rE   r   r   r   rf   r   s     r   _finalzLTelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._final  s    FF

V[[ 87 BCWI>/9DFFOO,		'"AFF

V[[ 87 BCMM$**D1MM
 Hr   )r[   r   r   r   r   r   )r   r   r  r  r  r2   s   `     r   'testNegotiationBlocksFurtherNegotiationz<TelnetTransportTests.testNegotiationBlocksFurtherNegotiation  sm     FF!!'*G	D	D	  I	e	fr   c                 x    | j                   j                  d      }| j                  |t        j                        S )N   )r[   r   r   r   AlreadyDisabled)r   r2   s     r   #testSuperfluousDisableRequestRaisesz8TelnetTransportTests.testSuperfluousDisableRequestRaises'  s-    FFKK !!!V%;%;<<r   c                     | j                   j                  d      }d|j                  _        | j                   j	                  d      }| j                  |t        j                        S )Nr
  r   )r[   r   r   r   r   r   r   AlreadyEnabledr   s      r   "testSuperfluousEnableRequestRaisesz7TelnetTransportTests.testSuperfluousEnableRequestRaises,  sL    FF!!'*FFIIg!!!V%:%:;;r   c                    | j                   j                  d      }| j                   j                  d      }| j                   j                  d      } G d dt              }| j                   j                   |d             | j	                  ||      }| j	                  ||      }| j	                  ||      }t        j                  |||g      S )Nr      #   4c                       e Zd Zy)LTelnetTransportTests.testLostConnectionFailsDeferreds.<locals>.TestExceptionN)rS   rT   rU   r   r   r   TestExceptionr  8  s    r   r  zTotal failure!)r[   r   	Exceptionr9   r   r   gatherResults)r   d1d2d3r  s        r    testLostConnectionFailsDeferredsz5TelnetTransportTests.testLostConnectionFailsDeferreds3  s    VVYYwVVYYwVVYYw	I 	 	m,<=>M2M2M2""BB<00r   N))rS   rT   rU   __doc__rc   rl   rt   rx   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   r^   r^   \   s    &
.&
6L"@&''&'&'&&&D0P6 $&" /	-	--
-;(;(
---&-&$88$#J=
<1r   r^   c                   (    e Zd ZdZd Zd Zd Zd Zy)
TestTelnetzP
    A trivial extension of the telnet protocol class useful to unit tests.
    c                 P    t         j                  j                  |        g | _        y r'   )r   Telnetr   eventsr   s    r   r   zTestTelnet.__init__H  s    t$r   c                 >    | j                   j                  d|f       y)z:
        Record the given data in C{self.events}.
        bytesNr!  r(   r5   s     r   applicationDataReceivedz"TestTelnet.applicationDataReceivedL  s     	GT?+r   c                 @    | j                   j                  d||f       y)z=
        Record the given command in C{self.events}.
        rM   Nr$  rQ   s      r   rO   zTestTelnet.unhandledCommandR  s     	Iw56r   c                 @    | j                   j                  d||f       y)zL
        Record the given subnegotiation command in C{self.events}.
        	negotiateNr$  rQ   s      r   rR   z"TestTelnet.unhandledSubnegotiationX  s     	K$78r   N)rS   rT   rU   r  r   r%  rO   rR   r   r   r   r  r  C  s    ,79r   r  c                   p    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zy)TelnetTestsz
    Tests for L{telnet.Telnet}.

    L{telnet.Telnet} implements the TELNET protocol (RFC 854), including option
    and suboption negotiation, and option state tracking.
    c                 "    t               | _        y)zM
        Create an unconnected L{telnet.Telnet} to be used by tests.
        N)r  re   r   s    r   rc   zTelnetTests.setUpg  s     #r   c                 X    | j                  | j                  j                  d             y)z
        L{telnet.Telnet.enableLocal} should reject all options, since
        L{telnet.Telnet} does not know how to implement any options.
            N)r   re   rA   r   s    r   test_enableLocalzTelnetTests.test_enableLocalm  s!    
 	2259:r   c                 X    | j                  | j                  j                  d             y)z
        L{telnet.Telnet.enableRemote} should reject all options, since
        L{telnet.Telnet} does not know how to implement any options.
        r-  N)r   re   rF   r   s    r   test_enableRemotezTelnetTests.test_enableRemotet  s!    
 	33E:;r   c                 Z    | j                  t        | j                  j                  d       y)a	  
        It is an error for L{telnet.Telnet.disableLocal} to be called, since
        L{telnet.Telnet.enableLocal} will never allow any options to be enabled
        locally.  If a subclass overrides enableLocal, it must also override
        disableLocal.
        r-  N)assertRaisesNotImplementedErrorre   rC   r   s    r   test_disableLocalzTelnetTests.test_disableLocal{  s!     	-t}}/I/I5Qr   c                 Z    | j                  t        | j                  j                  d       y)a  
        It is an error for L{telnet.Telnet.disableRemote} to be called, since
        L{telnet.Telnet.enableRemote} will never allow any options to be
        enabled remotely.  If a subclass overrides enableRemote, it must also
        override disableRemote.
        r-  N)r2  r3  re   rH   r   s    r   test_disableRemotezTelnetTests.test_disableRemote  s!     	-t}}/J/JERr   c                     t        j                         }| j                  j                  |       | j                  j	                  dd       | j                  |j                         d       y)z
        L{telnet.Telnet.requestNegotiation} formats the feature byte and the
        payload bytes into the subnegotiation format and sends them.

        See RFC 855.
           s   s   Nr   ra   re   r3   requestNegotiationrf   r   r   r1   s     r   test_requestNegotiationz#TelnetTests.test_requestNegotiation  sS     "113	$$Y/((+>OO+	
r   c                     t        j                         }| j                  j                  |       | j                  j	                  dd       | j                  |j                         d       y)z
        If the payload for a subnegotiation includes I{IAC}, it is escaped by
        L{telnet.Telnet.requestNegotiation} with another I{IAC}.

        See RFC 855.
        r8  rv   s   Nr9  r;  s     r   !test_requestNegotiationEscapesIACz-TelnetTests.test_requestNegotiationEscapesIAC  sP     "113	$$Y/((':*,KLr   c                     g x}| j                   _        | j                   j                  |       | j                  |t	        |             y)z
        Pass the given bytes to the protocol's C{dataReceived} method and
        assert that the given events occur.
        N)re   r!  r6   rf   r   )r   r   expectedreceiveds       r   _deliverzTelnetTests._deliver  s;    
 +-,4=='""4(4>2r   c                 (    | j                  dd       y)zc
        One application-data byte in the default state gets delivered right
        away.
           a)r#  rD  NrB  r   s    r   test_oneApplicationDataBytez'TelnetTests.test_oneApplicationDataByte  s    
 	dO,r   c                 (    | j                  dd       y)za
        Two application-data bytes in the default state get delivered
        together.
           bc)r#  rH  NrE  r   s    r   test_twoApplicationDataBytesz(TelnetTests.test_twoApplicationDataBytes  s    
 	e-.r   c                 J    | j                  dt        j                  z   d       y)z~
        Three application-data bytes followed by a control byte get
        delivered, but the control byte doesn't.
           def)r#  rK  NrB  r   rz   r   s    r   test_threeApplicationDataBytesz*TelnetTests.test_threeApplicationDataBytes  s    
 	fvzz)+<=r   c                     | j                  t        j                         | j                  t        j                  dz   dt        j                  dz   f       y)zy
        IAC in the escaped state gets delivered and so does another
        application-data byte following it.
           gr#  NrL  r   s    r   test_escapedControlzTelnetTests.test_escapedControl  s9    
 	fjj!fjj4''6::3D)EFr   c                    | j                  d       | j                  dd       | j                  dd       | j                  d       | j                  dd       | j                  dd       | j                  d       | j                  dd	       | j                  d
d	       | j                  d       | j                  t        j                  t        j                  z   dz   ddt        j                  z   dz   f       y)a  
        A carriage return only puts the protocol into the newline state.  A
        linefeed in the newline state causes just the newline to be
        delivered.  A nul in the newline state causes a carriage return to
        be delivered.  An IAC in the newline state causes a carriage return
        to be delivered and puts the protocol into the escaped state.
        Anything else causes a carriage return and that thing to be
        delivered.
        rq   ro   )r#  ro   s   
r-  )r#  rq   s    rD  )r#     arR     xr#  NrL  r   s    r   test_carriageReturnzTelnetTests.test_carriageReturn  s     	ee-.g/0ee-.g/0ed-.f/0eJJ#d*Wefjj6H46O,P	
r   c                     | j                  dt        j                  z   t        j                  z   ddt        j                  df       y)zt
        Application bytes received before a command are delivered before the
        command is processed.
        rS  )r#  rS  rM   N)rB  r   rz   r   r   s    r   'test_applicationDataBeforeSimpleCommandz3TelnetTests.test_applicationDataBeforeSimpleCommand  s6    
 	6::

*

D)	
r   c                     i | j                   _        | j                  dt        j                  z   t        j
                  z   dz   ddt        j
                  df       y)z~
        Application bytes received before a WILL/WONT/DO/DONT are delivered
        before the command is processed.
           yr-  )r#  rX  rM   N)re   r.   rB  r   rz   r   r   s    r   !test_applicationDataBeforeCommandz-TelnetTests.test_applicationDataBeforeCommand  sG    
 $& 6::+g5W-	
r   c                     | j                  dt        j                  z   t        j                  z   dz   t        j                  z   t        j                  z   ddddgf       y)z
        Application bytes received before a subnegotiation command are
        delivered before the negotiation is processed.
           zs   Qx)r#  r[  r(     QrS  N)rB  r   rz   r   r   r   s    r   (test_applicationDataBeforeSubnegotiationz4TelnetTests.test_applicationDataBeforeSubnegotiation  sK    
 	6::		)E1FJJ>J$'	
r   N)rS   rT   rU   r  rc   r.  r0  r4  r6  r<  r>  rB  rF  rI  rM  rP  rT  rV  rY  r]  r   r   r   r*  r*  _  s[    %;<RS
 
M3-/>G
6	


	
r   r*  N)r  zope.interfacer   zope.interface.verifyr   twisted.conchr   twisted.internetr   twisted.python.compatr   twisted.testr   twisted.trialr	   rZ   r   TestCaserW   r^   r   r  r*  r   r   r   <module>rf     s   

 ' .   " + & " V##$; ; %;|0h'' 0d18,, d1N9 98k
(## k
r   