%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/conch/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/conch/test/__pycache__/test_channel.cpython-312.pyc

�

Ϫ�f2���dZddlmZddlmZddlmZ	ddlmZddl	m
Z
ddlmZddl
mZdd	lmZdd
lmZddlmZdZddlmZGd�de�Z		d							dd�Zeee�Gd�de��Zy#e$rd
ZeZY�BwxYw)z
Test ssh/channel.py.
�)�annotations)�skipIf)�verifyObject)�channel)�SSHTransportAddress)�
SSHService)�SSHServerTransport)�
interfaces)�IPv4Address)�StringTransport�zConch SSH not supported.)�TestCasec�H�eZdZdZdd�Zd	d�Zd
d�Z								dd�Zdd�Zy)
�MockConnectiona�
    A mock for twisted.conch.ssh.connection.SSHConnection.  Record the data
    that channels send, and when they try to close the connection.

    @ivar data: a L{dict} mapping channel id #s to lists of data sent by that
        channel.
    @ivar extData: a L{dict} mapping channel id #s to lists of 2-tuples
        (extended data type, data) sent by that channel.
    @ivar closes: a L{dict} mapping channel id #s to True if that channel sent
        a close message.
    c�.�i|_i|_i|_y)N)�data�extData�closes��selfs �A/usr/lib/python3/dist-packages/twisted/conch/test/test_channel.py�__init__zMockConnection.__init__*s��;=��	�JL���68���c��y)z,
        Return our logging prefix.
        r�rs r�	logPrefixzMockConnection.logPrefix/s�� rc�Z�|jj|g�j|�y)z'
        Record the sent data.
        N)r�
setdefault�append)rrrs   r�sendDatazMockConnection.sendData5s#��	
�	�	���W�b�)�0�0��6rc�^�|jj|g�j||f�y)z0
        Record the sent extended data.
        N)rrr)rr�typers    r�sendExtendedDatazMockConnection.sendExtendedData;s'��	
�������,�3�3�T�4�L�Arc�"�d|j|<y)z?
        Record that the channel sent a close message.
        TN)r)rrs  r�	sendClosezMockConnection.sendCloseCs�� $����G�rN��return�None)r'�str)r�channel.SSHChannelr�bytesr'r()rr*r"�intrr+r'r()rr*r'r()	�__name__�
__module__�__qualname__�__doc__rrr r#r%rrrrrsE��
�9�
 �7�B�)�B�14�B�<A�B�	
�B�$rrNc�r�t�}|jt||���|j|�y)a�
    Connect a SSHTransport which is already connected to a remote peer to
    the channel under test.

    @param service: Service used over the connected transport.
    @type service: L{SSHService}

    @param hostAddress: Local address of the connected transport.
    @type hostAddress: L{interfaces.IAddress}

    @param peerAddress: Remote address of the connected transport.
    @type peerAddress: L{interfaces.IAddress}
    )�hostAddress�peerAddressN)r	�makeConnectionr�
setService)�servicer2r3�	transports    r�connectSSHTransportr8Js4��$#�$�I�
����K�[�I������!rc��eZdZdZdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z	dd�Z
dd	�Zdd
�Zdd�Z
dd�Zdd
�Zdd�Zdd�Zdd�Zy)�ChannelTestsz"
    Tests for L{SSHChannel}.
    c��t�|_tj|jd��|_d|j_y)z�
        Initialize the channel.  remoteMaxPacket is 10 so that data is able
        to be sent (the default of 0 means no data is sent because no packets
        are made).
        �
)�conn�remoteMaxPacketschannelN)rr=r�
SSHChannel�namers r�setUpzChannelTests.setUpis2��#�$��	��)�)�t�y�y�"�M���&����rc�j�|jttj|j��y)zK
        L{SSHChannel} instances provide L{interfaces.ITransport}.
        N)�
assertTruerr
�
ITransportrrs r�test_interfacezChannelTests.test_interfacess!��	
����Z�%:�%:�D�L�L�I�Jrc	�
�tj|j��}|j|jd�|j|j
d�|j|jd�|j|jd�|j|jd�|j|j|j�|j|j�|j|j�tjddddd	d
d�}|j|jd�|j|j
d�|j|jd�|j|jd�|j|jd�|j|jd	�|j|jd
�|j|jd�y)
a�
        Test that SSHChannel initializes correctly.  localWindowSize defaults
        to 131072 (2**17) and localMaxPacket to 32768 (2**15) as reasonable
        defaults (what OpenSSH uses for those variables).

        The values in the second set of assertions are meaningless; they serve
        only to verify that the instance variables are assigned in the correct
        order.
        )r=ii�r�������N)rr?r=�assertEqual�localWindowSize�localWindowLeft�localMaxPacket�remoteWindowLeftr>�assertIsNoner�avatar)r�c�c2s   r�	test_initzChannelTests.test_initys���
���D�I�I�.������*�*�F�3�����*�*�F�3�����)�)�5�1�����+�+�Q�/�����*�*�A�.����������+����!�&�&�!����!�(�(�#�
�
�
��1�a��A�q�!�
4������+�+�Q�/�����+�+�Q�/�����*�*�A�.�����,�,�a�0�����+�+�Q�/�������!�$�������!�$�������A�&rc��|jt|j�d�|jttjd���d�y)z{
        Test that str(SSHChannel) works gives the channel name and local and
        remote windows at a glance..
        z%<SSHChannel channel (lw 131072 rw 0)>rG��localWindowz<SSHChannel None (lw 1 rw 0)>N)rNr)rr?rs r�test_strzChannelTests.test_str�sB��
	
����T�\�\�*�,S�T������"�"�q�1�2�4S�	
rc��|j|jj�d�|jtjd��j�d�y)z
        Test that bytes(SSHChannel) works, gives the channel name and
        local and remote windows at a glance..

        s%<SSHChannel channel (lw 131072 rw 0)>rGrYs<SSHChannel None (lw 1 rw 0)>N)rNr�	__bytes__r?rs r�
test_byteszChannelTests.test_bytes�sO��	
����L�L�"�"�$�&N�	
�	
������1�-�7�7�9�,�	
rc�X�|j|jj�d�y)z�
        Test that SSHChannel.logPrefix gives the name of the channel, the
        local channel ID and the underlying connection.
        z.SSHChannel channel (unknown) on MockConnectionN)rNrrrs r�test_logPrefixzChannelTests.test_logPrefix�s%��
	
����L�L�"�"�$�&V�	
rc�4��dg�d
�fd�}||j_|jjd�|jjdd�|jj	d�|j|jjd�|j|jj�|j�d�|j|jjd�|j|jj|jdg�|j|jjg�|j|jj|jd	g�d�d<|jj	d
�|j�d�|jjd�|jj�|jj	d
�|j�d�y)zq
        Test that addWindowBytes adds bytes to the window and resumes writing
        if it was paused.
        Fc���d�d<y�NTrr��cbs�r�stubStartWritingz:ChannelTests.test_addWindowBytes.<locals>.stubStartWriting������B�q�Er�testrG�2�*rr)rGrh�sPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaNr&)r�startWriting�write�
writeExtended�addWindowBytesrNrRrC�
areWriting�bufr=r�extBufr�assertFalse�loseConnection)rrfres  @r�test_addWindowBytesz ChannelTests.test_addWindowBytes�s����
�W��	�%5����!������7�#����"�"�1�g�.����#�#�B�'�������6�6�
�C�������/�/�0�����1���������)�)�3�/������������5��y�A�������,�,�b�1�������*�*�4�<�<�8�<�.�I���1�����#�#�B�'�����A��������9�%����#�#�%����#�#�B�'�����A��rc�*�d�|j_|j|jjdd��|j	|jjdd��|j	|jjdd��y)zn
        Test that requestReceived handles requests by dispatching them to
        request_* methods.
        c��|dk(S)Nrr)rs r�<lambda>z3ChannelTests.test_requestReceived.<locals>.<lambda>�s
�����rstest-methodr�as
bad-methodN)r�request_test_methodrC�requestReceivedrsrs r�test_requestReceivedz!ChannelTests.test_requestReceived�sl��
,D����(�������4�4�^�S�I�J�������5�5�n�d�K�L�������5�5�m�S�I�Jrc���|j|jj�|jj�|j	|jj�y)zM
        Test that the default closeReceieved closes the connection.
        N)rsr�closing�
closeReceivedrCrs r�test_closeReceievedz ChannelTests.test_closeReceieved�sB��	
������-�-�.����"�"�$�������,�,�-rc�Z��dg�d�fd�}||j_|jjd�|jjd�|j|jj�|j�d�|jj
d�|jjd�|jj|j}|j|ddg�|j|jjd	�|jjd
�|j|gd��|j|jjd�d�d<|jjd
�|j|jj�|j�d�|j|gd��|j|jjd�|j|jjd�y)z�
        Test that write handles data correctly.  Send data up to the size
        of the remote window, splitting the data into packets of length
        remoteMaxPacket.
        Fc���d�d<yrcrrds�r�stubStopWritingz0ChannelTests.test_write.<locals>.stubStopWriting�rgr�dryrrk�ta�da��12345678901)r�r��
1234567890�1rK�123456)r�r�r�r��12345�6Nr&)r�stopWritingrmrsrprCror=rrNrRrq�rr�rres   @r�
test_writezChannelTests.test_write�s�����W��	�$3���� ������4� ������4� �������0�0�1�����1������#�#�B�'������5�!��y�y�~�~�d�l�l�+�������u�~�.�������6�6��;������>�*�����B�C�������6�6��:���1�������9�%�������0�0�1�����1�������L�M�������)�)�4�0�������6�6��:rc���dg�d�fd�}||j_|jjdd�|jjdd�|jjdd�|j|jj�|j�d�|jj
d	�|jjdd�|jj|j}|j|gd
��|j|jjd�|jjdd
�|j|gd��|j|jjd�d�d<|jjdd�|j|jj�|j�d�|j|gd��|j|jjddgg�|j|jjd�y)z�
        Test that writeExtended handles data correctly.  Send extended data
        up to the size of the window, splitting the extended data into packets
        of length remoteMaxPacket.
        Fc���d�d<yrcrrds�rr�z8ChannelTests.test_writeExtended.<locals>.stubStopWritingrgrrGr�ryrH�trrk)�rGr��rHr��rHryr�rIr�)r�r�r��rIr��rIr�rKrJr�)r�r�r�r�r�)rJr�r�Nr&)rr�rnrsrprCror=rrNrRrrr�s   @r�test_writeExtendedzChannelTests.test_writeExtended
s�����W��	�$3���� ����"�"�1�d�+����"�"�1�d�+����"�"�1�d�+�������0�0�1�����1������#�#�B�'����"�"�1�d�+��y�y� � ����.������A�B�������6�6��;����"�"�1�n�5�����S�	
�	
������6�6��:���1�����"�"�1�i�0�������0�0�1�����1�������
�
	
�	
������,�,��4�y�k�:�������6�6��:rc��|jjd�|jjd�td�D��|j	|j
j|jdg�y)zS
        Test that writeSequence is equivalent to write(''.join(sequece)).
        rkc3�(K�|]
}d|fz���y�w)s%dNr)�.0�is  r�	<genexpr>z2ChannelTests.test_writeSequence.<locals>.<genexpr>Cs����"C�A�5�A�4�<�"C�s�r<s
0123456789N)rro�
writeSequence�rangerNr=rrs r�test_writeSequencezChannelTests.test_writeSequence>sU��	
���#�#�B�'����"�"�"C��r��"C�C������������5�
��Grc��|jjd�|jjdd�|jj�|j	|j
jj|j��|jjd�|j	|j
jj|j��|jjd�|j|j
jj|j��y)zk
        Tesyt that loseConnection() doesn't close the channel until all
        the data is sent.
        sdatarGsdatadatarJ�N)
rrmrnrtrSr=r�getrorCrs r�test_loseConnectionz ChannelTests.test_loseConnectionFs���
	
�����7�#����"�"�1�k�2����#�#�%����$�)�)�*�*�.�.�t�|�|�<�=����#�#�A�&����$�)�)�*�*�.�.�t�|�|�<�=����#�#�A�&�����	�	�(�(�,�,�T�\�\�:�;rc���tddd�}t|jj|��|j	t|�|jj
��y)z�
        L{SSHChannel.getPeer} returns the same object as the underlying
        transport's C{getPeer} method returns.
        �TCPz192.168.0.1i1�)r6r3N)rr8rr=rNr�getPeer)r�peers  r�test_getPeerzChannelTests.test_getPeerTsI��
�5�-��7���D�L�L�$5�$5�4�H����,�T�2�D�L�L�4H�4H�4J�Krc���tddd�}t|jj|��|j	t|�|jj
��y)z�
        L{SSHChannel.getHost} returns the same object as the underlying
        transport's C{getHost} method returns.
        r�z	127.0.0.1i90)r6r2N)rr8rr=rNr�getHost)r�hosts  r�test_getHostzChannelTests.test_getHost^sI��
�5�+�u�5���D�L�L�$5�$5�4�H����,�T�2�D�L�L�4H�4H�4J�KrNr&)r-r.r/r0rArErWr[r^r`rur|r�r�r�r�r�r�r�rrrr:r:csY���'�K�'�<
�
�
� �>K�.�";�H/;�bH�<�L�Lrr:)NN)r6rr2�interfaces.IAddress | Noner3r�r'r()r0�
__future__r�unittestr�zope.interface.verifyr�twisted.conch.sshr�twisted.conch.ssh.addressr�twisted.conch.ssh.servicer�twisted.conch.ssh.transportr	�twisted.internetr
�twisted.internet.addressr�twisted.internet.testingr�skipTest�ImportError�object�twisted.trial.unittestrrr8r:rrr�<module>r�s����#��.��)�=�4�>�+�4�8��H�,�*$�Z�*$�^/3�.2�"�
�"�+�"�,�"�
�	"�2��(��BL�8�BL��BL��[��)�H��J��s�,A9�9	B�B

Zerion Mini Shell 1.0