+
    Dfj}w                       R t ^ RIHt ^ RIt^ RIHtHtHtHtH	t	H
t
HtHtHtHtHt ^ RIHt ^ RIHtHtHtHtHtHt ^ RIHtHt ^ RIHtHtHt ^ RIH t  ^ R	I!H"t"H#t#H$t$ ^ R
I%H&t& ^ RI'H(t( ^ RI)H*t* ^ RI+H,t,H-t-  ! R R4      t. ! R R].]P^                  4      t0 ! R R].]Pb                  4      t2 ! R R]04      t3 ! R R]44      t5 ! R R]P^                  4      t6]! ]Pn                  ! ]R4      '       * R4       ! R R]-4      4       t8]! ]Pn                  ! ]R4      '       * R4       ! R R]-4      4       t9R R  lt:]! ]PF                  ! ]R4      '       * R!4      ]! ]:! ]]]R"R#4      '       * R$4       ! R% R&]-4      4       4       t;]! ]PF                  ! ]R4      '       * R!4      ]*]! ]:! ]]	]
R'R(4      '       * R)4       ! R* R+];4      4       4       4       t<R# ),zG
Tests for implementations of L{IReactorUDP} and L{IReactorMulticast}.
)annotationsN)AF_INETAF_INET6IP_ADD_MEMBERSHIP
IPPROTO_IPIPPROTO_IPV6IPV6_JOIN_GROUP
SOCK_DGRAMAddressFamilyif_nameindex	inet_ptonsocket)skipIf)defererror
interfacesprotocolreactorudp)IPv4AddressIPv6Address)DeferredgatherResultsmaybeDeferred)MulticastJoinError)IMulticastTransportIReactorMulticastIReactorTime)
deferLater)runtime)skipWithoutIPv6)SkipTestTestCasec                  4    ] tR t^*t^ t^ tRtR tR tR t	Rt
R# )MixinNc                	    . V n         R # N)packetsselfs   &7/usr/lib/python3/dist-packages/twisted/test/test_udp.py__init__Mixin.__init__0   s	        c                	|    ^V n         V P                  e'   V P                  Ruqn        VP                  R4       R# R#    N)startedstartedDeferredcallbackr)   ds   & r*   startProtocolMixin.startProtocol3   s9    +&*&:&:D#A#JJt ,r-   c                	    ^V n         R# r/   )stoppedr(   s   &r*   stopProtocolMixin.stopProtocol9   s	    r-   )r'   r1   r2   r9   )__name__
__module____qualname____firstlineno__r1   r9   r2   r+   r6   r:   __static_attributes__ r-   r*   r$   r$   *   s     GGOr-   r$   c                  :    ] tR t^=t$ RtR]R&   ^ tR]R&   R tRtR# )ServerNzDeferred[None] | NonepacketReceivedr   	transportc                	    V P                   P                  W34       V P                  e'   V P                  R uq0n        VP                  R 4       R # R # r&   r'   appendrD   r3   )r)   dataaddrr5   s   &&& r*   datagramReceivedServer.datagramReceivedB   sF    TL)*%)%8%8$"A"JJt +r-   )rD   )	r<   r=   r>   r?   rD   __annotations__refusedrK   r@   rA   r-   r*   rC   rC   =   s    ,0N)0G""r-   rC   c                  0    ] tR t^ItRt^ tR tR tR tRt	R# )ClientNc                	    V P                   P                  V4       V P                  e'   V P                  R uq n        VP                  R 4       R # R # r&   rG   )r)   rI   r5   s   && r*   rK   Client.datagramReceivedM   sD    D!*%)%8%8$"A"JJt +r-   c                	v    V P                   e%   V P                   R uq n         VP                  V4       Wn        R # r&   )r2   errbackfailure)r)   rU   r5   s   && r*   connectionFailedClient.connectionFailedS   s2    +&*&:&:D#A#IIgr-   c                	    V P                   e9   V P                   R uqn         VP                  \        P                  ! R4      4       ^V n        R # Nyupr2   rT   r   ConnectionRefusedErrorrN   r4   s   & r*   connectionRefusedClient.connectionRefusedY   ?    +&*&:&:D#A#IIe2259:r-   )rU   rD   rN   r2   )
r<   r=   r>   r?   rD   rN   rK   rV   r]   r@   rA   r-   r*   rP   rP   I   s    NGr-   rP   c                      ] tR t^`tR tRtR# )
GoodClientc                	    V P                   e9   V P                   R uqn         VP                  \        P                  ! R4      4       ^V n        R # rY   r[   r4   s   & r*   r]   GoodClient.connectionRefuseda   r_   r-   )rN   r2   N)r<   r=   r>   r?   r]   r@   rA   r-   r*   ra   ra   `   s    r-   ra   c                      ] tR t^htRtRtR# )BadClientErrorzZ
Raised by BadClient at the end of every datagramReceived call to try and
screw stuff up.
rA   N)r<   r=   r>   r?   __doc__r@   rA   r-   r*   re   re   h   s    r-   re   c                  *    ] tR t^otRtRtR tR tRtR# )	BadClientz
A DatagramProtocol which always raises an exception from datagramReceived.
Used to test error handling behavior in the reactor for that method.
Nc                    Wn         R# )zM
Set the Deferred which will be called back when datagramReceived is
called.
Nr5   r4   s   &&r*   setDeferredBadClient.setDeferredw   s	    
 r-   c                	|    V P                   e%   V P                   R uq0n         VP                  V4       \        R4      h)NzApplication code is very buggy!)r5   r3   re   )r)   bytesrJ   r5   s   &&& r*   rK   BadClient.datagramReceived~   s3    66IAvJJu>??r-   rj   )	r<   r=   r>   r?   rf   r5   rk   rK   r@   rA   r-   r*   rh   rh   o   s    
 	A@r-   rh   !This reactor does not support UDPc                      ] tR t^tR tR tR tR tR t]	! ]
P                  P                  R4      R8H  R4      R	 4       tR
 tR tR tR tRtR# )UDPTestsc                   a a \        4       p\        P                  ! 4       ;q!n        \        P
                  ! ^ VRR7      oVV 3R lpVP                  V4      # )z]
The C{type} of the host address of a listening L{DatagramProtocol}'s
transport is C{"UDP"}.
	127.0.0.1	interfacec                |   < SP                  4       pSP                  VP                  R 4       SP                  4       # )UDP)getHostassertEqualtypestopListening)ignoredrJ   pr)   s   & r*   	cbStarted+UDPTests.test_oldAddress.<locals>.cbStarted   s/    99;DTYY.??$$r-   rC   r   r   r2   r   	listenUDPaddCallback)r)   serverr5   r   r~   s   f   @r*   test_oldAddressUDPTests.test_oldAddress   sH    
 %*^^%55"a;?	%
 }}Y''r-   c                   a aa \        4       o\        P                  ! 4       ;pSn        \        P
                  ! ^ SRR7      oVV V3R lpV V3R lpVP                  V4      P                  V4      # )z
The L{DatagramProtocol}'s C{startProtocol} and C{stopProtocol}
methods are called when its transports starts and stops listening,
respectively.
rt   ru   c                   < SP                  SP                  ^4       SP                  SP                  ^ 4       SP                  4       # )r0   )rz   r1   r9   r|   )r}   port1r)   r   s   &r*   r   *UDPTests.test_startStop.<locals>.cbStarted   s:    V^^Q/V^^Q/&&((r-   c                @   < SP                  SP                  ^4       R# r/   )rz   r9   )r}   r)   r   s   &r*   	cbStopped*UDPTests.test_startStop.<locals>.cbStopped   s    V^^Q/r-   r   )r)   r5   r   r   r   r   s   f   @@r*   test_startStopUDPTests.test_startStop   sZ     %*^^%55F"!!!V{C	)
	0 }}Y'33I>>r-   c                   aa \        4       o\        P                  ! 4       ;pSn        \        P
                  ! ^ SRR7      pR oVV3R lpVP                  SV4      # )zZ
Re-listening with the same L{DatagramProtocol} re-invokes the
C{startProtocol} callback.
rt   ru   c                "    VP                  4       # r&   r|   r}   ports   &&r*   r   'UDPTests.test_rebind.<locals>.cbStarted   s    %%''r-   c                   < \         P                  ! 4       ;pSn        \        P                  ! ^ SRR7      pVP                  SV4      #     rt   ru   )r   r   r2   r   r   r   )r}   r5   r~   r   r   s   &  r*   r   'UDPTests.test_rebind.<locals>.cbStopped   s<    ).)99A&!!!V{CA==A..r-   r   )r)   r5   r~   r   r   r   s   &   @@r*   test_rebindUDPTests.test_rebind   sQ    
 %*^^%55F"a;?	(	/
 }}Y**r-   c                   a aa \        4       o\        P                  ! 4       ;pSn        \        P
                  ! ^ SRR7      oVV V3R lpVP                  V4       V3R lpVP                  V4       V# )zx
A L{CannotListenError} exception is raised when attempting to bind a
second protocol instance to an already bound port
rt   ru   c                   < SP                  SP                  4       SP                  P                  4       4       \        4       pSP	                  \
        P                  \        P                  SP                  4       P                  VR R7       R# )rt   ru   N)
rz   ry   rE   rC   assertRaisesr   CannotListenErrorr   r   r   )r}   server2r   r)   r   s   & r*   r   *UDPTests.test_bindError.<locals>.cbStarted   si    T\\^V-=-=-E-E-GHhG''!!##%  r-   c                $   < SP                  4       # r&   r   r   s   &r*   
cbFinished+UDPTests.test_bindError.<locals>.cbFinished   s    %%''r-   r   )r)   r5   r   r   r   r   s   f   @@r*   test_bindErrorUDPTests.test_bindError   s_    
 %*^^%55F"  FkB		 	
i 	( 	
j!r-   c                  a aaa	a
 \        4       o
\        P                  ! 4       ;pS
n        \        P
                  ! ^ S
RR7      o	\        4       o\        P                  ! 4       ;oSn        VVV 3R lpVP                  V4      pVV
3R lpVP                  V4       VV V
3R lpVP                  V4       V	V 3R lpVP                  V4       V# )zv
Datagrams can be sent with the transport's C{write} method and
received via the C{datagramReceived} callback method.
rt   ru   c                D   < \         P                  ! ^ SRR7      Sn        S# r   )r   r   port2)r}   clientclientStartedr)   s   &r*   cbServerStarted2UDPTests.test_sendPackets.<locals>.cbServerStarted   s     **1fLDJ  r-   c                  <aa SP                   P                  R SP                   P                  4       P                  4       SP                   P                  4       pSP                   P                  4       p\        P
                  ! 4       ;pSn        SP                   P                  RVP                  VP                  34       RRRVP                  VP                  33.oVVVV3R lo\        P                  ! S! R4      V.RR7      # )	rt      helloN   cc                   < S'       dY   \         P                  ! 4       ;pSn        VP                  S4       SP                  P
                  ! SP                  ^ 4      !   V# R# r   N)r   r   rD   r   rE   writepop)r}   nextClientWritecbClientSendr   clientWritesr   s   & r*   r   HUDPTests.test_sendPackets.<locals>.cbClientStarted.<locals>.cbClientSend   sR    >Cnn>NNOf&;#//=$$**L,<,<Q,?@**	  r-   TfireOnOneErrback)   a)   bN)
rE   connectry   r   r   r   rD   r   hostDeferredList)r}   cAddrsAddr
serverSendr   r   r   r   s   &   @@r*   cbClientStarted2UDPTests.test_sendPackets.<locals>.cbClientStarted   s    $$[&2B2B2J2J2L2Q2QR$$,,.E$$,,.E161AAJ.""8ejj%**-EF#\D5::uzz:R3STL+ + %%d#Z04 r-   c                T  < SP                   P                  4       pSP                   P                  4       pSP                  SP                  R VP                  VP
                  33.4       VP                  VP
                  3pSP                  SP                  RV3RV3RV3.4       R# )r   r   r   r   N)rE   ry   rz   r'   r   r   )r}   r   r   
clientAddrr   r)   r   s   &   r*   cbSendsFinished2UDPTests.test_sendPackets.<locals>.cbSendsFinished  s    $$,,.E$$,,.EV^^x%**ejj9Q.R-ST**ejj1J
#dJ%7$
9KLr-   c                   < \         P                  ! \         P                  ! SP                  4      \         P                  ! SP                  P                  4      .R R7      # Tr   )r   r   r   r|   r   )r}   r   r)   s   &r*   r   -UDPTests.test_sendPackets.<locals>.cbFinished  sL    %%''(;(;<''

(@(@A "& r-   )rC   r   r   r2   r   r   ra   r   )r)   serverStartedr   r5   r   r   r   r   r   r   r   s   f      @@@@r*   test_sendPacketsUDPTests.test_sendPackets   s    
 161AA.!!!V{C161AA.	! %%o6	0 	
o&	 	
o&	 	
j!r-   INFRASTRUCTUREAZUREPIPELINESz"Hangs on Pipelines due to firewallc                  a aaaa	 \        4       o\        P                  ! 4       ;pSn        \        P
                  ! ^ SRR7      o\        4       o	\        P                  ! 4       ;pS	n        \        P
                  ! ^ S	RR7      o\        P                  ! W.RR7      pVV V	3R lpVP                  V4       VV3R lpVP                  V4       V# )z
A L{ConnectionRefusedError} exception is raised when a connection
attempt is actively refused by the other end.

Note: This test assumes no one is listening on port 80 UDP.
rt   ru   Tr   c                f  < \         P                  ! 4       ;pSn        SP                  P	                  R ^P4       \        ^
4       FJ  pSP                  P                  RV3,          4       SP                  P                  RV3,          R4       KL  	  SP                  V\        P                  4      # )rt      %drt   P   )
r   r   r2   rE   r   ranger   assertFailurer   r\   )r}   r]   ir   r)   r   s   &  r*   r   2UDPTests.test_connectionRefused.<locals>.cbStarted3  s    9>9II 6$$["52Y  &&ut|4  &&ut|5FG  %%&79U9UVVr-   c                   < \         P                  ! \         P                  ! SP                  4      \         P                  ! SP                  4      .R R7      # r   r   r   r   r|   )r}   r   r   s   &r*   r   3UDPTests.test_connectionRefused.<locals>.cbFinished?  sH    %%''(:(:;''(;(;< "& r-   )	ra   r   r   r2   r   r   rC   r   r   )
r)   r   r   r5   r   r   r   r   r   r   s
   f     @@@@r*   test_connectionRefusedUDPTests.test_connectionRefused  s     161AA.  FkB161AA.!!!V{C=PTU	W 	
i 	 	
j!r-   c                D  a a	a
aaa \        4       o	\        P                  ! 4       ;pS	n        \        P
                  ! ^ S	RR7      o
Ro\        4       o\        P                  ! 4       ;pSn        \        P                  ! 4       ;pSn        \        P
                  ! ^ SRR7      o\        P                  ! W.RR7      pV	VVV3R lpVP                  V4       \        P                  ! WC.RR7      pV VV3R lpVP                  V4       V
V3R lpVP                  V4       V# )	aC  
When a server fails to successfully read a packet the server should
still be able to process future packets.
The IOCP reactor had a historical problem where a failure to read caused
the reactor to ignore any future reads. This test should prevent a regression.

Note: This test assumes no one is listening on port 80 UDP.
rt   ru   s   Sending test packet to serverTr   c                   < SP                   P                  R R4       SP                   P                  SRSP                  34       R# )s$   write to port no one is listening tort   Nr   )rE   r   _realPortNumber)r}   r   r   
serverPorttest_data_to_sends   &r*   cbClientAndServerStartedAUDPTests.test_serverReadFailure.<locals>.cbClientAndServerStartedb  sE     ""79J ""!K1K1K#Lr-   c                \   < SP                  SP                  ^ ,          ^ ,          S4       R# r   )rz   r'   )r}   r)   r   r   s   &r*   verify_server_got_data?UDPTests.test_serverReadFailure.<locals>.verify_server_got_datau  s"    V^^A.q13DEr-   c                   < \         P                  ! \         P                  ! SP                  4      \         P                  ! SP                  4      .R R7      # r   r   )r}   
clientPortr   s   &r*   cleanup0UDPTests.test_serverReadFailure.<locals>.cleanupz  sH    %%''
(@(@A''
(@(@A "& r-   )
ra   r   r   r2   r   r   rC   rD   r   r   )r)   r   r   serverGotDataserver_client_started_dr   all_data_sentr   r   r   r   r   r   r   s   f        @@@@@r*   test_serverReadFailureUDPTests.test_serverReadFailureK  s     161AA.&&q&KH
<161AA.050@@-&&q&KH
"'"4"4*T#
	 	 	 ++,DE**$4t
	F 	!!"89	 	!!'*r-   c                d   \        4       p\        P                  ! ^ VRR7      pV P                  \        P
                  VP                  P                  R^P4       VP                  P                  R^P4       V P                  \        VP                  P                  R^P4       VP                  4       # )z
A call to the transport's connect method fails with an
L{InvalidAddressError} when a non-IP address is passed as the host
value.

A call to a transport's connect method fails with a L{RuntimeError}
when the transport is already connected.
rt   ru   	localhost)
ra   r   r   r   r   InvalidAddressErrorrE   r   RuntimeErrorr|   )r)   r   r   s   &  r*   test_badConnectUDPTests.test_badConnect  s       FkB%%v'7'7'?'?b	
 	  b1,(8(8(@(@+rR!!##r-   c                T  a aaaaaaa	 \         P                  ! 4       oV 3R lpSP                  V4       \        4       o\        P
                  ! ^ SRR7      oV3R lpSP                  V4       SP                  4       o\        \        ^<4      4      o. o	VVVVVV V	3R loS! 4        S# )zZ
When datagramReceived raises an exception it is logged but the port
is not disconnected.
c                   < SP                  \        4      pSP                  \        V4      ^R\        V4      3,          4       R# )za
Flush the exceptions which the reactor should have logged and make
sure they're actually there.
z'Incorrectly found %d errors, expected 2N)flushLoggedErrorsre   rz   len)ignerrsr)   s   & r*   cbCompleted8UDPTests.test_datagramReceivedError.<locals>.cbCompleted  s:    
 )).9DD	1G3t9,Vr-   rt   ru   c                l   <a  \         P                  ! SP                  4      P                  V 3R l4      # )z_
Disconnect the port we started and pass on whatever was given to us
in case it was a Failure.
c                   < S# r&   rA   )r   results   &r*   <lambda>HUDPTests.test_datagramReceivedError.<locals>.cbCleanup.<locals>.<lambda>  s    vr-   )r   r   r|   addBoth)r  r   s   fr*   	cbCleanup6UDPTests.test_datagramReceivedError.<locals>.cbCleanup  s(    
 &&t'9'9:BBCUVVr-   c                   <a S'       g    S
P                  R4       S
P                  SP                  RR4       RSP                  ^ 4      3,          p \        P                  ! 4       pSP                  V4       SP                  P                  V SP                  SP                  34       VV	VV3R lpV	3R lpVP                  W#4       VP                  SP                  4       \        P                  ! RVP                  \         P"                  ! R4      4      oR#   \         d    SP                  4         ELi ; i)	z
Send one packet to the listening BadClient.  Set up a 0.1 second
timeout to do re-transmits in case the packet is dropped.  When two
packets have been received by the BadClient, stop sending and let
the finalDeferred's callbacks do some assertions.
zNot enough packets receivedNzUDP Protocol lost its transportr   c                   < SP                  4        SP                  V 4       \        S4      ^8X  d%   \        P                  ! ^ SP
                  R4       R# S! 4        R# )zU
A packet arrived.  Cancel the timeout for it, record it, and
maybe finish the test.
N)cancelrH   r   r   	callLaterr3   )packetfinalDeferredmakeAttemptsucceededAttemptstimeoutCalls   &r*   cbPacketReceivedRUDPTests.test_datagramReceivedError.<locals>.makeAttempt.<locals>.cbPacketReceived  sL    
 ""$!((0()Q.
 %%a)?)?FMr-   c                   < S! 4        R# )aT  
The packet wasn't received quickly enough.  Try sending another
one.  It doesn't matter if the packet for which this was the
timeout eventually arrives: makeAttempt throws away the
Deferred on which this function is the errback, so when
datagramReceived callbacks, so it won't be on this Deferred, so
it won't raise an AlreadyCalledError.
NrA   )errr  s   &r*   ebPacketTimeoutQUDPTests.test_datagramReceivedError.<locals>.makeAttempt.<locals>.ebPacketTimeout  s
     r-   g?z&Timed out in testDatagramReceivedError)fail	ExceptionrT   failIfIdenticalrE   r   r   r   rk   r   r   r   addCallbacks
addErrbackr   r  r   TimeoutError)r  packetDeferredr  r  r  rJ   attemptsr   r  r  r)   r  s       @r*   r  8UDPTests.test_datagramReceivedError.<locals>.makeAttempt  s	    ,II;<     $(I hll1o//F"^^-N~.""6DIItyy+AB" " 	 ''(8J%%m&;&;<!++&&""#KLKU ! ,!))+,s   D D=<D=)
r   r   r   rh   r   r   r  ry   listr   )
r)   r   r  rJ   r  r   r  r  r   r  s
   f  @@@@@@@r*   test_datagramReceivedError#UDPTests.test_datagramReceivedError  s    
 (	 	!!+.  FkB	W 	i(||~ b	?8	 8	t 	r-   c                    ! R R4      p\         P                  ! ^ \        4       4      pV! 4       Vn        VP	                  RR4       V P                  V P                  .4      pV P                  \        V4      ^ 4       R# )a9  
C{'<broadcast>'} is an alternative way to say C{'255.255.255.255'}
({socket.gethostbyname("<broadcast>")} returns C{'255.255.255.255'}),
so because it becomes a valid IP address, no deprecation warning about
passing hostnames to L{twisted.internet.udp.Port.write} needs to be
emitted by C{write()} in this case.
c                      ] tR tRtR tRtR# )6UDPTests.test_NoWarningOnBroadcast.<locals>.fakeSocketi  c                	    R # r&   rA   )r)   foobars   &&&r*   sendto=UDPTests.test_NoWarningOnBroadcast.<locals>.fakeSocket.sendto  s    r-   rA   N)r<   r=   r>   r?   r)  r@   rA   r-   r*   
fakeSocketr%    s    r-   r+  s   testN)z<broadcast>i  )	r   PortrC   r   r   flushWarningstest_NoWarningOnBroadcastrz   r   )r)   r+  r~   warningss   &   r*   r.  "UDPTests.test_NoWarningOnBroadcast  se    	 	 HHQ!<	./%%t'E'E&FGX*r-   )r   N)r<   r=   r>   r?   r   r   r   r   r   r   osenvirongetr   r   r   r!  r.  r@   rA   r-   r*   rr   rr      sh    ( ?(+&8BH 


'(,<<,'	'R:x$$gR+r-   rr   c                  b    ] tR tRtRt]P                  ! ]R4      '       g   RtR t	R t
R tRtR# )	ReactorShutdownInteractionTestsi  z!Test reactor shutdown interactionNrp   c                t    \        4       V n        \        P                  ! ^ V P                  RR7      V n        R# )zStart a UDP portrt   ru   N)rC   r   r   r   r   r(   s   &r*   setUp%ReactorShutdownInteractionTests.setUp  s%    h%%aL	r-   c                6    V P                   P                  4       # )zStop the UDP port)r   r|   r(   s   &r*   tearDown(ReactorShutdownInteractionTests.tearDown#  s    yy&&((r-   c                  a a \         P                  ! 4       o\         P                  ! 4       ;pS P                  n        VV 3R lpVP	                  V4       V 3R lpSP	                  V4       S P                  P
                  P                  RRS P                  P
                  P                  4       P                  34       S# )z0Test reactor shutdown while in a recvfrom() loopc                   < SP                   P                  P                  4        \        P                  ! ^ SP
                  R4       R# r   )r   rE   connectionLostr   r  r3   )r}   finishedr)   s   &r*   pktReceQReactorShutdownInteractionTests.testShutdownFromDatagramReceived.<locals>.pktRece6  s3    KK!!002 a!2!2D9r-   c                (   < SP                  4        R # r&   )r   r}   r)   s   &r*   flushErrorsUReactorShutdownInteractionTests.testShutdownFromDatagramReceived.<locals>.flushErrors@  s    
 ""$r-   rt   s@                                                                   )	r   r   r   rD   r   rE   r   ry   r   )r)   prr@  rD  r?  s   f   @r*    testShutdownFromDatagramReceived@ReactorShutdownInteractionTests.testShutdownFromDatagramReceived'  s     >>#*/..*::T[['	: 	w	% 	[)##dkk&;&;&C&C&E&J&JK	
 r-   )r   r   )r<   r=   r>   r?   rf   r   IReactorUDPr   skipr7  r:  rG  r@   rA   r-   r*   r5  r5    s-    +!!'4002M
)$r-   r5  c               0    V ^8  d   QhRRRRRRRRRRR	R
/# )   afr
   ipprotointjoingroupstrbindtoreturnboolrA   )formats   "r*   __annotate__rW  N  s<       #+.7:DG	r-   c                :   \        V \        4      pVP                  V^ 34       \        W4      p\        W4      p VP	                  WWg,           4        VP                  4        R#   \         d     TP                  4        R# i ; i  TP                  4        i ; i)z
Bind a socket to the given network interface and attempt to join a
multicast group with the given address family.  This is used to determine
whether the local networking stack configuration allows for multicast
within the given address family.
TF)r   r	   bindr   
setsockoptcloseOSError)rM  rN  rP  rQ  rS  s	packgrouppackifs   &&&&&   r*   checkMulticastAvailabilityr`  N  s     	r:AFFFA;"$Ir"F	WI$67 		   	
	
 	
	s#   A& &B1B BB Bz'This reactor does not support multicast225.0.0.2500.0.0.0z:The local networking stack does not enable IPv4 multicast.c                     ] tR tRt$ RtRtR]R&   RtR]R&   RtR]R	&   R
t	R]R&   Rt
R]R&   RtR]R&   RtR]R&   RtR]R&   R tR tR R ltR R ltR R ltR R ltR R lt]! ]P.                  P1                  4       ;'       d     ]P.                  P3                  4       '       * R4      R 4       tR  t]! ]P.                  P1                  4       R!4      R" R# l4       tR$tR%# )&MulticastTestsie  zg
Tests for sending and receiving multicast datagrams.  (This suite supports
IPv4, see below for IPv6.)
rb  rR  rv   	str | intexpectedInterfacert   clientAddressra  multicastGroupalternateInterfacer   interfaceSynonyminvalidGroup::1wrongAddressFamilyc                	   \        4       V n        \        4       V n        \        P
                  ! ^ V P                  V P                  4      V n        \        P
                  ! ^ V P                  V P                  4      V n        V P                  P                  P                  V P                  V P                  P                  P                  4       P                  4       R# r   )rC   r   rP   r   r   listenMulticastrv   r   r   rE   r   rg  ry   r   r(   s   &r*   r7  MulticastTests.setUp  s    hh,,QT^^L
,,QT^^L
%%KK!!))+00	
r-   c                	    \        \        V P                  P                  4      \        V P                  P                  4      .4      # r&   )r   r   r   r|   r   r(   s   &r*   r:  MulticastTests.tearDown  s8    djj667djj667
 	
r-   c                   V ^8  d   QhRR/# rL  rT  NonerA   )rV  s   "r*   rW  MulticastTests.__annotate__  s       r-   c                	   a  S P                   P                  P                  \        8w  d   \	        R 4      hR V 3R llpV! S P
                  4       V! S P                   4       R# )z+only IPv4 multicast has TTLs, IPv6 has hopsc                    V ^8  d   QhRRRR/# )rL  ozServer | ClientrT  ru  rA   )rV  s   "r*   rW  ,MulticastTests.testTTL.<locals>.__annotate__  s     	6 	6 	6D 	6r-   c                6  < \         P                  ! V P                  4      '       g   Q hSP                  V P                  P	                  4       ^4       V P                  P                  ^4       SP                  V P                  P	                  4       ^4       R# r/   )r   
providedByrE   rz   getTTLsetTTL)ry  r)   s   &r*   checkttl(MulticastTests.testTTL.<locals>.checkttl  sj    &11!++>>>>Q[[//115KKq!Q[[//115r-   N)r   rE   addressFamilyr   r!   r   )r)   r  s   f r*   testTTLMulticastTests.testTTL  sK    ;;  ..'9HII	6 	6 	r-   c                   V ^8  d   QhRR/# rt  rA   )rV  s   "r*   rW  rv    s     6 6T 6r-   c                "  "   V P                   pV P                  V P                  P                  P	                  4       ^4       V P                  P                  P                  4       pV P                  P                  P                  V4      G Rj  xL
  \        4       V P                  n        V P                  P                  P                  RWP                  34       V P                  P                  G Rj  xL
  V P                  \        V P                  P                  4      ^4       V P                  P                  P                  ^ 4       V P                  V P                  P                  P	                  4       ^ 4       V P                  P                  P                  RWP                  34       \        \        \         4      ^ 4      G Rj  xL
  V P                  \        V P                  P                  4      ^4       R#  ELx EL L;5i)z^
Test that after loopback mode has been set, multicast packets are
delivered to their sender.
Nr   )rh  rz   r   rE   getLoopbackModery   	joinGroupr   rD   r   r   r   r'   setLoopbackModer   r   r   )r)   rQ  rJ   s   &  r*   test_loopbackMulticastTests.test_loopback  sm    
 ##..>>@!D{{$$,,.kk##--e444%-Z"##Huii.@Akk((((T[[00115--a0..>>@!D##Huii.@A g.222T[[00115 	5 	) 	3s8   BHHA'H7H
8CHH6H
HHc                   V ^8  d   QhRR/# rt  rA   )rV  s   "r*   rW  rv    s      T r-   c                  "   V P                  \        4      ;_uu_ 4        V P                  P                  P	                  V P
                  V P                  R7      G Rj  xL
  RRR4       R#  L  + '       g   i     R# ; i5i)z|
A sensible error will be reported when using the wrong address family
literal for the 'interface' argument to 'joinGroup'.
ru   N)r   r   r   rE   r  rh  rm  r(   s   &r*   test_wrongFamilyInterfaceJoin,MulticastTests.test_wrongFamilyInterfaceJoin  si     
 122++''11##t/F/F 2    32 322s.   B?A0A. A0$
B.A00B	;	Bc                   V ^8  d   QhRR/# rt  rA   )rV  s   "r*   rW  rv    s     
 
d 
r-   c                  "   V P                  V P                  P                  P                  4       V P                  4       V P                  V P
                  P                  P                  4       V P                  4       V P
                  P                  P                  V P                  4      G Rj  xL
  V P                  P                  P                  V P                  4      G Rj  xL
  V P                  V P                  P                  P                  4       V P                  4       V P                  V P
                  P                  P                  4       V P                  4       R#  L L5i)z;
Test C{getOutgoingInterface} and C{setOutgoingInterface}.
N)	rz   r   rE   getOutgoingInterfacerf  r   setOutgoingInterfaceri  rj  r(   s   &r*   test_interfaceMulticastTests.test_interface  s     	KK!!668$:P:P	
 	KK!!668$:P:P	
 kk##889P9PQQQkk##889N9NOOOKK!!668##	
 	KK!!668##	
 	ROs%   B/E/1E+26E/(E-)BE/-E/c                   V ^8  d   QhRR/# rt  rA   )rV  s   "r*   rW  rv    s     D Dd Dr-   c                  "   V P                   P                  P                  V P                  4      G Rj  xL
  V P                   P                  P	                  V P                  4      G Rj  xL
  V P
                  P                  P                  V P                  4      G Rj  xL
  V P
                  P                  P	                  V P                  4      G Rj  xL
  R#  L Lv LA L5i)z5
Test that multicast a group can be joined and left.
N)r   rE   r  rh  
leaveGroupr   r(   s   &r*   test_joinLeaveMulticastTests.test_joinLeave  s      kk##--d.A.ABBBkk##..t/B/BCCCkk##--d.A.ABBBkk##..t/B/BCCC 	CCBCsE   3C)C!6C),C#-6C)#C%$6C)C'C)#C)%C)'C)z2Windows' UDP multicast is not yet fully supported.c                    V P                  V P                  P                  P                  V P                  4      \
        P                  4      # )zr
Test that an attempt to join an address which is not a multicast
address fails with L{error.MulticastJoinError}.
)r   r   rE   r  rk  r   r   r(   s   &r*   test_joinFailureMulticastTests.test_joinFailure  s=     !!KK!!++D,=,=>@X@X
 	
r-   c                  a aaa \        4       o\        P                  ! ^ SS P                  4      oS P                  P
                  P                  4       oS P                  P
                  P                  S P                  4      pVVV 3R lpVP                  V4       V 3R lpVP                  V4       V3R lpVP                  V4       V# )zV
Test that a multicast group can be joined and messages sent to and
received from it.
c                   < \        4       ;pSP                  n        SP                  P	                  R SP
                  SP                  34       V# )   hello world)r   r   rD   rE   r   rh  r   )r}   r5   rJ   cr)   s   & r*   cbJoined/MulticastTests.test_multicast.<locals>.cbJoined  s>    -5Z7A*KKnt/B/BDII.NOHr-   c                p   < SP                  SP                  P                  ^ ,          ^ ,          R4       R# )r   r  N)rz   r   r'   rC  s   &r*   cbPacket/MulticastTests.test_multicast.<locals>.cbPacket  s'    T[[003A6Gr-   c                ^   <a  \        SP                  4      pVP                  V 3R  l4       V# )c                   < S# r&   rA   )r   passthroughs   &r*   r  @MulticastTests.test_multicast.<locals>.cleanup.<locals>.<lambda>
  s    ;r-   )r   r|   r   )r  r  r~   s   f r*   r   .MulticastTests.test_multicast.<locals>.cleanup  s%    "1??3F67Mr-   )
rC   r   ro  rv   r   rE   ry   r  rh  r   )r)   joinedr  r  r   rJ   r  r~   s   f    @@@r*   test_multicastMulticastTests.test_multicast  s    
 H##Aq$..9{{$$,,.&&001D1DE	
 	8$	H 	8$	
 	7#r-   zjon non-linux platforms it appears multiple processes can listen, but not multiple sockets in same process?c                   V ^8  d   QhRR/# rt  rA   )rV  s   "r*   rW  rv    s     .
 .
 .
r-   c                  "   \        4       p\        \        4      pVP                  ^ VRV P                  R7      pVP                  4       p\        V\        \        34      '       g   Q hVP                  p\        4       pVP                  VVRV P                  R7      p\        V P                  P                  P                  V P                  4      VP                  V P                  4      VP                  V P                  4      .4      G Rj  xL
  \        4       ;qn        \        4       ;qn        VP                  P#                  RV P                  V34       \        W.4      G Rj  xL
  V P%                  VP&                  ^ ,          ^ ,          R4       V P%                  VP&                  ^ ,          ^ ,          R4       \        \)        VP*                  4      \)        VP*                  4      .4      G Rj  xL
  R#  L L L
5i)z
Test that multiple sockets can listen on the same multicast port and
that they both receive multicast messages directed to that address.
T)listenMultiplerv   Nr  )rC   r   r   ro  rv   ry   
isinstancer   r   r   r   r   rE   r  rh  r   rD   r   rz   r'   r   r|   )
r)   firstClientmreactor	firstPortfpAddrportnosecondClient
secondPortd1d2s
   &         r*   test_multiListenMulticastTests.test_multiListen  s     h$W-,,{44>> - 
	 ""$&;"<====x--nn	 . 

 %%//0C0CD##D$7$78$$T%8%89
 	
 	
 +3*4'+3:5(##NT5H5H&4QRRH%%%,,Q/2NC--a03^Di556j667
 	
 	
'	
 	&
	
s8   DHH AH*H+BH9H:HHH)r   r   r   r   N)r<   r=   r>   r?   rf   rv   rM   rf  rg  rh  ri  rj  rk  rm  r7  r:  r  r  r  r  r  r   r   platform	isWindowsisVistar  r  r  r@   rA   r-   r*   rd  rd  e  s     Is#,y,$M3$'NC'$/	/"-i-#L####	

60
.D ""$GGW-=-=-E-E-G)G<
	
@ ""$	.
.
r-   rd  ff03::1::z/The local stack does not enable IPv6 multicast.c                      ] tR tRt$ RtRtR]R&   RtR]R&   RtR]R	&   ]	! R
 ]
! 4        4       4      tR]R&   ]tR]R&   RtR]R&   ^ tR]R&   RtR]R&   RtR# )MulticastTestsIPv6iH  z;
Tests for sending and receiving IPv6 multicast datagrams.
r  rR  rv   rl  rg  r  rh  c              #  	r   "   T F-  q^,          P                  R4      '       g   K"  V^ ,          x  K/  	  R# 5i)r0   loN)
startswith).0idxnms   & r*   	<genexpr>MulticastTestsIPv6.<genexpr>^  s'     K~eq1D1DT1Jq~s   77re  ri  rj  rk  rf  rt   rm  rA   N)r<   r=   r>   r?   rf   rv   rM   rg  rh  nextr   ri  rj  rk  rf  rm  r@   rA   r-   r*   r  r  H  sp     IsM3#NC#$(K|~K%	  #5i4L##$y$))r-   r  )=rf   
__future__r   r1  r   r   r   r   r   r   r   r	   r
   r   r   unittestr   twisted.internetr   r   r   r   r   r   twisted.internet.addressr   r   twisted.internet.deferr   r   r   twisted.internet.errorr   twisted.internet.interfacesr   r   r   twisted.internet.taskr   twisted.pythonr   twisted.test.testutilsr    twisted.trial.unittestr!   r"   r$   DatagramProtocolrC   ConnectedDatagramProtocolrP   ra   r  re   rh   rI  rr   r5  r`  rd  r  rA   r-   r*   <module>r     s  
 # 	     M M = I I 5 
 - " 2 5 &	UH-- 	UH66 . Y @)) @, J""7D113VWN+x N+ XN+b J""7D113VW3h 3 X3l. $$Wd33- ".y	  A	V
X V
	V
r $$Wd33- ",D	  6	* * 	*r-   