+
    Dfj(                     2   R t ^ RIt^ RIt^ RIt^ RIt^ RIHtHtHtHt ^ RI	H
t
HtHtHtH	t	 ^ RIHt  ^ RI	HtHt Rt^ RIHt ^ R	IHt ^ R
IHtHt ^ RIHt ^ RIHt ^ RIH t  ^ RI!H"t" ^ RI#H$t$ ]"PJ                  ! 4       '       d
   ^ RI	H&t& Rt'MRt' ^ RI(H)t)H*t*H+t+H,t, Rt-Rt. ! R R4      t/R t0 ! R R]14      t2 ! R R]4      t3R t4]! ]-].4       ! R R]$4      4       t5]! ]-].4       ! R R]$4      4       t6R#   ] d    Rt Li ; i  ] d    Rt-Rt. Lri ; i) 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                   H   a  ] tR t^5t o RtR tR tR tR tR t	R t
RtV tR	# )
	_FDHolderzH
A wrapper around a FD that will remember if it has been closed or not.
c                    Wn         R # N_fd)selffds   &&B/usr/lib/python3/dist-packages/twisted/python/test/test_sendmsg.py__init___FDHolder.__init__:   s        c                    V P                   # )z
Return the fileno of this FD.
r!   r#   s   &r%   fileno_FDHolder.fileno=   s     xxr(   c                f    V P                   '       d   \        V P                   4       RV n         R# R# )z8
Close the FD. If it's already been closed, do nothing.
N)r"   r   r*   s   &r%   r   _FDHolder.closeC   s$     888$((ODH r(   c                    V P                   '       d<   \        P                  ! RV P                    R2\        4       V P	                  4        R# R# )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___FDHolder.__del__K   s7     888MMCz)9:OLJJL r(   c                    V # r     r*   s   &r%   	__enter___FDHolder.__enter__S   s    r(   c                &    V P                  4        R # r    )r   )r#   exc_type	exc_value	tracebacks   &&&&r%   __exit___FDHolder.__exit__V   s    

r(   r!   N)__name__
__module____qualname____firstlineno____doc__r&   r+   r   r3   r7   r=   __static_attributes____classdictcell____classdict__s   @r%   r   r   5   s-      r(   r   c                 F    \        4       w  r\        V 4      \        V4      3# )zA
Create a pipe, and return the two FDs wrapped in L{_FDHolders}.
)r   r   )rws     r%   	_makePiperK   Z   s      6DAaL)A,''r(   c                   6   a  ] tR t^bt o RtV 3R lR ltRtV tR# )ExitedWithStderrz$
A process exited with some stderr.
c                    < V ^8  d   QhRS[ /# )   return)str)formatrG   s   "r%   __annotate__ExitedWithStderr.__annotate__g   s       r(   c                p    RP                  R.\        V P                  4      ,           4      p\        V4      # )zI
Dump the errors in a pretty way in the event of a subprocess traceback.
   
r(   )joinlistargsreprr#   results   & r%   __str__ExitedWithStderr.__str__g   s+     SEDO34F|r(   r6   N)r?   r@   rA   rB   rC   r]   rD   rE   rF   s   @r%   rM   rM   b   s      r(   rM   c                   B   a  ] tR t^ot o RtR tR tR tR tR t	Rt
V tR# )	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                ^    \        4       V n        \        4       V n        R V n        R V n        R# )r(   N)r   startedstoppedoutputerrorsr*   s   &r%   r&   !StartStopProcessProtocol.__init__   s"    zzr(   c                P    V P                   P                  V P                  4       R # r    )rb   callback	transportr*   s   &r%   connectionMade'StartStopProcessProtocol.connectionMade   s    dnn-r(   c                8    V ;P                   V,          un         R # r    )rd   r#   datas   &&r%   outReceived$StartStopProcessProtocol.outReceived       tr(   c                8    V ;P                   V,          un         R # r    )re   rm   s   &&r%   errReceived$StartStopProcessProtocol.errReceived   rq   r(   c                    VP                  \        4      '       d(   V P                  P                  V P                  4       R # V P                  P                  \        V P                  V P                  4      4       R # r    )checkr   rc   rh   rd   errbackrM   re   )r#   reasons   &&r%   processEnded%StartStopProcessProtocol.processEnded   sI    <<$$LL!!$++.LL  !1$++t{{!KLr(   )re   rd   rb   rc   N)r?   r@   rA   rB   rC   r&   rj   ro   rs   ry   rD   rE   rF   s   @r%   r`   r`   o   s*     .M Mr(   r`   c                    \        \        P                  4      P                  4       P                  p\        \        P                  4      p\        \        P                  ! \        P                  4      4      P                  4       P                  VR&   \        4       p\        P                  ! VVV\        \        4      P                  V R,           4      P                  4       P                  R.V^ R^R^R^V/R7       V# )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   17rJ   rI   )envchildFDs)r   sys
executable
asTextModepathdictosenvironr   rW   r`   r   spawnProcess__file__sibling)scriptoutputFDpyExer}   sspps   &&   r%   _spawnr      s     S^^$//166E
rzz
C chh!78CCEJJC#%DX&&v~6AACHH	

 S!S!S"h7
 Kr(   c                   |   a  ] tR t^t o RtR tR tR tR tR t	R t
R t]! ]R	4      R
 4       t]R 4       tRtV tR# )SendmsgTestsz:
Tests for the Python2/3 compatible L{sendmsg} interface.
c                >    \        \        4      w  V n        V n        R# )z 
Create a pair of UNIX sockets.
N)r   r   inputrd   r*   s   &r%   setUpSendmsgTests.setUp   s     #-W"5
DKr(   c                n    V P                   P                  4        V P                  P                  4        R# )z$
Close the sockets opened by setUp.
N)r   r   rd   r*   s   &r%   tearDownSendmsgTests.tearDown   s$     	

r(   c                    V P                   P                  4        V P                  \        \        V P                   R4      pV P                  VP                  ^ ,          \        P                  4       R# )z
If the underlying C{sendmsg} call fails, L{send1msg} raises
L{socket.error} with its errno set to the underlying errno value.
   hello, worldN	r   r   assertRaisesr	   r   assertEqualrY   errnoEBADFr#   excs   & r%   test_syscallErrorSendmsgTests.test_syscallError   sJ    
 	

w

OL!ekk2r(   c                    V P                   P                  4        V P                  \        \        V P                   RR.^ 4      pV P                  VP                  ^ ,          \        P                  4       R# )zx
The behavior when the underlying C{sendmsg} call fails is the same
whether L{sendmsg} is passed ancillary data or not.
r   N)    r   s   0123r   r   s   & r%   #test_syscallErrorWithControlMessage0SendmsgTests.test_syscallErrorWithControlMessage   sV    
 	

7DJJ/9JA
 	!ekk2r(   c                :   RpV P                  \        V4      \        V P                  V4      4       \	        V P
                  4      pV P                  VP                  R4       V P                  VP                  ^ 4       V P                  VP                  . 4       R# )z9
L{recvmsg} will retrieve a message sent via L{sendmsg}.
   hello, world!N)	r   lenr   r   r   rd   rn   flags	ancillary)r#   messager\   s   &  r%   test_roundtripSendmsgTests.test_roundtrip   su     #Wwtzz7'CD%&67q)))2.r(   c                D   RR,          ^,          pV P                   P                  R4       \        V P                   V4      pV P                  V\	        V4      8  4       \        V P                  \	        V4      4      pV P                  \	        V^ ,          4      V4       R# )zC
L{sendmsg} returns the number of bytes which it was able to send.
   FN   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)r   setblockingr   
assertTruer   r   rd   r   )r#   r   sentreceiveds   &   r%   test_shortsendSendmsgTests.test_shortsend   sy     $r)

u%tzz7+
 	s7|+,4;;G5Xa[)40r(   c                    \        V P                  R. ^ 4       \        V P                  4      pV P	                  VR. ^ 34       R# )z
L{sendmsg} treats an empty ancillary data list the same way it treats
receiving no argument for the ancillary parameter at all.
r   N)r   r   r   rd   r   r[   s   & r%   test_roundtripEmptyAncillary)SendmsgTests.test_roundtripEmptyAncillary   s=    
 	

,b!4%"2B!:;r(   z7MSG_DONTWAIT is only known to work as intended on Linuxc                   \        R4       F   p \        V P                  R\        R7       K"  	  V P                  R4       R#   \         d>   pT P                  TP                  ^ ,          \        P                  4        Rp? R# Rp?ii ; i)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   NzHFailed to fill up the send buffer, or maybe send1msg blocked for a whilei    r   )
ranger   r   r   OSErrorr   rY   r   EAGAINfail)r#   ies   &  r%   
test_flagsSendmsgTests.test_flags   sk     xA

K|D ! II8	    ELL9s   AB1BBc              #  |  "   \        RV P                  P                  4       4      pVP                  x  \	        4       w  r#V P                  VP                  4       V P                  VP                  4       V;_uu_ 4        \        V P                  R\        \        \        RVP                  4       4      3.4       RRR4       VP                  x  V P                  \        VP                  4       R4      R4       V P                  \        VP                  4       R4      R4       R#   + '       g   i     Lt; i5i)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   rd   r+   rb   rK   
addCleanupr   r   r   r   r   r   rc   r   r   )r#   r   pipeOutpipeIns   &   r%   test_sendSubProcessFD"SendmsgTests.test_sendSubProcessFD  s      j$++"4"4"67ll#+&%V

j$sFMMO*DEF  llgnn.57UVgnn.5s; Vs   A?D<<D)=A,D<)D9	4D<)r   rd   N)r?   r@   rA   rB   rC   r   r   r   r   r   r   r   r   dontWaitSkipr   r   r   rD   rE   rF   s   @r%   r   r      s^     63	3
/1< LST U* < <r(   r   c                   T   a  ] tR tRt o RtR tR tR t]! ]	R4      R 4       t
RtV tR	# )
GetSocketFamilyTestsi-  z
Tests for L{getSocketFamily}.
c                R    \        V4      pV P                  VP                  4       V# )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%   _socketGetSocketFamilyTests._socket3  s#     =! r(   c                j    V P                  \        \        V P                  \        4      4      4       R# )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_inetGetSocketFamilyTests.test_inet=  s"    
 	/$,,w2G"HIr(   c                j    V P                  \        \        V P                  \        4      4      4       R# )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_inet6GetSocketFamilyTests.test_inet6D  s"    
 	?4<<3I#JKr(   z)Platform does not support AF_UNIX socketsc                j    V P                  \        \        V P                  \        4      4      4       R# )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_unixGetSocketFamilyTests.test_unixK  s"     	/$,,w2G"HIr(   r6   N)r?   r@   rA   rB   rC   r   r   r   r   nonUNIXSkipr   rD   rE   rF   s   @r%   r   r   -  s:     JL KDEJ FJr(   r   )7rC   r   r   r   r0   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   rK   	ExceptionrM   r`   r   r   r   r6   r(   r%   <module>r      s3    	 
  ) ) ? ? * K  $ < . 5 , + +#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#   C9 D 9	DDDD