+
    Dfj                     d    R t ^ RIt^ RIHtHt ^ RIHt ^ RIHt  ! R R4      t	 ! R R]4      t
R# )	z&
Test code for basic Factory classes.
N)ProtocolReconnectingClientFactory)Clock)TestCasec                   0   a  ] tR t^t o RtR tR tRtV tR# )FakeConnectorzH
A fake connector class, to be used to mock connections failed or lost.
c                    R # N selfs   &=/usr/lib/python3/dist-packages/twisted/test/test_factories.pystopConnectingFakeConnector.stopConnecting           c                    R # r	   r
   r   s   &r   connectFakeConnector.connect   r   r   r
   N)	__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes____classdictcell____classdict__s   @r   r   r      s      r   r   c                   H   a  ] tR t^t o RtR tR tR tR tR t	R t
RtV tR	# )
ReconnectingFactoryTestsz)
Tests for L{ReconnectingClientFactory}.
c                     ! R R4      p\        4       p\        Vn        VP                  R4       VP	                  4        VP                  V! 4       R4       V P                  VP                  4       R# )z
If a L{ReconnectingClientFactory} has C{stopTrying} called while it is
connected, it does not subsequently attempt to reconnect if the
connection is later lost.
c                   ,   a  ] tR t^(t o R tR tRtV tR# )QReconnectingFactoryTests.test_stopTryingWhenConnected.<locals>.NoConnectConnectorc                    \        R 4      h)z%Shouldn't be called, we're connected.RuntimeErrorr   s   &r   r   `ReconnectingFactoryTests.test_stopTryingWhenConnected.<locals>.NoConnectConnector.stopConnecting)   s    "#JKKr   c                    \        R 4      h)zShouldn't be reconnecting.r$   r   s   &r   r   YReconnectingFactoryTests.test_stopTryingWhenConnected.<locals>.NoConnectConnector.connect,   s    "#?@@r   r
   N)r   r   r   r   r   r   r   r   r   s   @r   NoConnectConnectorr"   (   s     LA Ar   r)   N)r   r   protocolbuildProtocol
stopTryingclientConnectionLostassertFalsecontinueTrying)r   r)   cs   &  r   test_stopTryingWhenConnected5ReconnectingFactoryTests.test_stopTryingWhenConnected!   s\    	A 	A &'
			13T:))*r   c                2  a  ! V3R lR\         4      p\        4       o\        4       Sn        V! 4       Sn        SP                  4        V P                  SP                  P                  4       V P                  SP                  P                  4       4       R# )zg
Calling stopTrying on a L{ReconnectingClientFactory} doesn't attempt a
retry on any active connector.
c                   8   <a  ] tR t^>t o RtV3R ltR tRtV tR# )[ReconnectingFactoryTests.test_stopTryingDoesNotReconnect.<locals>.FactoryAwareFakeConnectorFc                ,   < SP                  V R4       R# )z`
Behave as though an ongoing connection attempt has now
failed, and notify the factory of this.
N)clientConnectionFailed)r   fs   &r   r   jReconnectingFactoryTests.test_stopTryingDoesNotReconnect.<locals>.FactoryAwareFakeConnector.stopConnectingA   s    
 ((t4r   c                    RV n         R# )zL
Record an attempt to reconnect, since this is what we
are trying to avoid.
TNattemptedRetryr   s   &r   r   cReconnectingFactoryTests.test_stopTryingDoesNotReconnect.<locals>.FactoryAwareFakeConnector.connectH   s    
 '+#r   r;   N)	r   r   r   r   r<   r   r   r   r   )r   r8   s   @r   FactoryAwareFakeConnectorr5   >   s     "N5+ +r   r>   N)	r   r   r   clock	connectorr,   r.   r<   getDelayedCalls)r   r>   r8   s   & @r   test_stopTryingDoesNotReconnect8ReconnectingFactoryTests.test_stopTryingDoesNotReconnect8   sl    	+ 	+" &'' 01	 	3340023r   c                    \        4       p\        P                  ! \        P                  ! V4      4      pV P	                  VP
                  VP
                  4       R# )z
A L{ReconnectingClientFactory} which hasn't been used for anything
can be pickled and unpickled and end up with the same state.
N)r   pickleloadsdumpsassertEqual__dict__)r   originalreconstituteds   &  r   test_serializeUnused-ReconnectingFactoryTests.test_serializeUnused[   s?    
 -.V\\(%;<**M,B,BCr   c                    \        4       p\        4       pWn        \        P                  ! \        P
                  ! V4      4      pV P                  VP                  4       R# )z
The clock attribute of L{ReconnectingClientFactory} is not serialized,
and the restored value sets it to the default value, the reactor.
N)r   r   r?   rE   rF   rG   assertIsNone)r   r?   rJ   rK   s   &   r   test_serializeWithClock0ReconnectingFactoryTests.test_serializeWithClockd   sC    
 ,.V\\(%;<---.r   c                   \        4       pVP                  \        4       R4       V P                  VP                  4       \
        P                  ! V4      p\
        P                  ! V4      pV P                  VP                  4       V P                  VP                  4       V P                  VP                  ^ 4       V P                  VP                  VP                  4       V P                  VP                   4       R# )z
A L{ReconnectingClientFactory} which is unpickled does not have an
L{IConnector} and has its reconnecting timing parameters reset to their
initial values.
N)r   r7   r   
addCleanupr,   rE   rG   rF   rO   r@   _callIDrH   retriesdelayinitialDelay
assertTruer/   )r   factory
serializedunserializeds   &   r   $test_deserializationResetsParameters=ReconnectingFactoryTests.test_deserializationResetsParameterso   s     ,-&&}=**+\\'*
||J/,001,../--q1++W-A-AB334r   c                    \        4       p\        4       pWn        VP                  \	        4       R4       V P                  \        VP                  4      ^4       R# )zq
The clock used by L{ReconnectingClientFactory} can be parametrized, so
that one can cleanly test reconnections.
N)r   r   r?   r-   r   rH   lencalls)r   r?   rY   s   &  r   test_parametrizedClock/ReconnectingFactoryTests.test_parametrizedClock   sC    
 +-$$]_d;U[[)1-r   r
   N)r   r   r   r   r   r1   rB   rL   rP   r\   ra   r   r   r   s   @r   r   r      s/     +.!4FD	/5$
. 
.r   r   )r   rE   twisted.internet.protocolr   r   twisted.internet.taskr   twisted.trial.unittestr   r   r   r
   r   r   <module>rf      s0   
  I ' +	 	o.x o.r   