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/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

�b�F�@s8dZddlZzddlmZWn	eyYnwddlmZmZddl	m
Z
mZddlm
Z
mZddlmZddlmZmZdd	lmZdd
lmZGdd�d�Zeej�Gd
d�d��Zeejej�Gdd�d��Zdd�Zdd�ZGdd�d�Z 		d#dd�Z!eeddfdd�Z"dd�Z#Gdd �d �Z$d$d!d"�Z%dS)%z0
Utilities and helpers for simulating a network
�N)�Error)�directlyProvides�implementer)�error�
interfaces)�TCP4ClientEndpoint�TCP4ServerEndpoint)�ConnectionRefusedError)�Factory�Protocol)�MemoryReactorClock)�Failurec@s*eZdZdd�Zdefdd�Zdd�ZdS)	�TLSNegotiationcCs||_||_d|_||_dS)NF)�obj�connectState�sent�readyToSend)�selfrr�r�4/usr/lib/python3/dist-packages/twisted/test/iosim.py�__init__s
zTLSNegotiation.__init__�returncCsd|j�d�S)NzTLSNegotiation(�))r�rrrr�__repr__"szTLSNegotiation.__repr__cCs&|j�|j�st�|_|��dSdS�N)r�iosimVerify�NativeOpenSSLError�disconnectReason�loseConnection)r�other�tptrrr�pretendToVerify%s�zTLSNegotiation.pretendToVerifyN)�__name__�
__module__�__qualname__r�strrr"rrrrrsrc@seZdZdZdS)�FakeAddressz]
    The default address type for the host and peer of L{FakeTransport}
    connections.
    N)r#r$r%�__doc__rrrrr'.sr'c@seZdZdZee��fdd��ZdZdZ	dZ
e�d�Z
dZdZdZd;dd�Zd	efd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Z d&d'�Z!d(d)�Z"d<d+d,�Z#d-d.�Z$d/d0�Z%d1d2�Z&d3d4�Z'd5d6�Z(d7d8�Z)d9d:�Z*dS)=�
FakeTransportz�
    A wrapper around a file-like object to make it behave as a Transport.

    This doesn't actually stream the file to the attached protocol,
    and is thus useful mainly as a utility for debugging protocols.
    cCstt|��Sr)�int�next)�counterrrr�<lambda>?szFakeTransport.<lambda>rzConnection doneNcCsH||_||_g|_|��|_|durt�}||_|durt�}||_dS)a�
        @param protocol: This transport will deliver bytes to this protocol.
        @type protocol: L{IProtocol} provider

        @param isServer: C{True} if this is the accepting side of the
            connection, C{False} if it is the connecting side.
        @type isServer: L{bool}

        @param hostAddress: The value to return from C{getHost}.  L{None}
            results in a new L{FakeAddress} being created to use as the value.
        @type hostAddress: L{IAddress} provider or L{None}

        @param peerAddress: The value to return from C{getPeer}.  L{None}
            results in a new L{FakeAddress} being created to use as the value.
        @type peerAddress: L{IAddress} provider or L{None}
        N)�protocol�isServer�stream�_nextserial�serialr'�hostAddress�peerAddress)rr.r/r3r4rrrrHs

zFakeTransport.__init__rcCs d�|jrdpd|j|jjj�S)NzFakeTransport<{},{},{}>�S�C)�formatr/r2r.�	__class__r#rrrrrds
�zFakeTransport.__repr__cCs4|jrdS|jdur|j�|�dS|j�|�dSr)�
disconnecting�tls�tlsbuf�appendr0)r�datarrr�writeks

zFakeTransport.writecCs"|jr
|js|j��dSdSdSr��producer�streamingProducer�resumeProducingrrrr�_checkProducerus�zFakeTransport._checkProducercCs ||_||_|s|��dSdS)z.
        From abstract.FileDescriptor
        Nr?)rr@�	streamingrrr�registerProducer{s
�zFakeTransport.registerProducercCs
d|_dSr)r@rrrr�unregisterProducer��
z FakeTransport.unregisterProducercCs|��|��dSr)rFrrrrr�
stopConsuming�szFakeTransport.stopConsumingcCs|�d�|��dS)N�)r>�join)r�iovecrrr�
writeSequence�szFakeTransport.writeSequencecCs
d|_dS�NT�r9rrrrr�rGzFakeTransport.loseConnectioncCs
d|_dS)zp
        For the time being, this is the same as loseConnection; no buffered
        data will be lost.
        TNrNrrrr�abortConnection�s
zFakeTransport.abortConnectioncCs,|jdur	t�}n|j}|j�t|��dSr)r:rrr.�connectionLostr
)r�errrrr�reportDisconnect�s
zFakeTransport.reportDisconnectcCsdS)zM
        Identify this transport/event source to the logging system.
        �iosimrrrrr�	logPrefix�szFakeTransport.logPrefixcC�|jSr)r4rrrr�getPeer��zFakeTransport.getPeercCrUr)r3rrrr�getHost�rWzFakeTransport.getHostcC�dSrrrrrrrB��zFakeTransport.resumeProducingcCrYrrrrrr�pauseProducing�rZzFakeTransport.pauseProducingcCs|��dSr)rrrrr�
stopProducing�szFakeTransport.stopProducingTcCs |j|A}t||�|_g|_dSr)r/rr:r;)r�contextFactory�beNormalrrrr�startTLS�s

zFakeTransport.startTLScCsB|j}|r
g|_d�|�S|jdur|jjrd|j_|jSdSdS)z�
        Get the pending writes from this transport, clearing them from the
        pending buffer.

        @return: the bytes written with C{transport.write}
        @rtype: L{bytes}
        rINT)r0rJr:rr)rr5rrr�getOutBuffer�s

zFakeTransport.getOutBuffercCsxt|t�r4|jdusJ�|jjr.|j�||�d|_|jd}|_|�|�t|tj	�dSd|j_
dS|j�|�dSrM)
�
isinstancerr:rr"r;rLrr�
ISSLTransportrr.�dataReceived)r�buf�brrr�bufferReceived�s

zFakeTransport.bufferReceivedcCrYrrrrrr�getTcpKeepAlive�rZzFakeTransport.getTcpKeepAlivecCrYrrrrrr�
getTcpNoDelay�rZzFakeTransport.getTcpNoDelaycCrYrrrrrr�loseWriteConnection�rZz!FakeTransport.loseWriteConnectioncCrYrr�r�enabledrrr�setTcpKeepAlive�rZzFakeTransport.setTcpKeepAlivecCrYrrrjrrr�
setTcpNoDelay�rZzFakeTransport.setTcpNoDelay)NN)T)+r#r$r%r(�staticmethod�	itertools�countr1�closedr9�disconnectedr�ConnectionDonerr@rAr:rr&rr>rCrErFrHrLrrOrRrTrVrXrBr[r\r_r`rfrgrhrirlrmrrrrr)6sF


		
r)cC�t|dd�S)z�
    Create and return a new in-memory transport hooked up to the given protocol.

    @param clientProtocol: The client protocol to use.
    @type clientProtocol: L{IProtocol} provider

    @return: The transport.
    @rtype: L{FakeTransport}
    F�r/�r))�clientProtocolrrr�makeFakeClient��
rxcCrt)z�
    Create and return a new in-memory transport hooked up to the given protocol.

    @param serverProtocol: The server protocol to use.
    @type serverProtocol: L{IProtocol} provider

    @return: The transport.
    @rtype: L{FakeTransport}
    Trurv)�serverProtocolrrr�makeFakeServerryr{c@s,eZdZdZdd�Zd
dd�Zd
dd�Zd	S)�IOPumpz�
    Utility to pump data between clients and servers for protocol testing.

    Perhaps this is a utility worthy of being in protocol.py?
    cCs"||_||_||_||_||_dSr)�client�server�clientIO�serverIO�debug)rr}r~rr�r�rrrrs

zIOPump.__init__FcCs.d}td�D]}|�|�rd}q|SJd��)zk
        Pump until there is no more input or output.

        Returns whether any data was moved.
        Fi�TrzToo long)�range�pump)rr��result�xrrr�flush&s
�zIOPump.flushcCs$|js|r	td�|j��}|j��}|j��|j��|js"|r:td�|r0tdt|��|r:tdt|��|rB|j�|�|rJ|j�|�|sN|rPdS|jjrp|jj	sp|js]|ratd�d|j_	d|j_|j�
�dS|jjr�|jj	s�|js}|r�td�d|j_	d|j_|j�
�dSdS)	zX
        Move data back and forth.

        Returns whether any data was moved.
        z
-- GLUG --�.zC: zS: Tz* Cz* SF)r��printr�r`rrC�reprrfr9rrrR)rr��sData�cDatarrrr�6sB









zIOPump.pumpN�F)r#r$r%r(rr�r�rrrrr|s

r|FTcCs4|�|�|�|�t|||||�}|r|��|S)aN
    Create a new L{IOPump} connecting two protocols.

    @param serverProtocol: The protocol to use on the accepting side of the
        connection.
    @type serverProtocol: L{IProtocol} provider

    @param serverTransport: The transport to associate with C{serverProtocol}.
    @type serverTransport: L{FakeTransport}

    @param clientProtocol: The protocol to use on the initiating side of the
        connection.
    @type clientProtocol: L{IProtocol} provider

    @param clientTransport: The transport to associate with C{clientProtocol}.
    @type clientTransport: L{FakeTransport}

    @param debug: A flag indicating whether to log information about what the
        L{IOPump} is doing.
    @type debug: L{bool}

    @param greet: Should the L{IOPump} be L{flushed <IOPump.flush>} once before
        returning to put the protocols into their post-handshake or
        post-server-greeting state?
    @type greet: L{bool}

    @return: An L{IOPump} which connects C{serverProtocol} and
        C{clientProtocol} and delivers bytes between them when it is pumped.
    @rtype: L{IOPump}
    )�makeConnectionr|r�)rz�serverTransportrw�clientTransportr��greetr�rrr�connect`s
&

�r�c
	Cs4|�}|�}||�}||�}	||t||	||||�fS)a
    Connect a given server and client class to each other.

    @param ServerClass: a callable that produces the server-side protocol.
    @type ServerClass: 0-argument callable returning L{IProtocol} provider.

    @param ClientClass: like C{ServerClass} but for the other side of the
        connection.
    @type ClientClass: 0-argument callable returning L{IProtocol} provider.

    @param clientTransportFactory: a callable that produces the transport which
        will be attached to the protocol returned from C{ClientClass}.
    @type clientTransportFactory: callable taking (L{IProtocol}) and returning
        L{FakeTransport}

    @param serverTransportFactory: a callable that produces the transport which
        will be attached to the protocol returned from C{ServerClass}.
    @type serverTransportFactory: callable taking (L{IProtocol}) and returning
        L{FakeTransport}

    @param debug: Should this dump an escaped version of all traffic on this
        connection to stdout for inspection?
    @type debug: L{bool}

    @param greet: Should the L{IOPump} be L{flushed <IOPump.flush>} once before
        returning to put the protocols into their post-handshake or
        post-server-greeting state?
    @type greet: L{bool}

    @return: the client protocol, the server protocol, and an L{IOPump} which,
        when its C{pump} and C{flush} methods are called, will move data
        between the created client and server protocol instances.
    @rtype: 3-L{tuple} of L{IProtocol}, L{IProtocol}, L{IOPump}
    )r�)
�ServerClass�ClientClass�clientTransportFactory�serverTransportFactoryr�r��c�s�cio�siorrr�connectedServerAndClient�s
*r�cCs.|\}}}}}|\}}}	}
||kr||fSdS)a'
    Should the client and server described by the arguments be connected to
    each other, i.e. do their port numbers match?

    @param clientInfo: the args for connectTCP
    @type clientInfo: L{tuple}

    @param serverInfo: the args for listenTCP
    @type serverInfo: L{tuple}

    @return: If they do match, return factories for the client and server that
        should connect; otherwise return L{None}, indicating they shouldn't be
        connected.
    @rtype: L{None} or 2-L{tuple} of (L{ClientFactory},
        L{IProtocolFactory})
    Nr)�
clientInfo�
serverInfo�
clientHost�
clientPort�
clientFactory�
clientTimeout�clientBindAddress�
serverPort�
serverFactory�
serverBacklog�serverInterfacerrr�_factoriesShouldConnect�s�r�c@s4eZdZdZdd�Zd
dd�Zee��fdd�Zd	S)�ConnectionCompleterz�
    A L{ConnectionCompleter} can cause synthetic TCP connections established by
    L{MemoryReactor.connectTCP} and L{MemoryReactor.listenTCP} to succeed or
    fail.
    cCs
||_dS)z�
        Create a L{ConnectionCompleter} from a L{MemoryReactor}.

        @param memoryReactor: The reactor to attach to.
        @type memoryReactor: L{MemoryReactor}
        N)�_reactor)r�
memoryReactorrrrr�s
zConnectionCompleter.__init__Fc
Cs�|j}t|j�D]?\}}|jD]7}t||�}|rF|j�|�|j�|�|\}}|�d�}	|�d�}
t	|
�}t
|	�}t|
||	||�SqqdS)a�
        Complete a single TCP connection established on this
        L{ConnectionCompleter}'s L{MemoryReactor}.

        @param debug: A flag; whether to dump output from the established
            connection to stdout.
        @type debug: L{bool}

        @return: a pump for the connection, or L{None} if no connection could
            be established.
        @rtype: L{IOPump} or L{None}
        N)r��	enumerate�
tcpClients�
tcpServersr��remove�
connectors�pop�
buildProtocolr{rxr�)
rr�r��	clientIdxr�r��	factoriesr�r�rwrzr�r�rrr�succeedOnce�s,




����zConnectionCompleter.succeedOncecCs(|jj�d�d�|jj�d�|�dS)z�
        Fail a single TCP connection established on this
        L{ConnectionCompleter}'s L{MemoryReactor}.

        @param reason: the reason to provide that the connection failed.
        @type reason: L{Failure}
        r�N)r�r�r��clientConnectionFailedr�)r�reasonrrr�failOnces�zConnectionCompleter.failOnceNr�)	r#r$r%r(rr�r
r	r�rrrrr��s

	!r�cCs8t�}t|dd�}t|d�}|�t�t��|t|�fS)a�
    Create an endpoint that can be fired on demand.

    @param debug: A flag; whether to dump output from the established
        connection to stdout.
    @type debug: L{bool}

    @return: A client endpoint, and an object that will cause one of the
        L{Deferred}s returned by that client endpoint.
    @rtype: 2-L{tuple} of (L{IStreamClientEndpoint}, L{ConnectionCompleter})
    z0.0.0.0i�)rrr�listenr
�forProtocolrr�)r��reactor�clientEndpoint�serverEndpointrrr�connectableEndpoints

r�)FTr�)&r(ro�OpenSSL.SSLrr�ImportError�zope.interfacerr�twisted.internetrr�twisted.internet.endpointsrr�twisted.internet.errorr	�twisted.internet.protocolr
r�twisted.internet.testingr�twisted.python.failurer
r�IAddressr'�
ITransport�
ITLSTransportr)rxr{r|r�r�r�r�r�rrrr�<module>sD�H

M
�4
�1>

Spamworldpro Mini