Your IP : 172.28.240.42


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

ó
ê=Nc@sâdZddlmZddlmZddlmZddlmZddl	m
Z
ddlmZm
Z
ddlmZmZd	efd
„ƒYZeeeƒdefd„ƒYZeeeƒd
efd„ƒYZdS(s:
Tests for (new code in) L{twisted.application.internet}.
iÿÿÿÿ(t
implements(tverifyClass(tFactory(tTestCase(tStreamServerEndpointService(tIStreamServerEndpointtIListeningPort(tDeferredtCancelledErrort
FakeServercBs]eZdZeeƒdZdZdZe	ƒZ
dZd„Zd„Z
d„Zd„ZRS(sq
    In-memory implementation of L{IStreamServerEndpoint}.

    @ivar result: The L{Deferred} resulting from the call to C{listen}, after
        C{listen} has been called.

    @ivar factory: The factory passed to C{listen}.

    @ivar cancelException: The exception to errback C{self.result} when it is
        cancelled.

    @ivar port: The L{IListeningPort} which C{listen}'s L{Deferred} will fire
        with.

    @ivar listenAttempts: The number of times C{listen} has been invoked.

    @ivar failImmediately: If set, the exception to fail the L{Deferred}
        returned from C{listen} before it is returned.
    icCstƒ|_dS(N(tFakePorttport(tself((sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pyt__init__/scs_ˆjd7_|ˆ_td‡fd†ƒˆ_ˆjdk	rXˆjjˆjƒnˆjS(sw
        Return a Deferred and store it for future use.  (Implementation of
        L{IStreamServerEndpoint}).
        it	cancellercs|jˆjƒS(N(terrbacktcancelException(td(R(sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pyt<lambda>;sN(tlistenAttemptstfactoryRtresulttfailImmediatelytNoneR(RR((RsJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pytlisten3s	cCs|jj|jƒdS(s°
        Test code should invoke this method after causing C{listen} to be
        invoked in order to fire the L{Deferred} previously returned from
        C{listen}.
        N(RtcallbackR(R((sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pytstartedListeningAscCs|jjjdƒdS(s
        Test code should invoke this method after causing C{stopListening} to
        be invoked on the port fired from the L{Deferred} returned from
        C{listen} in order to cause the L{Deferred} returned from
        C{stopListening} to fire.
        N(RtdeferredRR(R((sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pytstoppedListeningJsN(t__name__t
__module__t__doc__RRRRRRRRRR
RRR(((sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pyR	s
					R
cBs'eZdZeeƒdZd„ZRS(ss
    Fake L{IListeningPort} implementation.

    @ivar deferred: The L{Deferred} returned by C{stopListening}.
    cCstƒ|_|jS(N(RR(R((sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pyt
stopListeningbsN(RRRRRRRR (((sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pyR
Ws
tTestEndpointServicecBsteZdZd„Zd„Zdd„Zd„Zd„Zd„Z	d„Z
d„Zd	„Zd
„Z
d„ZRS(
s4
    Tests for L{twisted.application.internet}.
    cCs4tƒ|_tƒ|_t|j|jƒ|_dS(sp
        Construct a stub server, a stub factory, and a
        L{StreamServerEndpointService} to test.
        N(R	t
fakeServerRRRtsvc(R((sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pytsetUposcCs*|jjƒ|j|j|jjƒdS(s‡
        L{StreamServerEndpointService.privilegedStartService} calls its
        endpoint's C{listen} method with its factory.
        N(R#tprivilegedStartServicetassertIdenticalRR"(R((sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pyttest_privilegedStartServiceys
cCs;tƒ|j_t|j_|jt|p3|jjƒdS(sÜ
        L{StreamServerEndpointService.startService} should raise synchronously
        if the L{Deferred} returned by its wrapped
        L{IStreamServerEndpoint.listen} has already fired with an errback and
        the L{StreamServerEndpointService}'s C{_raiseSynchronously} flag has
        been set.  This feature is necessary to preserve compatibility with old
        behavior of L{twisted.internet.strports.service}, which is to return a
        service which synchronously raises an exception from C{startService}
        (so that, among other things, twistd will not start running).  However,
        since L{IStreamServerEndpoint.listen} may fail asynchronously, it is
        a bad idea to rely on this behavior.
        N(tZeroDivisionErrorR"RtTrueR#t_raiseSynchronouslytassertRaiseststartService(Rtthunk((sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pyt(test_synchronousRaiseRaisesSynchronously‚s
cCs|j|jjƒdS(sÒ
        L{StreamServerEndpointService.privilegedStartService} should behave the
        same as C{startService} with respect to
        L{TestEndpointService.test_synchronousRaiseRaisesSynchronously}.
        N(R.R#R%(R((sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pyttest_synchronousRaisePrivileged”scCsL|jjƒ|jjjtƒƒ|jtƒ}|jt|ƒdƒdS(s
        L{StreamServerEndpointService.startService} and
        L{StreamServerEndpointService.privilegedStartService} should both log
        an exception when the L{Deferred} returned from their wrapped
        L{IStreamServerEndpoint.listen} fails.
        iN(	R#R,R"RRR(tflushLoggedErrorstassertEqualtlen(Rtlogged((sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pyttest_failReportsErroržs
cCsEtƒ|j_|jjƒ|jtƒ}|jt|ƒdƒdS(sŸ
        Without the C{_raiseSynchronously} compatibility flag, failing
        immediately has the same behavior as failing later; it logs the error.
        iN(R(R"RR#R,R0R1R2(RR3((sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pyt test_synchronousFailReportsError«s
cCs@|jjƒ|j|j|jjƒ|j|jjtƒdS(sÃ
        L{StreamServerEndpointService.startService} sets the C{running} flag,
        and calls its endpoint's C{listen} method with its factory, if it
        has not yet been started.
        N(R#R,R&RR"R1trunningR)(R((sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pyttest_startServiceUnstarted¶s
cCsG|jƒ|jjƒ|j|jjdƒ|j|jjtƒdS(sš
        L{StreamServerEndpointService.startService} sets the C{running} flag,
        but nothing else, if the service has already been started.
        iN(R'R#R,R1R"RR6R)(R((sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pyttest_startServiceStartedÁs

cCsœ|jjƒ|jjƒ|jjƒ|jjƒ}g}|j|jƒ|jt	|ƒdƒ|jj
ƒ|jt	|ƒdƒ|j|jjƒdS(sã
        L{StreamServerEndpointService.stopService} calls C{stopListening} on
        the L{IListeningPort} returned from its endpoint, returns the
        C{Deferred} from stopService, and sets C{running} to C{False}.
        iiN(
R#R%R"RR,tstopServicetaddCallbacktappendR1R2RtassertFalseR6(RRtl((sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pyttest_stopServiceÌs



cCsb|jjƒ|jjƒ}g}|j|jƒ|j|dgƒ|j|jtƒgƒdS(sÚ
        L{StreamServerEndpointService.stopService} cancels the L{Deferred}
        returned by C{listen} if it has not yet fired.  No error will be logged
        about the cancellation of the listen attempt.
        N(	R#R%R9taddBothR;R1RR0R(RRR=((sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pyt#test_stopServiceBeforeStartFinishedßs
cCs}tƒ|j_|jjƒ|jjƒ}g}|j|jƒ|j|dgƒ|j
tƒ}|jt|ƒdƒdS(sá
        L{StreamServerEndpointService.stopService} cancels the L{Deferred}
        returned by C{listen} if it has not fired yet.  An error will be logged
        if the resulting exception is not L{CancelledError}.
        iN(R(R"RR#R%R9R:R;R1RR0R2(RRR=tstoppingErrors((sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pyt test_stopServiceCancelStartErrorís
N(RRRR$R'RR.R/R4R5R7R8R>R@RB(((sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pyR!js	
			
	
					N(Rtzope.interfaceRtzope.interface.verifyRttwisted.internet.protocolRttwisted.trial.unittestRttwisted.application.internetRttwisted.internet.interfacesRRttwisted.internet.deferRRtobjectR	R
R!(((sJ/usr/lib/python2.7/dist-packages/twisted/application/test/test_internet.pyt<module>sA