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_protocol.pyc

ó
ó’‡Nc@sôdZddlmZddlmZddlmZmZddlm	Z	ddl
mZmZddl
mZddlmZdd	lmZmZd
fd„ƒYZdeefd
„ƒYZdefd„ƒYZdefd„ƒYZdS(s)
Tests for L{twisted.internet.protocol}.
iÿÿÿÿ(tverifyObject(tFailure(t	IProtocoltILoggingContext(tCancelledError(tProtocolt
ClientCreator(tClock(tTestCase(t
MemoryReactortStringTransporttMemoryConnectorcBseZeZd„ZRS(cCs
t|_dS(N(tTruet
_disconnected(tself((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyt
disconnects(t__name__t
__module__tFalseR
R(((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyRst"MemoryReactorWithConnectorsAndTimecBs2eZdZd„Zd„Zd„Zd„ZRS(ss
    An extension of L{MemoryReactor} which returns L{IConnector}
    providers from its C{connectTCP} method.
    cCs'tj|ƒtj|ƒg|_dS(N(R	t__init__Rt
connectors(R((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyR!s

cOs0tj|||Žtƒ}|jj|ƒ|S(N(R	t
connectTCPRRtappend(Rtatkwt	connector((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyR's	cOs0tj|||Žtƒ}|jj|ƒ|S(N(R	tconnectUNIXRRR(RRRR((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyR.s	cOs0tj|||Žtƒ}|jj|ƒ|S(N(R	t
connectSSLRRR(RRRR((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyR5s	(RRt__doc__RRRR(((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyRs
			tClientCreatorTestscBsžeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z	d„Z
d	„Zd
„Zd„Z
d„Zd
„Zd„Zd„Zd„ZRS(s?
    Tests for L{twisted.internet.protocol.ClientCreator}.
    cCs`dtfd„ƒY}tƒ}t||ƒ}|||ƒ}|jdƒ}|j||ƒdS(s
        Helper for implementing a test to verify that one of the I{connect}
        methods of L{ClientCreator} passes the right arguments to the right
        reactor method.

        @param check: A function which will be invoked with a reactor and a
            L{ClientCreator} instance and which should call one of the
            L{ClientCreator}'s I{connect} methods and assert that all of its
            arguments except for the factory are passed on as expected to the
            reactor.  The factory should be returned.
        tSomeProtocolcBseZRS((RR(((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyRMsN(RRRt
buildProtocoltNonetassertIsInstance(RtcheckRtreactortcctfactorytprotocol((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyt_basicConnectTestAs	cs ‡fd†}ˆj|ƒdS(sä
        L{ClientCreator.connectTCP} calls C{reactor.connectTCP} with the host
        and port information passed to it, and with a factory which will
        construct the protocol passed to L{ClientCreator.__init__}.
        csx|jddddƒ|jjƒ\}}}}}ˆj|dƒˆj|dƒˆj|dƒˆj|dƒ|S(Nsexample.comiÒiás1.2.3.4i”&(s1.2.3.4i”&(s1.2.3.4i”&(Rt
tcpClientstpoptassertEqual(R$R%thosttportR&ttimeouttbindAddress(R(sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyR#]sN(R((RR#((RsG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyttest_connectTCPWscs ‡fd†}ˆj|ƒdS(sÕ
        L{ClientCreator.connectUNIX} calls C{reactor.connectUNIX} with the
        filename passed to it, and with a factory which will construct the
        protocol passed to L{ClientCreator.__init__}.
        csb|jddtƒ|jjƒ\}}}}ˆj|dƒˆj|dƒˆj|tƒ|S(Ns/foo/bari{(RRtunixClientsR*R+(R$R%taddressR&R.tcheckPID(R(sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyR#nsN(R((RR#((RsG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyttest_connectUNIXhscs ‡fd†}ˆj|ƒdS(sê
        L{ClientCreator.connectSSL} calls C{reactor.connectSSL} with the host,
        port, and context factory passed to it, and with a factory which will
        construct the protocol passed to L{ClientCreator.__init__}.
        c	s—tƒ}|jdd|ddƒ|jjƒ\}}}}}}ˆj|dƒˆj|dƒˆj||ƒˆj|dƒˆj|dƒ|S(Nsexample.comiÒiás4.3.2.1i.(s4.3.2.1i.(s4.3.2.1i.(tobjectRt
sslClientsR*R+tassertIdentical(	R$R%texpectedContextFactoryR,R-R&tcontextFactoryR.R/(R(sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyR#~s	!N(R((RR#((RsG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyttest_connectSSLxs
cCsmtƒ}t|tƒ}||ƒ}|jjƒ}|j|jƒ|jƒ|j|jƒ|j	|t
ƒS(s
        Helper for implementing a test to verify that cancellation of the
        L{Deferred} returned by one of L{ClientCreator}'s I{connect} methods is
        implemented to cancel the underlying connector.

        @param connect: A function which will be invoked with a L{ClientCreator}
            instance as an argument and which should call one its I{connect}
            methods and return the result.

        @return: A L{Deferred} which fires when the test is complete or fails if
            there is a problem.
        (RRRRR*tassertFalseR
tcancelt
assertTruet
assertFailureR(RtconnectR$R%tdR((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyt_cancelConnectTest‹s
	
cCsd„}|j|ƒS(s—
        The L{Deferred} returned by L{ClientCreator.connectTCP} can be cancelled
        to abort the connection attempt before it completes.
        cSs|jddƒS(Nsexample.comiÒ(R(R%((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyR?§s(RA(RR?((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyttest_cancelConnectTCP¢s	cCsd„}|j|ƒS(s—
        The L{Deferred} returned by L{ClientCreator.connectTCP} can be cancelled
        to abort the connection attempt before it completes.
        cSs
|jdƒS(Ns/foo/bar(R(R%((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyR?±s(RA(RR?((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyttest_cancelConnectUNIX¬s	cCsd„}|j|ƒS(s—
        The L{Deferred} returned by L{ClientCreator.connectTCP} can be cancelled
        to abort the connection attempt before it completes.
        cSs|jddtƒƒS(Nsexample.comiÒ(RR5(R%((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyR?»s(RA(RR?((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyttest_cancelConnectSSL¶s	cCs’tƒ}t|tƒ}|||ƒ}|jjƒ}|jt|jƒƒdƒ|jƒ|j|jƒgƒ|j	|j
ƒ|j|tƒS(sÍ
        Like L{_cancelConnectTest}, but for the case where the L{Deferred} is
        cancelled after the connection is set up but before it is fired with the
        resulting protocol instance.
        i(
RRRRR*R+tlentgetDelayedCallsR<R=R
R>R(RR?R$R%R@R((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyt_cancelConnectTimeoutTestÀs	
cCsd„}|j|ƒS(s¡
        L{ClientCreator.connectTCP} inserts a very short delayed call between
        the time the connection is established and the time the L{Deferred}
        returned from one of its connect methods actually fires.  If the
        L{Deferred} is cancelled in this interval, the established connection is
        closed, the timeout is cancelled, and the L{Deferred} fails with
        L{CancelledError}.
        c
SsY|jddƒ}|jjƒ\}}}}}|jdƒ}tƒ}	|j|	ƒ|S(Nsexample.comiÒ(RR)R*R R!R
tmakeConnection(
R$R%R@R,R-R&R.R/R't	transport((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyR?ås	
(RG(RR?((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyttest_cancelConnectTCPTimeoutÜs		cCsd„}|j|ƒS(s¢
        L{ClientCreator.connectUNIX} inserts a very short delayed call between
        the time the connection is established and the time the L{Deferred}
        returned from one of its connect methods actually fires.  If the
        L{Deferred} is cancelled in this interval, the established connection is
        closed, the timeout is cancelled, and the L{Deferred} fails with
        L{CancelledError}.
        c	SsS|jdƒ}|jjƒ\}}}}|jdƒ}tƒ}|j|ƒ|S(Ns/foo/bar(RR1R*R R!R
RH(	R$R%R@R2R&R.R/R'RI((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyR?øs	
(RG(RR?((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyttest_cancelConnectUNIXTimeoutïs		cCsd„}|j|ƒS(s¡
        L{ClientCreator.connectSSL} inserts a very short delayed call between
        the time the connection is established and the time the L{Deferred}
        returned from one of its connect methods actually fires.  If the
        L{Deferred} is cancelled in this interval, the established connection is
        closed, the timeout is cancelled, and the L{Deferred} fails with
        L{CancelledError}.
        cSsb|jddtƒƒ}|jjƒ\}}}}}}|jdƒ}	tƒ}
|	j|
ƒ|S(Nsexample.comiÒ(RR5R6R*R R!R
RH(R$R%R@R,R-R&R9R.tbindADdressR'RI((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyR?s!	
(RG(RR?((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyttest_cancelConnectSSLTimeouts		cCs¤tƒ}t|tƒ}|||ƒ\}}|jjƒ}|j|ttdƒƒƒ|jt	|j
ƒƒdƒ|jƒ|j|j
ƒgƒ|j|t
ƒS(sÌ
        Like L{_cancelConnectTest}, but for the case where the L{Deferred} is
        cancelled after the connection attempt has failed but before it is fired
        with the resulting failure.
        sSimulated failurei(RRRRR*tclientConnectionFailedRt	ExceptionR+RERFR<R>R(RR?R$R%R@R&R((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyt_cancelConnectFailedTimeoutTests	
cCsd„}|j|ƒS(sz
        Similar to L{test_cancelConnectTCPTimeout}, but for the case where the
        connection attempt fails.
        cSs:|jddƒ}|jjƒ\}}}}}||fS(Nsexample.comiÒ(RR)R*(R$R%R@R,R-R&R.R/((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyR?3s(RP(RR?((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyt"test_cancelConnectTCPFailedTimeout.s	cCsd„}|j|ƒS(s{
        Similar to L{test_cancelConnectUNIXTimeout}, but for the case where the
        connection attempt fails.
        cSs4|jdƒ}|jjƒ\}}}}||fS(Ns/foo/bar(RR1R*(R$R%R@R2R&R.R/((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyR??s(RP(RR?((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyt#test_cancelConnectUNIXFailedTimeout:s	cCsd„}|j|ƒS(sz
        Similar to L{test_cancelConnectSSLTimeout}, but for the case where the
        connection attempt fails.
        c	SsC|jddtƒƒ}|jjƒ\}}}}}}||fS(Nsexample.comiÒ(RR5R6R*(	R$R%R@R,R-R&R9R.RL((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyR?Ks!(RP(RR?((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyt"test_cancelConnectSSLFailedTimeoutFs	(RRRR(R0R4R:RARBRCRDRGRJRKRMRPRQRRRS(((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyR=s"						
	
	
							t
ProtocolTestscBs eZdZd„Zd„ZRS(s:
    Tests for L{twisted.internet.protocol.Protocol}.
    cCs9tƒ}|jtt|ƒƒ|jtt|ƒƒdS(sT
        L{Protocol} instances provide L{IProtocol} and L{ILoggingContext}.
        N(RR=RRR(Rtproto((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyttest_interfacesVs	cCs3dtfd„ƒY}|jd|ƒjƒƒdS(sJ
        L{Protocol.logPrefix} returns the protocol class's name.
        t	SomeThingcBseZRS((RR(((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyRWcsN(RR+t	logPrefix(RRW((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyttest_logPrefix_s(RRRRVRY(((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyRTRs		N(Rtzope.interface.verifyRttwisted.python.failureRttwisted.internet.interfacesRRttwisted.internet.deferRttwisted.internet.protocolRRttwisted.internet.taskRttwisted.trial.unittestRttwisted.test.proto_helpersR	R
RRRRT(((sG/usr/lib/python2.7/dist-packages/twisted/internet/test/test_protocol.pyt<module>s!ÿ