Ë
    „ÇVh(  ã                   ó  — d Z ddlZddlZddlZddlZddlmZmZmZmZ ddl	m
Z
mZmZmZm	Z	 ddlmZ 	 ddl	mZmZ dZdd	lmZ dd
lmZ ddlmZmZ ddlmZ ddlmZ ddlm Z  ddl!m"Z" ddl#m$Z$  e"jJ                  «       r	ddl	m&Z& dZ'ndZ'	 ddl(m)Z)m*Z*m+Z+m,Z, dZ-dZ. G d„ d«      Z/d„ Z0 G d„ de1«      Z2 G d„ de«      Z3d„ Z4 ee-e.«       G d„ de$«      «       Z5 ee-e.«       G d„ d e$«      «       Z6y# e$ r dZY Œ½w xY w# e$ r dZ-dZ.Y Œmw xY w)!z&
Tests for L{twisted.python.sendmsg}.
é    N)ÚcloseÚpathsepÚpipeÚread)ÚAF_INETÚAF_INET6Ú
SOL_SOCKETÚerrorÚsocket)Úpack)ÚAF_UNIXÚ
socketpairFT)ÚskipIf)Úreactor)ÚDeferredÚinlineCallbacks)ÚProcessDone)ÚProcessProtocol)ÚFilePath)Úplatform)ÚTestCase)ÚMSG_DONTWAIT)Ú
SCM_RIGHTSÚgetSocketFamilyÚrecvmsgÚsendmsgÚ z!Platform doesn't support sendmsg.c                   ó4   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	y)	Ú	_FDHolderzP
    A wrapper around a FD that will remember if it has been closed or not.
    c                 ó   — || _         y ©N©Ú_fd)ÚselfÚfds     úP/home/dcms/DCMS/lib/python3.12/site-packages/twisted/python/test/test_sendmsg.pyÚ__init__z_FDHolder.__init__:   s	   € Øˆó    c                 ó   — | j                   S )z/
        Return the fileno of this FD.
        r"   ©r$   s    r&   Úfilenoz_FDHolder.fileno=   s   € ð x‰xˆr(   c                 óV   — | j                   rt        | j                   «       d| _         yy)zH
        Close the FD. If it's already been closed, do nothing.
        N)r#   r   r*   s    r&   r   z_FDHolder.closeC   s"   € ð 8Š8Ü$—(‘(ŒOØˆDHð r(   c                 óŽ   — | j                   r9t        j                  d| j                   › dt        «       | j	                  «        yy)z>
        If C{self._fd} is unclosed, raise a warning.
        zFD z was not closed!N)r#   ÚwarningsÚwarnÚResourceWarningr   r*   s    r&   Ú__del__z_FDHolder.__del__K   s5   € ð 8Š8ÜM‰M˜C §¡˜zÐ)9Ð:¼OÔLØJ‰JLð r(   c                 ó   — | S r!   © r*   s    r&   Ú	__enter__z_FDHolder.__enter__S   s   € Øˆr(   c                 ó$   — | j                  «        y r!   )r   )r$   Úexc_typeÚ	exc_valueÚ	tracebacks       r&   Ú__exit__z_FDHolder.__exit__V   s   € Ø
‰
r(   N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r'   r+   r   r1   r4   r9   r3   r(   r&   r   r   5   s%   „ ñòòòòòór(   r   c                  óH   — t        «       \  } }t        | «      t        |«      fS )zI
    Create a pipe, and return the two FDs wrapped in L{_FDHolders}.
    )r   r   )ÚrÚws     r&   Ú	_makePiperA   Z   s"   € ô ‹6D€A€qÜa‹Lœ) A›,Ð'Ð'r(   c                   ó   — e Zd ZdZdefd„Zy)ÚExitedWithStderrz,
    A process exited with some stderr.
    Úreturnc                 óh   — dj                  dgt        | j                  «      z   «      }t        |«      S )zY
        Dump the errors in a pretty way in the event of a subprocess traceback.
        ó   
r(   )ÚjoinÚlistÚargsÚrepr©r$   Úresults     r&   Ú__str__zExitedWithStderr.__str__g   s+   € ð —‘˜S˜E¤D¨¯©£OÑ3Ó4ˆÜF‹|Ðr(   N)r:   r;   r<   r=   ÚstrrM   r3   r(   r&   rC   rC   b   s   „ ñð˜ô r(   rC   c                   ó.   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zy)Ú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.
    c                 ó\   — t        «       | _        t        «       | _        d| _        d| _        y )Nr(   )r   ÚstartedÚstoppedÚoutputÚerrorsr*   s    r&   r'   z!StartStopProcessProtocol.__init__   s"   € Ü“zˆŒÜ“zˆŒØˆŒØˆr(   c                 óN   — | j                   j                  | j                  «       y r!   )rR   ÚcallbackÚ	transportr*   s    r&   ÚconnectionMadez'StartStopProcessProtocol.connectionMade…   s   € Ø‰×Ñ˜dŸn™nÕ-r(   c                 ó.   — | xj                   |z  c_         y r!   )rT   ©r$   Údatas     r&   ÚoutReceivedz$StartStopProcessProtocol.outReceivedˆ   ó   € ØŠtÑŽr(   c                 ó.   — | xj                   |z  c_         y r!   )rU   r[   s     r&   ÚerrReceivedz$StartStopProcessProtocol.errReceived‹   r^   r(   c                 óì   — |j                  t        «      r&| j                  j                  | j                  «       y | j                  j                  t        | j                  | j                  «      «       y r!   )Úcheckr   rS   rW   rT   ÚerrbackrC   rU   )r$   Úreasons     r&   ÚprocessEndedz%StartStopProcessProtocol.processEndedŽ   sF   € Ø<‰<œÔ$ØL‰L×!Ñ! $§+¡+Õ.àL‰L× Ñ Ô!1°$·+±+¸t¿{¹{Ó!KÕLr(   N)	r:   r;   r<   r=   r'   rY   r]   r`   re   r3   r(   r&   rP   rP   o   s!   „ ñòò.òòóMr(   rP   c                 óî  — t        t        j                  «      j                  «       j                  }t        t        j                  «      }t        t        j                  t        j                  «      «      j                  «       j                  |d<   t        «       }t        j                  |||t        t        «      j                  | dz   «      j                  «       j                  dg|ddd|dœ¬«       |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}
    Ú
PYTHONPATHz.pys   17r@   r?   )r   é   é   é   )ÚenvÚchildFDs)r   ÚsysÚ
executableÚ
asTextModeÚpathÚdictÚosÚenvironr   rG   rP   r   ÚspawnProcessÚ__file__Úsibling)ÚscriptÚoutputFDÚpyExerk   Ússpps        r&   Ú_spawnr{   •   s¿   € ô ”S—^‘^Ó$×/Ñ/Ó1×6Ñ6€EÜ
Œrz‰zÓ
€CÜ ¤§¡¬c¯h©hÓ!7Ó8×CÑCÓE×JÑJ€CˆÑÜ#Ó%€DÜ×ÑØØàÜ”XÓ×&Ñ& v°¡~Ó6×AÑAÓC×HÑHØð	
ð
 Ø˜S S¨hÑ7õ
ð €Kr(   c                   óh   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
 eed	«      d
„ «       Zed„ «       Zy)ÚSendmsgTestszB
    Tests for the Python2/3 compatible L{sendmsg} interface.
    c                 ó<   — t        t        «      \  | _        | _        y)z0
        Create a pair of UNIX sockets.
        N)r   r   ÚinputrT   r*   s    r&   ÚsetUpzSendmsgTests.setUp·   s   € ô #-¬WÓ"5ÑˆŒ
D•Kr(   c                 ól   — | j                   j                  «        | j                  j                  «        y)z4
        Close the sockets opened by setUp.
        N)r   r   rT   r*   s    r&   ÚtearDownzSendmsgTests.tearDown½   s$   € ð 	
‰
×ÑÔØ‰×ÑÕr(   c                 óÞ   — | j                   j                  «        | j                  t        t        | j                   d«      }| j                  |j                  d   t        j                  «       y)z—
        If the underlying C{sendmsg} call fails, L{send1msg} raises
        L{socket.error} with its errno set to the underlying errno value.
        ó   hello, worldr   N©	r   r   ÚassertRaisesr
   r   ÚassertEqualrI   ÚerrnoÚEBADF©r$   Úexcs     r&   Útest_syscallErrorzSendmsgTests.test_syscallErrorÄ   sJ   € ð
 	
‰
×ÑÔØ×Ñ¤¤w°·
±
¸OÓLˆØ×Ñ˜Ÿ™ !™¤e§k¡kÕ2r(   c                 óä   — | j                   j                  «        | j                  t        t        | j                   ddgd«      }| j                  |j                  d   t        j                  «       y)z
        The behavior when the underlying C{sendmsg} call fails is the same
        whether L{sendmsg} is passed ancillary data or not.
        r„   )r   r   s   0123r   Nr…   rŠ   s     r&   Ú#test_syscallErrorWithControlMessagez0SendmsgTests.test_syscallErrorWithControlMessageÍ   sV   € ð
 	
‰
×ÑÔØ×ÑÜ”7˜DŸJ™J¨¸/Ð9JÈAó
ˆð 	×Ñ˜Ÿ™ !™¤e§k¡kÕ2r(   c                 ó8  — d}| j                  t        |«      t        | j                  |«      «       t	        | j
                  «      }| j                  |j                  d«       | j                  |j                  d«       | j                  |j                  g «       y)zI
        L{recvmsg} will retrieve a message sent via L{sendmsg}.
        ó   hello, world!r   N)	r‡   Úlenr   r   r   rT   r\   ÚflagsÚ	ancillary)r$   ÚmessagerL   s      r&   Útest_roundtripzSendmsgTests.test_roundtripØ   su   € ð #ˆØ×Ñœ˜W›¤w¨t¯z©z¸7Ó'CÔDä˜Ÿ™Ó%ˆØ×Ñ˜Ÿ™Ð&6Ô7Ø×Ñ˜Ÿ™ qÔ)Ø×Ñ˜×)Ñ)¨2Õ.r(   c                 ó*  — ddz  dz  }| j                   j                  d«       t        | j                   |«      }| j                  |t	        |«      k  «       t        | j                  t	        |«      «      }| j                  t	        |d   «      |«       y)zS
        L{sendmsg} returns the number of bytes which it was able to send.
        ó   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxé   é   Fr   N)r   Úsetblockingr   Ú
assertTruer‘   r   rT   r‡   )r$   r”   ÚsentÚreceiveds       r&   Útest_shortsendzSendmsgTests.test_shortsendä   sy   € ð  Ñ$ rÑ)ˆØ
‰
×Ñ˜uÔ%Üt—z‘z 7Ó+ˆð
 	‰˜œs 7›|Ñ+Ô,Ü˜4Ÿ;™;¬¨G«Ó5ˆØ×Ñœ˜X a™[Ó)¨4Õ0r(   c                 óˆ   — t        | j                  dg d«       t        | j                  «      }| j	                  |dg df«       y)z™
        L{sendmsg} treats an empty ancillary data list the same way it treats
        receiving no argument for the ancillary parameter at all.
        r   r   N)r   r   r   rT   r‡   rK   s     r&   Útest_roundtripEmptyAncillaryz)SendmsgTests.test_roundtripEmptyAncillaryó   s=   € ô
 	—
‘
Ð,¨b°!Ô4ä˜Ÿ™Ó%ˆØ×Ñ˜Ð"2°B¸Ð!:Õ;r(   z7MSG_DONTWAIT is only known to work as intended on Linuxc                 ó  — t        d«      D ]  }	 t        | j                  dt        ¬«       Œ! | j                  d«       y# t        $ r8}| j                  |j                  d   t        j                  «       Y d}~ yd}~ww xY w)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.
        i    r—   )r’   r   NzHFailed to fill up the send buffer, or maybe send1msg blocked for a while)
Úranger   r   r   ÚOSErrorr‡   rI   rˆ   ÚEAGAINÚfail)r$   ÚiÚes      r&   Ú
test_flagszSendmsgTests.test_flagsý   sp   € ô x“ò 
	ˆAðÜ˜Ÿ
™
 K´|ÖDð
	ð I‰Ið8õøô	 ò Ø× Ñ  §¡¨¡¬E¯L©LÔ9Ýûðús   A Á 	BÁ	-A<Á<Bc              #   ó^  K  — t        d| j                  j                  «       «      }|j                  –— t	        «       \  }}| j                  |j                  «       | j                  |j                  «       |5  t        | j                  dt        t        t        d|j                  «       «      fg«       ddd«       |j                  –— | j                  t        |j                  «       d«      d«       | j                  t        |j                  «       d«      d«       y# 1 sw Y   ŒlxY w­w)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}.
        Úpullpipes   blonkr¦   Nr˜   s   Test fixture data: blonk.
r(   )r{   rT   r+   rR   rA   Ú
addCleanupr   r   r   r	   r   r   rS   r‡   r   )r$   rz   ÚpipeOutÚpipeIns       r&   Útest_sendSubProcessFDz"SendmsgTests.test_sendSubProcessFD  sâ   è ø€ ô j $§+¡+×"4Ñ"4Ó"6Ó7ˆØl‰lÒÜ#›+‰ˆØ‰˜Ÿ™Ô&Ø‰˜Ÿ™Ô%àñ 	ÜØ—
‘
ØÜœj¬$¨s°F·M±M³OÓ*DÐEÐFô÷	ð l‰lÒØ×Ñœ˜gŸn™nÓ.°Ó5Ð7UÔVà×Ñœ˜gŸn™nÓ.°Ó5°sÕ;÷	ð 	üs   ‚A8D-Á:<D!Â6A+D-Ä!D*Ä&D-N)r:   r;   r<   r=   r€   r‚   rŒ   rŽ   r•   rž   r    r   ÚdontWaitSkipr¨   r   r®   r3   r(   r&   r}   r}   ±   s[   „ ñò6òò3ò	3ò
/ò1ò<ñ ˆLÐSÓTñó Uðð* ñ<ó ñ<r(   r}   c                   ó@   — e Zd ZdZd„ Zd„ Zd„ Z eed«      d„ «       Z	y)ÚGetSocketFamilyTestsz'
    Tests for L{getSocketFamily}.
    c                 óR   — t        |«      }| j                  |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.
        )r   r«   r   )r$   ÚaddressFamilyÚss      r&   Ú_socketzGetSocketFamilyTests._socket3  s#   € ô =Ó!ˆØ‰˜Ÿ™Ô Øˆr(   c                 óh   — | j                  t        t        | j                  t        «      «      «       y)z˜
        When passed the file descriptor of a socket created with the C{AF_INET}
        address family, L{getSocketFamily} returns C{AF_INET}.
        N)r‡   r   r   rµ   r*   s    r&   Ú	test_inetzGetSocketFamilyTests.test_inet=  s"   € ð
 	×Ñœ¤/°$·,±,¼wÓ2GÓ"HÕIr(   c                 óh   — | j                  t        t        | j                  t        «      «      «       y)zš
        When passed the file descriptor of a socket created with the
        C{AF_INET6} address family, L{getSocketFamily} returns C{AF_INET6}.
        N)r‡   r   r   rµ   r*   s    r&   Ú
test_inet6zGetSocketFamilyTests.test_inet6D  s"   € ð
 	×Ñœ¤?°4·<±<ÄÓ3IÓ#JÕKr(   z)Platform does not support AF_UNIX socketsc                 óh   — | j                  t        t        | j                  t        «      «      «       y)z˜
        When passed the file descriptor of a socket created with the C{AF_UNIX}
        address family, L{getSocketFamily} returns C{AF_UNIX}.
        N)r‡   r   r   rµ   r*   s    r&   Ú	test_unixzGetSocketFamilyTests.test_unixK  s"   € ð 	×Ñœ¤/°$·,±,¼wÓ2GÓ"HÕIr(   N)
r:   r;   r<   r=   rµ   r·   r¹   r   ÚnonUNIXSkipr»   r3   r(   r&   r±   r±   -  s7   „ ñòòJòLñ ˆKÐDÓEñJó FñJr(   r±   )7r=   rˆ   rr   rm   r.   r   r   r   r   r   r   r   r	   r
   Ústructr   r   r   r¼   ÚImportErrorÚunittestr   Útwisted.internetr   Útwisted.internet.deferr   r   Útwisted.internet.errorr   Útwisted.internet.protocolr   Útwisted.python.filepathr   Útwisted.python.runtimer   Útwisted.trial.unittestr   ÚisLinuxr   r¯   Útwisted.python.sendmsgr   r   r   r   ÚdoImportSkipÚimportSkipReasonr   rA   Ú	ExceptionrC   rP   r{   r}   r±   r3   r(   r&   ú<module>rÌ      s2  ðñó Û 	Û 
Û ß )Ó )ß ?Õ ?Ý ðß*ð €Kå å $ß <Ý .Ý 5Ý ,Ý +Ý +à€8×ÑÔÝ#àLð €LðßTÓTð
 €LØÐ÷"ñ "òJ(ô
yô 
ô#M˜ô #MòLñ8 ˆÐ&Ó'ôx<8ó x<ó (ðx<ñv ˆÐ&Ó'ô#J˜8ó #Jó (ñ#Jøðy ò Ø‚Kðûð6 ò ;Ø€LØ:Òð;ús#   ´C2 ÂC? Ã2C<Ã;C<Ã?	DÄ
D