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/connectionmixins.pyc

ó
B±Nc@sÿdZddlmZddlmZddlmZmZddlm	Z	ddl
mZmZm
Z
ddlmZmZddlmZmZd	„ZeZd
efd„ƒYZdefd
„ƒYZdefd„ƒYZdefd„ƒYZdS(s?
Various helpers for tests for connection-oriented transports.
iÿÿÿÿ(tcollect(tref(tcontexttlog(tfullyQualifiedName(tILogContexttmsgterr(tDeferredt
gatherResults(t
ServerFactorytProtocolcCstƒ}||_|S(s
    Helper function which returns a L{ServerFactory} which will build instances
    of C{protocol}.

    @param protocol: A callable which returns an L{IProtocol} provider to be
        used to handle connections to the port the returned factory listens on.
    (R
tprotocol(Rtfactory((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pytserverFactoryFors		t_AcceptOneClientcBs eZdZd„Zd„ZRS(sM
    This factory fires a L{Deferred} with a protocol instance shortly after it
    is constructed (hopefully long enough afterwards so that it has been
    connected to a transport).

    @ivar reactor: The reactor used to schedule the I{shortly}.
    @ivar result: A L{Deferred} which will be fired with the protocol instance.
    cCs||_||_dS(N(treactortresult(tselfRR((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyt__init__)s	cCs2tj||ƒ}|jjd|jj|ƒ|S(Ni(R
t
buildProtocolRt	callLaterRtcallback(RtaddrR((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyR.s(t__name__t
__module__t__doc__RR(((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyR s	tClosingLaterProtocolcBs2eZdZd„Zd„Zd„Zd„ZRS(sÕ
    ClosingLaterProtocol exchanges one byte with its peer and then disconnects
    itself.  This is mostly a work-around for the fact that connectionMade is
    called before the SSL handshake has completed.
    cCsd|_||_dS(N(tNonetlostConnectionReasontonConnectionLost(RR((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyR;s	cCstdƒdS(Ns#ClosingLaterProtocol.connectionMade(R(R((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pytconnectionMade@scCs"td|fƒ|jjƒdS(Ns$ClosingLaterProtocol.dataReceived %r(Rt	transporttloseConnection(Rtbytes((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pytdataReceivedDscCs'tdƒ||_|jj|ƒdS(Ns#ClosingLaterProtocol.connectionLost(RRRR(Rtreason((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pytconnectionLostIs
	(RRRRRR#R%(((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyR5s
			tConnectionTestsMixincBsDeZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(sg
    This mixin defines test methods which should apply to most L{ITransport}
    implementations.
    cCs tdt|jƒfƒ‚dS(s 
        Return an object providing L{IStreamServerEndpoint} for use in creating
        a server to use to establish the connection type to be tested.
        s#%s.serverEndpoint() not implementedN(tNotImplementedErrorRt	__class__(RR((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pytserverEndpointUscCs tdt|jƒfƒ‚dS(s 
        Return an object providing L{IStreamClientEndpoint} for use in creating
        a client to use to establish the connection type to be tested.
        s#%s.clientEndpoint() not implementedN(R'RR((RRt
serverAddress((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pytclientEndpoint^scshtƒ‰tˆˆƒ}||_ˆjˆƒ}|j|ƒ}‡‡‡‡fd†}|j|ƒ|S(sl
        Create a loopback connection of the type to be tested, using
        C{clientProtocol} and C{serverProtocol} to handle each end of the
        connection.

        @return: A L{Deferred} which fires when the connection is established.
            The result is a two-tuple of the client protocol instance and
            server protocol instance.
        cs=|jƒ}ˆjˆ|ƒ}t|jtˆƒƒˆgƒS(N(tgetHostR+R	tconnectt
factoryFor(tporttaddresstclient(RRtclientProtocoltaccepted(sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pytstartedListeningvs(RRRR)tlistentaddCallback(RRR2tserverProtocolR
tservert	listeningR4((RRR2R3sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pytloopbackgs
		
cs¯dtfd„ƒY‰ˆjƒ‰ˆjˆ‡fd†‡fd†ƒ}d„}|j|ƒ‡fd†}|j|ƒ|jtƒ|j‡fd†ƒˆjˆƒdS(	s›
        Client and server transports implement L{ILoggingContext.logPrefix} to
        return a message reflecting the protocol they are running.
        tCustomLogPrefixProtocolcBs#eZd„Zd„Zd„ZRS(cSs||_tƒ|_dS(N(t_prefixRtsystem(Rtprefix((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyR…s	cSs|jS(N(R<(R((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyt	logPrefix‰scSs!|jjtjtƒdƒdS(NR=(R=RRtgetR(RR"((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyR#Œs(RRRR?R#(((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyR;„s		cs
ˆdƒS(Ns
Custom Client(((R;(sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyt<lambda>’scs
ˆdƒS(Ns
Custom Server(((R;(sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyRA“scSsB|\}}|jjdƒ|jjdƒt|j|jgƒS(Ntfootbar(R twriteR	R=(t.0R1R8((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyt	connected”s	cs0|\}}ˆjd|ƒˆjd|ƒdS(Ns
Custom Clients
Custom Server(tassertIn(RER1R8(R(sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyt	gotSystemšs	cs
ˆjƒS(N(tstop(tignored(R(sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyRAŸsN(RtbuildReactorR:R6t
addErrbackRt
runReactor(RtdRFRH((RRR;sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyttest_logPrefixs	


cs·ˆjƒ‰g‰tƒ‰‡fd†}ˆjˆƒjt|ƒƒ}‡‡‡‡fd†}|j|ƒ|jtƒ|j‡fd†ƒˆjˆƒˆj	ˆt
t
gƒdS(s}
        After a connection is disconnected, L{ITransport.write} and
        L{ITransport.writeSequence} are no-ops.
        cs
tˆƒS(N(R((tserverConnectionLostDeferred(sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyRA­scs±td|jƒfƒˆjˆ|jƒƒ}tƒ‰‡fd†}|jt|ƒƒ}d„}|j|ˆjƒ‡fd†}ˆj|ƒˆj|ƒt	ˆˆgƒS(NsListening on %rcs
tˆƒS(N(R((tlostConnectionDeferred(sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyRAµscSs%td|fƒ|jjdƒdS(NsAbout to write to %rtx(RR RD(tproto((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyRD¸scsHtd|fƒ|jjdƒ|jjddgƒˆjtƒdS(Ns%r disconnectedssome bytes to get losttsometmore(RR RDt
writeSequencetappendtTrue(RS(tfinished(sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pytdisconnected¾s(
RR,R+RR-R.taddCallbacksterrbackR6R	(R/tendpointRR1RDRZ(RRRYRP(RQsJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyR9°s		


cs
ˆjƒS(N(RI(RJ(R(sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyRAÌsN(RKRR)R5RR6RLRRMtassertEqualRX(RRtportDeferredR9((RRRYRPsJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyttest_writeAfterDisconnect£s	


csÄtƒ‰tˆƒ‰tˆƒ}ˆjƒ‰ˆjˆƒjttƒƒ}‡‡‡‡fd†}|j|ƒ|j	t
ƒ|j‡fd†ƒˆjˆƒd‰t
ƒˆjd|ƒƒdS(s’
        After the connection a protocol is being used for is closed, the reactor
        discards all of its references to the protocol.
        cswtd|jƒfƒˆjˆ|jƒƒ}|jt‡fd†ƒƒ}d„}|j|ƒ|jˆjƒˆS(NsListening on %rcsˆS(N(((R2(sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyRAâscSs"td|fƒ|jjƒdS(NsAbout to disconnect %r(RR R!(RS((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyt
disconnectãs(RR,R+R-R.R6RLR\(R/R]R1Ra(RRRQR2(sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyR9Þs	
cs
ˆjƒS(N(RI(RJ(R(sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyRAìsN(RRRRKR)R5RRR6RLRRMRRtassertIdentical(Rt	clientRefR_R9((RRR2RQsJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyt'test_protocolGarbageAfterLostConnectionÒs	


(	RRRR)R+R:ROR`Rd(((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyR&Ps						$	/tLogObserverMixincBseZdZd„ZRS(sL
    Mixin for L{TestCase} subclasses which want to observe log events.
    cCs0g}tj|jƒ|jtj|jƒ|S(N(RtaddObserverRWt
addCleanuptremoveObserver(RtloggedMessages((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pytobserveüs(RRRRj(((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyReøsN(RtgcRtweakrefRttwisted.pythonRRttwisted.python.reflectRttwisted.python.logRRRttwisted.internet.deferRR	ttwisted.internet.protocolR
RRR.RRtobjectR&Re(((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/connectionmixins.pyt<module>s	
¨