Your IP : 172.28.240.42


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

ó
}3›Nc@s@dZeZddlmZddlmZddlmZddl	m
Z
ddlmZm
Z
ddlmZddlmZmZdd	lmZmZdd
lmZddlmZddlmZdd
lmZdefd„ƒYZdefd„ƒYZ deee fd„ƒYZ!e"ƒj#e!j$ƒƒdS(s.
Tests for implementations of L{IReactorUDP}.
iÿÿÿÿ(t
SOCK_DGRAM(t
implements(tverifyObject(tcontext(tILogContextterr(tReactorBuilder(tDeferredt
maybeDeferred(tILoggingContexttIListeningPort(tIPv4Address(tDatagramProtocol(tfindFreePort(tLogObserverMixintUDPPortMixincBs#eZd„Zd„Zd„ZRS(cCs|jd|ƒS(s0
        Get a UDP port from a reactor.
        i(t	listenUDP(tselftreactortprotocol((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pytgetListeningPortscCsd||jƒjfS(sY
        Get the message expected to be logged when a UDP port starts listening.
        s%s starting on %d(tgetHosttport(RRR((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyt#getExpectedStartListeningLogMessage#scCsd|jƒjfS(sJ
        Get the expected connection lost message for a UDP port.
        s(UDP Port %s Closed)(RR(RR((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyt#getExpectedConnectionLostLogMessage*s(t__name__t
__module__RRR(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyRs		tDatagramTransportTestsMixincBs)eZdZd„Zd„Zd„ZRS(sP
    Mixin defining tests which apply to any port/datagram based transport.
    cCsz|jƒ}|jƒ}dtfd„ƒY}|ƒ}|j||ƒ}|j|dƒ}|j|f|ddƒdS(su
        When a port starts, a message including a description of the associated
        protocol is logged.
        tSomeProtocolcBseZeeƒd„ZRS(cSsdS(NsCrazy Protocol((R((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyt	logPrefix?s(RRRR	R(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyR=s
sCrazy ProtocolitmessageN(tobservetbuildReactorRRRtassertEqual(RtloggedMessagesRRRtptexpectedMessage((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyttest_startedListeningLogMessage6s	cs™|jƒ‰|jƒ‰|jˆtƒƒ‰|jˆƒ}‡fd†‰‡‡‡fd†}ˆj|ƒ|jˆƒ|j|fˆddƒdS(sÓ
        When a connection is lost, an informative message should be logged (see
        L{getExpectedConnectionLostLogMessage}): an address identifying the port
        and the fact that it was closed.
        csˆjƒdS(N(tstop(tignored(R(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pytstopReactorSscsˆ2tˆjƒjˆƒdS(N(Rt
stopListeningtaddCallback((R"R(R#(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pytdoStopListeningVsiRN(RR RRRtcallWhenRunningt
runReactorR!(RR$R+((R"R(RR#sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyttest_connectionLostLogMessageHs

cs‚dtf‡fd†ƒY}|jƒ‰|ƒ}|jˆ|ƒ|jˆƒ|j|jƒ|j|jƒ|j|jƒdS(s´
        L{DatagramProtocol.stopProtocol} is called asynchronously (ie, not
        re-entrantly) when C{stopListening} is used to stop the the datagram
        transport.
        tDisconnectingProtocolcs8eZeZeZeZeZd„Z‡fd†ZRS(cSs,t|_t|_|jjƒt|_dS(N(tTruetstartedtinStartProtocolt	transportR)tFalse(R((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyt
startProtocolms		
cs#t|_|j|_ˆjƒdS(N(R0tstoppedR2tstoppedInStartR&(R(R(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pytstopProtocolss	(	RRR4R1R6R2R7R5R8((R(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyR/fs	N(	RR RR-t
assertTrueR1R6tassertFalseR7(RR/R((RsB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyttest_stopProtocolScheduling`s	
(RRt__doc__R%R.R;(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyR2s		tUDPServerTestsBuildercBs)eZdZd„Zd„Zd„ZRS(sF
    Builder defining tests relating to L{IReactorUDP.listenUDP}.
    cCs;|jƒ}|jdtƒƒ}|jtt|ƒƒdS(sY
        L{IReactorUDP.listenUDP} returns an object providing L{IListeningPort}.
        iN(R RRR9RR
(RRR((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyttest_interfaceˆscCsbtdtƒ\}}|jƒ}|j|tƒd|ƒ}|j|jƒtd||ƒƒdS(s³
        L{IListeningPort.getHost} returns an L{IPv4Address} giving a
        dotted-quad of the IPv4 address the port is listening on as well as
        the port number.
        ttypet	interfacetUDPN(R
RR RRR!RR(Rthostt
portNumberRR((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyttest_getHost‘scs¾dtfd„ƒY}ˆjƒ‰|dƒ}|j}ˆjd|ƒ}|jƒ}‡fd†}|j|ƒ|jtƒ|j‡fd†ƒ|jdd|j	fƒˆj
ˆƒd	S(
s’
        Datagram transports implement L{ILoggingContext.logPrefix} to return a
        message reflecting the protocol they are running.
        tCustomLogPrefixDatagramProtocolcBs#eZd„Zd„Zd„ZRS(cSs||_tƒ|_dS(N(t_prefixRtsystem(Rtprefix((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyt__init__¥s	cSs|jS(N(RF(R((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyR©scSsB|jdk	r>|j}d|_|jtjtƒdƒndS(NRG(RGtNonetcallbackRtgetR(RtbytestaddrRG((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pytdatagramReceived¬s		(RRRIRRO(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyRE¤s		sCustom Datagramsicsˆjd|ƒdS(NsCustom Datagrams (UDP)(R!(RG(R(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyt	gotSystem¸scs
ˆjƒS(N(R&(R'(R(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyt<lambda>¼ss
some bytess	127.0.0.1N(RR RGRRR*t
addErrbackRtwriteRR-(RRERtdRtaddressRP((RRsB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyttest_logPrefixŸs	

(RRR<R>RDRV(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyR=ƒs			N(%R<R?t
__metaclass__tsocketRtzope.interfaceRtzope.interface.verifyRttwisted.pythonRttwisted.python.logRRt#twisted.internet.test.reactormixinsRttwisted.internet.deferRRttwisted.internet.interfacesR	R
ttwisted.internet.addressRttwisted.internet.protocolRttwisted.internet.test.test_tcpR
t&twisted.internet.test.connectionmixinsRtobjectRRR=tglobalstupdatetmakeTestCaseClasses(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_udp.pyt<module>s$Q	>