%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/twisted/internet/test/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/twisted/internet/test/__pycache__/test_unix.cpython-312.pyc

�

Ϫ�f,����dZddlmZddlmZmZmZmZmZddl	m
Z
ddlmZm
Z
mZmZddlmZddlmZddlmZmZdd	lmZmZmZdd
lmZ	ddlmZeZdd
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!ZXGd"�d#�ZYd$�ZZGd%�d&e?�Z[Gd'�d(e=�Z\e e2�Gd)�d*e=��Z]Gd+�d,eYeCe>�Z^Gd-�d.eYeC�Z_Gd/�d0�Z`Gd1�d2�ZaGd3�d4�ZbGd5�d6eaebeCeG�ZcGd7�d8e`ebeCeG�ZdGd9�d:eHeC�Zeef�j�e^j���ef�j�e_j���ef�j�ecj���ef�j�edj���ef�j�eej���Gd;�d<eCe@�Zief�j�eij���y#e$rdZY��1wxYw)=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��eZdZdZd�Zy)�UNIXFamilyMixinzK
    Test-helper defining mixin for things related to AF_UNIX sockets.
    c���d}|j�}t||�|||��}|j�|jt	t|�j�|�y)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�assertEqualrr�st_mode)�self�
methodName�path�factoryrB�reactor�unixPorts       �A/usr/lib/python3/dist-packages/twisted/internet/test/test_unix.py�	_modeTestzUNIXFamilyMixin._modeTestOsY��
���#�#�%��/�7�7�J�/��g�D�I����� ������d��!3�!3�4�d�;�N)�__name__�
__module__�__qualname__�__doc__rO�rPrNr@r@Js���	<rPr@c�F�ttd��j�S)zI
    Return a new, unique abstract namespace path to be listened on.
    �d)rr�	hexdigest)�cases rN�
_abstractPathrZ[s���w�s�|��&�&�(�(rPc�T�eZdZUdZej
fZeee	e
ed<d�Zd�Z
y)�UNIXCreatorz(
    Create UNIX socket end points.
    �requiredInterfacesc�4�tdd��}t||�S)z3
        Construct a UNIX server endpoint.
        �.sock�.��suffix�dir)rr )rHrLrJs   rN�serverzUNIXCreator.serveris��
�W�#�.��!�'�4�0�0rPc�.�t||j�S)z3
        Construct a UNIX client endpoint.
        )r�name)rHrL�
serverAddresss   rN�clientzUNIXCreator.clientqs��"�'�=�+=�+=�>�>rPN)rQrRrSrTrr'r]rrrr�__annotations__rdrhrUrPrNr\r\bs7���@J�?V�?V�>X����$�y�/�!:�;�X�1�?rPr\c�&�eZdZdZdZd�Zd�Zd�Zy)�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.
    Nc� �||_||_y)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)rHrmrns   rN�__init__zSendFileDescriptor.__init__�s�������	rPc���|jj|j�|jr%|jj	|j�|jj�y)zn
        Send C{self.fd} and, if it is not L{None}, C{self.data}.  Then close the
        connection.
        N)�	transport�sendFileDescriptorrmrn�write�loseConnection�rHs rN�connectionMadez!SendFileDescriptor.connectionMade�sG��
	
���)�)�$�'�'�2��9�9��N�N� � ����+����%�%�'rPc�>�tj||�||_y�N)r,�connectionLost�reason�rHrzs  rNryz!SendFileDescriptor.connectionLost�s���*�*�4��8���rP)rQrRrSrTrzrorvryrUrPrNrkrkxs����F�	�(�rPrkc�0�eZdZdZdZdZd�Zd�Zd�Zd�Z	y)�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.
    Nc�z�|j�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.
        )rzr�waitingrrus rN�waitForDescriptorz'ReceiveFileDescriptor.waitForDescriptor�s0���;�;��#�:�D�L��<�<������$�$rPc�H�|jj|�d|_y)z�
        Fire the waiting Deferred, initialized by C{waitForDescriptor}, with the
        file descriptor just received.
        N)r�callback)rH�
descriptors  rN�fileDescriptorReceivedz,ReceiveFileDescriptor.fileDescriptorReceived�s��
	
�����j�)���rPc	��|j�9|jjttd|�d����d|_yy)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.)r�errbackr7�	Exception�rHrns  rN�dataReceivedz"ReceiveFileDescriptor.dataReceived�sF���<�<�#��L�L� � ��	�$4�T�H�<P�"Q�R�S�
� �D�L�	$rPc��tj||�|j�"|jj|�d|_||_y)zj
        Fail the waiting Deferred, initialized by C{waitForDescriptor}, if there
        is one.
        N)r,ryrr�rzr{s  rNryz$ReceiveFileDescriptor.connectionLost�s>��
	�*�*�4��8��<�<�#��L�L� � ��(��D�L���rP)
rQrRrSrTrzrr�r�r�ryrUrPrNr}r}�s'��
��F��G�
%�� �	rPr}c���eZdZdZefZe�Zd�Ze	e
j�d�d��Zd�Z
e	e
j�d�d��Zd�Ze	ee�d��Ze	d	d
�d��Ze	ee�d��Zd
�Ze	ee�d��Ze	e
j.�d�e	ee�d���Ze	ee�d��Ze	ee�d��Ze	ee�d��Zy)�UNIXTestsBuilderz=
    Builder defining tests relating to L{IReactorUNIX}.
    c�V�|jd|j�t��y)zs
        The UNIX socket created by L{IReactorUNIX.listenUNIX} is created with
        the mode specified.
        �
listenUNIXN)rOrr*rus rN�	test_modezUNIXTestsBuilder.test_mode�s��
	
���|�T�[�[�]�M�O�DrP�8Abstract namespace UNIX sockets only supported on Linux.c���t|�}|j�}|jd|zt��}|j	|j�t
d|z��y)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)rZrCr�r*rF�getHostr�rHrJrL�ports    rN�#test_listenOnLinuxAbstractNamespacez4UNIXTestsBuilder.test_listenOnLinuxAbstractNamespace�sS���T�"���#�#�%���!�!�$��+�}��?����������T�D�[�)A�BrPc���d�}|jtjd|�|j�}|j	t
�5|j
dt��ddd�y#1swYyxYw)z�
        L{IReactorUNIX.listenUNIX} raises L{CannotListenError} if the
        underlying port's createInternetSocket raises a socket error.
        c��td��)Nz FakeBasePort forced socket.error)�OSErrorrus rN�raiseSocketErrorz=UNIXTestsBuilder.test_listenFailure.<locals>.raiseSocketErrors���<�=�=rP�createInternetSocketznot-usedN)�patchr�BasePortrC�assertRaisesr!r�r*)rHr�rLs   rN�test_listenFailurez#UNIXTestsBuilder.test_listenFailure�sc��	>�	
�
�
�4�=�=�"8�:J�K��#�#�%��
�
�
�0�
1�	<����z�=�?�;�	<�	<�	<�s�
A.�.A7c���t|�}|j�}|jd|zt��}|j	|j�t
d|z��y)zc
        L{IReactorUNIX.connectUNIX} also accepts a Linux abstract namespace
        path.
        r�N)rZrC�connectUNIXr(rF�getDestinationr)rHrJrL�	connectors    rN�$test_connectToLinuxAbstractNamespacez5UNIXTestsBuilder.test_connectToLinuxAbstractNamespace
sV���T�"���#�#�%���'�'��t��]�_�E�	�����1�1�3�[����5M�NrPc��Gd�dt�}|�}|�}t||||j�|j|jd|jd�|j|jd|jd�y)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��eZdZd�Zy)�4UNIXTestsBuilder.test_addresses.<locals>.SaveAddressc��t|j�|j���|_|j	�y)N)�host�peer)�dictr��getPeer�	addressesrt)rHrqs  rN�makeConnectionzCUNIXTestsBuilder.test_addresses.<locals>.SaveAddress.makeConnection s3��!%�"�*�*�,�9�3D�3D�3F�"����(�(�*rPN)rQrRrSr�rUrPrN�SaveAddressr�s��
+rPr�r�r�N)r,r0�	endpointsrFr�)rHr�rdrhs    rN�test_addresseszUNIXTestsBuilder.test_addressess}��	+�-�	+���������f�f�d�n�n�E�����)�)�&�1�6�3C�3C�F�3K�L�����)�)�&�1�6�3C�3C�F�3K�LrPc�j�����ddlm�t���jd�t�j	�d��t�}|j
�}���fd�}|j|�|jtd�|j�fd��t��|�j�y)	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�junkc����|tt�}t|��j�j	�|j	���j�j
�|j
��yrx)r
rrrF�getsockname�assertNotEqual�fileno)r��receivedr��srHs  ���rN�checkDescriptorzAUNIXTestsBuilder.test_sendFileDescriptor.<locals>.checkDescriptor=sY����j�'�;�?�H��*��
���Q�]�]�_�h�.B�.B�.D�E�

������
�H�O�O�,=�>rPz-Sending file descriptor encountered a problemc�8���jj�Srx�rqrt��ignoredrds �rN�<lambda>z:UNIXTestsBuilder.test_sendFileDescriptor.<locals>.<lambda>M����&�"2�"2�"A�"A�"C�rPN)
r
r��bindrkr�r}r��addCallback�
addErrbackr:�addBothr0r�)rHrh�dr�r�r�rds`   @@@rN�test_sendFileDescriptorz(UNIXTestsBuilder.test_sendFileDescriptor.s����	"��H��	���w��#�A�H�H�J��8��&�(���$�$�&��	?�	
�
�
�o�&�	���S�I�J�	�	�	�C�D���f�f�d�n�n�ErPTzfails under LXC in Debian CIc���Gd�dt�}Gd�dt�}|�}|�}||_t||||j�|j	|j
d�y)z�
        If a L{IUNIXTransport.sendFileDescriptor} call fills up
        the send buffer, any registered producer is paused.
        c��eZdZd�Zy)�SUNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing.<locals>.DoesNotReadc�8�|jj�yrx)rq�pauseProducingrus rNrvzbUNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing.<locals>.DoesNotRead.connectionMadeYs�����-�-�/rPN�rQrRrSrvrUrPrN�DoesNotReadr�Xs��
0rPr�c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�`UNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing.<locals>.SendsManyFileDescriptorsFc�.��t��_�jj�d��fd�}t|��_�jj
�j_�jjd�jtd�y)NTc����jj�jj���jj	d�y)N�x)rqrrr
r�rsrus�rN�senderzUNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing.<locals>.SendsManyFileDescriptors.connectionMade.<locals>.sendercs4����N�N�5�5�d�k�k�6H�6H�6J�K��N�N�(�(��.rPrzSend loop failure)
r
rq�registerProducerr+�taskrL�clock�startr�r:)rHr�s` rNrvzoUNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing.<locals>.SendsManyFileDescriptors.connectionMade_sf���$�h������/�/��d�;�/�(��/��	�"&�.�.�"8�"8��	�	���	�	����"�-�-�c�3F�GrPc�$�|j�yrx��_disconnectrus rN�
stopProducingznUNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing.<locals>.SendsManyFileDescriptors.stopProducingk���� � �"rPc�$�|j�yrxr�rus rN�resumeProducingzpUNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing.<locals>.SendsManyFileDescriptors.resumeProducingnr�rPc�f�d|_|jj�|j�y)NT)�pausedrq�unregisterProducerr�rus rNr�zoUNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing.<locals>.SendsManyFileDescriptors.pauseProducingqs%��"������1�1�3�� � �"rPc��|jj�|jj�|jjj�yrx)r��stoprq�abortConnection�otherrus rNr�zlUNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing.<locals>.SendsManyFileDescriptors._disconnectvs6���	�	��� ����.�.�0��
�
�$�$�4�4�6rPN)	rQrRrSr�rvr�r�r�r�rUrPrN�SendsManyFileDescriptorsr�\s!���F�

H�
#�
#�
#�

7rPr�z*sendFileDescriptor producer was not pausedN)r,r�r0r��
assertTruer�)rHr�r�rdrhs     rN�-test_sendFileDescriptorTriggersPauseProducingz>UNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducingQsY��	0�-�	0�	7�':�	7�>*�+����������f�f�d�n�n�E�����
�
�'S�TrPc����t�}t|j�d��t�}g}|j	�}|j|j�|j�fd��t|�||j�|j|dt�|djt�|j�jjt�y)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}.
        Nc�8���jj�Srxr�r�s �rNr�z=UNIXTestsBuilder.test_fileDescriptorOverrun.<locals>.<lambda>�r�rPr)r
rkr�r}r�r��appendr0r��assertIsInstancer7�trapr"rz�valuer#)rH�cargorh�resultr�rds     @rN�test_fileDescriptorOverrunz+UNIXTestsBuilder.test_fileDescriptorOverrun�s�������#�E�L�L�N�D�9��&�(�����$�$�&��	�	�	�&�-�-� �	�	�	�C�D���f�f�d�n�n�E����f�Q�i��1��q�	���'�(����f�m�m�1�1�3H�IrPc�j��ddlm}ddlm}ddlm}d��t
t�G�fd�dt��}Gd�d	|�}|tt�\}}|j|j�|j|j�|�}	|||	�}
t�\}}t�\}
}|jt|�|jt|�d
}||
g}||�\}}||||�|
j�|j!t#|	j$�|�|j't)|�j+t)|	j$���|	j$r2|D�cgc]
}�|���}}|j!||	j,�yycc}w)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��sendmsgc�H�t|�}|j|jfSrx)r�st_dev�st_ino)rm�fss  rN�deviceInodeTuplezTUNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.deviceInodeTuple�s���r��B��I�I�r�y�y�)�)rPc���eZdZd�Z�fd�Zy)�PUNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.FakeProtocolc� �g|_g|_yrx)�fds�deviceInodesReceivedrus rNrozYUNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.FakeProtocol.__init__�s�����,.��)rPc���|jj|�|jj�|��t|�yrx)rr�rr)rHrmr�s  �rNr�zgUNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.FakeProtocol.fileDescriptorReceived�s4���������#��)�)�0�0�1A�"�1E�F��b�	rPN)rQrRrSror�)r�s�rN�FakeProtocolr��s
���
/�
rPrc�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�PUNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.FakeReceiver�c� �||_||_yrx)r
�protocol)rH�skt�protos   rNrozYUNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.FakeReceiver.__init__�s��!��� %��
rPc��yrxrUr�s  rN�
_dataReceivedz^UNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.FakeReceiver._dataReceived����rPc��yrxrUrus rNr�zXUNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.FakeReceiver.getHost�rrPc��yrxrUrus rNr�zXUNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.FakeReceiver.getPeer�rrPc��yrxrU)rH�os  rN�
_getLogPrefixz^UNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver.<locals>.FakeReceiver._getLogPrefix�rrPN)	rQrRrS�
bufferSizeror
r�r�rrUrPrN�FakeReceiverr�s ���J�
&�
�
�
�
rPrssome data needs to be sentN)r
r��twisted.internet.unixr��twisted.python.sendmsgr�rr$r,rr�
addCleanuprrr�doReadrF�lenr�assertFalse�set�intersectionr)rH�ancillaryPackerr�r�r�rr�
sendSocket�
recvSocketr�receiver�	fileOneFD�fileOneName�	fileTwoFD�fileTwoName�
dataToSend�	fdsToSend�	ancillary�
expectedCountrm�deviceInodesSentr�s                     @rN�)_sendmsgMixinFileDescriptorReceivedDriverz:UNIXTestsBuilder._sendmsgMixinFileDescriptorReceivedDriver�sx���:	&�7�2�	*�
�,�	-�	�.�	�
.�	�	�=�	�&",�G�[�!A��
�J����
�(�(�)����
�(�(�)�����
�E�2��")���	�;�!(���	�;������,������,�2�
��	�*�	�#2�9�#=� �	�=��
�J�	�2�����	
����U�Y�Y���7�	
����Y��4�4�S����^�D�E��9�9�?H�I�� 0�� 4�I��I����-�u�/I�/I�J���Is�F0c�>��ddlm��fd�}|j|�y)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_RIGHTSc�8��t�tdg|���fg}d}||fS)N�ii��rr)r'r(r)r.s   �rNrz[UNIXTestsBuilder.test_multiFileDescriptorReceivedPerRecvmsgOneCMSG.<locals>.ancillaryPackers,���$�j�$�t�2H�i�2H�I�J�I��M��m�+�+rPN�rr.r+�rHrr.s  @rN�1test_multiFileDescriptorReceivedPerRecvmsgOneCMSGzBUNIXTestsBuilder.test_multiFileDescriptorReceivedPerRecvmsgOneCMSG�s���	6�	,�
	
�6�6��GrPz=Multi control message ancillary sendmsg not supported on Mac.c�>��ddlm��fd�}|j|�y)z�
        _SendmsgMixin handles multiple file descriptors per recvmsg, calling
        L{IFileDescriptorReceiver.fileDescriptorReceived} once per received
        file descriptor. Scenario: two CMSGs with one FD each.
        rr-c	�Z��|D�cgc]}t�td|�f��}}d}||fScc}w)N�ir1r2)r'rmr(r)r.s    �rNrz\UNIXTestsBuilder.test_multiFileDescriptorReceivedPerRecvmsgTwoCMSGs.<locals>.ancillaryPackers9���KT�U�R�*�j�$�s�B�-�@�U�I�U��M��m�+�+��Vs�(Nr3r4s  @rN�2test_multiFileDescriptorReceivedPerRecvmsgTwoCMSGszCUNIXTestsBuilder.test_multiFileDescriptorReceivedPerRecvmsgTwoCMSGs
s���	6�	,�
	
�6�6��GrPc�*���ddlm�d�}�fd�}g}t|j�|j	t
|j�|j
�d|�|j|�d�t�fd�|D��}|j|d�y	)
z�
        _SendmsgMixin handles multiple file descriptors per recvmsg, calling
        L{IFileDescriptorReceiver.fileDescriptorReceived} once per received
        file descriptor. Scenario: unsupported CMSGs.
        rr�c��g}d}||fS)NrrU)r'r(r)s   rNrz[UNIXTestsBuilder.test_multiFileDescriptorReceivedPerRecvmsgBadCMSG.<locals>.ancillaryPacker0s���I��M��m�+�+rPc�8��d}dg}d}�j|||�S)Ns	some data)NNrPr)�ReceivedMessage)r
�args�kwargsrnr(�flagsr�s      �rN�fakeRecvmsgUnsupportedAncillaryzkUNIXTestsBuilder.test_multiFileDescriptorReceivedPerRecvmsgBadCMSG.<locals>.fakeRecvmsgUnsupportedAncillary5s*����D�*�+�I��E��*�*�4��E�B�BrP�recvmsgz#received unsupported ancillary datac3�,�K�|]}�|dv���
y�w)�formatNrU)�.0�e�expectedMessages  �rN�	<genexpr>zUUNIXTestsBuilder.test_multiFileDescriptorReceivedPerRecvmsgBadCMSG.<locals>.<genexpr>Ds�����C�q�O�q��{�2�C�s�z+Expected message not found in logged eventsN)
�twisted.pythonr�r9r�rr;r�r+�anyr�)rHrrA�events�foundrGr�s     @@rN�1test_multiFileDescriptorReceivedPerRecvmsgBadCMSGzBUNIXTestsBuilder.test_multiFileDescriptorReceivedPerRecvmsgBadCMSG!s~���	+�	,�
	C����F�M�M�"������
�
�6��
�
�7�I�'F�G��6�6��G�@���C�F�C�C������L�MrPc��ddlm}|�\}}g}t|j�|j	t
|j�Gd�dt�}||j�d�}t�}t||||j�|j�|jd�|jd|jd��d	}d
}	t|j |j"|	|��}
|D]1}|
j%�D]\}}
|
|j'|�k7s��0y|j)d|
�d
t+|��d��y)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��eZdZd�Zy)�RUNIXTestsBuilder.test_avoidLeakingFileDescriptors.<locals>.RecordEndpointAddressesc��|jj�|_|jj�|_t
j
|�yrx)rqr��hostAddressr��peerAddressrkrvrus rNrvzaUNIXTestsBuilder.test_avoidLeakingFileDescriptors.<locals>.RecordEndpointAddresses.connectionMade\s:��#'�>�>�#9�#9�#;�� �#'�>�>�#9�#9�#;�� �"�1�1�$�7rPNr�rUrPrN�RecordEndpointAddressesrP[s��
8rPrTr�FrPrz�%(protocolName)s (on %(hostAddress)r) does not provide IFileDescriptorReceiver; closing file descriptor received (from %(peerAddress)r).r,)rRrS�protocolNamerDzExpected event (z) not found in logged events (�)N)r
r�r9r�rr;rkr�r,r0r�r�setblockingrF�recvr�rSrR�items�getrr	)rHr��probeClient�probeServerrKrTrdrhrD�clsName�
expectedEvent�logEvent�k�vs              rN� test_avoidLeakingFileDescriptorsz1UNIXTestsBuilder.test_avoidLeakingFileDescriptorsGsJ��	&�#-�<� ��[����F�M�M�"������
�
�6�	8�&8�	8�)��);�);�)=�w�G��$�&����f�f�d�n�n�E�	����	����&�����k�.�.�t�4�5�
:�	�
(����*�*��*�*� ��	
�
��	�H�%�+�+�-�
���1�����Q��'��
�
�
	�
�I�I�"�����
rPc�h��tt�G�fd�dt��}t�}t	|j�d�}|�}t
�||�j��jt|jd��jdt|jdd��y)z�
        L{IUNIXTransport.sendFileDescriptor} sends file descriptors before
        L{ITransport.write} sends normal bytes.
        c�$��eZdZd�Z�fd�Zd�Zy)�JUNIXTestsBuilder.test_descriptorDeliveredBeforeBytes.<locals>.RecordEventsc�<�tj|�g|_yrx)r,rvrKrus rNrvzYUNIXTestsBuilder.test_descriptorDeliveredBeforeBytes.<locals>.RecordEvents.connectionMade�s��#�2�2�4�8� ��rPc�z���jt|�|jjt	|��yrx)rrrKr��type)�	innerSelfr�rHs  �rNr�zaUNIXTestsBuilder.test_descriptorDeliveredBeforeBytes.<locals>.RecordEvents.fileDescriptorReceived�s*�������z�2�� � �'�'��Z�(8�9rPc�:�|jj|�yrx)rK�extendr�s  rNr�zWUNIXTestsBuilder.test_descriptorDeliveredBeforeBytes.<locals>.RecordEvents.dataReceived�s�����"�"�4�(rPN)rQrRrSrvr�r�rus�rN�RecordEventsre�s���
!�
:�
)rPrlr�r�N)rr$r,r
rkr�r0r�rF�intrK�bytes)rHrlr�rdrhs`    rN�#test_descriptorDeliveredBeforeBytesz4UNIXTestsBuilder.test_descriptorDeliveredBeforeBytes�s����
�,�	-�
	)�.�
	)�
.�
	)����#�E�L�L�N�G�<�������f�f�d�n�n�E�����f�m�m�A�.�/�����%��
�
�a�b�(9�":�;rPN)rQrRrSrTr'r]r\r�r�rr=�isLinuxr�r�r�r�r��sendmsgSkipReasonr�r�r�r+r5�isMacOSXr9rMrbrprUrPrNr�r��s����'����
�I�E���H�����E��
C�	�
C�<���H�����E��O�	�O�M�,��K�*�+� F�,� F�D�D�0�1�.U�2�.U�`��K�*�+�J�,�J�.aK�F��K�*�+�
H�,�
H�������G����K�*�+�
H�,�	�

H���K�*�+�#N�,�#N�J��K�*�+�J�,�J�X��K�*�+�<�,�<rPr�c�n�eZdZdZej
fZd�Zee	j�d�d��Zy)�UNIXDatagramTestsBuilderzE
    Builder defining tests relating to L{IReactorUNIXDatagram}.
    c�V�|jd|j�t��y)z�
        The UNIX socket created by L{IReactorUNIXDatagram.listenUNIXDatagram}
        is created with the mode specified.
        �listenUNIXDatagramN)rOrr)rus rN�test_listenModez(UNIXDatagramTestsBuilder.test_listenMode�s��
	
���+�T�[�[�]�<L�<N�OrPr�c���t|�}|j�}|jd|zt��}|j	|j�t
d|z��y)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)rZrCrwr)rFr�rr�s    rNr�z<UNIXDatagramTestsBuilder.test_listenOnLinuxAbstractNamespace�sU���T�"���#�#�%���)�)�$��+�7G�7I�J����������T�D�[�)A�BrPN)rQrRrSrTr�IReactorUNIXDatagramr]rxrr=rqr�rUrPrNruru�sM���%�9�9�;��
P���H�����E��	C�	�	CrPruc�B�eZdZUdZeefZeee	e
ed<d�Zd�Z
y)�SocketUNIXMixinzb
    Mixin which uses L{IReactorSocket.adoptStreamPort} to hand out listening
    UNIX ports.
    r]c�B�tt�}tdd��}|j|�|j	d�|jd�	|j
|j�|j|�|j�S#|j�wxYw)zj
        Get a UNIX port from a reactor, wrapping an already-initialized file
        descriptor.
        r_r`ra�F)
r
rrr��listenrW�adoptStreamPortr��familyr)rHrLrK�portSockrJs     rN�getListeningPortz SocketUNIXMixin.getListeningPort�sv��
�'�?���W�#�.���
�
�d����������U�#�	��*�*�8�?�?�+<�h�o�o�w�W��N�N���H�N�N��s�*B�Bc�:�|j|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�rf�rHrL�addressrKs    rN�connectToListenerz!SocketUNIXMixin.connectToListener�����"�"�7�<�<��9�9rPN)rQrRrSrTr'r&r]rrrrrir�r�rUrPrNr|r|�s6���	��?����$�y�/�!:�;��
� :rPr|c��eZdZdZd�Zd�Zy)�ListenUNIXMixinzZ
    Mixin which uses L{IReactorTCP.listenUNIX} to hand out listening UNIX
    ports.
    c�@�tdd��}|j||�S)z0
        Get a UNIX port from a reactor
        r_r`ra)rr�)rHrLrKrJs    rNr�z ListenUNIXMixin.getListeningPorts#��
�W�#�.���!�!�$��0�0rPc�:�|j|j|�Sr�r�r�s    rNr�z!ListenUNIXMixin.connectToListenerr�rPN)rQrRrSrTr�r�rUrPrNr�r�s���
1�:rPr�c�<�eZdZUefZeeeee	d<d�Z
d�Zy)�UNIXPortTestsMixinr]c�R�|�dt|j�j���S)zZ
        Get the message expected to be logged when a UNIX port starts listening.
        z
 starting on �r6r�rf)rHr�rKs   rN�#getExpectedStartListeningLogMessagez6UNIXPortTestsMixin.getExpectedStartListeningLogMessage#s'����-��T�\�\�^�5H�5H�(I�'L�M�MrPc�P�dt|j�j��d�S)zJ
        Get the expected connection lost message for a UNIX port
        z(UNIX Port z Closed)r�)rHr�s  rN�getExpectedConnectionLostLogMsgz2UNIXPortTestsMixin.getExpectedConnectionLostLogMsg)s%���\�$�,�,�.�*=�*=�>�?�x�H�HrPN)rQrRrSr'r]rrrrrir�r�rUrPrNr�r� s)��?K�o����$�y�/�!:�;�M�N�IrPr�c��eZdZdZy)�UNIXPortTestsBuilderz.
    Tests for L{IReactorUNIX.listenUnix}
    N�rQrRrSrTrUrPrNr�r�0���rPr�c��eZdZdZy)�UNIXFDPortTestsBuilderz3
    Tests for L{IReactorUNIX.adoptStreamPort}
    Nr�rUrPrNr�r�;r�rPr�c�(�eZdZeeefZd�Zd�Zd�Z	y)�%UNIXAdoptStreamConnectionTestsBuilderc��|j�}ddlm}Gd�dt�}|tt
�\}}|j
d�|j|j�|j|j�|j�}|�}|j|t|�}|j|�y)z�
        {IReactorSocket.adoptStreamConnection} returns None if the given
        factory's buildProtocol returns None.
        rr�c��eZdZd�Zy)�XUNIXAdoptStreamConnectionTestsBuilder.test_buildProtocolReturnsNone.<locals>.NoneFactoryc��yrxrU)rHr�s  rN�
buildProtocolzfUNIXAdoptStreamConnectionTestsBuilder.test_buildProtocolReturnsNone.<locals>.NoneFactory.buildProtocol\s��rPN)rQrRrSr�rUrPrN�NoneFactoryr�[s��
rPr�FN)rCr
r�r*rrrWrrr��adoptStreamConnection�assertIsNone)	rHrLr�r��s1�s2�s1FDrKr�s	         rN�test_buildProtocolReturnsNonezCUNIXAdoptStreamConnectionTestsBuilder.test_buildProtocolReturnsNoneMs����#�#�%��%�	�-�	��G�[�1���B�
���u��������!�������!��y�y�{���-���.�.�t�W�g�F�����&�!rPc����fd�}�j�}�j|dd��}|j|��j|�y)z>
        Helper method to test UNIX server addresses.
        c�,��|\}}}	td|j�j�}�jd|jj
�d|�d�t
|j���jd|jj
�d|��|jj�|jjd}�j|t�|jj�y#|jj�wxYw)Nr>z<AccumulatingProtocol #z on �>zAccumulatingProtocol,�,r)
r8r�rfrFrq�	sessionno�str�logstrrK�
peerAddressesr�rrt)�	protocolsrhrdr��portPathrSrHs      �rN�	connectedzOUNIXAdoptStreamConnectionTestsBuilder.test_ServerAddressUNIX.<locals>.connectedns����#,� �F�F�D�
2�6�r�4�<�<�>�;N�;N�O��� � ��'�'�1�1�8�=���(�(�)��� � ��'�'�1�1�8�=��$�$�+�+��%�n�n�:�:�1�=���%�%�k�;�?�� � �/�/�1��� � �/�/�1�s�CC7�7DN)�	interface�
addressFamily)rC�getConnectedClientAndServerr��
runReactor)rHr�rLr�s`   rN�test_ServerAddressUNIXz<UNIXAdoptStreamConnectionTestsBuilder.test_ServerAddressUNIXisN���
	2�,�#�#�%���,�,��t�4�
-�
��	
�
�
�i� ����� rPc�����
��t�}t�|_t��t��_t��_t	�}t�|_t�|_tdd��}�j
||��
��fd�}|jj|�t|j�jg�}�fd�}	|j|	�t���j|	�t|j�jg�}
��
fd�}|
j|��j�
j�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.
        r_r`rac�����j|j��j|j��j|jj	�t
��yrx)�removeReaderrq�removeWriterr�r�r)rrLrds ��rN�firstServerConnectedz_UNIXAdoptStreamConnectionTestsBuilder.getConnectedClientAndServer.<locals>.firstServerConnected�sF���� � ����1�� � ����1��)�)�%�/�/�*@�*@�*B�G�V�TrPc�@���jr�j�|Srx)�runningr�)r�rLs �rNr�zOUNIXAdoptStreamConnectionTestsBuilder.getConnectedClientAndServer.<locals>.stop�s�����������MrPc�8��|\}}�j||�f�yrx)r�)r�rhrd�deferredr�s   ��rNr�zPUNIXAdoptStreamConnectionTestsBuilder.getConnectedClientAndServer.<locals>.start�s!���&�N�F�F����v�v�t�4�5rP)r3r�protocolConnectionMade�protocolConnectionLostr2rr�r�rr�r�r�r�rf)rHrLr�r��firstServerrhrJr��lostDeferredr��
startDeferredr�r�r�rds `          @@@rNr�zAUNIXAdoptStreamConnectionTestsBuilder.getConnectedClientAndServer�s(���&�'��-5�Z��*� �"��(0�
��%�(0�
��%� �"��(0�
��%�(0�
��%��W�#�.���!�!�$��4��	U�
	�*�*�6�6�7K�L�$�
�
*�
*�F�,I�,I�J�
��	�
	���T�"��:�����D�!�%�
�
*�
*�F�,I�,I�J�
�
�	6�	�!�!�%�(����D�L�L�N�/�/��8��rPN)
rQrRrSr%r&r'r]r�r�r�rUrPrNr�r�Fs#�������"�8 !�D6rPr�c�6�eZdZdZefZdZed��Zd�Z	d�Z
y)�UnixClientTestsBuilderz7
    Define tests for L{IReactorUNIX.connectUNIX}.
    Nc�R�|j�t|�|_|jS)z�
        Return a path usable by C{connectUNIX} and C{listenUNIX}.

        @return: A path instance, built with C{_abstractPath}.
        )�_pathrZrus rNrJzUnixClientTestsBuilder.path�s$���:�:��&�t�,�D�J��z�z�rPc�:�|j|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�rJ�rHrLrKs   rNrzUnixClientTestsBuilder.listen�s���!�!�$�)�)�W�5�5rPc�:�|j|j|�S)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�rJr�s   rN�connectzUnixClientTestsBuilder.connect�s���"�"�4�9�9�g�6�6rP)rQrRrSrTr'r]r��propertyrJrr�rUrPrNr�r��s2���'����E�
����
6�
7rPr�)jrT�hashlibr�osrrrrr�pprintr	r
r
rrr�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/r0�#twisted.internet.test.reactormixinsr1�twisted.internet.test.test_tcpr2r3r4r5�twisted.python.compatr6�twisted.python.failurer7�twisted.python.filepathr8�twisted.python.logr9r:r;�twisted.python.reflectr<�twisted.python.runtimer=r�rrr@rZr\rkr}r�rur|r�r�r�r�r��globals�update�makeTestCaseClassesr�rUrPrN�<module>r�s^���
�2�2��;�;���$�+�+���*��G�1�-�0�@�@�M���
��U�T�-���?���/�*�?�?�?�0�+�
�0�
1�����)�*�6�K��
<�<�")�?�/�?�,"�,�"�J
�
$�%�;�/�;�&�;�|S<���8L�S<�lC���C�B*:�*:�Z:�:�@
I�
I� �����	������	�{�,C�^�{�|�	���!�5�5�7�8��	���)�=�=�?�@��	���%�9�9�;�<��	���'�;�;�=�>��	���6�J�J�L�M�*7�^�-C�*7�Z�	���'�;�;�=�>��G���G��s�I=�=J�J

Zerion Mini Shell 1.0