HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/protocols/__pycache__/loopback.cpython-38.pyc
U


W[�.�@s:dZddlmZmZddlZddlmZddlmZddl	m
Z
mZmZm
Z
ddlmZddlmZdd	lmZGd
d�de�Zee�Gdd
�d
e��Zee
je
j�Gdd�de��Zdd�Zdd�Zefdd�Zdd�Zdd�Zee
je
j�Gdd�d��ZGdd�dej �Z!Gdd�dej"�Z#d%d!d"�Z$d&d#d$�Z%dS)'zF
Testing support for protocols -- loopback between client and server.
�)�division�absolute_importN)�implementer)�policies)�
interfaces�protocol�main�defer)�
deferLater)�failure)�IAddressc@s<eZdZdZdZdZdd�Zdd�Zdd	�ZeZ	d
d�Z
dS)�_LoopbackQueuez�
    Trivial wrapper around a list to give it an interface like a queue, which
    the addition of also sending notifications by way of a Deferred whenever
    the list has something added to it.
    NFcCs
g|_dS�N)�_queue��self�r�</usr/lib/python3/dist-packages/twisted/protocols/loopback.py�__init__"sz_LoopbackQueue.__init__cCs2|j�|�|jdk	r.|jd}|_|�d�dSr)r�append�_notificationDeferred�callback)r�v�drrr�put&s
z_LoopbackQueue.putcCs
t|j�Sr)�boolrrrrr�__nonzero__-sz_LoopbackQueue.__nonzero__cCs|j�d�S�Nr)r�poprrrr�get2sz_LoopbackQueue.get)�__name__�
__module__�__qualname__�__doc__r�
disconnectrrr�__bool__rrrrrr
sr
c@seZdZdS)�_LoopbackAddressN)r r!r"rrrrr&7sr&c@sdeZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�ZdS)�_LoopbackTransportFNcCs
||_dSr)�q)rr(rrrrCsz_LoopbackTransport.__init__cCs"t|t�std��|j�|�dS)Nz"Can only write bytes to ITransport)�
isinstance�bytes�	TypeErrorr(r�r�datarrr�writeFs
z_LoopbackTransport.writecCs|j�d�|��dS�N�)r(r�join�rZiovecrrr�
writeSequenceKsz _LoopbackTransport.writeSequencecCsd|j_|j�d�dS)NT)r(r$rrrrr�loseConnectionNsz!_LoopbackTransport.loseConnectioncCs|��dS)zB
        Abort the connection. Same as L{loseConnection}.
        N)r4rrrr�abortConnectionSsz"_LoopbackTransport.abortConnectioncCst�Sr�r&rrrr�getPeerZsz_LoopbackTransport.getPeercCst�Srr6rrrr�getHost]sz_LoopbackTransport.getHostcCs&|jdkst�||_||_|��dSr)�producer�AssertionError�streamingProducer�
_pollProducer�rr9Z	streamingrrr�registerProducerasz#_LoopbackTransport.registerProducercCs|jdk	st�d|_dSr)r9r:rrrr�unregisterProducergsz%_LoopbackTransport.unregisterProducercCs|jdk	r|js|j��dSr)r9r;�resumeProducingrrrrr<ksz _LoopbackTransport._pollProducer)r r!r"�
disconnectingr9rr.r3r4r5r7r8r>r?r<rrrrr'=sr'cCs&|r"|��}|dkrq"|�|�qdS)z�
    L{identityPumpPolicy} is a policy which delivers each chunk of data written
    to the given queue as-is to the target.

    This isn't a particularly realistic policy.

    @see: L{loopbackAsync}
    N)r�dataReceived)�queue�targetr*rrr�identityPumpPolicyqs
	rEcCs>g}|r&|��}|dkrq&|�|�q|r:|�d�|��dS)z�
    L{collapsingPumpPolicy} is a policy which collapses all outstanding chunks
    into a single string and delivers it to the target.

    @see: L{loopbackAsync}
    Nr0)rrrBr1)rCrDr*�chunkrrr�collapsingPumpPolicy�srGcCs8t�}t�}|�t|��|�t|��t|||||�S)a
    Establish a connection between C{server} and C{client} then transfer data
    between them until the connection is closed. This is often useful for
    testing a protocol.

    @param server: The protocol instance representing the server-side of this
        connection.

    @param client: The protocol instance representing the client-side of this
        connection.

    @param pumpPolicy: When either C{server} or C{client} writes to its
        transport, the string passed in is added to a queue of data for the
        other protocol.  Eventually, C{pumpPolicy} will be called with one such
        queue and the corresponding protocol object.  The pump policy callable
        is responsible for emptying the queue and passing the strings it
        contains to the given protocol's C{dataReceived} method.  The signature
        of C{pumpPolicy} is C{(queue, protocol)}.  C{queue} is an object with a
        C{get} method which will return the next string written to the
        transport, or L{None} if the transport has been disconnected, and which
        evaluates to C{True} if and only if there are more items to be
        retrieved via C{get}.

    @return: A L{Deferred} which fires when the connection has been closed and
        both sides have received notification of this.
    )r
ZmakeConnectionr'�_loopbackAsyncBody)�server�client�
pumpPolicy�serverToClient�clientToServerrrr�
loopbackAsync�s�rNc
s��fdd�}d}}}||||�}||||�}|sd|sdt��}	|	|_|	|_|	�t||||��|	S|jr|d}||||�n|jr�d}||||�|r|�t�t	j
��|�t�t	j
��t�d�SqdS)ak
    Transfer bytes from the output queue of each protocol to the input of the other.

    @param server: The protocol instance representing the server-side of this
    connection.

    @param serverToClient: The L{_LoopbackQueue} holding the server's output.

    @param client: The protocol instance representing the client-side of this
    connection.

    @param clientToServer: The L{_LoopbackQueue} holding the client's output.

    @param pumpPolicy: See L{loopbackAsync}.

    @return: A L{Deferred} which fires when the connection has been closed and
        both sides have received notification of this.
    cs,d}|r�||�d}|r(|s(|j��|S)NFT)Z	transportr<)�sourcer(rDZsent�rKrr�pump�s

z _loopbackAsyncBody.<locals>.pumpFTN)r	�Deferredr�addCallback�_loopbackAsyncContinuer$�connectionLostr�Failurer�CONNECTION_DONEZsucceed)
rIrLrJrMrKrQr$Z
clientSentZ
serverSentrrrPrrH�s6
�rHc	Cs.d|_d|_ddlm}t|dt|||||�S)Nr��reactor)r�twisted.internetrYr
rH)ZignoredrIrLrJrMrKrYrrrrT�s�rTc@sneZdZdZdZdZdZddd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�
LoopbackRelayr0rNcCs||_||_dSr)rD�logFile)rrDr\rrrrszLoopbackRelay.__init__cCs*|j||_|jr&|j�dt|��dS)Nzloopback writing %s
)�bufferr\r.�reprr,rrrr.szLoopbackRelay.writecCs|�d�|��dSr/)r.r1r2rrrr3 szLoopbackRelay.writeSequencecCs�|jdkrdS|jr|j��|jrX|jr@|j�dt|j��|j}d|_|j�|�|jdkr|d|_|j�	t
�tj
��dS)N���zloopback receiving %s
r0�)�
shouldLoser9r@r]r\r.r^rDrBrUrrVrrW)rr]rrr�clearBuffer#s


zLoopbackRelay.clearBuffercCs|jdkrd|_dS)Nr_r`)rarrrrr43s
zLoopbackRelay.loseConnectioncCsdS�NZloopbackrrrrrr87szLoopbackRelay.getHostcCsdSrcrrrrrr7:szLoopbackRelay.getPeercCs
||_dSr�r9r=rrrr>=szLoopbackRelay.registerProducercCs
d|_dSrrdrrrrr?@sz LoopbackRelay.unregisterProducercCsd|jjjfS)NzLoopback(%r))rD�	__class__r rrrr�	logPrefixCszLoopbackRelay.logPrefix)N)r r!r"r]rarAr9rr.r3rbr4r8r7r>r?rfrrrrr[s
r[c@s$eZdZdd�Zdd�Zdd�ZdS)�LoopbackClientFactorycCsd|_t��|_||_dSr)�disconnectedr	rR�deferredr)rrrrrrJs
zLoopbackClientFactory.__init__cCs|jSr)r)r�addrrrr�
buildProtocolOsz#LoopbackClientFactory.buildProtocolcCsd|_|j�d�dS)Nr`)rhrir)rZ	connector�reasonrrr�clientConnectionLostRsz*LoopbackClientFactory.clientConnectionLostN)r r!r"rrkrmrrrrrgHsrgc@seZdZdd�Zdd�ZdS)�_FireOnClosecCstj�|||�t��|_dSr)r�ProtocolWrapperrr	rRri)rr�factoryrrrrXsz_FireOnClose.__init__cCstj�||�|j�d�dSr)rrorUrir)rrlrrrrU\sz_FireOnClose.connectionLostN)r r!r"rrUrrrrrnWsrnTcs�ddlm}t�t���}t||��||_�fdd�|_|j	||dd��t
|�}||_|�d���j
|�|j}|��fdd��|��fdd��|S)	zBRun session between server and client protocol instances over TCP.rrXcs�Srr�rj��
serverWrapperrr�<lambda>gr0zloopbackTCP.<locals>.<lambda>z	127.0.0.1)Z	interfacecs�jSr�ri��xrrrrrtmr0cs���Sr�Z
stopListeningrv��
serverPortrrrtnr0)rZrYr�WrappingFactoryr�Factoryrn�noisyrkZ	listenTCPrgZ
connectTCPr8�portrirS)rIrJr~r}rY�f�clientFrr�rzrsr�loopbackTCPas
r�cs�t��}ddlm}t�t���}t||��||_	�fdd�|_
|�||��t|�}||_	|�
||�|j}|��fdd��|��fdd��|S)zJRun session between server and client protocol instances over UNIX socket.rrXcs�Srrrqrrrrrtyr0zloopbackUNIX.<locals>.<lambda>cs�jSrrurvrrrrrtr0cs���Srrxrvryrrrt�r0)�tempfileZmktemprZrYrr{rr|rnr}rkZ
listenUNIXrgZconnectUNIXrirS)rIrJr}�pathrYrr�rrr�r�loopbackUNIXrs
r�)rT)T)&r#Z
__future__rrr�Zzope.interfacerZtwisted.protocolsrrZrrrr	Ztwisted.internet.taskr
Ztwisted.pythonrZtwisted.internet.interfacesr�objectr
r&Z
ITransportZ	IConsumerr'rErGrNrHrTr[Z
ClientFactoryrgrornr�r�rrrr�<module>s03&C7