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


W[�g�@s�dZddlmZmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZdd	lmZeej�Gd
d�d��ZGdd
�d
e
j�ZGdd�de
j�ZGdd�dej�ZGdd�de
j�ZdS)z$
Tests for L{twisted.conch.telnet}.
�)�absolute_import�division)�implementer)�verifyObject)�defer)�telnet)�unittest)�
proto_helpers)�	iterbytesc@s\eZdZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dS)�TestProtocol�cCs.d|_g|_g|_g|_g|_g|_g|_dS)N�)�data�subcmd�calls�enabledLocal�
enabledRemote�
disabledLocal�disabledRemote��selfrr�@/usr/lib/python3/dist-packages/twisted/conch/test/test_telnet.py�__init__szTestProtocol.__init__csLi}|_�j|d<|j��}|_dD]}|f�fdd�	|tt|�<q(dS)N�)	�NOP�DM�BRK�IP�AO�AYT�EC�EL�GAcs�j�|�S�N)r�append)�arg�cmdrrr�<lambda>-r
z-TestProtocol.makeConnection.<locals>.<lambda>)ZnegotiationMap�neg_TEST_COMMAND�
commandMap�copy�getattrr)r�	transport�dr&rrr�makeConnection's


zTestProtocol.makeConnectioncCs|j|7_dSr#)r�rrrrr�dataReceived0szTestProtocol.dataReceivedcCsdSr#r)r�reasonrrr�connectionLost4szTestProtocol.connectionLostcCs
||_dSr#)r)rZpayloadrrrr(8szTestProtocol.neg_TEST_COMMANDcCs||jkr|j�|�dSdS�NTF)�localEnableablerr$�rZoptionrrr�enableLocal<s
zTestProtocol.enableLocalcCs|j�|�dSr#)rr$r5rrr�disableLocalCszTestProtocol.disableLocalcCs||jkr|j�|�dSdSr3)�remoteEnableablerr$r5rrr�enableRemoteGs
zTestProtocol.enableRemotecCs|j�|�dSr#)rr$r5rrr�
disableRemoteNszTestProtocol.disableRemoteN)�__name__�
__module__�__qualname__r4r8rr.r0r2r(r6r7r9r:rrrrrs	rc@seZdZdd�ZdS)�InterfacesTestscCst��}ttj|�dS)zO
        L{telnet.TelnetProtocol} implements L{telnet.ITelnetProtocol}
        N)rZTelnetProtocolr�ITelnetProtocol)r�prrr�test_interfaceTszInterfacesTests.test_interfaceN)r;r<r=rArrrrr>Ssr>c@s:eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zggggfd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFdG�Z&dHdI�Z'dJS)K�TelnetTransportTestsz.
    Tests for L{telnet.TelnetTransport}.
    cCs(t�t�|_t��|_|j�|j�dSr#)rZTelnetTransportrr@r	�StringTransport�tr.rrrr�setUpas
zTelnetTransportTests.setUpcCsF|jj}ddddddg}|D]}|j�|�q|�|jd�|��dS)Nshere are some bytes la la lassome more arrive hereslots of bytes to play withsla la lasta de dasdumr
)r@�protocolr0�assertEqualr�join�r�h�L�brrr�testRegularBytesgs�z%TelnetTransportTests.testRegularBytescCs�|jj}ddddg}|D]}|j�|�q|�|j|ddd�d|ddd�d	|d
dd�d|ddd�d	�dS)Nshere is the first line
shere is the second line
shere is the third line
shere is the last line
r����
��
��)r@rFr0rGrrIrrr�testNewlineHandlingys*�������z(TelnetTransportTests.testNewlineHandlingcCsH|jj}dddg}|D]}|j�|�q|�|jd�|��dd��dS)Ns*here are some bytes�� with an embedded IACs&and here is a test of a border escape�s� did you get that IAC?r
s����)r@rFr0rGrrH�replacerIrrr�
testIACEscape�s�z"TelnetTransportTests.testIACEscapecCsn|jj}tjtt|�}dd|dg}|D]}|j�|�q,|�|j|g�|�|jd�	|��
|d��dS)NsHere's some bytes, tra la lasBut ono!s
 an interruptr
)r@rFr�IACr+r0rGrrrHrV)rZcmdNamerJr&rKrLrrr�_simpleCommandTest�s
�z'TelnetTransportTests._simpleCommandTestcCs|�d�dS)Nr�rYrrrr�
testInterrupt�sz"TelnetTransportTests.testInterruptcCs|�d�dS)NrrZrrrr�testNoOperation�sz$TelnetTransportTests.testNoOperationcCs|�d�dS)NrrZrrrr�testDataMark�sz!TelnetTransportTests.testDataMarkcCs|�d�dS)NrrZrrrr�	testBreak�szTelnetTransportTests.testBreakcCs|�d�dS)NrrZrrrr�testAbortOutput�sz$TelnetTransportTests.testAbortOutputcCs|�d�dS)NrrZrrrr�testAreYouThere�sz$TelnetTransportTests.testAreYouTherecCs|�d�dS)Nr rZrrrr�testEraseCharacter�sz'TelnetTransportTests.testEraseCharactercCs|�d�dS)Nr!rZrrrr�
testEraseLine�sz"TelnetTransportTests.testEraseLinecCs|�d�dS)Nr"rZrrrr�testGoAhead�sz TelnetTransportTests.testGoAheadcCs||jj}tjtjdtjtj}d|dg}|D]}|j�|�q4|�|jd�	|��
|d��|�|jtt
d���dS)Nshello worldsThese are some bytes but soonsthere will be some morer
shello world)r@rFrrX�SB�SEr0rGrrHrVr�listr
�rrJr&rKrLrrr�testSubnegotiation�s�z'TelnetTransportTests.testSubnegotiationcCs�|jj}tjtjdtjtjtj}d|ddg}|D]}|j�|�q>|�|jd�	|��
|d��|�|jtjg�dS)NrsSome bytes are heresand herer
)r@rFrrXrdrer0rGrrHrVrrgrrr� testSubnegotiationWithEmbeddedSE�s"
����
�z5TelnetTransportTests.testSubnegotiationWithEmbeddedSEcCs�tjtjdtjdtjtj}tt|��D]�}t�}|j_|�	|j�|d|�||d�}}d||dg}|D]}|j�
|�q~|�|jd�
|��|d��|�|jtjgttd���q2dS)Nrshellos
first parts	last partr
)rrXrdre�range�lenrr@rFr.r0rGrrHrVrrfr
)rr&�irJ�arLrKrrrr�testBoundarySubnegotiation�s,
������z/TelnetTransportTests.testBoundarySubnegotiationcCs<|�|j|�|�|j|�|�|j|�|�|j|�dSr#)rGrrrr)r�o�eL�eR�dL�dRrrr�_enabledHelpersz#TelnetTransportTests._enabledHelpercCsrtjtjd}d|d}|j�|�|�|jjj|�|d��|�|j	�
�tjtjd�|�|jj�dS�Nrssurrounding bytessto spice things upr
)
rrX�WILLr@r0rGrFrrVrD�value�DONTrt�rr&rrrr�testRefuseWillsz#TelnetTransportTests.testRefuseWillcCsrtjtjd}d|d}|j�|�|�|jjj|�|d��|�|j	�
�tjtjd�|�|jj�dSru)
rrX�DOr@r0rGrFrrVrDrw�WONTrtryrrr�testRefuseDosz!TelnetTransportTests.testRefuseDocCshtjtjd}d|d}|jj}d|_|j�|�|�|j�	�tjtj
d�|j|dgd�dS)N��paddingstrailer)r~)rp)rrXr{r@rFr4r0rGrDrwrvrt�rr&rrJrrr�testAcceptDo*sz!TelnetTransportTests.testAcceptDocCshtjtjd}d|d}|jj}d|_|j�|�|�|j�	�tjtj
d�|j|dgd�dS)N��sheaderr)r��rq)rrXrvr@rFr8r0rGrDrwr{rtr�rrr�testAcceptWill8sz#TelnetTransportTests.testAcceptWillcCs�tjtjd}|j�d�}d|j_d|}|j�|�|�|jj	j
|�|d��|�|j�
�tjtjd�|�|jjd�|j|jj	dgd�dS)N�)�yess
fiddle deer
�no�rs)rrXr|r@�getOptionState�him�stater0rGrFrrVrDrwrxrt�rr&�srrrr�testAcceptWontEsz#TelnetTransportTests.testAcceptWontcCs�tjtjd}|j�d�}d|j_d|}|j�|�|�|jj	j
|�|d��|�|j�
�tjtjd�|�|jjd�|j|jj	dgd�dS)Nr�r�sfiddle dum r
r�)rr)rrXrxr@r��usr�r0rGrFrrVrDrwr|rtr�rrr�testAcceptDontZsz#TelnetTransportTests.testAcceptDontcCsftjtjd}d|d}|j�|�|�|jjj|�|d��|�|j	�
�d�|�|jj�dS�N�G�
dum de dum�	tra la lar
)rrXr|r@r0rGrFrrVrDrwrtryrrr�testIgnoreWontosz#TelnetTransportTests.testIgnoreWontcCsftjtjd}d|d}|j�|�|�|jjj|�|d��|�|j	�
�d�|�|jj�dSr�)rrXrxr@r0rGrFrrVrDrwrtryrrr�testIgnoreDont|sz#TelnetTransportTests.testIgnoreDontcCsztjtjd}|j�d�}d|j_d|d}|j�|�|�|jj	j
|�|d��|�|j�
�d�|�|jj	�dS�N�Vr�r�r�r
)rrXrvr@r�r�r�r0rGrFrrVrDrwrtr�rrr�testIgnoreWill�sz#TelnetTransportTests.testIgnoreWillcCsztjtjd}|j�d�}d|j_d|d}|j�|�|�|jj	j
|�|d��|�|j�
�d�|�|jj	�dSr�)rrXr{r@r�r�r�r0rGrFrrVrDrwrtr�rrr�testIgnoreDo�sz!TelnetTransportTests.testIgnoreDocsv�j�d�}�jj�d�_���j��tjtj	d��j�
tjtjd�|��jd�|���fdd��|S)N�B�r�Tcs�j�dgd�S)Nr�r�)rt��_�rJrrrr'�r
z@TelnetTransportTests.testAcceptedEnableRequest.<locals>.<lambda>)
r@�dorFr8rGrDrwrrXr{r0rv�addCallback�rr-rr�r�testAcceptedEnableRequest�sz.TelnetTransportTests.testAcceptedEnableRequestcs�d�jj_�j�d�}���j��tjtj	d��j�
d�����jjd����j
jd����jj����j
j��j�tjtjd���|tj�}|��fdd��|���fdd��|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�cs���jj�Sr#�rtr@rF�Zignoredrrrr'�r
z@TelnetTransportTests.test_refusedEnableRequest.<locals>.<lambda>cs���jj�Sr#)�assertFalser��negotiatingr��r�rrrr'�r
)r@rFr8r�rGrDrwrrXr{r�r�r�r��
assertTruer�r�r0r|�
assertFailure�
OptionRefusedr�r�rr�r�test_refusedEnableRequest�s

�z.TelnetTransportTests.test_refusedEnableRequestcs�d�jj_�j�d�}���j��tjtj	d��j�
d�����jjd����j
jd����jj����j
j��j�tjtjd���|tj�}|��fdd��|���fdd��|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�cs���jj�Sr#r�r�rrrr'�r
z>TelnetTransportTests.test_refusedEnableOffer.<locals>.<lambda>cs���jj�Sr#)r�r�r�r�r�rrr'�r
)r@rFr4ZwillrGrDrwrrXrvr�r�r�r�r�r�r�r0rxr�r�r�r�rr�r�test_refusedEnableOffer�s

�z,TelnetTransportTests.test_refusedEnableOffercsz�j�d�}d|j_�j�d�}���j��tj	tj
d��j�tj	tjd�|�
�jd�|�
�fdd��|S)Nr�r�Tcs�j�jjdgd�S)Nr�r�r�r�rrrr's
�zATelnetTransportTests.testAcceptedDisableRequest.<locals>.<lambda>)r@r�r�r��dontrGrDrwrrXrxr0r|r��rr�r-rrr�testAcceptedDisableRequestsz/TelnetTransportTests.testAcceptedDisableRequestcsd�j�d�}d|j_�j�d��fdd�}�fdd�}�fdd�}|d�}|�|�|�|�|S)	N�$r�cs�j�d�}��|tj�S�Nr�)r@r�r�r�AlreadyNegotiating��xr-rrr�_doszITelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._docs�j�d�}��|tj�Sr�)r@r�r�rr�r�rrr�_dont"szKTelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._dontcs~�j�tjtjd��j�jjdgd�d�jj_�j�d�}�j�tjtj	d�|�
�jd�|�
�fdd��|S)Nr�r�)r�Tcs�j�jjdgdgd�S)Nr�)rqrsr�r�rrrr'0s
�z^TelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._final.<locals>.<lambda>)r@r0rrXr|rtrFr8r�rvr�rGr�rrr�_final's
zLTelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._final)r@r�r�r�r�r�)rr�r�r�r�r-rrr�'testNegotiationBlocksFurtherNegotiations

z<TelnetTransportTests.testNegotiationBlocksFurtherNegotiationcCs|j�d�}|�|tj�S)N��)r@r�r�rZAlreadyDisabledr�rrr�#testSuperfluousDisableRequestRaises;sz8TelnetTransportTests.testSuperfluousDisableRequestRaisescCs.|j�d�}d|j_|j�d�}|�|tj�S)Nr�r�)r@r�r�r�r�r�rZAlreadyEnabledr�rrr�"testSuperfluousEnableRequestRaisesAsz7TelnetTransportTests.testSuperfluousEnableRequestRaisescCsx|j�d�}|j�d�}|j�d�}Gdd�dt�}|j�|d��|�||�}|�||�}|�||�}t�|||g�S)Nr�#�4c@seZdZdS)zLTelnetTransportTests.testLostConnectionFailsDeferreds.<locals>.TestExceptionN)r;r<r=rrrr�
TestExceptionNsr�zTotal failure!)r@r��	Exceptionr2r�rZ
gatherResults)rZd1Zd2Zd3r�rrr� testLostConnectionFailsDeferredsIsz5TelnetTransportTests.testLostConnectionFailsDeferredsN)(r;r<r=�__doc__rErMrTrWrYr[r\r]r^r_r`rarbrcrhrirnrtrzr}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrB]sJ

&rBc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�
TestTelnetzP
    A trivial extension of the telnet protocol class useful to unit tests.
    cCstj�|�g|_dSr#)r�Telnetr�eventsrrrrr]szTestTelnet.__init__cCs|j�d|f�dS)z:
        Record the given data in C{self.events}.
        �bytesN�r�r$r/rrr�applicationDataReceivedbsz"TestTelnet.applicationDataReceivedcCs|j�d||f�dS)z=
        Record the given command in C{self.events}.
        �commandNr��rr�rrrr�unhandledCommandiszTestTelnet.unhandledCommandcCs|j�d||f�dS)zL
        Record the given subnegotiation command in C{self.events}.
        �	negotiateNr�r�rrr�unhandledSubnegotiationpsz"TestTelnet.unhandledSubnegotiationN)r;r<r=r�rr�r�r�rrrrr�Ys
r�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"S)#�TelnetTestsz�
    Tests for L{telnet.Telnet}.

    L{telnet.Telnet} implements the TELNET protocol (RFC 854), including option
    and suboption negotiation, and option state tracking.
    cCst�|_dS)zM
        Create an unconnected L{telnet.Telnet} to be used by tests.
        N)r�rFrrrrrEszTelnetTests.setUpcCs|�|j�d��dS)z�
        L{telnet.Telnet.enableLocal} should reject all options, since
        L{telnet.Telnet} does not know how to implement any options.
        �N)r�rFr6rrrr�test_enableLocal�szTelnetTests.test_enableLocalcCs|�|j�d��dS)z�
        L{telnet.Telnet.enableRemote} should reject all options, since
        L{telnet.Telnet} does not know how to implement any options.
        r�N)r�rFr9rrrr�test_enableRemote�szTelnetTests.test_enableRemotecCs|�t|jjd�dS)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�NotImplementedErrorrFr7rrrr�test_disableLocal�szTelnetTests.test_disableLocalcCs|�t|jjd�dS)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)r�r�rFr:rrrr�test_disableRemote�szTelnetTests.test_disableRemotecCs6t��}|j�|�|j�dd�|�|��d�dS)z�
        L{telnet.Telnet.requestNegotiation} formats the feature byte and the
        payload bytes into the subnegotiation format and sends them.

        See RFC 855.
        �ss����N�r	rCrFr.ZrequestNegotiationrGrw�rr,rrr�test_requestNegotiation�s�z#TelnetTests.test_requestNegotiationcCs6t��}|j�|�|j�dd�|�|��d�dS)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.
        r�rUs������Nr�r�rrr�!test_requestNegotiationEscapesIAC�s�z-TelnetTests.test_requestNegotiationEscapesIACcGs,g}|j_|j�|�|�|t|��dS)z
        Pass the given bytes to the protocol's C{dataReceived} method and
        assert that the given events occur.
        N)rFr�r0rGrf)rrZexpectedZreceivedrrr�_deliver�szTelnetTests._delivercCs|�dd�dS)zc
        One application-data byte in the default state gets delivered right
        away.
        �a)r�r�N�r�rrrr�test_oneApplicationDataByte�sz'TelnetTests.test_oneApplicationDataBytecCs|�dd�dS)za
        Two application-data bytes in the default state get delivered
        together.
        �bc)r�r�Nr�rrrr�test_twoApplicationDataBytes�sz(TelnetTests.test_twoApplicationDataBytescCs|�dtjd�dS)z~
        Three application-data bytes followed by a control byte get
        delivered, but the control byte doesn't.
        �def)r�r�N�r�rrXrrrr�test_threeApplicationDataBytes�sz*TelnetTests.test_threeApplicationDataBytescCs,|�tj�|�tjddtjdf�dS)zy
        IAC in the escaped state gets delivered and so does another
        application-data byte following it.
        �gr�Nr�rrrr�test_escapedControl�szTelnetTests.test_escapedControlcCs�|�d�|�dd�|�dd�|�d�|�dd�|�dd�|�d�|�dd	�|�d
d	�|�d�|�tjtjdddtjdf�d
S)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.
        rQrO)r�rOs
r�)r�rQs
r�)r��
ar��xr�Nr�rrrr�test_carriageReturn�s




�zTelnetTests.test_carriageReturncCs&|�dtjtjddtjdf�dS)zt
        Application bytes received before a command are delivered before the
        command is processed.
        r�)r�r�r�N)r�rrXrrrrr�'test_applicationDataBeforeSimpleCommands

�z3TelnetTests.test_applicationDataBeforeSimpleCommandcCs2i|j_|�dtjtjdddtjdf�dS)z~
        Application bytes received before a WILL/WONT/DO/DONT are delivered
        before the command is processed.
        �yr�)r�r�r�N)rFr)r�rrXrvrrrr�!test_applicationDataBeforeCommands
�z-TelnetTests.test_applicationDataBeforeCommandcCs6|�dtjtjdtjtjddddgf�dS)z�
        Application bytes received before a subnegotiation command are
        delivered before the negotiation is processed.
        �zsQx)r�r�r��Qr�N)r�rrXrdrerrrr�(test_applicationDataBeforeSubnegotiation$s

�z4TelnetTests.test_applicationDataBeforeSubnegotiationN)r;r<r=r�rEr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�xs"


	
r�N)r�Z
__future__rrZzope.interfacerZzope.interface.verifyrZtwisted.internetrZ
twisted.conchrZ
twisted.trialrZtwisted.testr	Ztwisted.python.compatr
r?rZTestCaser>rBr�r�r�rrrr�<module>s$;