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


=Nc@sdZddlZddlmZddlmZmZddlmZddl	m
Z
mZddlm
Z
de
fd	YZd
e
fdYZdefd
YZdefdYZdS(s&
Test code for basic Factory classes.
iN(tTestCase(treactortdefer(tClock(tFactorytReconnectingClientFactory(tInt16StringReceivertIncBs,eZdZdZdZdZRS(cCs
i|_dS(N(tmsgs(tself((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyt__init__scCs|jjd7_dS(Ni(tfactorytconnections(R	((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pytconnectionMadescCs<tj|\}}||j|<|jtj|dS(N(tpickletloadsRt
sendStringtdumps(R	tmsgtn((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pytstringReceiveds
cCsN|jjj|jt|jj|jjkrJ|jjjdndS(N(	RtallMessagestappendRtlentgoaltdtcallbacktNone(R	treason((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pytconnectionLosts(t__name__t
__module__R
R
RR(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyRs			tOutcBsReZegedD]Zedef^qZdZdZdZRS(i
tXcCstjj|_dS(N(R Rtcopy(R	((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyR
)scCsAx:|jjD])}|jtj||j|fqWdS(N(RtkeysRRR(R	ti((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyR
,scCsjtj|}|j|=|jsf|jj|jjd8_|jjdkrf|jjqfndS(Nii(RRRt	transporttloseConnectionRthowManyTimest
stopTrying(R	RR((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyR0s
	
(	RRtdicttrangetxRR
R
R(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyR &s/		t
FakeConnectorcBs eZdZdZdZRS(sP
    A fake connector class, to be used to mock connections failed or lost.
    cCsdS(N((R	((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pytstopConnecting@scCsdS(N((R	((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pytconnectDs(RRt__doc__R-R.(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyR,;s	tReconnectingFactoryTestCasecBsVeZdZdZde_dZdZdZdZdZ	dZ
RS(	s1
    Tests for L{ReconnectingClientFactory}.
    cCst}t|_d|_g|_d|_tj|_t	}d|_
|_t|_d|_
tjd|}|j|j|jj}tjd|||jj|j|||jS(Niig?s	127.0.0.1(RRtprotocolRRRRtDeferredRRtinitialDelaytdelayR R'Rt	listenTCPt
addCleanupt
stopListeningtgetHosttportt
connectTCPtaddCallbackt_testStopTrying_1(R	tftcR9tPORT((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyttestStopTryingNs 								i
cCst|jt|jdd|j|j|jdd|j|j|jtjgd|j|jddS(Nisnot enough messages -- %ss-Number of successful connections incorrect %ds&stopTrying never called or ineffective(tassertEqualRRRR RtfailIftcontinueTrying(R	tresR=R>((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyR<escstdtffdY}tt_|_j|jjj|jjjdS(s
        Calling stopTrying on a L{ReconnectingClientFactory} doesn't attempt a
        retry on any active connector.
        tFactoryAwareFakeConnectorcs&eZeZfdZdZRS(csj|ddS(s
                Behave as though an ongoing connection attempt has now
                failed, and notify the factory of this.
                N(tclientConnectionFailedR(R	(R=(s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyR-wscSs
t|_dS(s|
                Record an attempt to reconnect, since this is what we
                are trying to avoid.
                N(tTruetattemptedRetry(R	((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyR.~s(RRtFalseRHR-R.((R=(s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyREtsN(	R,RRtclockt	connectorR(tassertFalseRHtgetDelayedCalls(R	RE((R=s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyttest_stopTryingDoesNotReconnectos	
cCs;t}tjtj|}|j|j|jdS(s
        A L{ReconnectingClientFactory} which hasn't been used for anything
        can be pickled and unpickled and end up with the same state.
        N(RRRRRAt__dict__(R	toriginalt
reconstituted((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyttest_serializeUnuseds	cCsJt}t}||_tjtj|}|j|jddS(s
        The clock attribute of L{ReconnectingClientFactory} is not serialized,
        and the restored value sets it to the default value, the reactor.
        N(RRRJRRRtassertIdenticalR(R	RJRPRQ((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyttest_serializeWithClocks
			cCst}|jtd|j|jtj|}tj|}|j	|j
d|j	|jd|j	|jd|j	|j
|j|j	|jtdS(s
        A L{ReconnectingClientFactory} which is unpickled does not have an
        L{IConnector} and has its reconnecting timing parameters reset to their
        initial values.
        iN(RRFR,RR6R(RRRRARKt_callIDtretriesR4R3RCRG(R	Rt
serializedtunserialized((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyt$test_deserializationResetsParameterss	cCsKt}t}||_|jtd|jt|jddS(s
        The clock used by L{ReconnectingClientFactory} can be parametrized, so
        that one can cleanly test reconnections.
        iN(	RRRJtclientConnectionLostR,RRARtcalls(R	RJR((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyttest_parametrizedClocks
			(RRR/R@ttimeoutR<RNRRRTRYR\(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyR0Is			
	#	
		(R/Rttwisted.trial.unittestRttwisted.internetRRttwisted.internet.taskRttwisted.internet.protocolRRttwisted.protocols.basicRRR tobjectR,R0(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyt<module>s