Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.52 (Ubuntu)
System : Linux webserver 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2 x86_64
User : www-data ( 33)
PHP Version : 8.1.2-1ubuntu2.21
Disable Function : NONE
Directory :  /lib/python3/dist-packages/twisted/internet/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

�b�N�@s�dZddlZddlmZddlmZddlmZddlm	Z	ddl
mZmZddl
mZmZdd	lmZmZmZdd
lmZddlmZmZddlmZdd
lmZmZmZddlm Z ddl!m"Z"ddl#m$Z$dej%ej&fdd�Z'Gdd�de�Z(Gdd�d�Z)Gdd�de�Z*dd�Z+dd�Z,Gdd�de�Z-Gd d!�d!�Z.Gd"d#�d#e�Z/Gd$d%�d%e(�Z0Gd&d'�d'�Z1Gd(d)�d)�Z2Gd*d+�d+�Z3Gd,d-�d-�Z4dS).z?
Various helpers for tests for connection-oriented transports.
�N)�collect)�Optional)�ref)�verifyObject)�Deferred�
gatherResults)�
IConnector�
IReactorFDSet)�
ClientFactory�Protocol�
ServerFactory)�needsRunningReactor)�context�log)�Failure)�ILogContext�err�msg)�platform)�ClosingProtocol)�SkipTestz	127.0.0.1cCs�t�|d�dd}t�||�}z.|�|�|tjkr6|��}t�|tjtjB�d}||dfW|��S|��W|��S|��w)a�
    Ask the platform to allocate a free port on the specified interface, then
    release the socket and return the address which was allocated.

    @param interface: The local address to try to bind the port on.
    @type interface: C{str}

    @param type: The socket type which will use the resulting port.

    @return: A two-tuple of address and port, like that returned by
        L{socket.getsockname}.
    r��)	�socket�getaddrinfo�bind�AF_INET6�getsockname�getnameinfo�NI_NUMERICHOST�NI_NUMERICSERV�close)�	interface�family�type�addr�probe�sockname�hostname�r)�H/usr/lib/python3/dist-packages/twisted/internet/test/connectionmixins.py�findFreePorts


��
�r+c@�$eZdZdZdZdd�Zdd�ZdS)�ConnectableProtocolab
    A protocol to be used with L{runProtocolsWithReactor}.

    The protocol and its pair should eventually disconnect from each other.

    @ivar reactor: The reactor used in this test.

    @ivar disconnectReason: The L{Failure} passed to C{connectionLost}.

    @ivar _done: A L{Deferred} which will be fired when the connection is
        lost.
    NcCs||_||_dS)aN
        Set attributes on the protocol that are known only externally; this
        will be called by L{runProtocolsWithReactor} when this protocol is
        instantiated.

        @param reactor: The reactor used in this test.

        @param done: A L{Deferred} which will be fired when the connection is
           lost.
        N)�reactor�_done)�selfr.�doner)r)r*�_setAttributesJs
z"ConnectableProtocol._setAttributescCs||_|j�d�|`dS�N)�disconnectReasonr/�callback�r0�reasonr)r)r*�connectionLostXsz"ConnectableProtocol.connectionLost)�__name__�
__module__�__qualname__�__doc__r4r2r8r)r)r)r*r-:s

r-c@� eZdZdZdd�Zdd�ZdS)�EndpointCreatorzT
    Create client and server endpoints that know how to connect to each other.
    cC�t��)z�
        Return an object providing C{IStreamServerEndpoint} for use in creating
        a server to use to establish the connection type to be tested.
        ��NotImplementedError�r0r.r)r)r*�serverc�zEndpointCreator.servercCr?)z�
        Return an object providing C{IStreamClientEndpoint} for use in creating
        a client to use to establish the connection type to be tested.
        r@)r0r.�
serverAddressr)r)r*�clientjrDzEndpointCreator.clientN)r9r:r;r<rCrFr)r)r)r*r>^sr>c@r=)�_SingleProtocolFactoryz�
    Factory to be used by L{runProtocolsWithReactor}.

    It always returns the same protocol (i.e. is intended for only a single
    connection).
    cC�
||_dSr3��	_protocol)r0�protocolr)r)r*�__init__z�
z_SingleProtocolFactory.__init__cC�|jSr3rI)r0r%r)r)r*�
buildProtocol}�z$_SingleProtocolFactory.buildProtocolN�r9r:r;r<rLrOr)r)r)r*rGrsrGc	s�|���|��t��|��t��t|�}t|������}|�|�}���fdd�}|�|�dd�}t|j|jg��|��fdd��|�	|�|��fdd��|�
���S)a�
    Connect two protocols using endpoints and a new reactor instance.

    A new reactor will be created and run, with the client and server protocol
    instances connected to each other using the given endpoint creator. The
    protocols should run through some set of tests, then disconnect; when both
    have disconnected the reactor will be stopped and the function will
    return.

    @param reactorBuilder: A L{ReactorBuilder} instance.

    @param serverProtocol: A L{ConnectableProtocol} that will be the server.

    @param clientProtocol: A L{ConnectableProtocol} that will be the client.

    @param endpointCreator: An instance of L{EndpointCreator}.

    @return: The reactor run by this test.
    cs���|���}|���Sr3)rF�getHost�connect)�p�clientEndpoint)�
clientFactory�endpointCreatorr.r)r*�gotPort�s
z(runProtocolsWithReactor.<locals>.gotPortcSst�|d�dS)NzConnection setup failed.)rr)�resultr)r)r*�failed��z'runProtocolsWithReactor.<locals>.failedc��Sr3r)��_)�disconnectedr)r*�<lambda>��z)runProtocolsWithReactor.<locals>.<lambda>cst��j�Sr3)r
�stopr]�r.r)r*r`��)�buildReactorr2rrGrC�listen�addCallbackrr/�
addErrback�
runReactor)	�reactorBuilder�serverProtocol�clientProtocolrW�
serverFactory�serverEndpoint�drXrZr))rVr_rWr.r*�runProtocolsWithReactor�s 




rpcCs2t�|�r	|��Sd|jjvr|jStd|����)zZ
    Like L{IReactorFDSet.getWriters}, but with support for IOCP reactor as
    well.
    �IOCPzCannot find writers on )r	�
providedBy�
getWriters�	__class__r9�handles�	Exceptionrcr)r)r*�_getWriters�s

rwc@r=)�_AcceptOneClientaN
    This factory fires a L{Deferred} with a protocol instance shortly after it
    is constructed (hopefully long enough afterwards so that it has been
    connected to a transport).

    @ivar reactor: The reactor used to schedule the I{shortly}.

    @ivar result: A L{Deferred} which will be fired with the protocol instance.
    cCs||_||_dSr3)r.rY)r0r.rYr)r)r*rL��
z_AcceptOneClient.__init__cCs$t�||�}|j�d|jj|�|S)Nr)rrOr.�	callLaterrYr5)r0r%rKr)r)r*rO�sz_AcceptOneClient.buildProtocolNrQr)r)r)r*rx�s
rxc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�_SimplePullProducerz�
    A pull producer which writes one byte whenever it is resumed.  For use by
    C{test_unregisterProducerAfterDisconnect}.
    cCrHr3)�consumer)r0r|r)r)r*rL�rMz_SimplePullProducer.__init__cCsdSr3r)�r0r)r)r*�
stopProducing�sz!_SimplePullProducer.stopProducingcCst�d�|j�d�dS)N�Producer.resumeProducing�x)rrr|�writer}r)r)r*�resumeProducing�s
z#_SimplePullProducer.resumeProducingN)r9r:r;r<rLr~r�r)r)r)r*r{�s
r{c@r,)�StopzQ
    A client factory which stops a reactor when a connection attempt fails.
    NcCrHr3rcrBr)r)r*rL�rMz
Stop.__init__cCs&||_td|�����|j��dS)NzStop(CF) cCFailed: )�
failReasonr�getErrorMessager.rb)r0�	connectorr7r)r)r*�clientConnectionFailed�szStop.clientConnectionFailed)r9r:r;r<r�rLr�r)r)r)r*r��s
r�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�ClosingLaterProtocolz�
    ClosingLaterProtocol exchanges one byte with its peer and then disconnects
    itself.  This is mostly a work-around for the fact that connectionMade is
    called before the SSL handshake has completed.
    cCsd|_||_dSr3)�lostConnectionReason�onConnectionLost)r0r�r)r)r*rLryzClosingLaterProtocol.__init__cCstd�dS)N�#ClosingLaterProtocol.connectionMade)rr}r)r)r*�connectionMadesr�cCstd|���|j��dS)Nz"ClosingLaterProtocol.dataReceived �r�	transport�loseConnection�r0�bytesr)r)r*�dataReceived�z!ClosingLaterProtocol.dataReceivedcCstd�||_|j�|�dS)N�#ClosingLaterProtocol.connectionLost)rr�r�r5r6r)r)r*r8sr�N)r9r:r;r<rLr�r�r8r)r)r)r*r��sr�c@s:eZdZUdZdZeeed<dd�Zdd�Z	dd	�Z
dS)
�ConnectionTestsMixinzg
    This mixin defines test methods which should apply to most L{ITransport}
    implementations.
    N�	endpointscCsPGdd�dt�}|d�}|d�}t||||j�|�d|j�|�d|j�dS)z�
        Client and server transports implement L{ILoggingContext.logPrefix} to
        return a message reflecting the protocol they are running.
        c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
zDConnectionTestsMixin.test_logPrefix.<locals>.CustomLogPrefixProtocolcSs||_d|_dSr3)�_prefix�system)r0�prefixr)r)r*rL ryzMConnectionTestsMixin.test_logPrefix.<locals>.CustomLogPrefixProtocol.__init__cSs|j�d�dS)N�a)r�r�r}r)r)r*r�$r[zSConnectionTestsMixin.test_logPrefix.<locals>.CustomLogPrefixProtocol.connectionMadecSrNr3)r�r}r)r)r*�	logPrefix'rPzNConnectionTestsMixin.test_logPrefix.<locals>.CustomLogPrefixProtocol.logPrefixcSs6t�t�d|_|j�d�d|vr|j��dSdS)Nr��b)r�getrr�r�r�r�r�r)r)r*r�*s
�zQConnectionTestsMixin.test_logPrefix.<locals>.CustomLogPrefixProtocol.dataReceivedN)r9r:r;rLr�r�r�r)r)r)r*�CustomLogPrefixProtocols
r�z
Custom Clientz
Custom ServerN)r-rpr��assertInr�)r0r�rFrCr)r)r*�test_logPrefixsz#ConnectionTestsMixin.test_logPrefixcs�����g�t���fdd�}�j����t�|�������fdd�����fdd�}t�|�������	�ddg�dS)	z}
        After a connection is disconnected, L{ITransport.write} and
        L{ITransport.writeSequence} are no-ops.
        c�t��Sr3�r�r))�serverConnectionLostDeferredr)r*r`B�z@ConnectionTestsMixin.test_writeAfterDisconnect.<locals>.<lambda>cs�td|������j��|���}t���fdd�}|�t�|��}dd�}|�|�j	��fdd�}��
|���
|�t��g�S)N�
Listening on cr�r3r�r)��lostConnectionDeferredr)r*r`Lr�zSConnectionTestsMixin.test_writeAfterDisconnect.<locals>.listening.<locals>.<lambda>cSstd|���|j�d�dS)NzAbout to write to r�)rr�r���protor)r)r*r�OszPConnectionTestsMixin.test_writeAfterDisconnect.<locals>.listening.<locals>.writecs8t|�d��|j�d�|j�ddg���d�dS)Nz
 disconnectedssome bytes to get lostssomesmoreT)rr�r��
writeSequence�appendr���finishedr)r*r_UszWConnectionTestsMixin.test_writeAfterDisconnect.<locals>.listening.<locals>.disconnected)rrRr�rFrrSr
�forProtocol�addCallbacks�errbackrgr)�port�endpointrKrFr�r_)r�r.r0r�r�r*�	listeningGs

zAConnectionTestsMixin.test_writeAfterDisconnect.<locals>.listeningcs*������t����fdd��dS)Nc����Sr3�rb��ignoredrcr)r*r`br�zRConnectionTestsMixin.test_writeAfterDisconnect.<locals>.onListen.<locals>.<lambda>)rgrhrr)�r��portDeferredr.r)r*�onListen_�

z@ConnectionTestsMixin.test_writeAfterDisconnect.<locals>.onListenTN)
rerr�rCrfrr�r
ri�assertEqual)r0rKr�r))r�r�r�r.r0r�r*�test_writeAfterDisconnect8s�

z.ConnectionTestsMixin.test_writeAfterDisconnectcs�t��t���t��}�����j����t�t	�������fdd�����fdd�}t
�|�����d�t���
|��dS)z�
        After the connection a protocol is being used for is closed, the
        reactor discards all of its references to the protocol.
        cs^td|������j��|���}|�t��fdd���}dd�}|�|�|��j	��S)Nr�cr\r3r)r))rlr)r*r`{razaConnectionTestsMixin.test_protocolGarbageAfterLostConnection.<locals>.listening.<locals>.<lambda>cSstd|���|j��dS)NzAbout to disconnect r�r�r)r)r*�
disconnect}r�zcConnectionTestsMixin.test_protocolGarbageAfterLostConnection.<locals>.listening.<locals>.disconnect)
rrRr�rFrSr
r�rgrhr�)r�r�rFr�)rlr�r.r0r)r*r�ws
zOConnectionTestsMixin.test_protocolGarbageAfterLostConnection.<locals>.listeningcs*������t����fdd��dS)Ncr�r3r�r�rcr)r*r`�r�zcConnectionTestsMixin.test_protocolGarbageAfterLostConnection.<locals>.onListening.<locals>.<lambda>)rgrhr�addBothr)r�r)r*�onListening�r�zQConnectionTestsMixin.test_protocolGarbageAfterLostConnection.<locals>.onListeningN)rr�rrer�rCrfrr�rr
rir�assertIsNone)r0�	clientRefr�r))rlr�r�r�r.r0r*�'test_protocolGarbageAfterLostConnectionis�

z<ConnectionTestsMixin.test_protocolGarbageAfterLostConnection)r9r:r;r<r�rr>�__annotations__r�r�r�r)r)r)r*r�s
1r�c@seZdZdZdd�ZdS)�LogObserverMixinzL
    Mixin for L{TestCase} subclasses which want to observe log events.
    cCs$g}t�|j�|�tj|j�|Sr3)r�addObserverr��
addCleanup�removeObserver)r0�loggedMessagesr)r)r*�observe�szLogObserverMixin.observeN)r9r:r;r<r�r)r)r)r*r��sr�c@seZdZdZdZdd�ZdS)�BrokenContextFactoryzv
    A context factory with a broken C{getContext} method, for exercising the
    error handling for such a case.
    zSome path was wrong maybecCs
t|j��r3)�
ValueError�messager}r)r)r*�
getContext�rMzBrokenContextFactory.getContextN)r9r:r;r<r�r�r)r)r)r*r��sr�c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�StreamClientTestsMixinau
    This mixin defines tests applicable to SOCK_STREAM client implementations.

    This must be mixed in to a L{ReactorBuilder
    <twisted.internet.test.reactormixins.ReactorBuilder>} subclass, as it
    depends on several of its methods.

    Then the methods C{connect} and C{listen} must defined, defining a client
    and a server communicating with each other.
    cCs*|��}|�|t��}|�tt|��dS)zR
        The C{connect} method returns an object providing L{IConnector}.
        N)rerSr
�
assertTruerr)r0r.r�r)r)r*�test_interface�sz%StreamClientTestsMixin.test_interfacecs*����t���fdd������dS)zl
        The reactor can be stopped by a client factory's
        C{clientConnectionFailed} method.
        cs���t���Sr3)rSr�r)�r.r0r)r*r`�szPStreamClientTestsMixin.test_clientConnectionFailedStopsReactor.<locals>.<lambda>N)rer
rir}r)r�r*�'test_clientConnectionFailedStopsReactor�sz>StreamClientTestsMixin.test_clientConnectionFailedStopsReactorcsn�������t�t��g�G��fdd�dt�}t���|�_t����fdd�������	��dS)z�
        This test checks that we correctly get notifications event for a
        client.  This ought to prevent a regression under Windows using the
        GTK2 reactor.  See #3925.
        cseZdZ��fdd�ZdS)zAStreamClientTestsMixin.test_connectEvent.<locals>.CheckConnectioncs��|����dSr3)r�rbr}��	connectedr.r)r*r��s
zPStreamClientTestsMixin.test_connectEvent.<locals>.CheckConnection.connectionMadeN)r9r:r;r�r)r�r)r*�CheckConnection�sr�cs�����Sr3)rSr))rVr.r0r)r*r`�rdz:StreamClientTestsMixin.test_connectEvent.<locals>.<lambda>N)
rerfrr�rr�rKr
�runr�)r0r�r))rVr�r.r0r*�test_connectEvent�sz(StreamClientTestsMixin.test_connectEventcs�|���|��t�t��t����tj���	�fdd��g�G���fdd�dt
�}t�}||_|�
�|�|���|��dd�dS)a3
        If a producer is unregistered from a transport after the transport has
        been disconnected (by the peer) and after C{loseConnection} has been
        called, the transport is not re-added to the reactor as a writer as
        would be necessary if the transport were still connected.
        cr�r3r���ignrcr)r*r`�r�zOStreamClientTestsMixin.test_unregisterProducerAfterDisconnect.<locals>.<lambda>cs0eZdZdZdd�Z���fdd�Zdd�ZdS)	zUStreamClientTestsMixin.test_unregisterProducerAfterDisconnect.<locals>.ClientProtocolz�
            Protocol to connect, register a producer, try to lose the
            connection, wait for the server to disconnect from us, and then
            unregister the producer.
            cSs,t�d�|j�t|j�d�|j��dS)N�ClientProtocol.connectionMadeF)rrr��registerProducerr{r�r}r)r)r*r��s


�zdStreamClientTestsMixin.test_unregisterProducerAfterDisconnect.<locals>.ClientProtocol.connectionMadecs4t�d�|����|jt��v���d�dS�NzClientProtocol.connectionLost)rr�
unregisterr�r�rwr5r6�r�r.�writingr)r*r8s
zdStreamClientTestsMixin.test_unregisterProducerAfterDisconnect.<locals>.ClientProtocol.connectionLostcSst�d�|j��dS)N�ClientProtocol unregister)rrr��unregisterProducerr}r)r)r*r��
z`StreamClientTestsMixin.test_unregisterProducerAfterDisconnect.<locals>.ClientProtocol.unregisterN)r9r:r;r<r�r8r�r)r�r)r*�ClientProtocol�s
r�rz/Transport was writing after unregisterProducer.N)rerfrr�rrrhrrrgrr
rKrSri�assertFalse)r0r�rVr)r�r*�&test_unregisterProducerAfterDisconnect�s
z=StreamClientTestsMixin.test_unregisterProducerAfterDisconnectcs�|���ddg}�jj}||vrt��rtd��Gdd�d��|��t�t	��t
����tj
����fdd��G���fdd	�d	t	�}t�}||_|��|�|���d
S)z�
        If C{loseConnection} is called while a producer is registered with the
        transport, the connection is closed after the producer is unregistered.
        �Glib2Reactor�Gtk2Reactorz=A pygobject/pygtk bug disables this functionality on Windows.c@seZdZdd�ZdS)zFStreamClientTestsMixin.test_disconnectWhileProducing.<locals>.ProducercSst�d�dS)Nr)rrr}r)r)r*r�%szVStreamClientTestsMixin.test_disconnectWhileProducing.<locals>.Producer.resumeProducingN)r9r:r;r�r)r)r)r*�Producer$sr�cr�r3r�r�rcr)r*r`,r�zFStreamClientTestsMixin.test_disconnectWhileProducing.<locals>.<lambda>cs8eZdZdZ��fdd�Z��fdd�Z�fdd�ZdS)	zLStreamClientTestsMixin.test_disconnectWhileProducing.<locals>.ClientProtocolz�
            Protocol to connect, register a producer, try to lose the
            connection, unregister the producer, and wait for the connection to
            actually be lost.
            cs<t�d�|j���d�|j����d�jd|j�dS)Nr�Fr)rrr�r�r�rzr�r})r�r.r)r*r�5s

z[StreamClientTestsMixin.test_disconnectWhileProducing.<locals>.ClientProtocol.connectionMadecs0t�d�|j����d�jttd���dS)Nr�g�?zConnection was not lost)rrr�r�rzr�rrvr})r�r.r)r*r�?s


�zWStreamClientTestsMixin.test_disconnectWhileProducing.<locals>.ClientProtocol.unregistercst�d���d�dSr�)rrr5r6r�r)r*r8Ir�z[StreamClientTestsMixin.test_disconnectWhileProducing.<locals>.ClientProtocol.connectionLostN)r9r:r;r<r�r�r8r)�r�r�r.r)r*r�.s


r�N)rertr9r�	isWindowsrrfrr�rrrhrrrgr
rKrSri)r0�skippedReactors�reactorClassNamer�rVr)r�r*�test_disconnectWhileProducings"�z4StreamClientTestsMixin.test_disconnectWhileProducingN)	r9r:r;r<r�r�r�r�r�r)r)r)r*r��s	.r�)5r<r�gcr�typingr�weakrefr�zope.interface.verifyr�twisted.internet.deferrr�twisted.internet.interfacesrr	�twisted.internet.protocolr
rr�#twisted.internet.test.reactormixinsr
�twisted.pythonrr�twisted.python.failurer�twisted.python.logrrr�twisted.python.runtimer�twisted.test.test_tcpr�twisted.trial.unittestr�AF_INET�SOCK_STREAMr+r-r>rGrprwrxr{r�r�r�r�r�r�r)r)r)r*�<module>s>$4

Spamworldpro Mini