Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/test/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyc


S+Nc@sdZddlmZddlmZmZmZddlmZm	Z	m
Z
mZmZm
Z
ddlmZdfdYZdeejfd	YZd
eejfdYZdefd
YZdefdYZdejfdYZdejfdYZdejfdYZdejfdYZeje	ersde_de_nej e	erde_ndZ!e!dS(sG
Tests for implementations of L{IReactorUDP} and L{IReactorMulticast}.
i(tunittest(tDeferredt
gatherResultst
maybeDeferred(tprotocoltreactorterrortdefert
interfacestudp(truntimetMixincBs5eZdZdZdZdZdZdZRS(icCs
g|_dS(N(tpackets(tself((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt__init__scCs?d|_|jdk	r;|jd}|_|jdndS(Ni(tstartedtstartedDeferredtNonetcallback(R
td((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt
startProtocols	cCs
d|_dS(Ni(tstopped(R
((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytstopProtocol sN(	t__name__t
__module__RRRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRs		tServercBseZdZdZdZRS(icCsL|jj||f|jdk	rH|jd}|_|jdndS(N(RtappendtpacketReceivedRR(R
tdatataddrR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytdatagramReceived)sN(RRRRtrefusedR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR$stClientcBs/eZdZdZdZdZdZRS(icCsF|jj||jdk	rB|jd}|_|jdndS(N(RRRRR(R
RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR6scCs?|jdk	r2|jd}|_|j|n||_dS(N(RRterrbacktfailure(R
R"R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytconnectionFailed<scCsH|jdk	r;|jd}|_|jtjdnd|_dS(Ntyupi(RRR!RtConnectionRefusedErrorR(R
R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytconnectionRefusedBsN(RRRRRRR#R&(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR 1s
		t
GoodClientcBseZdZRS(cCsH|jdk	r;|jd}|_|jtjdnd|_dS(NR$i(RRR!RR%R(R
R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR&Ks(RRR&(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR'IstBadClientErrorcBseZdZRS(sf
    Raised by BadClient at the end of every datagramReceived call to try and
    screw stuff up.
    (RRt__doc__(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR(Sst	BadClientcBs&eZdZdZdZdZRS(s
    A DatagramProtocol which always raises an exception from datagramReceived.
    Used to test error handling behavior in the reactor for that method.
    cCs
||_dS(se
        Set the Deferred which will be called back when datagramReceived is
        called.
        N(R(R
R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytsetDeferredbscCsB|jdk	r2|jd}|_|j|ntddS(NsApplication code is very buggy!(RRRR((R
tbytesRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRjsN(RRR)RRR+R(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR*[s	tUDPTestCasecBsbeZdZdZdZdZdZdZdZdZ	dZ
d	ZRS(
csSt}tj}|_tjd|ddfd}|j|S(su
        The C{type} of the host address of a listening L{DatagramProtocol}'s
        transport is C{"UDP"}.
        it	interfaces	127.0.0.1cs)j}j|jdjS(NtUDP(tgetHosttassertEqualttypet
stopListening(tignoredR(R
tp(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt	cbStarted|s(RRRRRt	listenUDPtaddCallback(R
tserverRR6((R
R5s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyttest_oldAddressts
	csqttj}_tjdddfd}fd}|j|j|S(s
        The L{DatagramProtocol}'s C{startProtocol} and C{stopProtocol}
        methods are called when its transports starts and stops listening,
        respectively.
        iR.s	127.0.0.1cs0jjdjjdjS(Nii(R1RRR3(R4(R
tport1R9(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR6scsjjddS(Ni(R1R(R4(R
R9(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt	cbStoppeds(RRRRRR7R8(R
RR6R<((R
R9R;s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyttest_startStops	cs_ttj}_tjddd}dfd}|j|S(sr
        Re-listening with the same L{DatagramProtocol} re-invokes the
        C{startProtocol} callback.
        iR.s	127.0.0.1cSs
|jS(N(R3(R4tport((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR6scs;tj}_tjddd}|j|S(NiR.s	127.0.0.1(RRRRR7R8(R4RR5(R9R6(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR<s(RRRRRR7R8(R
RR5R<((R6R9s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyttest_rebinds		csvttj}_tjdddfd}|j|fd}|j||S(s
        A L{CannotListenError} exception is raised when attempting to bind a
        second protocol instance to an already bound port
        iR.s	127.0.0.1csWjjjjt}jtjtjjj	|dddS(NR.s	127.0.0.1(
R1R0t	transportRtassertRaisesRtCannotListenErrorRR7R>(R4tserver2(R
R9R>(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR6s	cs
jS(N(R3(R4(R>(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt
cbFinisheds(RRRRRR7R8(R
RR6RD((R
R9R>s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyttest_bindErrors	

csttj}_tjdddttj_fd}|j|}fd}|j|fd}|j|fd}|j||S(s
        Datagrams can be sent with the transport's C{write} method and
        received via the C{datagramReceived} callback method.
        iR.s	127.0.0.1cstjddd_S(NiR.s	127.0.0.1(RR7tport2(R4(R
tclientt
clientStarted(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytcbServerStartedscsjjdjjjjj}jj}tj}_jjd|j|jfdd	d|j|jffgfdtj
d|gdtS(
Ns	127.0.0.1thellotatbtccsGrCtj}_|jjjjd|SdS(Ni(RRRR8R@twritetpop(R4tnextClientWrite(R9RGtcbClientSendtclientWrites(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRQs

tfireOnOneErrback(RK(RLN(R@tconnectR0R>RRRRNthostRtDeferredListtTrue(R4tcAddrtsAddrt
serverSend(R9RG(RQRRs9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytcbClientStarteds
		csjj}jj}jjd|j|jffg|j|jf}jjd|fd|fd|fgdS(NRJRKRLRM(R@R0R1RRUR>(R4RXRYt
clientAddr(R
R9RG(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytcbSendsFinisheds		cs4tjtjjtjjjgdtS(NRS(RRVRR3RFRW(R4(R
R;(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRDs(RRRRRR7R'R8(R
t
serverStartedRIRR[R]RD((RHR
RGR9R;s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyttest_sendPacketss		



csttj}_tjdddttj}_tjdddtj||gdt}fd}|j	|fd}|j	||S(s
        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.
        iR.s	127.0.0.1RScstj}_jjddxCtdD]5}jjt|jjt|dq3Wj|t	j
S(Ns	127.0.0.1iPi
(s	127.0.0.1iP(RRRR@RTtrangeRNtstrt
assertFailureRR%(R4R&ti(R
R9RG(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR6scs1tjtjjtjjgdtS(NRS(RRVRR3RW(R4(RFR>(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRD,s(
R'RRRRR7RRVRWR8(R
RHR^RR6RD((R
R9RGRFR>s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyttest_connectionRefuseds			

cCsvt}tjd|dd}|jt|jjdd|jjdd|jt|jjdd|jS(s
        A call to the transport's connect method fails with a L{ValueError}
        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.
        iR.s	127.0.0.1t	localhostiP(	R'RR7RAt
ValueErrorR@RTtRuntimeErrorR3(R
RGR>((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyttest_badConnect6s	

cstjfd}j|ttjdddfd}j|jtdgfdS(sr
        When datagramReceived raises an exception it is logged but the port
        is not disconnected.
        cs9jt}jt|ddt|fdS(s
            Flush the exceptions which the reactor should have logged and make
            sure they're actually there.
            is'Incorrectly found %d errors, expected 2N(tflushLoggedErrorsR(R1tlen(tignterrs(R
(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytcbCompletedPsiR.s	127.0.0.1cs"tjjjfdS(s
            Disconnect the port we started and pass on whatever was given to us
            in case it was a Failure.
            csS(N((Rk(tresult(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt<lambda>as(RRR3taddBoth(Rn(R>(Rns9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt	cbCleanup\si<css.yjdWq.jq.Xnjjddtjd}tj}j	|jj
|jjffd}fd}|j
|||jjtjd|jtjddS(	s6
            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.
            sNot enough packets receivedsUDP Protocol lost its transporticsMjj|tdkrBtjdjdndS(s
                A packet arrived.  Cancel the timeout for it, record it, and
                maybe finish the test.
                iiN(tcancelRRjRt	callLaterRR(tpacket(tsucceededAttemptstmakeAttemptttimeoutCallt
finalDeferred(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytcbPacketReceiveds


csdS(s
                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.
                N((terr(Rv(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytebPacketTimeouts	g?s&Timed out in testDatagramReceivedErrorN(tfailR!tfailIfIdenticalR@RRaRORRR+RNRUR>taddCallbackst
addErrbackRRsRtTimeoutError(RttpacketDeferredRyR{(RuRRvR
tattemptsRGRx(Rws9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRvqs$
	(	RRR8R*RR7RpR0R`(R
RmRq((RuRvR
RRGRxR>Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyttest_datagramReceivedErrorIs
	

!7cst}tjd|tjjjtjdkfd}t	j
j}|j||S(s
        The port number being listened on can be found in the string
        returned from calling repr() on L{twisted.internet.udp.Port}.
        iics&jtjdkdS(Ni(tfailIftreprtfind(Rk(R
tportNoR5(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytstoppedListenings(
R'RR7RaR0R>RRRRRR3R8(R
RGRR((RR
R5s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt
test_portReprs	"
cCssdddY}tjdt}||_|jdd	|j|jg}|jt|ddS(
si
        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.
        t
fakeSocketcBseZdZRS(cSsdS(N((R
tfootbar((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytsendtos(RRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRsittests<broadcast>iN((s<broadcast>i(	R	tPortRtsocketRNt
flushWarningsttest_NoWarningOnBroadcastR1Rj(R
RR5twarnings((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRs(RRR:R=R?RER_RdRhRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR-rs					J	+		c	tReactorShutdownInteractioncBs)eZdZdZdZdZRS(s!Test reactor shutdown interactioncCs.t|_tjd|jdd|_dS(sStart a UDP portiR.s	127.0.0.1N(RR9RR7R>(R
((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytsetUpscCs
|jjS(sStop the UDP port(R>R3(R
((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyttearDownscstjtj}j_fd}|j|fd}j|jjjdddjjjjfS(s0Test reactor shutdown while in a recvfrom() loopcs*jjjtjdjddS(Ni(R9R@tconnectionLostRRsRR(R4(R
tfinished(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytpktRecescsjdS(N(Ri(R4(R
(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytflushErrorssti@s	127.0.0.1(	RRR9RR8R@RNR0R>(R
tprRR((R
Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt testShutdownFromDatagramReceiveds

(RRR)RRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRs		tMulticastTestCasecBseZdZdZdZdZdZdZdZe	j
jrpe	j
jrpde_
ndZd	Ze	j
jrd
e_nRS(cCsqt|_t|_tjd|j|_tjd|j|_|jjj	d|jjj
jdS(Nis	127.0.0.1(RR9R RGRtlistenMulticastR;RFR@RTR0R>(R
((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRscCs(tt|jjt|jjgS(N(RRR;R3RF(R
((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRscCscx\|j|jfD]H}|j|jjd|jjd|j|jjdqWdS(Nii(RGR9R1R@tgetTTLtsetTTL(R
to((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyttestTTLscsjjjjdjjjjjjd}fd}|j|fd}|j|fd}|j||S(sv
        Test that after loopback mode has been set, multicast packets are
        delivered to their sender.
        is225.0.0.250cs6t}j_jjjddjf|S(NRJs225.0.0.250(RR9RR@RNR>(R4R(RR
(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytcbJoined$scsjtjjdjjjdjjjjdjjjddjft	}t
jd|jd|S(NiiRJs225.0.0.250(R1RjR9RR@tsetLoopbackModetgetLoopbackModeRNR>RRRsRR(R4R(RR
(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytcbPacket*s	cs jtjjddS(Ni(R1RjR9R(R4(R
(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt
cbNoPacket6s(R1R9R@RR0t	joinGroupR8(R
tjoinedRRR((RR
s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt
test_loopbacks



csjjjjdjjjjdjjjd}jjjd}t||g}fd}|j||S(sK
        Test C{getOutgoingInterface} and C{setOutgoingInterface}.
        s0.0.0.0s	127.0.0.1cs<jjjjdjjjjddS(Ns	127.0.0.1(R1RGR@tgetOutgoingInterfaceR9(R4(R
(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytcbInterfacesJs(R1RGR@RR9tsetOutgoingInterfaceRR8(R
td1td2RnR((R
s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyttest_interface=s
csmjjjd}fd}|j|fd}|j|fd}|j||S(sE
        Test that multicast a group can be joined and left.
        s225.0.0.250csjjjdS(Ns225.0.0.250(RGR@t
leaveGroup(R4(R
(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytclientJoinedYscsjjjdS(Ns225.0.0.250(R9R@R(R4(R
(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt
clientLeft]scsjjjdS(Ns225.0.0.250(R9R@R(R4(R
(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytserverJoinedas(RGR@RR8(R
RRRR((R
s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyttest_joinLeaveSs


cCs"|j|jjjdtjS(s
        Test that an attempt to join an address which is not a multicast
        address fails with L{error.MulticastJoinError}.
        s	127.0.0.1(RbRGR@RRtMulticastJoinError(R
((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyttest_joinFailurehssWindows' multicast is wonkycsttjdjjjjjjd}fd}|j|fd}|j|fd}|j||S(sn
        Test that a multicast group can be joined and messages sent to and
        received from it.
        is225.0.0.250cs3t}j_jjddjf|S(Nshello worlds225.0.0.250(RR9RR@RNR>(R4R(RMRR
(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRscs"jjjddddS(Nishello world(R1R9R(R4(R
(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRscs)tj}|jfd|S(NcsS(N((Rk(tpassthrough(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRos(RR3R8(RRn(R5(Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytcleanups(RRRR9R@R0RR8(R
RRRR((RMRR
R5s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyttest_multicastus	


csttjddtjjttjdtdtjjj	j	j	g}fd}|j
|fd}|j
|fd}|j||S(s
        Test that multiple sockets can listen on the same multicast port and
        that they both receive multicast messages directed to that address.
        itlistenMultiples225.0.0.250csIt}_t}_jjdft||gS(Nshello world(RRR@RNR(R4RR(tportnottheGrouptfirstClienttsecondClient(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRscs:jjdddjjddddS(Nishello world(R1R(R4(R
RR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt
gotPacketsscs>ttjtjg}|jfd|S(NcsS(N((Rk(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRos(RRR3R8(RRn(t
secondPortt	firstPort(Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRs
(RRRRWR0R>RR9R@RR8Rp(R
RRRR((RRR
RRRRs9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyttest_multiListens$		


sjon non-linux platforms it appears multiple processes can listen, but not multiple sockets in same process?(RRRRRRRRRR
tplatformt	isWindowstisVistattodoRRtskip(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRs	
			"						)s!This reactor does not support UDPs'This reactor does not support multicastcCsddl}|jjdrtdj}|jdr|jd}|jdd ddgkrtjj	}d|_
qqndS(Nis
/proc/versions
Linux versionit.t2s&figure out why this fails in linux 2.2(tostpathtexiststopentreadt
startswithtsplitRt
testInterfacetim_funcR(Rtstf((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pytcheckForLinux22sN("R)t
twisted.trialRttwisted.internet.deferRRRttwisted.internetRRRRRR	ttwisted.pythonR
RtDatagramProtocolRtConnectedDatagramProtocolR R't	ExceptionR(R*tTestCaseR-RRtIReactorUDPRRtIReactorMulticastR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt<module>s*.

`1