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: //proc/self/root/lib/python3/dist-packages/twisted/test/__pycache__/test_protocols.cpython-38.pyc
U


W[�@s�dZddlmZddlmZmZddlmZddlm	Z	m
Z
mZmZddl
mZGdd�dej�ZGd	d
�d
ej�ZGdd�dej�ZGd
d�dej�ZGdd�dej�ZdS)z+
Test cases for twisted.protocols package.
�)�unittest)�wire�portforward)�	iterbytes)�reactor�defer�address�protocol)�
proto_helpersc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�	WireTestsz
    Test wire protocols.
    cCs`t��}t��}|�|�|�d�|�d�|�d�|�d�|�d�|�|��d�dS)zT
        Test wire.Echo protocol: send some data and check it send it back.
        �hello�world�how�are�youshelloworldhowareyouN)r
�StringTransportr�Echo�makeConnection�dataReceived�assertEqual�value��self�t�a�r�=/usr/lib/python3/dist-packages/twisted/test/test_protocols.py�	test_echos





zWireTests.test_echocCs.t��}t��}|�|�|�|��d�dS)z)
        Test wire.Who protocol.
        sroot
N)r
rrZWhorrrrrrr�test_who#s
zWireTests.test_whocCs.t��}t��}|�|�|�|��d�dS)z*
        Test wire.QOTD protocol.
        s'An apple a day keeps the doctor away.
N)r
rrZQOTDrrrrrrr�	test_QOTD-s

�zWireTests.test_QOTDcCs`t��}t��}|�|�|�d�|�d�|�d�|�d�|�d�|�|��d�dS)z-
        Test wire.Discard protocol.
        rr
rrr�N)r
rrZDiscardrrrrrrrr�test_discard8s





zWireTests.test_discardN)�__name__�
__module__�__qualname__�__doc__rrrr!rrrrrs

rc@seZdZdZdd�ZdS)�TestableProxyClientFactoryz�
    Test proxy client factory that keeps the last created protocol instance.

    @ivar protoInstance: the last instance of the protocol.
    @type protoInstance: L{portforward.ProxyClient}
    cCstj�||�}||_|S)zE
        Create the protocol instance and keeps track of it.
        )r�ProxyClientFactory�
buildProtocol�
protoInstance�r�addr�protorrrr(Psz(TestableProxyClientFactory.buildProtocolN�r"r#r$r%r(rrrrr&Hsr&c@seZdZdZdd�ZdS)�TestableProxyFactoryal
    Test proxy factory that keeps the last created protocol instance.

    @ivar protoInstance: the last instance of the protocol.
    @type protoInstance: L{portforward.ProxyServer}

    @ivar clientFactoryInstance: client factory used by C{protoInstance} to
        create forward connections.
    @type clientFactoryInstance: L{TestableProxyClientFactory}
    cs.tj��|�}t��_�fdd�|_|�_|S)z�
        Create the protocol instance, keeps track of it, and makes it use
        C{clientFactoryInstance} as client factory.
        cs�jS�N)�clientFactoryInstancer�rrr�<lambda>nr z4TestableProxyFactory.buildProtocol.<locals>.<lambda>)r�ProxyFactoryr(r&r0ZclientProtocolFactoryr)r*rr1rr(fs
z"TestableProxyFactory.buildProtocolNr-rrrrr.Zsr.c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�PortforwardingTestsz
    Test port forwarding.
    cCst��|_t��|_g|_dSr/)rr�serverProtocolr	ZProtocol�clientProtocol�	openPortsr1rrr�setUpys

zPortforwardingTests.setUpcCs�z|jjj��Wntk
r&YnXz|jjj}|j��Wntk
rTYnXz|jj��Wntk
rzYnXz|jj��Wntk
r�YnXt�	dd�|j
D��S)NcSsg|]}t�|j��qSr)rZ
maybeDeferredZ
stopListening)�.0�prrr�
<listcomp>�sz0PortforwardingTests.tearDown.<locals>.<listcomp>)�proxyServerFactoryr)�	transportZloseConnection�AttributeErrorr0r6r5rZ
gatherResultsr7)rZpirrr�tearDowns(
�zPortforwardingTests.tearDowncs�t��}�fdd�|_tjd|dd�}�j�|�td|��j��_	tjd�j	dd�}�j�|�d�g�t
�������fdd�}|�j_
��fd	d
�}|�j_t��}�fdd�|_t�d|��j|��S)z=
        Test port forwarding through Echo protocol.
        cs�jSr/)r5rr1rrr2�r z6PortforwardingTests.test_portforward.<locals>.<lambda>r�	127.0.0.1)Z	interfacei�cs>��t|��t���kr:��d���d����d�dS)Nr �x)�extendr�lenr�join�callback)�data��d�nBytesZreceivedrrr�testDataReceived�sz>PortforwardingTests.test_portforward.<locals>.testDataReceivedcs�jj�d��dS)NrA)r6r=�writer)rIrrr�testConnectionMade�sz@PortforwardingTests.test_portforward.<locals>.testConnectionMadecs�jSr/)r6rr1rrr2�r )r	Z
ServerFactoryrZ	listenTCPr7�appendr.ZgetHost�portr<rZDeferredr6rZconnectionMadeZ
ClientFactoryZ
connectTCP)rZrealServerFactoryZrealServerPortZproxyServerPortrJrL�
clientFactoryrrGr�test_portforward�s8��
��z$PortforwardingTests.test_portforwardcCs�t�ddd�}t�dd��|�}t��}||_t��}|�	|�|�
t|j�d�|jd\}}}}}	|�
|tj�|�|�}
t��}|
�	|�|�|j|�|�|j|�|�|j�|�|j�dS)zm
        The proxy client registers itself as a producer of the proxy server and
        vice versa.
        ZTCPr@r�N)rZIPv4Addressrr3r(r
Z
MemoryReactorrrrrrCZ
tcpClientsZassertIsInstancer'ZassertIsZproducerZ
assertTrueZ	streaming)rr+ZserverrZserverTransportZhostrNrOZtimeout�_ZclientZclientTransportrrr�test_registerProducers�s 


z*PortforwardingTests.test_registerProducersN)r"r#r$r%r8r?rPrSrrrrr4ts
)r4c@seZdZdZdd�ZdS)�StringTransportTestszA
    Test L{proto_helpers.StringTransport} helper behaviour.
    cCst��}|�t|jd�dS)zY
        Test that L{proto_helpers.StringTransport} doesn't accept unicode data.
        ZfooN)r
rZassertRaises�	TypeErrorrK)r�srrr�test_noUnicode�sz#StringTransportTests.test_noUnicodeN)r"r#r$r%rWrrrrrT�srTN)r%Z
twisted.trialrZtwisted.protocolsrrZtwisted.python.compatrZtwisted.internetrrrr	Ztwisted.testr
ZTestCaserr'r&r3r.r4rTrrrr�<module>s9o