AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/twisted/internet/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3/dist-packages/twisted/internet/test/__pycache__/test_protocol.cpython-310.pyc
o

�bXH�@s�dZddlmZddlmZddlmZddlmZddl	m
Z
mZmZm
Z
ddlmZmZmZmZmZmZddlmZmZdd	lmZdd
lmZmZddlmZGdd
�d
e�ZGdd�de�Z Gdd�de�Z!Gdd�de�Z"Gdd�de�Z#dS)z)
Tests for L{twisted.internet.protocol}.
�)�BytesIO)�implementer)�verifyObject)�CancelledError)�	IConsumer�ILoggingContext�	IProtocol�IProtocolFactory)�
ClientCreator�ConsumerToProtocolAdapter�Factory�FileWrapper�Protocol�ProtocolToConsumerAdapter)�LogLevel�globalLogPublisher)�Failure)�MemoryReactorClock�StringTransport)�TestCasec@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)#�ClientCreatorTestsz?
    Tests for L{twisted.internet.protocol.ClientCreator}.
    cCsDGdd�dt�}t�}t||�}|||�}|�d�}|�||�dS)a
        Helper for implementing a test to verify that one of the I{connect}
        methods of L{ClientCreator} passes the right arguments to the right
        reactor method.

        @param check: A function which will be invoked with a reactor and a
            L{ClientCreator} instance and which should call one of the
            L{ClientCreator}'s I{connect} methods and assert that all of its
            arguments except for the factory are passed on as expected to the
            reactor.  The factory should be returned.
        c@�eZdZdS)z:ClientCreatorTests._basicConnectTest.<locals>.SomeProtocolN��__name__�
__module__�__qualname__�rr�E/usr/lib/python3/dist-packages/twisted/internet/test/test_protocol.py�SomeProtocol5�rN)rrr
�
buildProtocol�assertIsInstance)�self�checkr�reactor�cc�factory�protocolrrr�_basicConnectTest(s



z$ClientCreatorTests._basicConnectTestc��fdd�}��|�dS)z�
        L{ClientCreator.connectTCP} calls C{reactor.connectTCP} with the host
        and port information passed to it, and with a factory which will
        construct the protocol passed to L{ClientCreator.__init__}.
        csX|�dddd�|j��\}}}}}��|d���|d���|d���|d�|S)N�example.com����)z1.2.3.4i�&)�
connectTCP�
tcpClients�pop�assertEqual)r$r%�host�portr&�timeout�bindAddress�r"rrr#Esz1ClientCreatorTests.test_connectTCP.<locals>.checkN�r(�r"r#rr5r�test_connectTCP>s	z"ClientCreatorTests.test_connectTCPcr))z�
        L{ClientCreator.connectUNIX} calls C{reactor.connectUNIX} with the
        filename passed to it, and with a factory which will construct the
        protocol passed to L{ClientCreator.__init__}.
        csF|�ddd�|j��\}}}}��|d���|d���|�|S)N�/foo/bar�{T)�connectUNIX�unixClientsr/r0�
assertTrue)r$r%�addressr&r3�checkPIDr5rrr#Ws
z2ClientCreatorTests.test_connectUNIX.<locals>.checkNr6r7rr5r�test_connectUNIXPsz#ClientCreatorTests.test_connectUNIXcr))z�
        L{ClientCreator.connectSSL} calls C{reactor.connectSSL} with the host,
        port, and context factory passed to it, and with a factory which will
        construct the protocol passed to L{ClientCreator.__init__}.
        c	snt�}|�dd|dd�|j��\}}}}}}��|d���|d���||���|d���|d�|S)Nr*r+r,)z4.3.2.1i.)�object�
connectSSL�
sslClientsr/r0�assertIs)	r$r%�expectedContextFactoryr1r2r&�contextFactoryr3r4r5rrr#hs$
�
�z1ClientCreatorTests.test_connectSSL.<locals>.checkNr6r7rr5r�test_connectSSLasz"ClientCreatorTests.test_connectSSLcCsNt�}t|t�}||�}|j��}|�|j�|��|�|j�|�	|t
�S)a
        Helper for implementing a test to verify that cancellation of the
        L{Deferred} returned by one of L{ClientCreator}'s I{connect} methods is
        implemented to cancel the underlying connector.

        @param connect: A function which will be invoked with a L{ClientCreator}
            instance as an argument and which should call one its I{connect}
            methods and return the result.

        @return: A L{Deferred} which fires when the test is complete or fails if
            there is a problem.
        )rr
r�
connectorsr/�assertFalse�
_disconnected�cancelr=�
assertFailurer�r"�connectr$r%�d�	connectorrrr�_cancelConnectTest~s

z%ClientCreatorTests._cancelConnectTestcC�dd�}|�|�S)��
        The L{Deferred} returned by L{ClientCreator.connectTCP} can be cancelled
        to abort the connection attempt before it completes.
        cSs|�dd�S�Nr*r+)r-�r%rrrrN�sz9ClientCreatorTests.test_cancelConnectTCP.<locals>.connect�rQ�r"rNrrr�test_cancelConnectTCP��
z(ClientCreatorTests.test_cancelConnectTCPcCrR)rScSs
|�d�S�Nr9)r;rUrrrrN�s
z:ClientCreatorTests.test_cancelConnectUNIX.<locals>.connectrVrWrrr�test_cancelConnectUNIX�rYz)ClientCreatorTests.test_cancelConnectUNIXcCrR)rScSs|�ddt��SrT)rBrArUrrrrN��z9ClientCreatorTests.test_cancelConnectSSL.<locals>.connectrVrWrrr�test_cancelConnectSSL�rYz(ClientCreatorTests.test_cancelConnectSSLcCsht�}t|t�}|||�}|j��}|�t|���d�|��|�|��g�|�	|j
�|�|t�S)z�
        Like L{_cancelConnectTest}, but for the case where the L{Deferred} is
        cancelled after the connection is set up but before it is fired with the
        resulting protocol instance.
        �)
rr
rrHr/r0�len�getDelayedCallsrKr=rJrLrrMrrr�_cancelConnectTimeoutTest�s


z,ClientCreatorTests._cancelConnectTimeoutTestcCrR)a�
        L{ClientCreator.connectTCP} inserts a very short delayed call between
        the time the connection is established and the time the L{Deferred}
        returned from one of its connect methods actually fires.  If the
        L{Deferred} is cancelled in this interval, the established connection is
        closed, the timeout is cancelled, and the L{Deferred} fails with
        L{CancelledError}.
        c
Ss>|�dd�}|j��\}}}}}|�d�}t�}	|�|	�|SrT)r-r.r/r r�makeConnection)
r$r%rOr1r2r&r3r4r'�	transportrrrrN�s

z@ClientCreatorTests.test_cancelConnectTCPTimeout.<locals>.connect�rarWrrr�test_cancelConnectTCPTimeout��

z/ClientCreatorTests.test_cancelConnectTCPTimeoutcCrR)a�
        L{ClientCreator.connectUNIX} inserts a very short delayed call between
        the time the connection is established and the time the L{Deferred}
        returned from one of its connect methods actually fires.  If the
        L{Deferred} is cancelled in this interval, the established connection is
        closed, the timeout is cancelled, and the L{Deferred} fails with
        L{CancelledError}.
        c	Ss:|�d�}|j��\}}}}|�d�}t�}|�|�|SrZ)r;r<r/r rrb)	r$r%rOr>r&r3r4r'rcrrrrN�s


zAClientCreatorTests.test_cancelConnectUNIXTimeout.<locals>.connectrdrWrrr�test_cancelConnectUNIXTimeout�rfz0ClientCreatorTests.test_cancelConnectUNIXTimeoutcCrR)a�
        L{ClientCreator.connectSSL} inserts a very short delayed call between
        the time the connection is established and the time the L{Deferred}
        returned from one of its connect methods actually fires.  If the
        L{Deferred} is cancelled in this interval, the established connection is
        closed, the timeout is cancelled, and the L{Deferred} fails with
        L{CancelledError}.
        cSsD|�ddt��}|j��\}}}}}}|�d�}	t�}
|	�|
�|SrT)rBrArCr/r rrb)r$r%rOr1r2r&rFr3�bindADdressr'rcrrrrNs�

z@ClientCreatorTests.test_cancelConnectSSLTimeout.<locals>.connectrdrWrrr�test_cancelConnectSSLTimeout�s

z/ClientCreatorTests.test_cancelConnectSSLTimeoutcCstt�}t|t�}|||�\}}|j��}|�|ttd���|�t	|�
��d�|��|�|�
�g�|�|t
�S)z�
        Like L{_cancelConnectTest}, but for the case where the L{Deferred} is
        cancelled after the connection attempt has failed but before it is fired
        with the resulting failure.
        zSimulated failurer^)rr
rrHr/�clientConnectionFailedr�	Exceptionr0r_r`rKrLr)r"rNr$r%rOr&rPrrr�_cancelConnectFailedTimeoutTests

�z2ClientCreatorTests._cancelConnectFailedTimeoutTestcCrR)zz
        Similar to L{test_cancelConnectTCPTimeout}, but for the case where the
        connection attempt fails.
        cSs(|�dd�}|j��\}}}}}||fSrT)r-r.r/)r$r%rOr1r2r&r3r4rrrrN2szFClientCreatorTests.test_cancelConnectTCPFailedTimeout.<locals>.connect�rlrWrrr�"test_cancelConnectTCPFailedTimeout,�
z5ClientCreatorTests.test_cancelConnectTCPFailedTimeoutcCrR)z{
        Similar to L{test_cancelConnectUNIXTimeout}, but for the case where the
        connection attempt fails.
        cSs$|�d�}|j��\}}}}||fSrZ)r;r<r/)r$r%rOr>r&r3r4rrrrN?s
zGClientCreatorTests.test_cancelConnectUNIXFailedTimeout.<locals>.connectrmrWrrr�#test_cancelConnectUNIXFailedTimeout9roz6ClientCreatorTests.test_cancelConnectUNIXFailedTimeoutcCrR)zz
        Similar to L{test_cancelConnectSSLTimeout}, but for the case where the
        connection attempt fails.
        c	Ss.|�ddt��}|j��\}}}}}}||fSrT)rBrArCr/)	r$r%rOr1r2r&rFr3rhrrrrNLs�zFClientCreatorTests.test_cancelConnectSSLFailedTimeout.<locals>.connectrmrWrrr�"test_cancelConnectSSLFailedTimeoutFs
z5ClientCreatorTests.test_cancelConnectSSLFailedTimeoutN)rrr�__doc__r(r8r@rGrQrXr[r]rarergrirlrnrprqrrrrr#s$

rc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�
ProtocolTestsz:
    Tests for L{twisted.internet.protocol.Protocol}.
    cC�*t�}|�tt|��|�tt|��dS)zT
        L{Protocol} instances provide L{IProtocol} and L{ILoggingContext}.
        N)rr=rrr)r"�protorrr�test_interfaces`szProtocolTests.test_interfacescC�&Gdd�dt�}|�d|����dS)zJ
        L{Protocol.logPrefix} returns the protocol class's name.
        c@r)z/ProtocolTests.test_logPrefix.<locals>.SomeThingNrrrrr�	SomeThingmrrxN)rr0�	logPrefix)r"rxrrr�test_logPrefixh�zProtocolTests.test_logPrefixcs@g�G�fdd�dt�}t�}|�}|�|�|��|g�dS)zz
        L{Protocol.makeConnection} sets the given transport on itself, and
        then calls C{connectionMade}.
        c�eZdZ�fdd�ZdS)z7ProtocolTests.test_makeConnection.<locals>.SomeProtocolcs��|j�dS�N)�appendrcr5��resultrr�connectionMadezr\zFProtocolTests.test_makeConnection.<locals>.SomeProtocol.connectionMadeN)rrrr�rrrrrysrN)rrArbr0)r"rrcr'rrr�test_makeConnectionrs
z!ProtocolTests.test_makeConnectionN)rrrrrrvrzr�rrrrrs[s

rsc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�FactoryTestsz(
    Tests for L{protocol.Factory}.
    cCrt)zg
        L{Factory} instances provide both L{IProtocolFactory} and
        L{ILoggingContext}.
        N)rr=rr	r)r"r&rrrrv�szFactoryTests.test_interfacescCrw)zM
        L{Factory.logPrefix} returns the name of the factory class.
        c@r)z6FactoryTests.test_logPrefix.<locals>.SomeKindOfFactoryNrrrrr�SomeKindOfFactory�rr�N)rr0ry)r"r�rrrrz�r{zFactoryTests.test_logPrefixcCsDGdd�dt�}t�}||_|�d�}|�||�|�|j|�dS)z�
        L{Factory.buildProtocol} by default constructs a protocol by calling
        its C{protocol} attribute, and attaches the factory to the result.
        c@r)z<FactoryTests.test_defaultBuildProtocol.<locals>.SomeProtocolNrrrrrr�rrN)rrr'r r!rDr&)r"r�fr'rrr�test_defaultBuildProtocol�s
z&FactoryTests.test_defaultBuildProtocolcCsTGdd�dt�}|jtdddd�}|�|jt�|�|jd�|�|jddi�d	S)
z�
        L{Factory.forProtocol} constructs a Factory, passing along any
        additional arguments, and sets its C{protocol} attribute to the given
        Protocol subclass.
        c@seZdZdd�ZdS)z7FactoryTests.test_forProtocol.<locals>.ArgTakingFactoryc_s|||_|_dSr})�args�kwargs)r"r�r�rrr�__init__�sz@FactoryTests.test_forProtocol.<locals>.ArgTakingFactory.__init__N)rrrr�rrrr�ArgTakingFactory�sr�r^��)�foo)r^r�r�N)r�forProtocolrr0r'r�r�)r"r�r&rrr�test_forProtocol�s
zFactoryTests.test_forProtocolcsrg�t��j�|��fdd��t�}|��|��dd|�|��ddtj	�|��ddd�dS)	z�
        L{Factory.doStart} logs that it is starting a factory, followed by
        the L{repr} of the L{Factory} instance that is being started.
        c�t��j�Sr}�r�removeObserverr~r��eventsrr�<lambda>��z;FactoryTests.test_doStartLoggingStatement.<locals>.<lambda>rr&�	log_level�
log_formatzStarting factory {factory!r}N)
r�addObserverr~�
addCleanupr�doStartrDr0r�info)r"r�rr�r�test_doStartLoggingStatement�sz)FactoryTests.test_doStartLoggingStatementcs�g�t��j�|��fdd��Gdd�dt�}|�}|��|��dd|�|��ddtj	�|��ddd	�d
S)z�
        L{Factory.doStop} logs that it is stopping a factory, followed by
        the L{repr} of the L{Factory} instance that is being stopped.
        cr�r}r�rr�rrr��r�z:FactoryTests.test_doStopLoggingStatement.<locals>.<lambda>c@seZdZdZdS)z;FactoryTests.test_doStopLoggingStatement.<locals>.MyFactoryr^N)rrr�numPortsrrrr�	MyFactory�sr�rr&r�r�zStopping factory {factory!r}N)
rr�r~r�r�doStoprDr0rr�)r"r�r�rr�r�test_doStopLoggingStatement�sz(FactoryTests.test_doStopLoggingStatementN)
rrrrrrvrzr�r�r�r�rrrrr��s	
r�c@� eZdZdZdd�Zdd�ZdS)�AdapterTestszR
    Tests for L{ProtocolToConsumerAdapter} and L{ConsumerToProtocolAdapter}.
    cCsBg}t�}|j|_t|�}|�d�|�|dg�|�|t�dS)z}
        L{IProtocol} providers can be adapted to L{IConsumer} providers using
        L{ProtocolToConsumerAdapter}.
        �helloN)rr~�dataReceivedr�writer0r!r)r"r��p�consumerrrr�test_protocolToConsumer�s
z$AdapterTests.test_protocolToConsumercsTg�tt�G�fdd�d��}|�}t|�}|�d�|��dg�|�|t�dS)z}
        L{IConsumer} providers can be adapted to L{IProtocol} providers using
        L{ProtocolToConsumerAdapter}.
        cr|)z6AdapterTests.test_consumerToProtocol.<locals>.Consumercs��|�dSr})r~)r"rOrrrr��sz<AdapterTests.test_consumerToProtocol.<locals>.Consumer.writeN)rrrr�rrrr�Consumer�sr�r�N)rrrr�r0r!r)r"r��cr'rrr�test_consumerToProtocol�s
z$AdapterTests.test_consumerToProtocolN)rrrrrr�r�rrrrr��s
r�c@r�)�FileWrapperTestsz2
    L{twisted.internet.protocol.FileWrapper}
    cCsPtt��}|�d�|�|j��d�tt��}|�d�|�|j��d�dS)z@
        L{twisted.internet.protocol.FileWrapper.write}
        �test1�stuffN)r
rr�r0�file�getvalue�assertNotEqual�r"�wrapperrrr�
test_writes



zFileWrapperTests.test_writecCsLtt��}|�ddg�|�|j��d�tt��}|�t|jddg�dS)zH
        L{twisted.internet.protocol.FileWrapper.writeSequence}
        r�stest2s
test1test2�test3�test4N)r
r�
writeSequencer0r�r��assertRaises�	TypeErrorr�rrr�test_writeSequences


z#FileWrapperTests.test_writeSequenceN)rrrrrr�r�rrrrr�sr�N)$rr�ior�zope.interfacer�zope.interface.verifyr�twisted.internet.deferr�twisted.internet.interfacesrrrr	�twisted.internet.protocolr
rrr
rr�twisted.loggerrr�twisted.python.failurer�twisted.test.proto_helpersrr�twisted.trial.unittestrrrsr�r�r�rrrr�<module>s$ :([%

Anon7 - 2022
AnonSec Team