AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/twisted/internet/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

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

�b&��@s`dZddlmZddlmZmZmZmZmZddl	m
Z
ddlmZm
Z
mZmZddlmZddlmZddlmZmZdd	lmZmZmZdd
lmZzddlmZWney_dZYnweZdd
lmZm Z ddl!m"Z"m#Z#ddl$m%Z%ddl&m'Z'm(Z(m)Z)ddl*m+Z+m,Z,ddl-m.Z.m/Z/m0Z0ddl1m2Z2m3Z3m4Z4m5Z5ddl6m7Z7m8Z8m9Z9ddl:m;Z;ddl<m=Z=m>Z>m?Z?m@Z@mAZAddlBmCZCddlDmEZEmFZFmGZGmHZHddlImJZJddlKmLZLddlMmNZNddlOmPZPmQZQmRZRddlSmTZTddlUmVZVeTd�ZWd ZXeTd�du�rd!ZXGd"d#�d#�ZYd$d%�ZZGd&d'�d'e?�Z[Gd(d)�d)e=�Z\e e2�Gd*d+�d+e=��Z]Gd,d-�d-eYeCe>�Z^Gd.d/�d/eYeC�Z_Gd0d1�d1�Z`Gd2d3�d3�ZaGd4d5�d5�ZbGd6d7�d7eaebeCeG�ZcGd8d9�d9e`ebeCeG�ZdGd:d;�d;eHeC�Zeef��ge^�h��ef��ge_�h��ef��gec�h��ef��ged�h��ef��gee�h��Gd<d=�d=eCe@�Zief��gei�h��dS)>z/
Tests for implementations of L{IReactorUNIX}.
�)�md5)�close�fstat�stat�unlink�urandom)�pformat)�AF_INET�SOCK_STREAM�
SOL_SOCKET�socket)�S_IMODE)�pack)�mkstemp�mktemp)�Optional�Sequence�Type)�skipIf)�AF_UNIXN)�	Interface�implementer)�base�
interfaces)�UNIXAddress)�Deferred�fail�
gatherResults)�UNIXClientEndpoint�UNIXServerEndpoint)�CannotListenError�ConnectionClosed�FileDescriptorOverrun)�IFileDescriptorReceiver�
IReactorFDSet�IReactorSocket�IReactorUNIX)�
ClientFactory�DatagramProtocol�
ServerFactory)�LoopingCall)�ConnectableProtocol�ConnectionTestsMixin�EndpointCreator�StreamClientTestsMixin�runProtocolsWithReactor)�ReactorBuilder)�MyClientFactory�MyServerFactory�StreamTransportTestsMixin�WriteSequenceTestsMixin)�nativeString)�Failure)�_coerceToFilesystemEncoding)�addObserver�err�removeObserver)�
requireModule)�platformztwisted.python.sendmsg�z>sendmsg extension unavailable, extended UNIX features disabledc@seZdZdZdd�ZdS)�UNIXFamilyMixinzK
    Test-helper defining mixin for things related to AF_UNIX sockets.
    cCsBd}|��}t||�|||d�}|��|�tt|�j�|�dS)z}
        Assert that the mode of the created unix socket is set to the mode
        specified to the reactor method.
        i�)�modeN)�buildReactor�getattr�
stopListening�assertEqualr
r�st_mode)�self�
methodName�path�factoryr?�reactor�unixPort�rK�A/usr/lib/python3/dist-packages/twisted/internet/test/test_unix.py�	_modeTestOs
zUNIXFamilyMixin._modeTestN)�__name__�
__module__�__qualname__�__doc__rMrKrKrKrLr>Jsr>cCsttd����S)zI
    Return a new, unique abstract namespace path to be listened on.
    �d)rr�	hexdigest)�caserKrKrL�
_abstractPath[srUc@s>eZdZUdZejfZeee	e
ed<dd�Zdd�Z
dS)�UNIXCreatorz(
    Create UNIX socket end points.
    �requiredInterfacescCstddd�}t||�S)z3
        Construct a UNIX server endpoint.
        �.sock�.��suffix�dir)rr)rErIrGrKrKrL�serveri�
zUNIXCreator.servercCst||j�S)z3
        Construct a UNIX client endpoint.
        )r�name)rErI�
serverAddressrKrKrL�clientqszUNIXCreator.clientN)rNrOrPrQrr&rWrrrr�__annotations__r]rarKrKrKrLrVbs

rVc@s,eZdZdZdZdd�Zdd�Zdd�ZdS)	�SendFileDescriptorz�
    L{SendFileDescriptorAndBytes} sends a file descriptor and optionally some
    normal bytes and then closes its connection.

    @ivar reason: The reason the connection was lost, after C{connectionLost}
        is called.
    NcCs||_||_dS)z�
        @param fd: A C{int} giving a file descriptor to send over the
            connection.

        @param data: A C{str} giving data to send over the connection, or
            L{None} if no data is to be sent.
        N)�fd�data)rErdrerKrKrL�__init__�s
zSendFileDescriptor.__init__cCs0|j�|j�|jr|j�|j�|j��dS)zn
        Send C{self.fd} and, if it is not L{None}, C{self.data}.  Then close the
        connection.
        N)�	transport�sendFileDescriptorrdre�write�loseConnection�rErKrKrL�connectionMade�sz!SendFileDescriptor.connectionMadecCst�||�||_dS�N)r+�connectionLost�reason�rErorKrKrLrn�s
z!SendFileDescriptor.connectionLost)rNrOrPrQrorfrlrnrKrKrKrLrcxs
rcc@s8eZdZdZdZdZdd�Zdd�Zdd�Zd	d
�Z	dS)�ReceiveFileDescriptora}
    L{ReceiveFileDescriptor} provides an API for waiting for file descriptors to
    be received.

    @ivar reason: The reason the connection was lost, after C{connectionLost}
        is called.

    @ivar waiting: A L{Deferred} which fires with a file descriptor once one is
        received, or with a failure if the connection is lost with no descriptor
        arriving.
    NcCs"|jdurt�|_|jSt|j�S)z�
        Return a L{Deferred} which will fire with the next file descriptor
        received, or with a failure if the connection is or has already been
        lost.
        N)ror�waitingrrkrKrKrL�waitForDescriptor�s

z'ReceiveFileDescriptor.waitForDescriptorcCs|j�|�d|_dS)z�
        Fire the waiting Deferred, initialized by C{waitForDescriptor}, with the
        file descriptor just received.
        N)rr�callback)rE�
descriptorrKrKrL�fileDescriptorReceived�r^z,ReceiveFileDescriptor.fileDescriptorReceivedcCs4|jdur|j�ttd|�d����d|_dSdS)a_
        Fail the waiting Deferred, if it has not already been fired by
        C{fileDescriptorReceived}.  The bytes sent along with a file descriptor
        are guaranteed to be delivered to the protocol's C{dataReceived} method
        only after the file descriptor has been delivered to the protocol's
        C{fileDescriptorReceived}.
        NzReceived bytes (z) before descriptor.)rr�errbackr6�	Exception�rErerKrKrL�dataReceived�s
�
�z"ReceiveFileDescriptor.dataReceivedcCs2t�||�|jdur|j�|�d|_||_dS)zj
        Fail the waiting Deferred, initialized by C{waitForDescriptor}, if there
        is one.
        N)r+rnrrrwrorprKrKrLrn�s


z$ReceiveFileDescriptor.connectionLost)
rNrOrPrQrorrrsrvrzrnrKrKrKrLrq�srqc@seZdZdZefZe�Zdd�Ze	e
��d�dd��Zdd�Z
e	e
��d�d	d
��Zdd�Ze	ee�d
d��Ze	ee�dd��Ze	ee�dd��Zdd�Ze	ee�dd��Ze	e
��d�e	ee�dd���Ze	ee�dd��Ze	ee�dd��Ze	ee�dd��Zd S)!�UNIXTestsBuilderz=
    Builder defining tests relating to L{IReactorUNIX}.
    cC�|�d|��t��dS)zs
        The UNIX socket created by L{IReactorUNIX.listenUNIX} is created with
        the mode specified.
        �
listenUNIXN)rMrr)rkrKrKrL�	test_mode��zUNIXTestsBuilder.test_mode�8Abstract namespace UNIX sockets only supported on Linux.cC�>t|�}|��}|�d|t��}|�|��td|��dS)z�
        On Linux, a UNIX socket path may begin with C{''} to indicate
        a socket in the abstract namespace.  L{IReactorUNIX.listenUNIX}
        accepts such a path.
        �N)rUr@r}r)rC�getHostr�rErGrI�portrKrKrL�#test_listenOnLinuxAbstractNamespace�sz4UNIXTestsBuilder.test_listenOnLinuxAbstractNamespacecCs^dd�}|�tjd|�|��}|�t��|�dt��Wd�dS1s(wYdS)z�
        L{IReactorUNIX.listenUNIX} raises L{CannotListenError} if the
        underlying port's createInternetSocket raises a socket error.
        cSstd��)Nz FakeBasePort forced socket.error)�OSErrorrkrKrKrL�raiseSocketErrorsz=UNIXTestsBuilder.test_listenFailure.<locals>.raiseSocketError�createInternetSocketznot-usedN)�patchr�BasePortr@�assertRaisesr r}r))rEr�rIrKrKrL�test_listenFailure�s"�z#UNIXTestsBuilder.test_listenFailurecCr�)zc
        L{IReactorUNIX.connectUNIX} also accepts a Linux abstract namespace
        path.
        r�N)rUr@�connectUNIXr'rC�getDestinationr)rErGrI�	connectorrKrKrL�$test_connectToLinuxAbstractNamespace
s	z5UNIXTestsBuilder.test_connectToLinuxAbstractNamespacecCs`Gdd�dt�}|�}|�}t||||j�|�|jd|jd�|�|jd|jd�dS)z�
        A client's transport's C{getHost} and C{getPeer} return L{UNIXAddress}
        instances which have the filesystem path of the host and peer ends of
        the connection.
        c@�eZdZdd�ZdS)z4UNIXTestsBuilder.test_addresses.<locals>.SaveAddresscSs"t|��|��d�|_|��dS)N)�host�peer)�dictr��getPeer�	addressesrj)rErgrKrKrL�makeConnection s�zCUNIXTestsBuilder.test_addresses.<locals>.SaveAddress.makeConnectionN)rNrOrPr�rKrKrKrL�SaveAddress�r�r�r�N)r+r/�	endpointsrCr�)rEr�r]rarKrKrL�test_addressesszUNIXTestsBuilder.test_addressescs�ddlm�t����d�t���d��t�}|��}���fdd�}|�|�|�t	d�|�
�fdd	��t��|�j�d
S)z�
        L{IUNIXTransport.sendFileDescriptor} accepts an integer file descriptor
        and sends a copy of it to the process reading from the connection.
        r)�fromfd)r=r�junkcs@�|tt�}t|������|��������|���dSrm)r	r
rrC�getsockname�assertNotEqual�fileno)ru�received)r��srErKrL�checkDescriptor=szAUNIXTestsBuilder.test_sendFileDescriptor.<locals>.checkDescriptorz-Sending file descriptor encountered a problemc�
�j��Srm�rgrj��ignored�r]rKrL�<lambda>M�
z:UNIXTestsBuilder.test_sendFileDescriptor.<locals>.<lambda>N)
rr��bindrcr�rqrs�addCallback�
addErrbackr9�addBothr/r�)rEra�dr�rK)r�r�rEr]rL�test_sendFileDescriptor.s

z(UNIXTestsBuilder.test_sendFileDescriptorcCsTGdd�dt�}Gdd�dt�}|�}|�}||_t||||j�|�|jd�dS)z�
        If a L{IUNIXTransport.sendFileDescriptor} call fills up
        the send buffer, any registered producer is paused.
        c@r�)zSUNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing.<locals>.DoesNotReadcSs|j��dSrm)rg�pauseProducingrkrKrKrLrlYszbUNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing.<locals>.DoesNotRead.connectionMadeN�rNrOrPrlrKrKrKrL�DoesNotReadXr�r�c@�8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
z`UNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing.<locals>.SendsManyFileDescriptorsFcsPt��_�j��d��fdd�}t|��_�jj�j_�j�d��t	d�dS)NTcs"�j��j����j�d�dS)N�x)rgrhrr�rirKrkrKrL�sendercszUNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing.<locals>.SendsManyFileDescriptors.connectionMade.<locals>.senderrzSend loop failure)
rrg�registerProducerr*�taskrI�clock�startr�r9)rEr�rKrkrLrl_s
zoUNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing.<locals>.SendsManyFileDescriptors.connectionMadecS�|��dSrm��_disconnectrkrKrKrL�
stopProducingk�znUNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing.<locals>.SendsManyFileDescriptors.stopProducingcSr�rmr�rkrKrKrL�resumeProducingnr�zpUNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing.<locals>.SendsManyFileDescriptors.resumeProducingcSsd|_|j��|��dS)NT)�pausedrg�unregisterProducerr�rkrKrKrLr�qs
zoUNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing.<locals>.SendsManyFileDescriptors.pauseProducingcSs$|j��|j��|jj��dSrm)r��stoprg�abortConnection�otherrkrKrKrLr�vs

zlUNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing.<locals>.SendsManyFileDescriptors._disconnectN)	rNrOrPr�rlr�r�r�r�rKrKrKrL�SendsManyFileDescriptors\sr�z*sendFileDescriptor producer was not pausedN)r+r�r/r��
assertTruer�)rEr�r�r]rarKrKrL�-test_sendFileDescriptorTriggersPauseProducingQsz>UNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducingcs�t�}t|��d��t�}g}|��}|�|j�|��fdd��t|�||j�|�	|dt
�|d�t�|�	�j
jt�dS)ag
        If L{IUNIXTransport.sendFileDescriptor} is used to queue a greater
        number of file descriptors than the number of bytes sent using
        L{ITransport.write}, the connection is closed and the protocol connected
        to the transport has its C{connectionLost} method called with a failure
        wrapping L{FileDescriptorOverrun}.
        Ncr�rmr�r�r�rKrLr��r�z=UNIXTestsBuilder.test_fileDescriptorOverrun.<locals>.<lambda>r)rrcr�rqrsr��appendr/r��assertIsInstancer6�trapr!ro�valuer")rE�cargora�resultr�rKr�rL�test_fileDescriptorOverrun�s	z+UNIXTestsBuilder.test_fileDescriptorOverruncs@ddlm}ddlm}ddlm}dd��tt�G�fdd�dt��}Gd	d
�d
|�}|t	t
�\}}|�|j�|�|j�|�}	|||	�}
t
�\}}t
�\}
}|�t|�|�t|�d}||
g}||�\}}||||�|
��|�t|	j�|�|�t|��t|	j���|	jr��fdd
�|D�}|�||	j�dSdS)a�
        Drive _SendmsgMixin via sendmsg socket calls to check that
        L{IFileDescriptorReceiver.fileDescriptorReceived} is called once
        for each file descriptor received in the ancillary messages.

        @param ancillaryPacker: A callable that will be given a list of
            two file descriptors and should return a two-tuple where:
            The first item is an iterable of zero or more (cmsg_level,
            cmsg_type, cmsg_data) tuples in the same order as the given
            list for actual sending via sendmsg; the second item is an
            integer indicating the expected number of FDs to be received.
        r��
socketpair)�
_SendmsgMixin��sendmsgcSst|�}|j|jfSrm)r�st_dev�st_ino)rd�fsrKrKrL�deviceInodeTuple�szTUNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.deviceInodeTuplecs eZdZdd�Z�fdd�ZdS)zPUNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.FakeProtocolcSsg|_g|_dSrm)�fds�deviceInodesReceivedrkrKrKrLrf��
zYUNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.FakeProtocol.__init__cs(|j�|�|j��|��t|�dSrm)r�r�r�r)rErd�r�rKrLrv�szgUNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.FakeProtocol.fileDescriptorReceivedN)rNrOrPrfrvrKr�rKrL�FakeProtocol�sr�c@r�)
zPUNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.FakeReceiver�cSs||_||_dSrm)r�protocol)rE�skt�protorKrKrLrf�r�zYUNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.FakeReceiver.__init__cS�dSrmrKryrKrKrL�
_dataReceived��z^UNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.FakeReceiver._dataReceivedcSr�rmrKrkrKrKrLr��r�zXUNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.FakeReceiver.getHostcSr�rmrKrkrKrKrLr��r�zXUNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.FakeReceiver.getPeercSr�rmrK)rE�orKrKrL�
_getLogPrefix�r�z^UNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.FakeReceiver._getLogPrefixN)	rNrOrP�
bufferSizerfr�r�r�r�rKrKrKrL�FakeReceiver�sr�ssome data needs to be sentcsg|]}�|��qSrKrK��.0rdr�rKrL�
<listcomp>�szNUNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.<listcomp>N)rr��twisted.internet.unixr��twisted.python.sendmsgr�rr#r+rr
�
addCleanuprrr�doReadrC�lenr��assertFalse�set�intersectionr�)rE�ancillaryPackerr�r�r�r�r��
sendSocket�
recvSocketr��receiver�	fileOneFD�fileOneName�	fileTwoFD�fileTwoName�
dataToSend�	fdsToSend�	ancillary�
expectedCount�deviceInodesSentrKr�rL�)_sendmsgMixinFileDescriptorReceivedDriver�s6



�z:UNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriverc�&ddlm��fdd�}|�|�dS)z�
        _SendmsgMixin handles multiple file descriptors per recvmsg, calling
        L{IFileDescriptorReceiver.fileDescriptorReceived} once per received
        file descriptor. Scenario: single CMSG with two FDs.
        r��
SCM_RIGHTScs$t�tdg|�R�fg}d}||fS)N�ii��rr�r�r�rrrKrLr�sz[UNIXTestsBuilder.test_multiFileDescriptorReceivedPerRecvmsgOneCMSG.<locals>.ancillaryPackerN�r�rr�rEr�rKrrL�1test_multiFileDescriptorReceivedPerRecvmsgOneCMSG�szBUNIXTestsBuilder.test_multiFileDescriptorReceivedPerRecvmsgOneCMSGz=Multi control message ancillary sendmsg not supported on Mac.cr)z�
        _SendmsgMixin handles multiple file descriptors per recvmsg, calling
        L{IFileDescriptorReceiver.fileDescriptorReceived} once per received
        file descriptor. Scenario: two CMSGs with one FD each.
        rrcs�fdd�|D�}d}||fS)Ncsg|]
}t�td|�f�qS)�irr�rrKrLr�szpUNIXTestsBuilder.test_multiFileDescriptorReceivedPerRecvmsgTwoCMSGs.<locals>.ancillaryPacker.<locals>.<listcomp>rrKr	rrKrLr�sz\UNIXTestsBuilder.test_multiFileDescriptorReceivedPerRecvmsgTwoCMSGs.<locals>.ancillaryPackerNr
rrKrrL�2test_multiFileDescriptorReceivedPerRecvmsgTwoCMSGs
szCUNIXTestsBuilder.test_multiFileDescriptorReceivedPerRecvmsgTwoCMSGscs~ddlm�dd�}�fdd�}g}t|j�|�t|j�|��d|�|�|�d�t�fd	d
�|D��}|�	|d�dS)
z�
        _SendmsgMixin handles multiple file descriptors per recvmsg, calling
        L{IFileDescriptorReceiver.fileDescriptorReceived} once per received
        file descriptor. Scenario: unsupported CMSGs.
        rr�cSsg}d}||fS)NrrKr	rKrKrLr�0sz[UNIXTestsBuilder.test_multiFileDescriptorReceivedPerRecvmsgBadCMSG.<locals>.ancillaryPackercsd}dg}d}��|||�S)Ns	some data)NN�r)�ReceivedMessage)r��args�kwargsrer��flagsr�rKrL�fakeRecvmsgUnsupportedAncillary5szkUNIXTestsBuilder.test_multiFileDescriptorReceivedPerRecvmsgBadCMSG.<locals>.fakeRecvmsgUnsupportedAncillary�recvmsgz#received unsupported ancillary datac3s�|]	}�|dvVqdS)�formatNrK)r��e)�expectedMessagerKrL�	<genexpr>Ds�zUUNIXTestsBuilder.test_multiFileDescriptorReceivedPerRecvmsgBadCMSG.<locals>.<genexpr>z+Expected message not found in logged eventsN)
�twisted.pythonr�r8r�r�r:r�r�anyr�)rEr�r�events�foundrK)rr�rL�1test_multiFileDescriptorReceivedPerRecvmsgBadCMSG!s


zBUNIXTestsBuilder.test_multiFileDescriptorReceivedPerRecvmsgBadCMSGcCs�ddlm}|�\}}g}t|j�|�t|j�Gdd�dt�}||��d�}t�}t	||||j
�|��|�d�|�
d|�d��d	}d
}	t|j|j|	|d�}
|D]}|
��D]
\}}
|
|�|�krhnq[d
SqU|�d|
t|�f�d
S)z�
        If associated with a protocol which does not provide
        L{IFileDescriptorReceiver}, file descriptors received by the
        L{IUNIXTransport} implementation are closed and a warning is emitted.
        rr�c@r�)zRUNIXTestsBuilder.test_avoidLeakingFileDescriptors.<locals>.RecordEndpointAddressescSs&|j��|_|j��|_t�|�dSrm)rgr��hostAddressr��peerAddressrcrlrkrKrKrLrl\szaUNIXTestsBuilder.test_avoidLeakingFileDescriptors.<locals>.RecordEndpointAddresses.connectionMadeNr�rKrKrKrL�RecordEndpointAddresses[r�r!r�Frr�z�%(protocolName)s (on %(hostAddress)r) does not provide IFileDescriptorReceiver; closing file descriptor received (from %(peerAddress)r).r+)rr �protocolNamerz3Expected event (%s) not found in logged events (%s)N)rr�r8r�r�r:rcr�r+r/r�r�setblockingrC�recvr�r r�items�getrr)rEr��probeClient�probeServerrr!r]rar�clsName�
expectedEvent�logEvent�k�vrKrKrL� test_avoidLeakingFileDescriptorsGsJ


��������z1UNIXTestsBuilder.test_avoidLeakingFileDescriptorscsvtt�G�fdd�dt��}t�}t|��d�}|�}t�||�j���t	|j
d���dt|j
dd���dS)z�
        L{IUNIXTransport.sendFileDescriptor} sends file descriptors before
        L{ITransport.write} sends normal bytes.
        cs(eZdZdd�Z�fdd�Zdd�ZdS)zJUNIXTestsBuilder.test_descriptorDeliveredBeforeBytes.<locals>.RecordEventscSst�|�g|_dSrm)r+rlrrkrKrKrLrl�s

zYUNIXTestsBuilder.test_descriptorDeliveredBeforeBytes.<locals>.RecordEvents.connectionMadecs ��t|�|j�t|��dSrm)r�rrr��type)�	innerSelfrurkrKrLrv�szaUNIXTestsBuilder.test_descriptorDeliveredBeforeBytes.<locals>.RecordEvents.fileDescriptorReceivedcSs|j�|�dSrm)r�extendryrKrKrLrz�szWUNIXTestsBuilder.test_descriptorDeliveredBeforeBytes.<locals>.RecordEvents.dataReceivedN)rNrOrPrlrvrzrKrkrKrL�RecordEvents�sr2r�r�N)rr#r+rrcr�r/r�rC�intr�bytes)rEr2r�r]rarKrkrL�#test_descriptorDeliveredBeforeBytes�sz4UNIXTestsBuilder.test_descriptorDeliveredBeforeBytesN)rNrOrPrQr&rWrVr�r~rr<�isLinuxr�r�r�r�r��sendmsgSkipReasonr�r�r�rr�isMacOSXrrr.r6rKrKrKrLr{�sL�
�




"

0

c
�



%

Lr{c@s8eZdZdZejfZdd�Zee	�
�d�dd��ZdS)�UNIXDatagramTestsBuilderzE
    Builder defining tests relating to L{IReactorUNIXDatagram}.
    cCr|)z�
        The UNIX socket created by L{IReactorUNIXDatagram.listenUNIXDatagram}
        is created with the mode specified.
        �listenUNIXDatagramN)rMrr(rkrKrKrL�test_listenMode�rz(UNIXDatagramTestsBuilder.test_listenModer�cCr�)z�
        On Linux, a UNIX socket path may begin with C{''} to indicate a
        socket in the abstract namespace.  L{IReactorUNIX.listenUNIXDatagram}
        accepts such a path.
        r�N)rUr@r;r(rCr�rr�rKrKrLr��s
z<UNIXDatagramTestsBuilder.test_listenOnLinuxAbstractNamespaceN)rNrOrPrQr�IReactorUNIXDatagramrWr<rr<r7r�rKrKrKrLr:�s�r:c@s>eZdZUdZeefZeee	e
ed<dd�Zdd�Z
dS)�SocketUNIXMixinzb
    Mixin which uses L{IReactorSocket.adoptStreamPort} to hand out listening
    UNIX ports.
    rWcCs\tt�}tddd�}|�|�|�d�|�d�z|�|��|j|�W|�	�S|�	�w)zj
        Get a UNIX port from a reactor, wrapping an already-initialized file
        descriptor.
        rXrYrZ�F)
rrrr��listenr#�adoptStreamPortr��familyr)rErIrH�portSockrGrKrKrL�getListeningPort�s


z SocketUNIXMixin.getListeningPortcC�|�|j|�S�aZ
        Connect to a listening UNIX socket.

        @param reactor: The reactor under test.
        @type reactor: L{IReactorUNIX}

        @param address: The listening's address.
        @type address: L{UNIXAddress}

        @param factory: The client factory.
        @type factory: L{ClientFactory}

        @return: The connector
        �r�r_�rErI�addressrHrKrKrL�connectToListener��z!SocketUNIXMixin.connectToListenerN)rNrOrPrQr&r%rWrrrrrbrDrJrKrKrKrLr>�s
�r>c@s eZdZdZdd�Zdd�ZdS)�ListenUNIXMixinzZ
    Mixin which uses L{IReactorTCP.listenUNIX} to hand out listening UNIX
    ports.
    cCstddd�}|�||�S)z0
        Get a UNIX port from a reactor
        rXrYrZ)rr})rErIrHrGrKrKrLrDsz ListenUNIXMixin.getListeningPortcCrErFrGrHrKrKrLrJrKz!ListenUNIXMixin.connectToListenerN)rNrOrPrQrDrJrKrKrKrLrLsrLc@s8eZdZUefZeeeee	d<dd�Z
dd�ZdS)�UNIXPortTestsMixinrWcCs|�dt|��j���S)zZ
        Get the message expected to be logged when a UNIX port starts listening.
        z
 starting on �r5r�r_)rEr�rHrKrKrL�#getExpectedStartListeningLogMessage#sz6UNIXPortTestsMixin.getExpectedStartListeningLogMessagecCsdt|��j��d�S)zJ
        Get the expected connection lost message for a UNIX port
        z(UNIX Port z Closed)rN)rEr�rKrKrL�getExpectedConnectionLostLogMsg)sz2UNIXPortTestsMixin.getExpectedConnectionLostLogMsgN)rNrOrPr&rWrrrrrbrOrPrKrKrKrLrM s
rMc@�eZdZdZdS)�UNIXPortTestsBuilderz.
    Tests for L{IReactorUNIX.listenUnix}
    N�rNrOrPrQrKrKrKrLrR0�rRc@rQ)�UNIXFDPortTestsBuilderz3
    Tests for L{IReactorUNIX.adoptStreamPort}
    NrSrKrKrKrLrU;rTrUc@s.eZdZeeefZdd�Zdd�Zdd�Z	dS)�%UNIXAdoptStreamConnectionTestsBuilderc	Cs~|��}ddlm}Gdd�dt�}|tt�\}}|�d�|�|j�|�|j�|�	�}|�}|�
|t|�}|�|�dS)z�
        {IReactorSocket.adoptStreamConnection} returns None if the given
        factory's buildProtocol returns None.
        rr�c@r�)zXUNIXAdoptStreamConnectionTestsBuilder.test_buildProtocolReturnsNone.<locals>.NoneFactorycSr�rmrK)rErIrKrKrL�
buildProtocol\r�zfUNIXAdoptStreamConnectionTestsBuilder.test_buildProtocolReturnsNone.<locals>.NoneFactory.buildProtocolN)rNrOrPrWrKrKrKrL�NoneFactory[r�rXFN)r@rr�r)rr
r#r�rr��adoptStreamConnection�assertIsNone)	rErIr�rX�s1�s2�s1FDrHr�rKrKrL�test_buildProtocolReturnsNoneMs

zCUNIXAdoptStreamConnectionTestsBuilder.test_buildProtocolReturnsNonecs<�fdd�}���}�j|ddd�}|�|���|�dS)z>
        Helper method to test UNIX server addresses.
        cs�|\}}}z9td|��j�}��d|jj|ft|j����d|jj|f|jj�|jj	d}��
|t�W|j��dS|j��w)Nr=z <AccumulatingProtocol #%s on %s>zAccumulatingProtocol,%s,%sr)
r7r�r_rCrg�	sessionno�str�logstrrH�
peerAddressesr�rrj)�	protocolsrar]r��portPathr rkrKrL�	connectedns$

��
��zOUNIXAdoptStreamConnectionTestsBuilder.test_ServerAddressUNIX.<locals>.connectedN)�	interface�
addressFamily)r@�getConnectedClientAndServerr��
runReactor)rErerIr�rKrkrL�test_ServerAddressUNIXis�
z<UNIXAdoptStreamConnectionTestsBuilder.test_ServerAddressUNIXcs�t�}t�|_t��t��_t��_t�}t�|_t�|_tddd�}��||����fdd�}|j�|�t|j�jg�}�fdd�}	|�	|	�t����
|	�t|j�jg�}
��fdd	�}|
�|������j
|��S)
a0
        Return a L{Deferred} firing with a L{MyClientFactory} and
        L{MyServerFactory} connected pair, and the listening C{Port}. The
        particularity is that the server protocol has been obtained after doing
        a C{adoptStreamConnection} against the original server connection.
        rXrYrZcs0��|j���|j���|j��t��dSrm)�removeReaderrg�removeWriterrYr�r)r�)rIr]rKrL�firstServerConnected�sz_UNIXAdoptStreamConnectionTestsBuilder.getConnectedClientAndServer.<locals>.firstServerConnectedcs�jr���|Srm)�runningr�)r�)rIrKrLr��szOUNIXAdoptStreamConnectionTestsBuilder.getConnectedClientAndServer.<locals>.stopcs|\}}��||�f�dSrm)rt)rcrar])�deferredr�rKrLr��szPUNIXAdoptStreamConnectionTestsBuilder.getConnectedClientAndServer.<locals>.start)r2r�protocolConnectionMade�protocolConnectionLostr1rr}r�rr�r�r�r�r_)rErIrfrg�firstServerrarGrm�lostDeferredr��
startDeferredr�rK)ror�rIr]rLrh�s4
�


�
zAUNIXAdoptStreamConnectionTestsBuilder.getConnectedClientAndServerN)
rNrOrPr$r%r&rWr^rjrhrKrKrKrLrVFs�"rVc@s6eZdZdZefZdZedd��Zdd�Z	dd�Z
dS)	�UnixClientTestsBuilderz7
    Define tests for L{IReactorUNIX.connectUNIX}.
    NcCs|jdur
t|�|_|jS)z�
        Return a path usable by C{connectUNIX} and C{listenUNIX}.

        @return: A path instance, built with C{_abstractPath}.
        N)�_pathrUrkrKrKrLrG�s

zUnixClientTestsBuilder.pathcC�|�|j|�S)z�
        Start an UNIX server with the given C{factory}.

        @param reactor: The reactor to create the UNIX port in.

        @param factory: The server factory.

        @return: A UNIX port instance.
        )r}rG�rErIrHrKrKrLr@��
zUnixClientTestsBuilder.listencCrw)z�
        Start an UNIX client with the given C{factory}.

        @param reactor: The reactor to create the connection in.

        @param factory: The client factory.

        @return: A UNIX connector instance.
        )r�rGrxrKrKrL�connect�ryzUnixClientTestsBuilder.connect)rNrOrPrQr&rWrv�propertyrGr@rzrKrKrKrLru�s

ru)jrQ�hashlibr�osrrrrr�pprintrrr	r
rr
�structr�tempfilerr�typingrrr�unittestrr�_AF_UNIX�ImportError�zope.interfacerr�twisted.internetrr�twisted.internet.addressr�twisted.internet.deferrrr�twisted.internet.endpointsrr�twisted.internet.errorr r!r"�twisted.internet.interfacesr#r$r%r&�twisted.internet.protocolr'r(r)�twisted.internet.taskr*�&twisted.internet.test.connectionmixinsr+r,r-r.r/�#twisted.internet.test.reactormixinsr0�twisted.internet.test.test_tcpr1r2r3r4�twisted.python.compatr5�twisted.python.failurer6�twisted.python.filepathr7�twisted.python.logr8r9r:�twisted.python.reflectr;�twisted.python.runtimer<r�r8r>rUrVrcrqr{r:r>rLrMrRrUrV�globals�update�makeTestCaseClassesrurKrKrKrL�<module>s���%>Y!- 
�
�~-

Anon7 - 2022
AnonSec Team