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: //lib/python3/dist-packages/twisted/python/test/__pycache__/test_sendmsg.cpython-38.pyc
U


W[�b�@sVdZddlZddlZddlZddlmZmZmZmZm	Z	ddl
mZddlm
Z
mZmZmZmZzddlmZmZWnek
r�dZYnXdZddlmZdd	lmZmZdd
lmZddlmZddlmZm Z m!Z!dd
l"m#Z#ddl$m%Z%ddl&m'Z'e%�(��rddlm)Z)dZ*ndZ*z$ddl+m,Z,m-Z-ddl+m.Z.m/Z/Wnek
�r\dZ0YnXdZ0z ddl+m1Z1m2Z2ddl+m3Z3Wnek
�r�dZ4YnXdZ4Gdd�de5�Z6dd�Z7Gdd�de8�Z9Gdd�de�Z:d d!�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'�ZAGd,d-�d-e'�ZBGd.d/�d/e'�ZCdS)0z&
Tests for L{twisted.python.sendmsg}.
�N)�devnull�pipe�read�close�pathsep)�pack)�
SOL_SOCKET�AF_INET�AF_INET6�socket�error)�AF_UNIX�
socketpairz)Platform does not support AF_UNIX sockets)�reactor)�Deferred�inlineCallbacks)�ProcessDone)�ProcessProtocol)�_PY3�
intToBytes�bytesEnviron)�FilePath)�platform)�TestCase)�MSG_DONTWAITz7MSG_DONTWAIT is only known to work as intended on Linux)�sendmsg�recvmsg)�
SCM_RIGHTS�getSocketFamilyz!Platform doesn't support sendmsg.)�send1msg�recv1msg)�
getsockfamz$Cannot import twisted.python.sendmsgc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�	_FDHolderzP
    A wrapper around a FD that will remember if it has been closed or not.
    cCs
||_dS�N��_fd)�self�fd�r(�B/usr/lib/python3/dist-packages/twisted/python/test/test_sendmsg.py�__init__@sz_FDHolder.__init__cCs|jS)z/
        Return the fileno of this FD.
        r$�r&r(r(r)�filenoCsz_FDHolder.filenocCs|jrt|j�d|_dS)zH
        Close the FD. If it's already been closed, do nothing.
        N)r%rr+r(r(r)rIs
z_FDHolder.closecCs.|jr*tst}t�d|jf|�|��dS)z>
        If C{self._fd} is unclosed, raise a warning.
        zFD %s was not closed!N)r%r�Warning�warnings�warnr)r&�ResourceWarningr(r(r)�__del__Qs�z_FDHolder.__del__cCs|Sr#r(r+r(r(r)�	__enter__\sz_FDHolder.__enter__cCs|��dSr#)r)r&�exc_type�	exc_value�	tracebackr(r(r)�__exit___sz_FDHolder.__exit__N)
�__name__�
__module__�__qualname__�__doc__r*r,rr1r2r6r(r(r(r)r"<sr"cCst�\}}t|�t|�fS)zI
    Create a pipe, and return the two FDs wrapped in L{_FDHolders}.
    )rr")�r�wr(r(r)�	_makePipecs
r=c@seZdZdZdd�ZdS)�ExitedWithStderrz,
    A process exited with some stderr.
    cCs&d�dgt|j��}tr"t|�}|S)zY
        Dump the errors in a pretty way in the event of a subprocess traceback.
        �
�)�join�list�argsr�repr�r&�resultr(r(r)�__str__qszExitedWithStderr.__str__N)r7r8r9r:rGr(r(r(r)r>lsr>c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�StartStopProcessProtocola�
    An L{IProcessProtocol} with a Deferred for events where the subprocess
    starts and stops.

    @ivar started: A L{Deferred} which fires with this protocol's
        L{IProcessTransport} provider when it is connected to one.

    @ivar stopped: A L{Deferred} which fires with the process output or a
        failure if the process produces output on standard error.

    @ivar output: A C{str} used to accumulate standard output.

    @ivar errors: A C{str} used to accumulate standard error.
    cCs t�|_t�|_d|_d|_dS)Nr@)r�started�stopped�output�errorsr+r(r(r)r*�sz!StartStopProcessProtocol.__init__cCs|j�|j�dSr#)rI�callbackZ	transportr+r(r(r)�connectionMade�sz'StartStopProcessProtocol.connectionMadecCs|j|7_dSr#)rK�r&�datar(r(r)�outReceived�sz$StartStopProcessProtocol.outReceivedcCs|j|7_dSr#)rLrOr(r(r)�errReceived�sz$StartStopProcessProtocol.errReceivedcCs4|�t�r|j�|j�n|j�t|j|j��dSr#)ZcheckrrJrMrKZerrbackr>rL)r&�reasonr(r(r)�processEnded�s
�z%StartStopProcessProtocol.processEndedN)	r7r8r9r:r*rNrQrRrTr(r(r(r)rH|srHc
Cs|ttj���j}t�}tt�tj����j|d<t�}t	j
|||tt��|d���jt
|�g|dddddd||id�|S)	z�
    Start a script that is a peer of this test as a subprocess.

    @param script: the module name of the script in this directory (no
        package prefix, no '.py')
    @type script: C{str}

    @rtype: L{StartStopProcessProtocol}
    s
PYTHONPATHz.pyrr<�r;�)�envZchildFDs)r�sys�
executableZasBytesMode�pathrrrArHrZspawnProcess�__file__Zsiblingr)ZscriptZoutputFDZpyExerW�ssppr(r(r)�_spawn�s"

���	r]cs$eZdZdZdZ�fdd�Z�ZS)�BadLista$
    A list which cannot be iterated sometimes.

    This is a C{list} subclass to get past the type check in L{send1msg}, not
    as an example of how real programs might want to interact with L{send1msg}
    (or anything else).  A custom C{list} subclass makes it easier to trigger
    certain error cases in the implementation.

    @ivar iterate: A flag which indicates whether an instance of L{BadList}
        will allow iteration over itself or not.  If C{False}, an attempt to
        iterate over the instance will raise an exception.
    Tcs&|jrd|_tt|���Std��dS)a
        Allow normal list iteration, or raise an exception.

        If C{self.iterate} is C{True}, it will be flipped to C{False} and then
        normal iteration will proceed.  If C{self.iterate} is C{False},
        L{RuntimeError} is raised instead.
        FzSomething bad happenedN)�iterate�superr^�__iter__�RuntimeErrorr+��	__class__r(r)ra�szBadList.__iter__)r7r8r9r:r_ra�
__classcell__r(r(rcr)r^�sr^c@seZdZdZdd�ZdS)�	WorseListz�
    A list which at first gives the appearance of being iterable, but then
    raises an exception.

    See L{BadList} for a warning about not writing code like this.
    cCsGdd�dt�}|�S)zn
        Return an iterator which will raise an exception as soon as C{next} is
        called on it.
        c@seZdZdd�ZdS)z'WorseList.__iter__.<locals>.BadIteratorcSstd��dS)NzThis is a really bad case.)rbr+r(r(r)�next�sz,WorseList.__iter__.<locals>.BadIterator.nextN)r7r8r9rgr(r(r(r)�BadIterator�srh)�object)r&rhr(r(r)ra�szWorseList.__iter__N)r7r8r9r:rar(r(r(r)rf�srfc@s�eZdZdZedk	reZnedk	r&eZdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�Zedk	r�ee_dd�Zedd��Zdd�ZdS)�CModuleSendmsgTestszf
    Tests for sendmsg extension module and associated file-descriptor sending
    functionality.
    NcCstt�\|_|_dS�z0
        Create a pair of UNIX sockets.
        N�rr
�inputrKr+r(r(r)�setUp�szCModuleSendmsgTests.setUpcCs|j��|j��dS�z4
        Close the sockets opened by setUp.
        N�rmrrKr+r(r(r)�tearDowns
zCModuleSendmsgTests.tearDownc	Cs�|�tt�|�ttd�|�ttdddgt��|�ttt�ddg�|�ttdt�dg�|�ttddt�g�|�ttdddt��dS)a�
        The argument types accepted by L{send1msg} are:

          1. C{int}
          2. read-only character buffer
          3. C{int}
          4. sequence

        The 3rd and 4th arguments are optional.  If fewer than two arguments or
        more than four arguments are passed, or if any of the arguments passed
        are not compatible with these types, L{TypeError} is raised.
        rU�hello worldrVN)�assertRaises�	TypeErrorrrir+r(r(r)�test_sendmsgBadArguments
s�z,CModuleSendmsgTests.test_sendmsgBadArgumentscCsHt�}|�d�d|_|�ttddd|�d|_|�ttddd|�dS)z�
        If iteration over the ancillary data list fails (at the point of the
        C{__iter__} call), the exception with which it fails is propagated to
        the caller of L{send1msg}.
        )rUrVrrFrUrrrVTN)r^�appendr_rsrbr)r&ZbadListr(r(r)�test_badAncillaryIter's
z)CModuleSendmsgTests.test_badAncillaryItercCst�}|�ttddd|�dS)z�
        If iteration over the ancillary data list fails (at the point of a
        C{next} call), the exception with which it fails is propagated to the
        caller of L{send1msg}.
        rUrrrVN)rfrsrbr)r&Z	worseListr(r(r)�test_badAncillaryNext8s�z)CModuleSendmsgTests.test_badAncillaryNextcCs�|�ttddddg�|�ttddddg�|�ttddddg�|�ttddddddt�fg�|�ttdddt�g�}|�dt|��|�ttdddt�ddfg�|�ttddddt�dfg�|�ttdddddt�fg�d	S)
a
        The ancillary data list contains three-tuples with element types of:

          1. C{int}
          2. C{int}
          3. read-only character buffer

        If a tuple in the ancillary data list does not elements of these types,
        L{TypeError} is raised.
        rUrrrVr()rU)rUrVZgoodbyezFsend1msg argument 3 expected list of tuple, got list containing objectN)rsrtrri�assertEqual�str�r&�excr(r(r)�test_sendmsgBadAncillaryItemCs^������z0CModuleSendmsgTests.test_sendmsgBadAncillaryItemc	CsDtt��}|��}W5QRX|�tt|d�}|�|jdtj	�dS)��
        If the underlying C{sendmsg} call fails, L{send1msg} raises
        L{socket.error} with its errno set to the underlying errno value.
        �hello, worldrN�
�openrr,rsrrryrC�errno�EBADF�r&Zprober'r|r(r(r)�test_syscallErrorhs
z%CModuleSendmsgTests.test_syscallErrorc	CsJtt��}|��}W5QRX|�tt|dddg�}|�|jdtj	�dS)z�
        The behavior when the underlying C{sendmsg} call fails is the same
        whether L{send1msg} is passed ancillary data or not.
        rr)rrZ0123Nr�r�r(r(r)�#test_syscallErrorWithControlMessagess
�z7CModuleSendmsgTests.test_syscallErrorWithControlMessagecCsHd}|�t|�t|j��|d��t|j��d�}|�||dgf�dS)zK
        L{recv1msg} will retrieve a message sent via L{send1msg}.
        �
hello, world!r�r'N)ry�lenrrmr,r rK�r&�messagerFr(r(r)�test_roundtrips�z"CModuleSendmsgTests.test_roundtripcCs:t|j��ddg�t|j��d�}|�|ddgf�dS)z�
        L{send1msg} treats an empty ancillary data list the same way it treats
        receiving no argument for the ancillary parameter at all.
        r�rr�N)rrmr,r rKryrEr(r(r)�test_roundtripEmptyAncillary�sz0CModuleSendmsgTests.test_roundtripEmptyAncillarycCsttd�D]\}zt|j��dt�Wqtk
rb}z"|�|jdtj	�WY�qpW5d}~XYqXq|�
d�dS)z�
        The C{flags} argument to L{send1msg} is passed on to the underlying
        C{sendmsg} call, to affect it in whatever way is defined by those
        flags.
        � AxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxrN�HFailed to fill up the send buffer, or maybe send1msg blocked for a while)�rangerrmr,rrryrCr��EAGAIN�fail�r&�i�er(r(r)�
test_flags�s	�zCModuleSendmsgTests.test_flagscCs.|�tt|j��ddd�}|�t|�d�dS)z�
        L{send1msg} will show a helpful exception message when given the wrong
        type of object for the 'ancillary' argument.
        r�ri�z*send1msg argument 3 expected list, got intN)rsrtrrmr,ryrz)r&rr(r(r)�test_wrongTypeAncillary�s�
�z+CModuleSendmsgTests.test_wrongTypeAncillaryccs�td|j���}|jVt�\}}|�|j�|�|j�|�,t|j��ddt	t
td|���fg�W5QRX|jV|�
t|��d�d�|�
t|��d�d�dS)	z�
        Calling L{sendsmsg} with SOL_SOCKET, SCM_RIGHTS, and a platform-endian
        packed file descriptor number should send that file descriptor to a
        different process, where it can be retrieved by using L{recv1msg}.
        ZcmodulepullpipeZblonkrr��zTest fixture data: blonk.
�N)r]rKr,rIr=�
addCleanuprrrmrrrrJryr�r&r\ZpipeOutZpipeInr(r(r)�test_sendSubProcessFD�s"
��z)CModuleSendmsgTests.test_sendSubProcessFDcCs^tttd|j���ftttd|j���fg}zt|j��dd|�Wntk
rXYnXdS)zf
        L{sendmsg} with two FDs in two separate ancillary entries
        does not segfault.
        r�s	some datarN)rrrrmr,rKrr)r&�	ancillaryr(r(r)�'test_sendmsgTwoAncillaryDoesNotSegfault�s�z;CModuleSendmsgTests.test_sendmsgTwoAncillaryDoesNotSegfault)r7r8r9r:�nonUNIXSkip�skip�CModuleImportSkiprnrqrurwrxr}r�r�r�r�r��dontWaitSkipr�rr�r�r(r(r(r)rj�s,%

rjc@sJeZdZdZedk	reZdd�Zdd�Zdd�Zd	d
�Z	e
dk	rFe
e	_dS)�CModuleRecvmsgTestszA
    Tests for L{recv1msg} (primarily error handling cases).
    Nc	Cs�|�tt�|�ttddddt��|�ttt�ddd�|�ttdt�dd�|�ttddt�d�|�ttdddt��dS)a�
        The argument types accepted by L{recv1msg} are:

          1. C{int}
          2. C{int}
          3. C{int}
          4. C{int}

        The 2nd, 3rd, and 4th arguments are optional.  If fewer than one
        argument or more than four arguments are passed, or if any of the
        arguments passed are not compatible with these types, L{TypeError} is
        raised.
        rUrV��N)rsrtr rir+r(r(r)�test_badArguments�sz%CModuleRecvmsgTests.test_badArgumentscCs|�ttdddd�dS)z�
        L{recv1msg} raises L{OverflowError} if passed a value for the
        C{cmsg_size} argument which exceeds C{SOCKLEN_MAX}.
        ri���N)rs�
OverflowErrorr r+r(r(r)�test_cmsgSpaceOverflowsz*CModuleRecvmsgTests.test_cmsgSpaceOverflowc	CsBtt��}|��}W5QRX|�tt|�}|�|jdtj	�dS)z�
        If the underlying C{recvmsg} call fails, L{recv1msg} raises
        L{socket.error} with its errno set to the underlying errno value.
        rN)
r�rr,rsrr ryrCr�r�r�r(r(r)r�s
z%CModuleRecvmsgTests.test_syscallErrorcCs8tt�\}}|�tt|��t�}|�|jdt	j
�dS)z�
        The C{flags} argument to L{recv1msg} is passed on to the underlying
        C{recvmsg} call, to affect it in whatever way is defined by those
        flags.
        rN)rr
rsrr r,rryrCr�r�)r&�reader�writerr|r(r(r)r�s�zCModuleRecvmsgTests.test_flags)r7r8r9r:r�r�r�r�r�r�r�r(r(r(r)r��sr�c@sZeZdZdZedk	reZdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zedk	rVee_dS)�CModuleGetSocketFamilyTestszh
    Tests for L{getsockfam}, a helper which reveals the address family of an
    arbitrary socket.
    NcCst|�}|�|j�|��S�z�
        Create a new socket using the given address family and return that
        socket's file descriptor.  The socket will automatically be closed when
        the test is torn down.
        )rr�rr,�r&Z
addressFamily�sr(r(r)�_socket/sz#CModuleGetSocketFamilyTests._socketcCs0|�tt�|�ttdd�|�ttt��dS)z�
        L{getsockfam} accepts a single C{int} argument.  If it is called in
        some other way, L{TypeError} is raised.
        rUrVN)rsrtr!rir+r(r(r)r�:sz-CModuleGetSocketFamilyTests.test_badArgumentsc	CsBtt��}|��}W5QRX|�tt|�}|�tj|j	d�dS)z�
        If the underlying C{getsockname} call fails, L{getsockfam} raises
        L{socket.error} with its errno set to the underlying errno value.
        rN)
r�rr,rsrr!ryr�r�rCr�r(r(r)r�Ds
z-CModuleGetSocketFamilyTests.test_syscallErrorcCs|�tt|�t���dS)z�
        When passed the file descriptor of a socket created with the C{AF_INET}
        address family, L{getsockfam} returns C{AF_INET}.
        N)ryr	r!r�r+r(r(r)�	test_inetOsz%CModuleGetSocketFamilyTests.test_inetcCs|�tt|�t���dS)z�
        When passed the file descriptor of a socket created with the
        C{AF_INET6} address family, L{getsockfam} returns C{AF_INET6}.
        N)ryr
r!r�r+r(r(r)�
test_inet6Wsz&CModuleGetSocketFamilyTests.test_inet6cCs|�tt|�t���dS)z�
        When passed the file descriptor of a socket created with the C{AF_UNIX}
        address family, L{getsockfam} returns C{AF_UNIX}.
        N)ryr
r!r�r+r(r(r)�	test_unix_sz%CModuleGetSocketFamilyTests.test_unix)
r7r8r9r:r�r�r�r�r�r�r�r�r�r(r(r(r)r�'s
r�c@sveZdZdZedk	reZdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
edk	rfee
_edd��ZdS)�SendmsgTestszB
    Tests for the Python2/3 compatible L{sendmsg} interface.
    NcCstt�\|_|_dSrkrlr+r(r(r)rnqszSendmsgTests.setUpcCs|j��|j��dSrorpr+r(r(r)rqxs
zSendmsgTests.tearDowncCs4|j��|�tt|jd�}|�|jdtj�dS)r~�hello, worldrN�	rmrrsrrryrCr�r�r{r(r(r)r��s
zSendmsgTests.test_syscallErrorcCs:|j��|�tt|jddgd�}|�|jdtj�dS)z�
        The behavior when the underlying C{sendmsg} call fails is the same
        whether L{sendmsg} is passed ancillary data or not.
        r�)rrs0123rNr�r{r(r(r)r��s
�z0SendmsgTests.test_syscallErrorWithControlMessagecCsTd}|�t|�t|j|��t|j�}|�|jd�|�|jd�|�|jg�dS)zI
        L{recvmsg} will retrieve a message sent via L{sendmsg}.
        �
hello, world!rN)	ryr�rrmrrKrP�flagsr�r�r(r(r)r��s
�
zSendmsgTests.test_roundtripcCs^ddd}|j�d�t|j|�}|�|t|�k�t|jt|��}|�t|d�|�dS)zS
        L{sendmsg} returns the number of bytes which it was able to send.
        �xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr��FrN)rmZsetblockingrZ
assertTruer�rrKry)r&r�ZsentZreceivedr(r(r)�test_shortsend�szSendmsgTests.test_shortsendcCs0t|jdgd�t|j�}|�|dgdf�dS)z�
        L{sendmsg} treats an empty ancillary data list the same way it treats
        receiving no argument for the ancillary parameter at all.
        r�rN)rrmrrKryrEr(r(r)r��s
z)SendmsgTests.test_roundtripEmptyAncillarycCsrtd�D]Z}zt|jdtd�Wqtk
r`}z"|�|jdtj�WY�qnW5d}~XYqXq|�	d�dS)z�
        The C{flags} argument to L{sendmsg} is passed on to the underlying
        C{sendmsg} call, to affect it in whatever way is defined by those
        flags.
        r�r�)r�rNr�)
r�rrmrrryrCr�r�r�r�r(r(r)r��s	�zSendmsgTests.test_flagsc
cs�td|j���}|jVt�\}}|�|j�|�|j�|�&t|jdt	t
td|���fg�W5QRX|jV|�
t|��d�d�|�
t|��d�d�dS)z�
        Calling L{sendmsg} with SOL_SOCKET, SCM_RIGHTS, and a platform-endian
        packed file descriptor number should send that file descriptor to a
        different process, where it can be retrieved by using L{recv1msg}.
        Zpullpipesblonkr�r�sTest fixture data: blonk.
r@N)r]rKr,rIr=r�rrrmrrrrJryrr�r(r(r)r��s 
��z"SendmsgTests.test_sendSubProcessFD)r7r8r9r:�
importSkipr�rnrqr�r�r�r�r�r�r�rr�r(r(r(r)r�js
r�c@sJeZdZdZedk	reZdd�Zdd�Zdd�Zd	d
�Z	e
dk	rFe
e	_dS)�GetSocketFamilyTestsz'
    Tests for L{getSocketFamily}.
    NcCst|�}|�|j�|Sr�)rr�rr�r(r(r)r��szGetSocketFamilyTests._socketcCs|�tt|�t���dS)z�
        When passed the file descriptor of a socket created with the C{AF_INET}
        address family, L{getSocketFamily} returns C{AF_INET}.
        N)ryr	rr�r+r(r(r)r�szGetSocketFamilyTests.test_inetcCs|�tt|�t���dS)z�
        When passed the file descriptor of a socket created with the
        C{AF_INET6} address family, L{getSocketFamily} returns C{AF_INET6}.
        N)ryr
rr�r+r(r(r)r�
szGetSocketFamilyTests.test_inet6cCs|�tt|�t���dS)z�
        When passed the file descriptor of a socket created with the C{AF_UNIX}
        address family, L{getSocketFamily} returns C{AF_UNIX}.
        N)ryr
rr�r+r(r(r)r�szGetSocketFamilyTests.test_unix)r7r8r9r:r�r�r�r�r�r�r�r(r(r(r)r��sr�)Dr:rXr�r.�osrrrrrZstructrrrr	r
rr
r�ImportErrorr�Ztwisted.internetrZtwisted.internet.deferrrZtwisted.internet.errorrZtwisted.internet.protocolrZtwisted.python.compatrrrZtwisted.python.filepathrZtwisted.python.runtimerZtwisted.trial.unittestrZisLinuxrr�Ztwisted.python.sendmsgrrrrr�rr r!r�rir"r=�	Exceptionr>rHr]rBr^rfrjr�r�r�r�r(r(r(r)�<module>sb



'	+qCC