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

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

�b,��@s�dZddlmZddlmZddlmZddlmZddl	m
Z
ddlmZm
Z
mZmZmZddlmZdd	lmZdd
lmZdd�ZGd
d�dej�ZGdd�de�ZGdd�de�ZdZdZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�de�Z!Gdd�de�Z"Gdd �d e�Z#Gd!d"�d"e�Z$Gd#d$�d$e�Z%Gd%d&�d&e�Z&Gd'd(�d(e�Z'Gd)d*�d*e�Z(Gd+d,�d,ej�Z)Gd-d.�d.ej�Z*Gd/d0�d0�Z+Gd1d2�d2�Z,d3d4d5efd6d7�Z-e-�Z.d8d9�Z/Gd:d;�d;�Z0Gd<d=�d=ej�Z1gd>�Z2d?S)@a�
Reactor-based Services

Here are services to run clients, servers and periodic services using
the reactor.

If you want to run a server service, L{StreamServerEndpointService} defines a
service that can wrap an arbitrary L{IStreamServerEndpoint
<twisted.internet.interfaces.IStreamServerEndpoint>}
as an L{IService}. See also L{twisted.application.strports.service} for
constructing one of these directly from a descriptive string.

Additionally, this module (dynamically) defines various Service subclasses that
let you represent clients and servers in a Service hierarchy.  Endpoints APIs
should be preferred for stream server services, but since those APIs do not yet
exist for clients or datagram services, many of these are still useful.

They are as follows::

  TCPServer, TCPClient,
  UNIXServer, UNIXClient,
  SSLServer, SSLClient,
  UDPServer,
  UNIXDatagramServer, UNIXDatagramClient,
  MulticastServer

These classes take arbitrary arguments in their constructors and pass
them straight on to their respective reactor.listenXXX or
reactor.connectXXX calls.

For example, the following service starts a web server on port 8080:
C{TCPServer(8080, server.Site(r))}.  See the documentation for the
reactor.listen/connect* methods for more information.
�)�random)�List)�MethodicalMachine)�service)�task)�CancelledError�Deferred�fail�
maybeDeferred�succeed)�Logger)�log)�FailurecCs|durddlm}|S|S)zR
    @return: the argument, or the global reactor if the argument is L{None}.
    Nr)�reactor)�twisted.internetr)�maybeReactorr�r�>/usr/lib/python3/dist-packages/twisted/application/internet.py�_maybeGlobalReactor<src@s&eZdZUgZeeed<dd�ZdS)�_VolatileDataService�volatilecCs*tj�|�}|jD]	}||vr||=q	|S�N)r�Service�__getstate__r)�self�d�attrrrrrLs
�z!_VolatileDataService.__getstate__N)�__name__�
__module__�__qualname__rr�str�__annotations__rrrrrrHs
rc@sTeZdZUdZdgZdZeed<dZdZ	dd�Z
dd	�Zd
d�Zdd
�Z
dd�ZdS)�_AbstractServera
    @cvar volatile: list of attribute to remove from pickling.
    @type volatile: C{list}

    @ivar method: the type of method to call on the reactor, one of B{TCP},
        B{UDP}, B{SSL} or B{UNIX}.
    @type method: C{str}

    @ivar reactor: the current running reactor.
    @type reactor: a provider of C{IReactorTCP}, C{IReactorUDP},
        C{IReactorSSL} or C{IReactorUnix}.

    @ivar _port: instance of port set when the service is started.
    @type _port: a provider of L{twisted.internet.interfaces.IListeningPort}.
    �_port��methodNcO�$||_d|vr
|�d�|_||_dS�Nr��args�popr�kwargs�rr)r+rrr�__init__k�
z_AbstractServer.__init__cC�tj�|�|��|_dSr)rr�privilegedStartService�_getPortr#�rrrrr0q�z&_AbstractServer.privilegedStartServicecCs(tj�|�|jdur|��|_dSdSr)rr�startServicer#r1r2rrrr4us
�z_AbstractServer.startServicecCs,tj�|�|jdur|j��}|`|SdSr)rr�stopServicer#�
stopListening)rrrrrr5zs

�z_AbstractServer.stopServicecCs&tt|j�d�|j��|ji|j��S)z�
        Wrapper around the appropriate listen method of the reactor.

        @return: the port object returned by the listen method.
        @rtype: an object providing
            L{twisted.internet.interfaces.IListeningPort}.
        zlisten{})�getattrrr�formatr%r)r+r2rrrr1�s����z_AbstractServer._getPort)rrr�__doc__rr%r r!rr#r-r0r4r5r1rrrrr"Ts
	r"c@sLeZdZUdZdgZdZeed<dZdZ	dd�Z
dd	�Zd
d�Zdd
�Z
dS)�_AbstractClienta&
    @cvar volatile: list of attribute to remove from pickling.
    @type volatile: C{list}

    @ivar method: the type of method to call on the reactor, one of B{TCP},
        B{UDP}, B{SSL} or B{UNIX}.
    @type method: C{str}

    @ivar reactor: the current running reactor.
    @type reactor: a provider of C{IReactorTCP}, C{IReactorUDP},
        C{IReactorSSL} or C{IReactorUnix}.

    @ivar _connection: instance of connection set when the service is started.
    @type _connection: a provider of L{twisted.internet.interfaces.IConnector}.
    �_connectionr$r%NcOr&r'r(r,rrrr-�r.z_AbstractClient.__init__cCr/r)rrr4�_getConnectionr;r2rrrr4�r3z_AbstractClient.startServicecCs,tj�|�|jdur|j��|`dSdSr)rrr5r;�
disconnectr2rrrr5�s


�z_AbstractClient.stopServicecCs&tt|j�d|j���|ji|j��S)z�
        Wrapper around the appropriate connect method of the reactor.

        @return: the port object returned by the connect method.
        @rtype: an object providing L{twisted.internet.interfaces.IConnector}.
        �connect)r7rrr%r)r+r2rrrr<�s
��z_AbstractClient._getConnection)rrrr9rr%r r!rr;r-r4r5r<rrrrr:�s
r:ztConnect to {tran}

Call reactor.connect{tran} when the service starts, with the
arguments given to the constructor.
z�Serve {tran} clients

Call reactor.listen{tran} when the service starts, with the
arguments given to the constructor. When the service stops,
stop listening. See twisted.internet.interfaces for documentation
on arguments to the reactor method.
c@�eZdZejdd�ZdZdS)�	TCPServer�TCP��tranN�rrr�
_serverDocr8r9r%rrrrr@��r@c@r?)�	TCPClientrArBN�rrr�
_clientDocr8r9r%rrrrrG�rFrGc@r?)�
UNIXServer�UNIXrBNrDrrrrrJ�rFrJc@r?)�
UNIXClientrKrBNrHrrrrrL�rFrLc@r?)�	SSLServer�SSLrBNrDrrrrrM�rFrMc@r?)�	SSLClientrNrBNrHrrrrrO�rFrOc@r?)�	UDPServer�UDPrBNrDrrrrrP�rFrPc@r?)�UNIXDatagramServer�UNIXDatagramrBNrDrrrrrR�rFrRc@r?)�UNIXDatagramClientrSrBNrHrrrrrT�rFrTc@r?)�MulticastServer�	MulticastrBNrDrrrrrUrFrUc@s8eZdZdZddgZdd�Zdd�Zdd	�Zd
d�ZdS)
�TimerServicea�
    Service to periodically call a function

    Every C{step} seconds call the given function with the given arguments.
    The service starts the calls when it starts, and cancels them
    when it stops.

    @ivar clock: Source of time. This defaults to L{None} which is
        causes L{twisted.internet.reactor} to be used.
        Feel free to set this to something else, but it probably ought to be
        set *before* calling L{startService}.
    @type clock: L{IReactorTime<twisted.internet.interfaces.IReactorTime>}

    @ivar call: Function and arguments to call periodically.
    @type call: L{tuple} of C{(callable, args, kwargs)}
    �_loop�
_loopFinishedcOs||_|||f|_d|_dS)a+
        @param step: The number of seconds between calls.
        @type step: L{float}

        @param callable: Function to call
        @type callable: L{callable}

        @param args: Positional arguments to pass to function
        @param kwargs: Keyword arguments to pass to function
        N)�step�call�clock)rrZ�callabler)r+rrrr-s
zTimerService.__init__cCsftj�|�|j\}}}tj|g|�Ri|��|_t|j�|j_|jj	|j
dd�|_|j�|j
�dS)NT)�now)rrr4r[r�LoopingCallrXrr\�startrZrY�
addErrback�_failed)rr]r)r+rrrr4*szTimerService.startServicecCsd|j_t�|�dS�NF)rX�runningr
�err)r�whyrrrrb6szTimerService._failedcs,�jjr	�j���j��fdd���jS)z�
        Stop the service.

        @rtype: L{Deferred<defer.Deferred>}
        @return: a L{Deferred<defer.Deferred>} which is fired when the
            currently running call (if any) is finished.
        cstj���Sr)rrr5��_r2rr�<lambda>Gsz*TimerService.stopService.<locals>.<lambda>)rXrd�stoprY�addCallbackr2rr2rr5=s
zTimerService.stopServiceN)	rrrr9rr-r4rbr5rrrrrWsrWc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�CooperatorServicezb
    Simple L{service.IService} which starts and stops a L{twisted.internet.task.Cooperator}.
    cCstjdd�|_dS)NF)�started)r�
Cooperator�coopr2rrrr-PszCooperatorService.__init__cC�|j�|�Sr)ro�	coiterate)r�iteratorrrrrqS�zCooperatorService.coiteratecC�|j��dSr)ror`r2rrrr4V�zCooperatorService.startServicecCrtr)rorjr2rrrr5YruzCooperatorService.stopServiceN)rrrr9r-rqr4r5rrrrrlKsrlc@s4eZdZdZdZdd�Zdd�Zdd�Zd	d
�ZdS)�StreamServerEndpointServiceaP
    A L{StreamServerEndpointService} is an L{IService} which runs a server on a
    listening port described by an L{IStreamServerEndpoint
    <twisted.internet.interfaces.IStreamServerEndpoint>}.

    @ivar factory: A server factory which will be used to listen on the
        endpoint.

    @ivar endpoint: An L{IStreamServerEndpoint
        <twisted.internet.interfaces.IStreamServerEndpoint>} provider
        which will be used to listen when the service starts.

    @ivar _waitingForPort: a Deferred, if C{listen} has yet been invoked on the
        endpoint, otherwise None.

    @ivar _raiseSynchronously: Defines error-handling behavior for the case
        where C{listen(...)} raises an exception before C{startService} or
        C{privilegedStartService} have completed.

    @type _raiseSynchronously: C{bool}

    @since: 10.2
    FcCs||_||_d|_dSr)�endpoint�factory�_waitingForPort)rrwrxrrrr-xs
z$StreamServerEndpointService.__init__csTtj����j��j��_g���fdd�}�j�|��r%�d��d�_	dS)z2
        Start listening on the endpoint.
        cs0�jr
��|�dS|�t�st�|�dSdSr)�_raiseSynchronously�append�checkrr
re)re��	raisedNowrrr�handleIt�s

�zDStreamServerEndpointService.privilegedStartService.<locals>.handleItrFN)
rrr0rw�listenrxryra�raiseExceptionrz)rrrr}rr0}s
z2StreamServerEndpointService.privilegedStartServicecCs&tj�|�|jdur|��dSdS)zu
        Start listening on the endpoint, unless L{privilegedStartService} got
        around to it already.
        N)rrr4ryr0r2rrrr4�s
�z(StreamServerEndpointService.startServicecs8�j��dd�}�j�|�}�fdd�}|�|�|S)a
        Stop listening on the port if it is already listening, otherwise,
        cancel the attempt to listen.

        @return: a L{Deferred<twisted.internet.defer.Deferred>} which fires
            with L{None} when the port has stopped listening.
        cSs|dur|��SdSr)r6)�portrrr�stopIt�s�z7StreamServerEndpointService.stopService.<locals>.stopItcs
d�_|Src)rd)�passthroughr2rrrj�sz5StreamServerEndpointService.stopService.<locals>.stop)ry�cancelrk�addBoth)rr�rrjrr2rr5�s

z'StreamServerEndpointService.stopServiceN)	rrrr9rzr-r0r4r5rrrrrv]s	rvc@�6eZdZdZdd�Zdd�Zdd�Zdefd	d
�ZdS)�_ReconnectingProtocolProxyz�
    A proxy for a Protocol to provide connectionLost notification to a client
    connection service, in support of reconnecting when connections are lost.
    cCs||_||_dS)a�
        Create a L{_ReconnectingProtocolProxy}.

        @param protocol: the application-provided L{interfaces.IProtocol}
            provider.
        @type protocol: provider of L{interfaces.IProtocol} which may
            additionally provide L{interfaces.IHalfCloseableProtocol} and
            L{interfaces.IFileDescriptorReceiver}.

        @param lostNotification: a 1-argument callable to invoke with the
            C{reason} when the connection is lost.
        N)�	_protocol�_lostNotification)r�protocol�lostNotificationrrrr-�s
z#_ReconnectingProtocolProxy.__init__c	Cs&z|j�|�W|�|�S|�|�w)z�
        The connection was lost.  Relay this information.

        @param reason: The reason the connection was lost.

        @return: the underlying protocol's result
        )r��connectionLostr�)r�reasonrrrr��sz)_ReconnectingProtocolProxy.connectionLostcC�t|j|�Sr)r7r��r�itemrrr�__getattr__�rsz&_ReconnectingProtocolProxy.__getattr__�returncCsd|jj�d|j�d�S)N�<z
 wrapping �>)�	__class__rr�r2rrr�__repr__�sz#_ReconnectingProtocolProxy.__repr__N)	rrrr9r-r�r�r r�rrrrr��s
r�c@r�)�_DisconnectFactoryz�
    A L{_DisconnectFactory} is a proxy for L{IProtocolFactory} that catches
    C{connectionLost} notifications and relays them.
    cCs||_||_dSr)�_protocolFactory�_protocolDisconnected)r�protocolFactory�protocolDisconnectedrrrr-�s
z_DisconnectFactory.__init__cCst|j�|�|j�S)a2
        Create a L{_ReconnectingProtocolProxy} with the disconnect-notification
        callback we were called with.

        @param addr: The address the connection is coming from.

        @return: a L{_ReconnectingProtocolProxy} for a protocol produced by
            C{self._protocolFactory}
        )r�r��
buildProtocolr�)r�addrrrrr��s
�z _DisconnectFactory.buildProtocolcCr�r)r7r�r�rrrr��rsz_DisconnectFactory.__getattr__r�cCsd�|jj|j�S)Nz<{} wrapping {!r}>)r8r�rr�r2rrrr��s
�z_DisconnectFactory.__repr__N)	rrrr9r-r�r�r r�rrrrr��sr�g�?gN@g�?cs����fdd�}|S)a�
    A timeout policy for L{ClientService} which computes an exponential backoff
    interval with configurable parameters.

    @since: 16.1.0

    @param initialDelay: Delay for the first reconnection attempt (default
        1.0s).
    @type initialDelay: L{float}

    @param maxDelay: Maximum number of seconds between connection attempts
        (default 60 seconds, or one minute).  Note that this value is before
        jitter is applied, so the actual maximum possible delay is this value
        plus the maximum possible result of C{jitter()}.
    @type maxDelay: L{float}

    @param factor: A multiplicative factor by which the delay grows on each
        failed reattempt.  Default: 1.5.
    @type factor: L{float}

    @param jitter: A 0-argument callable that introduces noise into the delay.
        By default, C{random.random}, i.e. a pseudorandom floating-point value
        between zero and one.
    @type jitter: 0-argument callable returning L{float}

    @return: a 1-argument callable that, given an attempt count, returns a
        floating point number; the number of seconds to delay.
    @rtype: see L{ClientService.__init__}'s C{retryPolicy} argument.
    cs>zt��td|���}Wnty�}Ynw|��S)N�d)�min�
OverflowError)�attempt�delay��factor�initialDelay�jitter�maxDelayrr�policys�
zbackoffPolicy.<locals>.policyr)r�r�r�r�r�rr�r�
backoffPolicy�s!r�cCst|�dS)aO
    Return the first element of a generator and exhaust it.

    C{MethodicalMachine.upon}'s C{collector} argument takes a generator of
    output results. If the generator is exhausted, the later outputs aren't
    actually run.

    @param gen: Generator to extract values from

    @return: The first element of the generator.
    r)�list)�genrrr�_firstResult*sr�c@s|eZdZdZe�Zdd�Zejdd�dd��Ze��dd	��Z	e��d
d��Z
e��dd
��Ze��dd��Ze��dd��Z
e��dd��Ze��dd��Ze��dd��Zdd�Ze��dd��Ze��dd��Ze��dd��Ze��d d!��Ze��d"d#��Ze��d$d%��Ze��d&d'��Ze��d(d)��Ze��d*d+��Ze��d,d-��Ze��d.d/��Zd0d1�Ze��d2d3��Z e��d4d5��Z!e��d6d7��Z"e��d8d9��Z#e��d:d;��Z$e��d<d=��Z%e��d>d?��Z&d@dA�Z'e��dSdCdD��Z(e��dSdEdF��Z)e��dSdGdH��Z*e��dSdIdJ��Z+e��dKdL��Z,dMdN�Z-e��dOdP��Z.ej/ee	egdQ�ej/eee,ge0dR�e	j/ee	gdQ�e	j/eeeege0dR�e	j/eeegdQ�e	j/ee
ee.gdQ�e
j/ee
gdQ�e
j/eeee#ee%ge0dR�e
j/e e	egdQ�ej/eegdQ�ej/eeeege0dR�ej/e!e
e"egdQ�ej/ee
egdQ�ej/eeege0dR�ej/e!ee#e%e"gdQ�ej/eee$e&gdQ�e
j/ee
gdQ�e
j/eeege0dR�e
j/e!e	e%egdQ�ej/ee	egdQ�ej/eee,ge0dR�ej/e(ee+ge0dR�e	j/e(e	e+ge0dR�e
j/e(e
e+ge0dR�ej/e(ee)ge0dR�ej/e(ee+ge0dR�e
j/e(e
e+ge0dR�ej/e(ee*ge0dR�dBS)T�_ClientMachinea
    State machine for maintaining a single outgoing connection to an endpoint.

    @ivar _awaitingConnected: notifications to make when connection
        succeeds, fails, or is cancelled
    @type _awaitingConnected: list of (Deferred, count) tuples

    @see: L{ClientService}
    cCsJ||_d|_d|_||_||_||_||_td�|_g|_	g|_
||_dS)z�
        @see: L{ClientService.__init__}

        @param log: The logger for the L{ClientService} instance this state
            machine is associated to.
        @type log: L{Logger}
        rFN)�	_endpoint�_failedAttempts�_stopped�_factory�_timeoutForAttempt�_clock�_prepareConnectionr�_connectionInProgress�_awaitingConnected�_stopWaiters�_log)rrwrx�retryPolicyr\�prepareConnectionr
rrrr-Fs

z_ClientMachine.__init__T)�initialcC�dS)z3
        The service has not been started.
        Nrr2rrr�_init\�z_ClientMachine._initcCr�)z5
        The service has started connecting.
        Nrr2rrr�_connectingbr�z_ClientMachine._connectingcCr�)za
        The service is waiting for the reconnection period
        before reconnecting.
        Nrr2rrr�_waitinghr�z_ClientMachine._waitingcCr�)z+
        The service is connected.
        Nrr2rrr�
_connectedor�z_ClientMachine._connectedcCr�)zM
        The service is disconnecting after being asked to shutdown.
        Nrr2rrr�_disconnectingur�z_ClientMachine._disconnectingcCr�)zM
        The service is disconnecting and has been asked to restart.
        Nrr2rrr�_restarting{r�z_ClientMachine._restartingcCr�)zC
        The service has been stopped and is disconnected.
        Nrr2rrrr��r�z_ClientMachine._stoppedcCr�)�T
        Start this L{ClientService}, initiating the connection retry loop.
        Nrr2rrrr`�r�z_ClientMachine.startcs>t�j�fdd��}�j�|���j���j���j��_	dS)z-
        Start a connection attempt.
        cs���Sr)�_clientDisconnectedrgr2rrri�sz)_ClientMachine._connect.<locals>.<lambda>N)
r�r�r�r>rk�_runPrepareConnection�_connectionMadera�_connectionFailedr�)r�factoryProxyrr2r�_connect�s�
�z_ClientMachine._connectcs$|jrt|j����fdd��S�S)am
        Run any C{prepareConnection} callback with the connected protocol,
        ignoring its return value but propagating any failure.

        @param protocol: The protocol of the connection.
        @type protocol: L{IProtocol}

        @return: Either:

            - A L{Deferred} that succeeds with the protocol when the
              C{prepareConnection} callback has executed successfully.

            - A L{Deferred} that fails when the C{prepareConnection} callback
              throws or returns a failed L{Deferred}.

            - The protocol, when no C{prepareConnection} callback is defined.
        cs�Srrrg�r�rrri�r�z6_ClientMachine._runPrepareConnection.<locals>.<lambda>)r�r
rk�rr�rr�rr��s

�z$_ClientMachine._runPrepareConnectioncCs
d|_dS)z6
        Reset the number of failed attempts.
        rN)r�r2rrr�_resetFailedAttempts�s
z#_ClientMachine._resetFailedAttemptscCr�)z�
        Stop trying to connect and disconnect any current connection.

        @return: a L{Deferred} that fires when all outstanding connections are
            closed and all in-progress connection attempts halted.
        Nrr2rrrrj�r�z_ClientMachine.stopcCs|j�t��|jdS)z�
        Return a deferred that will fire when the service has finished
        disconnecting.

        @return: L{Deferred} that fires when the service has finished
            disconnecting.
        ���)r�r{rr2rrr�_waitForStop�s	
z_ClientMachine._waitForStopcCs|j��dS)z2
        Stop pending connection attempt.
        N)r�r�r2rrr�_stopConnecting�sz_ClientMachine._stopConnectingcCs|j��|`dS)z4
        Stop pending attempt to reconnect.
        N)�
_retryCallr�r2rrr�
_stopRetrying�s
z_ClientMachine._stopRetryingcCs|jj��dS)z4
        Disconnect the current connection.
        N)�_currentConnection�	transport�loseConnectionr2rrr�_disconnect�sz_ClientMachine._disconnectcCr�)z�
        A connection has been made.

        @param protocol: The protocol of the connection.
        @type protocol: L{IProtocol}
        Nrr�rrrr��r�z_ClientMachine._connectionMadecCsd|_|j|_|�|j�dS)z�
        Notify all pending requests for a connection that a connection has been
        made.

        @param protocol: The protocol of the connection.
        @type protocol: L{IProtocol}
        rN)r�r�r��_unawaitr�rrr�_notifyWaiters�sz_ClientMachine._notifyWaiterscCr�)z8
        The current connection attempt failed.
        Nr�r�frrrr�r�z _ClientMachine._connectionFailedcC�|��dS)z+
        Schedule a retry attempt.
        N��_doWaitr2rrr�_wait�z_ClientMachine._waitcCs|��S)zM
        Schedule a retry attempt, and ignore the Failure passed in.
        r�r�rrr�_ignoreAndWait
�z_ClientMachine._ignoreAndWaitcCsH|jd7_|�|j�}|jjd|j|j|d�|j�||j�|_dS)N�zDScheduling retry {attempt} to connect {endpoint} in {delay} seconds.)r�rwr�)	r�r�r��infor�r��	callLater�
_reconnectr�)rr�rrrr�s�z_ClientMachine._doWaitcCr�)z?
        The wait between connection attempts is done.
        Nrr2rrrr�r�z_ClientMachine._reconnectcCr�)z?
        The current connection has been disconnected.
        Nrr2rrrr�%r�z"_ClientMachine._clientDisconnectedcCs|`dS)z0
        Forget the current connection.
        N)r�r2rrr�_forgetConnection+r�z _ClientMachine._forgetConnectioncC�|�tt���dS)zm
        Notify all pending requests for a connection that no more connections
        are expected.
        N�r�rrr2rrr�_cancelConnectWaiters2�z$_ClientMachine._cancelConnectWaiterscCr�)z�
        Notify all pending requests for a connection that no more connections
        are expected, after ignoring the Failure passed in.
        Nr�r�rrr�_ignoreAndCancelConnectWaiters:r�z-_ClientMachine._ignoreAndCancelConnectWaiterscCr�)zG
        Notify all deferreds waiting on the service stopping.
        N��_doFinishStoppingr2rrr�_finishStoppingBr�z_ClientMachine._finishStoppingcCr�)zq
        Notify all deferreds waiting on the service stopping, and ignore the
        Failure passed in.
        Nr�r�rrr�_ignoreAndFinishStoppingIsz'_ClientMachine._ignoreAndFinishStoppingcCs&g|j|_}|D]}|�d�q	dSr)r��callback)r�waiting�wrrrr�Qs�z _ClientMachine._doFinishStoppingNcCr�)�i
        Retrieve the currently-connected L{Protocol}, or the next one to
        connect.

        @param failAfterFailures: number of connection failures after which
            the Deferred will deliver a Failure (None means the Deferred will
            only fail if/when the service is stopped).  Set this to 1 to make
            the very first connection failure signal an error.  Use 2 to
            allow one failure but signal an error if the subsequent retry
            then fails.
        @type failAfterFailures: L{int} or None

        @return: a Deferred that fires with a protocol produced by the
            factory passed to C{__init__}
        @rtype: L{Deferred} that may:

            - fire with L{IProtocol}

            - fail with L{CancelledError} when the service is stopped

            - fail with e.g.
              L{DNSLookupError<twisted.internet.error.DNSLookupError>} or
              L{ConnectionRefusedError<twisted.internet.error.ConnectionRefusedError>}
              when the number of consecutive failed connection attempts
              equals the value of "failAfterFailures"
        Nr�r�failAfterFailuresrrr�
whenConnectedVr�z_ClientMachine.whenConnectedcCs
t|j�S)z�
        Return the currently connected protocol.

        @return: L{Deferred} that is fired with currently connected protocol.
        )rr�r�rrrr�s�
z!_ClientMachine._currentConnectioncCs
tt��S)z�
        Notify the caller that no connection is expected.

        @return: L{Deferred} that is fired with L{CancelledError}.
        )r	rr�rrr�
_noConnection|r�z_ClientMachine._noConnectioncCst�}|j�||f�|S)z�
        Return a deferred that will fire with the next connected protocol.

        @return: L{Deferred} that will fire with the next connected protocol.
        )rr�r{)rr��resultrrr�_awaitingConnection�sz"_ClientMachine._awaitingConnectioncCstd�S)z�
        Return a deferred that has already fired with L{None}.

        @return: A L{Deferred} that has already fired with L{None}.
        N)rr2rrr�_deferredSucceededWithNone�sz)_ClientMachine._deferredSucceededWithNonecCs*g|j|_}|D]	\}}|�|�q	dS)z�
        Fire all outstanding L{ClientService.whenConnected} L{Deferred}s.

        @param value: the value to fire the L{Deferred}s with.
        N)r�r�)r�valuer�r��	remainingrrrr��s�z_ClientMachine._unawaitcCstg}g}|jD]#\}}|dur|�||f�q|dkr!|�|�q|�||df�q||_|D]}|�|�q0dS)z�
        Deliver connection failures to any L{ClientService.whenConnected}
        L{Deferred}s that have met their failAfterFailures threshold.

        @param f: the Failure to fire the L{Deferred}s with.
        Nr�)r�r{r�)rr��ready�notReadyr�r�rrr�_deliverConnectionFailure�s�z(_ClientMachine._deliverConnectionFailure)�enter�outputs)rr�	collectorr)1rrrr9r�_machiner-�stater�r�r�r�r�r�r��inputr`�outputr�r�r�rjr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�uponr�rrrrr�9sf
































���
��
�
���
�
��������

�r�csHeZdZdZe�Z	ddd�Zddd�Z�fdd�Z�fd	d
�Z	�Z
S)
�
ClientServicez�
    A L{ClientService} maintains a single outgoing connection to a client
    endpoint, reconnecting after a configurable timeout when a connection
    fails, either before or after connecting.

    @since: 16.1.0
    NcCs4t|�}|dur
tn|}t||||||jd�|_dS)aZ
        @param endpoint: A L{stream client endpoint
            <interfaces.IStreamClientEndpoint>} provider which will be used to
            connect when the service starts.

        @param factory: A L{protocol factory <interfaces.IProtocolFactory>}
            which will be used to create clients for the endpoint.

        @param retryPolicy: A policy configuring how long L{ClientService} will
            wait between attempts to connect to C{endpoint}.
        @type retryPolicy: callable taking (the number of failed connection
            attempts made in a row (L{int})) and returning the number of
            seconds to wait before making another attempt.

        @param clock: The clock used to schedule reconnection.  It's mainly
            useful to be parametrized in tests.  If the factory is serialized,
            this attribute will not be serialized, and the default value (the
            reactor) will be restored when deserialized.
        @type clock: L{IReactorTime}

        @param prepareConnection: A single argument L{callable} that may return
            a L{Deferred}. It will be called once with the L{protocol
            <interfaces.IProtocol>} each time a new connection is made.  It may
            call methods on the protocol to prepare it for use (e.g.
            authenticate) or validate it (check its health).

            The C{prepareConnection} callable may raise an exception or return
            a L{Deferred} which fails to reject the connection.  A rejected
            connection is not used to fire an L{Deferred} returned by
            L{whenConnected}.  Instead, L{ClientService} handles the failure
            and continues as if the connection attempt were a failure
            (incrementing the counter passed to C{retryPolicy}).

            L{Deferred}s returned by L{whenConnected} will not fire until
            any L{Deferred} returned by the C{prepareConnection} callable
            fire. Otherwise its successful return value is consumed, but
            ignored.

            Present Since Twisted 18.7.0

        @type prepareConnection: L{callable}

        N)r�r
)r�_defaultPolicyr�r�r)rrwrxr�r\r�rrrr-;s.�zClientService.__init__cCrp)r�)rr�r�rrrr�uszClientService.whenConnectedcs.|jr|j�d�dSt���|j��dS)r�z1Duplicate ClientService.startService {log_source}N)rdr��warn�superr4rr`r2�r�rrr4�s

zClientService.startServicecst���|j��S)z�
        Stop attempting to reconnect and close any existing connections.

        @return: a L{Deferred} that fires when all outstanding connections are
            closed and all in-progress connection attempts halted.
        )r
r5rrjr2rrrr5�s

zClientService.stopService)NNNr)rrrr9rr�r-r�r4r5�
__classcell__rrrrr
0s
�
:
r
)rWrlrUrvrPr
r@rGrJrLrMrOrRrTN)3r9r�_goodEnoughRandom�typingr�automatr�twisted.applicationrrr�twisted.internet.deferrrr	r
r�twisted.loggerr�twisted.pythonr
�twisted.python.failurerrrrr"r:rIrEr@rGrJrLrMrOrPrRrTrUrWrlrvr�r�r�rr�r�r
�__all__rrrr�<module>sR$?3	DT*"
�+zw

Spamworldpro Mini