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

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

�b{S�@sBdZddlZddlmZmZddlmZmZddlm	Z	m
Z
ddlmZddl
mZmZmZddlmZd	d
�ZGdd�de�ZGd
d�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd �d e�ZGd!d"�d"e�ZGd#d$�d$�Z dS)%z]
Resource limiting policies.

@seealso: See also L{twisted.protocols.htb} for rate limiting.
�N)�Optional�Type)�directlyProvides�
providedBy)�error�
interfaces)�ILoggingContext)�
ClientFactory�Protocol�
ServerFactory)�logcCs0t�|�r
|��}n|jj}|�d|jj�d�S)zY
    Compute a log prefix for a wrapper and the object it wraps.

    @rtype: C{str}
    z (�))rr�	logPrefix�	__class__�__name__)�wrapper�wrappedr�r�</usr/lib/python3/dist-packages/twisted/protocols/policies.py�_wrappedLogPrefixs

rc@s�eZdZdZdZdddejfdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"S)#�ProtocolWrappera�
    Wraps protocol instances and acts as their transport as well.

    @ivar wrappedProtocol: An L{IProtocol<twisted.internet.interfaces.IProtocol>}
        provider to which L{IProtocol<twisted.internet.interfaces.IProtocol>}
        method calls onto this L{ProtocolWrapper} will be proxied.

    @ivar factory: The L{WrappingFactory} which created this
        L{ProtocolWrapper}.
    r�factory�WrappingFactory�wrappedProtocolcCs||_||_dS�N)rr)�selfrrrrr�__init__5s
zProtocolWrapper.__init__cC�t||j�S)zo
        Use a customized log prefix mentioning both the wrapped protocol and
        the current one.
        )rr�rrrrr;szProtocolWrapper.logPrefixcCs6t|t|��t�||�|j�|�|j�|�dS)z�
        When a connection is made, register this wrapper with its factory,
        save the real transport, and connect the wrapped protocol to this
        L{ProtocolWrapper} to intercept any transport calls it makes.
        N)rrr
�makeConnectionr�registerProtocolr)r�	transportrrrrBszProtocolWrapper.makeConnectioncC�|j�|�dSr)r!�write�r�datarrrr#O�zProtocolWrapper.writecCr"r)r!�
writeSequencer$rrrr'Rr&zProtocolWrapper.writeSequencecCsd|_|j��dS�N�)�
disconnectingr!�loseConnectionrrrrr+UszProtocolWrapper.loseConnectioncC�
|j��Sr)r!�getPeerrrrrr-Y�
zProtocolWrapper.getPeercCr,r)r!�getHostrrrrr/\r.zProtocolWrapper.getHostcC�|j�||�dSr)r!�registerProducer�r�producer�	streamingrrrr1_�z ProtocolWrapper.registerProducercC�|j��dSr)r!�unregisterProducerrrrrr7b�z"ProtocolWrapper.unregisterProducercCr6r)r!�
stopConsumingrrrrr9er8zProtocolWrapper.stopConsumingcCst|j|�Sr)�getattrr!�r�namerrr�__getattr__hszProtocolWrapper.__getattr__cCr"r)r�dataReceivedr$rrrr>mr&zProtocolWrapper.dataReceivedcCs"|j�|�|j�|�d|_dSr)r�unregisterProtocolr�connectionLost�r�reasonrrrr@ps
zProtocolWrapper.connectionLostN)r�
__module__�__qualname__�__doc__r*r�	IProtocolrrrr#r'r+r-r/r1r7r9r=r>r@rrrrr's*�
�
rc@sreZdZUdZeZeeed<dd�Z	dd�Z
dd�Zd	d
�Zdd�Z
d
d�Zdd�Zdd�Zdd�Zdd�ZdS)rzE
    Wraps a factory and its protocols, and keeps track of them.
    �protocolcCs||_i|_dSr)�wrappedFactory�	protocols)rrHrrrrs
zWrappingFactory.__init__cCr)zY
        Generate a log prefix mentioning both the wrapped factory and this one.
        )rrHrrrrr��zWrappingFactory.logPrefixcC�|j��t�|�dSr)rH�doStartr	rrrrrL��
zWrappingFactory.doStartcCrKr)rH�doStopr	rrrrrN�rMzWrappingFactory.doStopcCr"r)rH�startedConnecting)r�	connectorrrrrO�r&z!WrappingFactory.startedConnectingcCr0r)rH�clientConnectionFailed�rrPrBrrrrQ�r5z&WrappingFactory.clientConnectionFailedcCr0r)rH�clientConnectionLostrRrrrrS�r5z$WrappingFactory.clientConnectionLostcCs|�||j�|��Sr)rGrH�
buildProtocol�r�addrrrrrT�szWrappingFactory.buildProtocolcCsd|j|<dS)z8
        Called by protocol to register itself.
        r)N�rI�r�prrrr �sz WrappingFactory.registerProtocolcCs|j|=dS)z8
        Called by protocols when they go away.
        NrWrXrrrr?�rJz"WrappingFactory.unregisterProtocolN)rrCrDrErrGrr
�__annotations__rrrLrNrOrQrSrTr r?rrrrrxs
rc@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�ThrottlingProtocolz,
    Protocol for L{ThrottlingFactory}.
    cC� |j�t|��t�||�dSr)r�registerWritten�lenrr#r$rrrr#��zThrottlingProtocol.writecCs&|j�ttt|���t�||�dSr)rr]�sum�mapr^rr'�r�seqrrrr'�sz ThrottlingProtocol.writeSequencecCr\r)r�registerReadr^rr>r$rrrr>�r_zThrottlingProtocol.dataReceivedcCs||_t�|||�dSr)r3rr1r2rrrr1�sz#ThrottlingProtocol.registerProducercCs|`t�|�dSr)r3rr7rrrrr7�sz%ThrottlingProtocol.unregisterProducercCr6r)r!�pauseProducingrrrr�
throttleReads�r8z ThrottlingProtocol.throttleReadscCr6r)r!�resumeProducingrrrr�unthrottleReads�r8z"ThrottlingProtocol.unthrottleReadscC�t|d�r|j��dSdS�Nr3)�hasattrr3rerrrr�throttleWrites��
�z!ThrottlingProtocol.throttleWritescCrirj)rkr3rgrrrr�unthrottleWrites�rmz#ThrottlingProtocol.unthrottleWritesN)
rrCrDrEr#r'r>r1r7rfrhrlrnrrrrr[�sr[c@s~eZdZdZeZejddfdd�Zdd�Z	dd�Z
d	d
�Zdd�Zd
d�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�ThrottlingFactoryz�
    Throttles bandwidth and number of connections.

    Write bandwidth will only be throttled if there is a producer
    registered.
    NcCsLt�||�d|_||_||_||_d|_d|_d|_d|_	d|_
d|_dS�Nr)rr�connectionCount�maxConnectionCount�	readLimit�
writeLimit�readThisSecond�writtenThisSecond�unthrottleReadsID�checkReadBandwidthID�unthrottleWritesID�checkWriteBandwidthID)rrHrrrsrtrrrr�s
zThrottlingFactory.__init__cC�ddlm}|�||�S�z�
        Wrapper around
        L{reactor.callLater<twisted.internet.interfaces.IReactorTime.callLater>}
        for test purpose.
        r)�reactor��twisted.internetr}�	callLater�r�period�funcr}rrrr���zThrottlingFactory.callLatercC�|j|7_dS)zH
        Called by protocol to tell us more bytes were written.
        N)rv�r�lengthrrrr]��z!ThrottlingFactory.registerWrittencCr�)zE
        Called by protocol to tell us more bytes were read.
        N)rur�rrrrdr�zThrottlingFactory.registerReadcCsR|j|jkr|��t|j�|jd}|�||j�|_d|_|�d|j�|_dS)z:
        Checks if we've passed bandwidth limits.
        ��?rr)N)	rursrf�floatr�rhrw�checkReadBandwidthrx�r�throttleTimerrrr�sz$ThrottlingFactory.checkReadBandwidthcCsR|j|jkr|��t|j�|jd}|�||j�|_d|_|�d|j�|_dS)Nr�rr))	rvrtrlr�r�rnry�checkWriteBandwidthrzr�rrrr�s�z%ThrottlingFactory.checkWriteBandwidthcC�*t�d|�|j��D]}|��qdS)z2
        Throttle reads on all protocols.
        zThrottling reads on %sN)r�msgrI�keysrfrXrrrrf�
�zThrottlingFactory.throttleReadscC�0d|_t�d|�|j��D]}|��qdS)z9
        Stop throttling reads on all protocols.
        NzStopped throttling reads on %s)rwrr�rIr�rhrXrrrrh%�

�z!ThrottlingFactory.unthrottleReadscCr�)z3
        Throttle writes on all protocols.
        zThrottling writes on %sN)rr�rIr�rlrXrrrrl.r�z ThrottlingFactory.throttleWritescCr�)z:
        Stop throttling writes on all protocols.
        NzStopped throttling writes on %s)ryrr�rIr�rnrXrrrrn6r�z"ThrottlingFactory.unthrottleWritescCsb|jdkr|jdur|��|jdur|��|j|jkr*|jd7_t�||�St�	d�dS)Nrr)zMax connection count reached!)
rqrsr�rtr�rrrrTrr�rUrrrrT?s



zThrottlingFactory.buildProtocolcCs�t�||�|jd8_|jdkr<|jdur|j��|jdur&|j��|jdur0|j��|jdur>|j��dSdSdS�Nr)r)rr?rqrw�cancelrxryrzrXrrrr?Ms







�z$ThrottlingFactory.unregisterProtocol)rrCrDrEr[rG�sys�maxsizerr�r]rdr�r�rfrhrlrnrTr?rrrrro�s$
�
		roc@seZdZdd�Zdd�ZdS)�SpewingProtocolcC�t�d|�t�||�dS)NzReceived: %r)rr�rr>r$rrrr>\�zSpewingProtocol.dataReceivedcCr�)NzSending: %r)rr�rr#r$rrrr#`r�zSpewingProtocol.writeN)rrCrDr>r#rrrrr�[sr�c@seZdZeZdS)�SpewingFactoryN)rrCrDr�rGrrrrr�esr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�LimitConnectionsByPeer�cCs
i|_dSr)�peerConnectionsrrrr�startFactorymr.z#LimitConnectionsByPeer.startFactorycCs>|d}|j�|d�}||jkrdS|d|j|<t�||�S)Nrr))r��get�maxConnectionsPerPeerrrT)rrV�peerHostrqrrrrTps
z$LimitConnectionsByPeer.buildProtocolcCs<|��d}|j|d8<|j|dkr|j|=dSdSr�)r-r�)rrYr�rrrr?xs
�z)LimitConnectionsByPeer.unregisterProtocolN)rrCrDr�r�rTr?rrrrr�is
r�c@sFeZdZUdZdZdZdZeee	e
d<dd�Zdd�Zd	d
�Z
dS)�LimitTotalConnectionsFactorya�
    Factory that limits the number of simultaneous connections.

    @type connectionCount: C{int}
    @ivar connectionCount: number of current connections.
    @type connectionLimit: C{int} or L{None}
    @cvar connectionLimit: maximum number of connections.
    @type overflowProtocol: L{Protocol} or L{None}
    @cvar overflowProtocol: Protocol to use for new connections when
        connectionLimit is exceeded.  If L{None} (the default value), excess
        connections will be closed immediately.
    rN�overflowProtocolcCsX|jdus|j|jkr|��}n|jdurdS|��}||_t||�}|jd7_|Sr()�connectionLimitrqrGr�rr)rrVrrGrrrrT�s


z*LimitTotalConnectionsFactory.buildProtocolcCsdSrrrXrrrr �sz-LimitTotalConnectionsFactory.registerProtocolcCs|jd8_dSr()rqrXrrrr?�r5z/LimitTotalConnectionsFactory.unregisterProtocol)rrCrDrErqr�r�rrr
rZrTr r?rrrrr�s

r�c@sZeZdZdZdd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�TimeoutProtocolzN
    Protocol that automatically disconnects when the connection is idle.
    cCs(t�|||�d|_d|_|�|�dS)z�
        Constructor.

        @param factory: An L{TimeoutFactory}.
        @param wrappedProtocol: A L{Protocol} to wrapp.
        @param timeoutPeriod: Number of seconds to wait for activity before
            timing out.
        N)rr�timeoutCall�
timeoutPeriod�
setTimeout)rrrr�rrrr�s	zTimeoutProtocol.__init__NcCs2|��||_|dur|j�|j|j�|_dSdS)z�
        Set a timeout.

        This will cancel any existing timeouts.

        @param timeoutPeriod: If not L{None}, change the timeout period.
            Otherwise, use the existing value.
        N)�
cancelTimeoutr�rr��timeoutFuncr�)rr�rrrr��s	
��zTimeoutProtocol.setTimeoutc	CsDd|_|jr z|j��Wn
tjtjfyYnwd|_dSdS)zg
        Cancel the timeout.

        If the timeout was already cancelled, this does nothing.
        N)r�r�r�r�
AlreadyCalled�AlreadyCancelledrrrrr��s�
�zTimeoutProtocol.cancelTimeoutcCs|jr|j�|j�dSdS)zQ
        Reset the timeout, usually because some activity just happened.
        N)r��resetr�rrrr�resetTimeout�s�zTimeoutProtocol.resetTimeoutcC�|��t�||�dSr)r�rr#r$rrrr#��zTimeoutProtocol.writecCr�r)r�rr'rbrrrr'�r�zTimeoutProtocol.writeSequencecCr�r)r�rr>r$rrrr>�r�zTimeoutProtocol.dataReceivedcCr�r)r�rr@rArrrr@�r�zTimeoutProtocol.connectionLostcCs|��dS)z�
        This method is called when the timeout is triggered.

        By default it calls I{loseConnection}.  Override this if you want
        something else to happen.
        N)r+rrrrr��szTimeoutProtocol.timeoutFuncr)
rrCrDrErr�r�r�r#r'r>r@r�rrrrr��s
r�c@s.eZdZdZeZd
dd�Zdd�Zdd�Zd	S)�TimeoutFactoryz%
    Factory for TimeoutWrapper.
    �cCs||_t�||�dSr)r�rr)rrHr�rrrrszTimeoutFactory.__init__cCs|j||j�|�|jd�S)N)r�)rGrHrTr�rUrrrrTs

�zTimeoutFactory.buildProtocolcCr{r|r~r�rrrr�r�zTimeoutFactory.callLaterN)r�)	rrCrDrEr�rGrrTr�rrrrr��s
r�c@sVeZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�ZdS)�TrafficLoggingProtocolNrcCs$t�|||�||_||_||_dS)a
        @param factory: factory which created this protocol.
        @type factory: L{protocol.Factory}.
        @param wrappedProtocol: the underlying protocol.
        @type wrappedProtocol: C{protocol.Protocol}.
        @param logfile: file opened for writing used to write log messages.
        @type logfile: C{file}
        @param lengthLimit: maximum size of the datareceived logged.
        @type lengthLimit: C{int}
        @param number: identifier of the connection.
        @type number: C{int}.
        N)rr�logfile�lengthLimit�_number)rrrr�r��numberrrrrs

zTrafficLoggingProtocol.__init__cCs|j�|d�|j��dS)N�
)r�r#�flush)r�linerrr�_log*szTrafficLoggingProtocol._logcCs.|jrt|�|jkr|d|jd�d}|S)N�z<... elided>)r�r^r$rrr�
_mungeData.sz!TrafficLoggingProtocol._mungeDatacCs|�d�t�|�S)N�*)r�r�connectionMaderrrrr�4s

z%TrafficLoggingProtocol.connectionMadecC�&|�d|j|�|�f�t�||�S�NzC %d: %r)r�r�r�rr>r$rrrr>8�z#TrafficLoggingProtocol.dataReceivedcCs |�d|j|f�t�||�Sr�)r�r�rr@rArrrr@<sz%TrafficLoggingProtocol.connectionLostcCr�)NzS %d: %r)r�r�r�rr#r$rrrr#Ar�zTrafficLoggingProtocol.writecs.��d�j�fdd�|D�f�t��|�S)Nz	SV %d: %rcsg|]}��|��qSr)r�)�.0�drrr�
<listcomp>Fsz8TrafficLoggingProtocol.writeSequence.<locals>.<listcomp>)r�r�rr')r�iovecrrrr'Es"z$TrafficLoggingProtocol.writeSequencecCs|�d|jf�t�|�S)NzS %d: *)r�r�rr+rrrrr+Is
z%TrafficLoggingProtocol.loseConnectionrp)rrCrDrr�r�r�r>r@r#r'r+rrrrr�s
r�c@s6eZdZeZdZddd�Zdd�Zdd�Zd	d
�Z	dS)�TrafficLoggingFactoryrNcCs||_||_t�||�dSr)�
logfilePrefixr�rr)rrHr�r�rrrrSszTrafficLoggingFactory.__init__cCs
t|d�S)N�w)�openr;rrrr�Xr.zTrafficLoggingFactory.opencCsF|jd7_|�|jdt|j��}|�||j�|�||j|j�S)Nr)�-)�_counterr�r��strrGrHrTr�)rrVr�rrrrT[s
�z#TrafficLoggingFactory.buildProtocolcCs
d|_dS)zN
        Reset the value of the counter used to identify connections.
        rN)r�rrrr�resetCounterfs
z"TrafficLoggingFactory.resetCounterr)
rrCrDr�rGr�rr�rTr�rrrrr�Ns
r�c@sNeZdZUdZdZeeed<dZdd�Z	dd�Z
dd	�Zd
d�Zdd
�Z
dS)�TimeoutMixinaL
    Mixin for protocols which wish to timeout connections.

    Protocols that mix this in have a single timeout, set using L{setTimeout}.
    When the timeout is hit, L{timeoutConnection} is called, which, by
    default, closes the connection.

    @cvar timeOut: The number of seconds after which to timeout the connection.
    N�timeOutcCr{r|r~r�rrrr�|r�zTimeoutMixin.callLatercCs.|jdur|jdur|j�|j�dSdSdS)a�
        Reset the timeout count down.

        If the connection has already timed out, then do nothing.  If the
        timeout has been cancelled (probably using C{setTimeout(None)}), also
        do nothing.

        It's often a good idea to call this when the protocol has received
        some meaningful input from the other end of the connection.  "I've got
        some data, they're still there, reset the timeout".
        N)�_TimeoutMixin__timeoutCallr�r�rrrrr��s�zTimeoutMixin.resetTimeoutc	Cs~|j}||_|jdur1|dur)z|j��Wn
tjtjfy#Ynwd|_|S|j�|�|S|dur=|�||j�|_|S)z�
        Change the timeout period

        @type period: C{int} or L{None}
        @param period: The period, in seconds, to change the timeout to, or
        L{None} to disable the timeout.
        N)	r�r�r�rr�r�r�r��_TimeoutMixin__timedOut)rr��prevrrrr��s 
���zTimeoutMixin.setTimeoutcCsd|_|��dSr)r��timeoutConnectionrrrr�
__timedOut�szTimeoutMixin.__timedOutcCs|j��dS)z�
        Called when the connection times out.

        Override to define behavior other than dropping the connection.
        N)r!r+rrrrr��szTimeoutMixin.timeoutConnection)rrCrDrEr�r�intrZr�r�r�r�r�r�rrrrr�ms


r�)!rEr��typingrr�zope.interfacerrrrr�twisted.internet.interfacesr�twisted.internet.protocolr	r
r�twisted.pythonrrrrr[ror�r�r�r�r�r�r�r�r�rrrr�<module>s.
Q2*
)R7

Spamworldpro Mini