
    h}w                       S r SSKJr  SSKrSSKJrJrJrJrJ	r	J
r
JrJrJrJrJr  SSKJr  SSKJrJrJrJrJrJr  SSKJrJr  SSKJrJrJr  SS	KJ r   SS
K!J"r"J#r#J$r$  SSK%J&r&  SSK'J(r(  SSK)J*r*  SSK+J,r,J-r-   " S S5      r. " S S\.\R^                  5      r0 " S S\.\Rb                  5      r2 " S S\05      r3 " S S\45      r5 " S S\R^                  5      r6\" \Rn                  " \S5      (       + S5       " S S\-5      5       r8\" \Rn                  " \S5      (       + S5       " S S\-5      5       r9            S,S  jr:\" \RF                  " \S5      (       + S!5      \" \:" \\\S"S#5      (       + S$5       " S% S&\-5      5       5       r;\" \RF                  " \S5      (       + S!5      \*\" \:" \\	\
S'S(5      (       + S)5       " S* S+\;5      5       5       5       r<g)-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                  2    \ rS rSrSrSrSrS rS rS r	Sr
g)Mixin*   r   Nc                    / U l         g N)packetsselfs    \/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/test/test_udp.py__init__Mixin.__init__0   s	        c                v    SU l         U R                  b%  U R                  S sol        UR                  S 5        g g N   )startedstartedDeferredcallbackr+   ds     r,   startProtocolMixin.startProtocol3   s9    +&*&:&:D#A#JJt ,r/   c                    SU l         g r1   )stoppedr*   s    r,   stopProtocolMixin.stopProtocol9   s	    r/   )r)   r3   r4   r;   )__name__
__module____qualname____firstlineno__r3   r;   r4   r-   r8   r<   __static_attributes__ r/   r,   r%   r%   *   s     GGOr/   r%   c                  8    \ rS rSr% SrS\S'   SrS\S'   S rS	rg)
Server=   NzDeferred[None] | NonepacketReceivedr   r   	transportc                    U R                   R                  X45        U R                  b%  U R                  S so0l        UR                  S 5        g g r(   r)   appendrG   r5   )r+   dataaddrr7   s       r,   datagramReceivedServer.datagramReceivedB   sF    TL)*%)%8%8$"A"JJt +r/   )rG   )	r>   r?   r@   rA   rG   __annotations__refusedrN   rB   rC   r/   r,   rE   rE   =   s    ,0N)0G""r/   rE   c                  .    \ rS rSrSrSrS rS rS rSr	g)ClientI   Nr   c                    U R                   R                  U5        U R                  b%  U R                  S so l        UR                  S 5        g g r(   rJ   )r+   rL   r7   s      r,   rN   Client.datagramReceivedM   sD    D!*%)%8%8$"A"JJt +r/   c                r    U R                   b$  U R                   S so l         UR                  U5        Xl        g r(   )r4   errbackfailure)r+   rY   r7   s      r,   connectionFailedClient.connectionFailedS   s2    +&*&:&:D#A#IIgr/   c                    U R                   b8  U R                   S sol         UR                  [        R                  " S5      5        SU l        g Nyupr2   r4   rX   r   ConnectionRefusedErrorrQ   r6   s     r,   connectionRefusedClient.connectionRefusedY   ?    +&*&:&:D#A#IIe2259:r/   )rY   rG   rQ   r4   )
r>   r?   r@   rA   rG   rQ   rN   rZ   ra   rB   rC   r/   r,   rS   rS   I   s    NGr/   rS   c                      \ rS rSrS rSrg)
GoodClient`   c                    U R                   b8  U R                   S sol         UR                  [        R                  " S5      5        SU l        g r]   r_   r6   s     r,   ra   GoodClient.connectionRefuseda   rc   r/   )rQ   r4   N)r>   r?   r@   rA   ra   rB   rC   r/   r,   re   re   `   s    r/   re   c                      \ rS rSrSrSrg)BadClientErrorh   zZ
Raised by BadClient at the end of every datagramReceived call to try and
screw stuff up.
rC   N)r>   r?   r@   rA   __doc__rB   rC   r/   r,   rj   rj   h   s    r/   rj   c                  (    \ rS rSrSrSrS rS rSrg)	BadCliento   z
A DatagramProtocol which always raises an exception from datagramReceived.
Used to test error handling behavior in the reactor for that method.
Nc                    Xl         g)zM
Set the Deferred which will be called back when datagramReceived is
called.
Nr7   r6   s     r,   setDeferredBadClient.setDeferredw   s	    
 r/   c                z    U R                   b$  U R                   S so0l         UR                  U5        [        S5      e)NzApplication code is very buggy!)r7   r5   rj   )r+   bytesrM   r7   s       r,   rN   BadClient.datagramReceived~   s3    66IAvJJu>??r/   rq   )	r>   r?   r@   rA   rl   r7   rr   rN   rB   rC   r/   r,   rn   rn   o   s    
 	A@r/   rn   !This reactor does not support UDPc                      \ rS rSrS rS rS rS rS r\	" \
R                  R                  S5      S:H  S	5      S
 5       rS rS rS rS rSrg)UDPTests   c                   ^ ^ [        5       n[        R                  " 5       =o!l        [        R
                  " SUSS9mUU 4S jnUR                  U5      $ )z]
The C{type} of the host address of a listening L{DatagramProtocol}'s
transport is C{"UDP"}.
r   	127.0.0.1	interfacec                |   > TR                  5       nTR                  UR                  S5        TR                  5       $ )NUDP)getHostassertEqualtypestopListening)ignoredrM   pr+   s     r,   	cbStarted+UDPTests.test_oldAddress.<locals>.cbStarted   s/    99;DTYY.??$$r/   rE   r   r   r4   r   	listenUDPaddCallback)r+   serverr7   r   r   s   `   @r,   test_oldAddressUDPTests.test_oldAddress   sH    
 %*^^%55"a;?	%
 }}Y''r/   c                   ^ ^^ [        5       m[        R                  " 5       =nTl        [        R
                  " STSS9mUU U4S jnU U4S jnUR                  U5      R                  U5      $ )z
The L{DatagramProtocol}'s C{startProtocol} and C{stopProtocol}
methods are called when its transports starts and stops listening,
respectively.
r   r|   r}   c                   > TR                  TR                  S5        TR                  TR                  S5        TR                  5       $ )Nr2   r   )r   r3   r;   r   )r   port1r+   r   s    r,   r   *UDPTests.test_startStop.<locals>.cbStarted   s:    V^^Q/V^^Q/&&((r/   c                >   > TR                  TR                  S5        g r1   )r   r;   )r   r+   r   s    r,   	cbStopped*UDPTests.test_startStop.<locals>.cbStopped   s    V^^Q/r/   r   )r+   r7   r   r   r   r   s   `   @@r,   test_startStopUDPTests.test_startStop   sZ     %*^^%55F"!!!V{C	)
	0 }}Y'33I>>r/   c                   ^^ [        5       m[        R                  " 5       =nTl        [        R
                  " STSS9nS mUU4S jnUR                  TU5      $ )zZ
Re-listening with the same L{DatagramProtocol} re-invokes the
C{startProtocol} callback.
r   r|   r}   c                "    UR                  5       $ r(   r   r   ports     r,   r   'UDPTests.test_rebind.<locals>.cbStarted   s    %%''r/   c                   > [         R                  " 5       =nTl        [        R                  " STSS9nUR                  TU5      $ Nr   r|   r}   )r   r   r4   r   r   r   )r   r7   r   r   r   s      r,   r   'UDPTests.test_rebind.<locals>.cbStopped   s<    ).)99A&!!!V{CA==A..r/   r   )r+   r7   r   r   r   r   s       @@r,   test_rebindUDPTests.test_rebind   sQ    
 %*^^%55F"a;?	(	/
 }}Y**r/   c                   ^ ^^ [        5       m[        R                  " 5       =nTl        [        R
                  " STSS9mUU U4S jnUR                  U5        U4S jnUR                  U5        U$ )zx
A L{CannotListenError} exception is raised when attempting to bind a
second protocol instance to an already bound port
r   r|   r}   c                  > TR                  TR                  5       TR                  R                  5       5        [        5       nTR	                  [
        R                  [        R                  TR                  5       R                  USS9  g )Nr|   r}   )
r   r   rH   rE   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                $   > TR                  5       $ r(   r   r   s    r,   
cbFinished+UDPTests.test_bindError.<locals>.cbFinished   s    %%''r/   r   )r+   r7   r   r   r   r   s   `   @@r,   test_bindErrorUDPTests.test_bindError   s_    
 %*^^%55F"  FkB		 	
i 	( 	
j!r/   c                  ^ ^^^	^
 [        5       m
[        R                  " 5       =nT
l        [        R
                  " ST
SS9m	[        5       m[        R                  " 5       =mTl        UUU 4S jnUR                  U5      nUU
4S jnUR                  U5        UU U
4S jnUR                  U5        U	U 4S jnUR                  U5        U$ )zv
Datagrams can be sent with the transport's C{write} method and
received via the C{datagramReceived} callback method.
r   r|   r}   c                >   > [         R                  " STSS9Tl        T$ r   )r   r   port2)r   clientclientStartedr+   s    r,   cbServerStarted2UDPTests.test_sendPackets.<locals>.cbServerStarted   s     **1fLDJ  r/   c                  >^^ TR                   R                  STR                   R                  5       R                  5        TR                   R                  5       nTR                   R                  5       n[        R
                  " 5       =nTl        TR                   R                  SUR                  UR                  45        SSSUR                  UR                  44/mUUUU4S jm[        R                  " T" S 5      U/SS9$ )	Nr|      hello)   a)   bN   cc                   > T(       aW  [         R                  " 5       =nTl        UR                  T5        TR                  R
                  " TR                  S5      6   U$ g Nr   )r   r   rG   r   rH   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)
rH   connectr   r   r   r   rG   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                R  > TR                   R                  5       nTR                   R                  5       nTR                  TR                  SUR                  UR
                  44/5        UR                  UR
                  4nTR                  TR                  SU4SU4SU4/5        g )Nr   r   r   r   )rH   r   r   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                   > [         R                  " [         R                  " TR                  5      [         R                  " TR                  R                  5      /SS9$ NTr   )r   r   r   r   r   )r   r   r+   s    r,   r   -UDPTests.test_sendPackets.<locals>.cbFinished  sL    %%''(;(;<''

(@(@A "& r/   )rE   r   r   r4   r   r   re   r   )r+   serverStartedr   r7   r   r   r   r   r   r   r   s   `      @@@@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                  ^ ^^^^	 [        5       m[        R                  " 5       =nTl        [        R
                  " STSS9m[        5       m	[        R                  " 5       =nT	l        [        R
                  " ST	SS9m[        R                  " X/SS9nUU U	4S jnUR                  U5        UU4S jnUR                  U5        U$ )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.
r   r|   r}   Tr   c                V  > [         R                  " 5       =nTl        TR                  R	                  SS5        [        S5       HB  nTR                  R                  SU4-  5        TR                  R                  SU4-  S5        MD     TR                  U[        R                  5      $ )Nr|   P   
      %dr|   r   )
r   r   r4   rH   r   ranger   assertFailurer   r`   )r   ra   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                   > [         R                  " [         R                  " TR                  5      [         R                  " TR                  5      /SS9$ r   r   r   r   r   )r   r   r   s    r,   r   3UDPTests.test_connectionRefused.<locals>.cbFinished?  sH    %%''(:(:;''(;(;< "& r/   )	re   r   r   r4   r   r   rE   r   r   )
r+   r   r   r7   r   r   r   r   r   r   s
   `     @@@@r,   test_connectionRefusedUDPTests.test_connectionRefused  s     161AA.  FkB161AA.!!!V{C=PTU	W 	
i 	 	
j!r/   c                ,  ^ ^	^
^^^ [        5       m	[        R                  " 5       =nT	l        [        R
                  " ST	SS9m
Sm[        5       m[        R                  " 5       =nTl        [        R                  " 5       =nTl        [        R
                  " STSS9m[        R                  " X/SS9nU	UUU4S jnUR                  U5        [        R                  " XC/SS9nU UU4S jnUR                  U5        U
U4S	 jnUR                  U5        U$ )
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.
r   r|   r}   s   Sending test packet to serverTr   c                   > TR                   R                  SS5        TR                   R                  TSTR                  45        g )Ns$   write to port no one is listening tor   r|   )rH   r   _realPortNumber)r   r   r   
serverPorttest_data_to_sends    r,   cbClientAndServerStartedAUDPTests.test_serverReadFailure.<locals>.cbClientAndServerStartedb  sE     ""79J ""!K1K1K#Lr/   c                J   > TR                  TR                  S   S   T5        g r   )r   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                   > [         R                  " [         R                  " TR                  5      [         R                  " TR                  5      /SS9$ r   r   )r   
clientPortr   s    r,   cleanup0UDPTests.test_serverReadFailure.<locals>.cleanupz  sH    %%''
(@(@A''
(@(@A "& r/   )
re   r   r   r4   r   r   rE   rG   r   r   )r+   r   r   serverGotDataserver_client_started_dr   all_data_sentr   r   r   r   r   r   r   s   `        @@@@@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                ^   [        5       n[        R                  " SUSS9nU R                  [        R
                  UR                  R                  SS5        UR                  R                  SS5        U R                  [        UR                  R                  SS5        UR                  5       $ )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.
r   r|   r}   	localhostr   )
re   r   r   r   r   InvalidAddressErrorrH   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                N  ^ ^^^^^^^	 [         R                  " 5       mU 4S jnTR                  U5        [        5       m[        R
                  " STSS9mU4S jnTR                  U5        TR                  5       m[        [        S5      5      m/ m	UUUUUU U	4S jmT" 5         T$ )zZ
When datagramReceived raises an exception it is logged but the port
is not disconnected.
c                   > TR                  [        5      nTR                  [        U5      SS[        U5      4-  5        g)za
Flush the exceptions which the reactor should have logged and make
sure they're actually there.
   z'Incorrectly found %d errors, expected 2N)flushLoggedErrorsrj   r   len)ignerrsr+   s     r,   cbCompleted8UDPTests.test_datagramReceivedError.<locals>.cbCompleted  s:    
 )).9DD	1G3t9,Vr/   r   r|   r}   c                l   >^  [         R                  " TR                  5      R                  U 4S j5      $ )z_
Disconnect the port we started and pass on whatever was given to us
in case it was a Failure.
c                   > T$ r(   rC   )r  results    r,   <lambda>HUDPTests.test_datagramReceivedError.<locals>.cbCleanup.<locals>.<lambda>  s    vr/   )r   r   r   addBoth)r  r   s   `r,   	cbCleanup6UDPTests.test_datagramReceivedError.<locals>.cbCleanup  s(    
 &&t'9'9:BBCUVVr/   <   c                 r  >^ T(       d   T
R                  S5        T
R                  TR                  SS5        STR                  S5      4-  n [        R                  " 5       nTR                  U5        TR                  R                  U TR                  TR                  45        UU	UU4S jnU	4S jnUR                  X#5        UR                  TR                  5        [        R                  " SUR                  [         R"                  " S	5      5      mg! [         a    TR                  5          GNf = f)
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   r   c                   > TR                  5         TR                  U 5        [        T5      S:X  a#  [        R                  " STR
                  S5        gT" 5         g)zU
A packet arrived.  Cancel the timeout for it, record it, and
maybe finish the test.
r  r   N)cancelrK   r  r   	callLaterr5   )packetfinalDeferredmakeAttemptsucceededAttemptstimeoutCalls    r,   cbPacketReceivedRUDPTests.test_datagramReceivedError.<locals>.makeAttempt.<locals>.cbPacketReceived  sL    
 ""$!((0()Q.
 %%a)?)?FMr/   c                   > T" 5         g)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.
NrC   )errr  s    r,   ebPacketTimeoutQUDPTests.test_datagramReceivedError.<locals>.makeAttempt.<locals>.ebPacketTimeout  s
     r/   g?z&Timed out in testDatagramReceivedError)fail	ExceptionrX   failIfIdenticalrH   r   r   r   rr   r   r   r   addCallbacks
addErrbackr   r  r   TimeoutError)r  packetDeferredr  r  r  rM   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 D65D6)
r   r   r   rn   r   r   r  r   listr   )
r+   r  r  rM   r(  r   r  r  r   r  s
   `  @@@@@@@r,   test_datagramReceivedError#UDPTests.test_datagramReceivedError  s    
 (	 	!!+.  FkB	W 	i(||~ b	?8	 8	t 	r/   c                     " S S5      n[         R                  " S[        5       5      nU" 5       Ul        UR	                  SS5        U R                  U R                  /5      nU R                  [        U5      S5        g)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                      \ rS rSrS rSrg)6UDPTests.test_NoWarningOnBroadcast.<locals>.fakeSocketi  c                    g r(   rC   )r+   foobars      r,   sendto=UDPTests.test_NoWarningOnBroadcast.<locals>.fakeSocket.sendto  s    r/   rC   N)r>   r?   r@   rA   r3  rB   rC   r/   r,   
fakeSocketr/    s    r/   r5  r   s   test)z<broadcast>i  N)	r   PortrE   r   r   flushWarningstest_NoWarningOnBroadcastr   r  )r+   r5  r   warningss       r,   r8  "UDPTests.test_NoWarningOnBroadcast  se    	 	 HHQ!<	./%%t'E'E&FGX*r/   )r   N)r>   r?   r@   rA   r   r   r   r   r   r   osenvirongetr   r   r   r+  r8  rB   rC   r/   r,   ry   ry      sh    ( ?(+&8BH 


'(,<<,'	'R:x$$gR+r/   ry   c                  ^    \ rS rSrSr\R                  " \S5      (       d  SrS r	S r
S rSrg)	ReactorShutdownInteractionTestsi  z!Test reactor shutdown interactionNrw   c                l    [        5       U l        [        R                  " SU R                  SS9U l        g)zStart a UDP portr   r|   r}   N)rE   r   r   r   r   r*   s    r,   setUp%ReactorShutdownInteractionTests.setUp  s%    h%%aL	r/   c                6    U R                   R                  5       $ )zStop the UDP port)r   r   r*   s    r,   tearDown(ReactorShutdownInteractionTests.tearDown#  s    yy&&((r/   c                  ^ ^ [         R                  " 5       m[         R                  " 5       =nT R                  l        UU 4S jnUR	                  U5        U 4S jnTR	                  U5        T R                  R
                  R                  SST R                  R
                  R                  5       R                  45        T$ )z0Test reactor shutdown while in a recvfrom() loopc                   > TR                   R                  R                  5         [        R                  " STR
                  S 5        g r   )r   rH   connectionLostr   r  r5   )r   finishedr+   s    r,   pktReceQReactorShutdownInteractionTests.testShutdownFromDatagramReceived.<locals>.pktRece6  s3    KK!!002 a!2!2D9r/   c                &   > TR                  5         g r(   )r  r   r+   s    r,   flushErrorsUReactorShutdownInteractionTests.testShutdownFromDatagramReceived.<locals>.flushErrors@  s    
 ""$r/   s@                                                                   r|   )	r   r   r   rG   r   rH   r   r   r   )r+   prrJ  rN  rI  s   `   @r,    testShutdownFromDatagramReceived@ReactorShutdownInteractionTests.testShutdownFromDatagramReceived'  s     >>#*/..*::T[['	: 	w	% 	[)##dkk&;&;&C&C&E&J&JK	
 r/   )r   r   )r>   r?   r@   rA   rl   r   IReactorUDPr   skiprA  rD  rQ  rB   rC   r/   r,   r?  r?    s-    +!!'4002M
)$r/   r?  c                ,   [        U [        5      nUR                  US45        [        X5      n[        X5      n UR	                  XXg-   5         UR                  5         g! [         a     UR                  5         gf = f! UR                  5         f = f)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.
r   TF)r   r
   bindr   
setsockoptcloseOSError)afipprotojoingroupbindtos	packgrouppackifs           r,   checkMulticastAvailabilityrb  N  s     	r:AFFFA;"$Ir"F	WI$67 		   	
	
 	
	s#   A! !
A>+B =A>>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                     \ rS rSr% SrSrS\S'   SrS\S'   SrS\S	'   S
r	S\S'   Sr
S\S'   SrS\S'   SrS\S'   SrS\S'   S rS rS S jrS S jrS S jrS S jrS S jr\" \R.                  R1                  5       =(       a    \R.                  R3                  5       (       + S5      S 5       rS r\" \R.                  R1                  5       S5      S S j5       rSrg)!MulticastTestsie  zg
Tests for sending and receiving multicast datagrams.  (This suite supports
IPv4, see below for IPv6.)
rd  strr~   	str | intexpectedInterfacer|   clientAddressrc  multicastGroupalternateInterfacer   interfaceSynonyminvalidGroup::1wrongAddressFamilyc                   [        5       U l        [        5       U l        [        R
                  " SU R                  U R                  5      U l        [        R
                  " SU R                  U R                  5      U l        U R                  R                  R                  U R                  U R                  R                  R                  5       R                  5        g r   )rE   r   rS   r   r   listenMulticastr~   r   r   rH   r   rj  r   r   r*   s    r,   rA  MulticastTests.setUp  s    hh,,QT^^L
,,QT^^L
%%KK!!))+00	
r/   c                    [        [        U R                  R                  5      [        U R                  R                  5      /5      $ r(   )r   r   r   r   r   r*   s    r,   rD  MulticastTests.tearDown  s8    djj667djj667
 	
r/   c                   ^  T R                   R                  R                  [        :w  a  [	        S5      eSU 4S jjnU" T R
                  5        U" T R                   5        g )Nz+only IPv4 multicast has TTLs, IPv6 has hopsc                2  > [         R                  " U R                  5      (       d   eTR                  U R                  R	                  5       S5        U R                  R                  S5        TR                  U R                  R	                  5       S5        g )Nr2   r  )r   
providedByrH   r   getTTLsetTTL)or+   s    r,   checkttl(MulticastTests.testTTL.<locals>.checkttl  sj    &11!++>>>>Q[[//115KKq!Q[[//115r/   )r{  zServer | ClientreturnNone)r   rH   addressFamilyr   r"   r   )r+   r|  s   ` r,   testTTLMulticastTests.testTTL  sF    ;;  ..'9HII	6 	r/   c                   #    U R                   nU R                  U R                  R                  R	                  5       S5        U R                  R                  R                  5       nU R                  R                  R                  U5      I Sh  vN   [        5       U R                  l        U R                  R                  R                  SXR                  45        U R                  R                  I Sh  vN   U R                  [        U R                  R                  5      S5        U R                  R                  R                  S5        U R                  U R                  R                  R	                  5       S5        U R                  R                  R                  SXR                  45        [        [        [         5      S5      I Sh  vN   U R                  [        U R                  R                  5      S5        g GNw GN N:7f)z^
Test that after loopback mode has been set, multicast packets are
delivered to their sender.
r2   Nr   r   )rk  r   r   rH   getLoopbackModer   	joinGroupr   rG   r   r   r  r)   setLoopbackModer   r   r   )r+   r]  rM   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5H	HHc                   #    U R                  [        5         U R                  R                  R	                  U R
                  U R                  S9I Sh  vN   SSS5        g N! , (       d  f       g= f7f)z|
A sensible error will be reported when using the wrong address family
literal for the 'interface' argument to 'joinGroup'.
r}   N)r   r   r   rH   r  rk  rp  r*   s    r,   test_wrongFamilyInterfaceJoin,MulticastTests.test_wrongFamilyInterfaceJoin  sc     
 12++''11##t/F/F 2    32 32s.   A5<A$A"A$	A5"A$$
A2.A5c                  #    U R                  U R                  R                  R                  5       U R                  5        U R                  U R
                  R                  R                  5       U R                  5        U R
                  R                  R                  U R                  5      I Sh  vN   U R                  R                  R                  U R                  5      I Sh  vN   U R                  U R                  R                  R                  5       U R                  5        U R                  U R
                  R                  R                  5       U R                  5        g N N7f)z;
Test C{getOutgoingInterface} and C{setOutgoingInterface}.
N)	r   r   rH   getOutgoingInterfaceri  r   setOutgoingInterfacerl  rm  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                  #    U R                   R                  R                  U R                  5      I Sh  vN   U R                   R                  R	                  U R                  5      I Sh  vN   U R
                  R                  R                  U R                  5      I Sh  vN   U R
                  R                  R	                  U R                  5      I Sh  vN   g N Nu N@ N7f)z5
Test that multicast a group can be joined and left.
N)r   rH   r  rk  
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                    U R                  U R                  R                  R                  U R                  5      [
        R                  5      $ )zr
Test that an attempt to join an address which is not a multicast
address fails with L{error.MulticastJoinError}.
)r   r   rH   r  rn  r   r   r*   s    r,   test_joinFailureMulticastTests.test_joinFailure  s=     !!KK!!++D,=,=>@X@X
 	
r/   c                  ^ ^^^ [        5       m[        R                  " STT R                  5      mT R                  R
                  R                  5       mT R                  R
                  R                  T R                  5      nUUU 4S jnUR                  U5        U 4S jnUR                  U5        U4S jnUR                  U5        U$ )zV
Test that a multicast group can be joined and messages sent to and
received from it.
r   c                   > [        5       =nTR                  l        TR                  R	                  STR
                  TR                  45        U$ )N   hello world)r   r   rG   rH   r   rk  r   )r   r7   rM   cr+   s     r,   cbJoined/MulticastTests.test_multicast.<locals>.cbJoined  s>    -5Z7A*KKnt/B/BDII.NOHr/   c                ^   > TR                  TR                  R                  S   S   S5        g )Nr   r  )r   r   r)   rM  s    r,   cbPacket/MulticastTests.test_multicast.<locals>.cbPacket  s'    T[[003A6Gr/   c                ^   >^  [        TR                  5      nUR                  U 4S j5        U$ )Nc                   > T$ r(   rC   )r  passthroughs    r,   r  @MulticastTests.test_multicast.<locals>.cleanup.<locals>.<lambda>
  s    ;r/   )r   r   r   )r  r  r   s   ` r,   r   .MulticastTests.test_multicast.<locals>.cleanup  s%    "1??3F67Mr/   )
rE   r   rr  r~   r   rH   r   r  rk  r   )r+   joinedr  r  r   rM   r  r   s   `    @@@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                  #    [        5       n[        [        5      nUR                  SUSU R                  S9nUR                  5       n[        U[        [        45      (       d   eUR                  n[        5       nUR                  UUSU R                  S9n[        U R                  R                  R                  U R                  5      UR                  U R                  5      UR                  U R                  5      /5      I Sh  vN   [        5       =ol        [        5       =ol        UR                  R#                  SU R                  U45        [        X/5      I Sh  vN   U R%                  UR&                  S   S   S5        U R%                  UR&                  S   S   S5        [        [)        UR*                  5      [)        UR*                  5      /5      I Sh  vN   g N N N	7f)z
Test that multiple sockets can listen on the same multicast port and
that they both receive multicast messages directed to that address.
r   T)listenMultipler~   Nr  )rE   r   r   rr  r~   r   
isinstancer   r   r   r   r   rH   r  rk  r   rG   r   r   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G.G(AG.#G*$A>G."G,#G.*G.,G.)r   r   r   r   N)r~  r  )r>   r?   r@   rA   rl   r~   rP   ri  rj  rk  rl  rm  rn  rp  rA  rD  r  r  r  r  r  r   r    platform	isWindowsisVistar  r  r  rB   rC   r/   r,   rf  rf  e  s     Is#,y,$M3$'NC'$/	/"-i-#L####	

60
.D ""$GW-=-=-E-E-G)G<
	
@ ""$	.
.
r/   rf  ff03::1::z/The local stack does not enable IPv6 multicast.c                      \ rS rSr% SrSrS\S'   SrS\S'   SrS\S	'   \	" S
 \
" 5        5       5      rS\S'   \rS\S'   SrS\S'   SrS\S'   SrS\S'   Srg)MulticastTestsIPv6iH  z;
Tests for sending and receiving IPv6 multicast datagrams.
r  rg  r~   ro  rj  r  rk  c              #  `   #    U  H$  oS    R                  S5      (       d  M  US   v   M&     g7f)r2   lor   N)
startswith).0idxnms     r,   	<genexpr>MulticastTestsIPv6.<genexpr>^  s%     K~eq1D1DT1Jq~s   ..rh  rl  rm  rn  r   ri  r|   rp  rC   N)r>   r?   r@   rA   rl   r~   rP   rj  rk  nextr   rl  rm  rn  ri  rp  rB   rC   r/   r,   r  r  H  sp     IsM3#NC#$(K|~K%	  #5i4L##$y$))r/   r  )rZ  r   r[  intr\  r  r]  rg  r^  rg  r~  bool)=rl   
__future__r   r;  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%   DatagramProtocolrE   ConnectedDatagramProtocolrS   re   r"  rj   rn   rS  ry   r?  rb  rf  r  rC   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 #+.7:DG	. $$Wd33- ".y	  A	V
X V
	V
r $$Wd33- ",D	  6	* * 	*r/   