
    Yf                     p    d Z ddlZddlmZmZ ddlmZ ddlmZ  G d d          Z	 G d d	e          Z
dS )
z&
Test code for basic Factory classes.
    N)ProtocolReconnectingClientFactory)Clock)TestCasec                       e Zd ZdZd Zd ZdS )FakeConnectorzP
    A fake connector class, to be used to mock connections failed or lost.
    c                     d S N selfs    M/var/www/html/env/lib/python3.11/site-packages/twisted/test/test_factories.pystopConnectingzFakeConnector.stopConnecting           c                     d S r
   r   r   s    r   connectzFakeConnector.connect   r   r   N)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s<               r   r   c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	ReconnectingFactoryTestsz1
    Tests for L{ReconnectingClientFactory}.
    c                     G d d          }t                      }t          |_        |                    d           |                                 |                     |            d           |                     |j                   dS )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                       e Zd Zd Zd ZdS )QReconnectingFactoryTests.test_stopTryingWhenConnected.<locals>.NoConnectConnectorc                      t          d          )Nz%Shouldn't be called, we're connected.RuntimeErrorr   s    r   r   z`ReconnectingFactoryTests.test_stopTryingWhenConnected.<locals>.NoConnectConnector.stopConnecting)   s    "#JKKKr   c                      t          d          )NzShouldn't be reconnecting.r   r   s    r   r   zYReconnectingFactoryTests.test_stopTryingWhenConnected.<locals>.NoConnectConnector.connect,   s    "#?@@@r   N)r   r   r   r   r   r   r   r   NoConnectConnectorr   (   s:        L L LA A A A Ar   r!   N)r   r   protocolbuildProtocol
stopTryingclientConnectionLostassertFalsecontinueTrying)r   r!   cs      r   test_stopTryingWhenConnectedz5ReconnectingFactoryTests.test_stopTryingWhenConnected!   s    	A 	A 	A 	A 	A 	A 	A 	A &''
			1133T:::)*****r   c                 P    G fddt                     }t                      t                      _         |            _                                         |                     j        j                   |                     j                                                   dS )z
        Calling stopTrying on a L{ReconnectingClientFactory} doesn't attempt a
        retry on any active connector.
        c                   $    e Zd ZdZ fdZd ZdS )[ReconnectingFactoryTests.test_stopTryingDoesNotReconnect.<locals>.FactoryAwareFakeConnectorFc                 4                         | d           dS )z
                Behave as though an ongoing connection attempt has now
                failed, and notify the factory of this.
                N)clientConnectionFailed)r   fs    r   r   zjReconnectingFactoryTests.test_stopTryingDoesNotReconnect.<locals>.FactoryAwareFakeConnector.stopConnectingA   s!    
 ((t44444r   c                     d| _         dS )z|
                Record an attempt to reconnect, since this is what we
                are trying to avoid.
                TN)attemptedRetryr   s    r   r   zcReconnectingFactoryTests.test_stopTryingDoesNotReconnect.<locals>.FactoryAwareFakeConnector.connectH   s    
 '+###r   N)r   r   r   r1   r   r   )r/   s   r   FactoryAwareFakeConnectorr,   >   sB        "N5 5 5 5 5+ + + + +r   r2   N)	r   r   r   clock	connectorr$   r&   r1   getDelayedCalls)r   r2   r/   s     @r   test_stopTryingDoesNotReconnectz8ReconnectingFactoryTests.test_stopTryingDoesNotReconnect8   s    	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+" &'''' 0/11	 	3444002233333r   c                     t                      }t          j        t          j        |                    }|                     |j        |j                   dS )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_serializeUnusedz-ReconnectingFactoryTests.test_serializeUnused[   sJ    
 -..V\(%;%;<<*M,BCCCCCr   c                     t                      }t                      }||_        t          j        t          j        |                    }|                     |j                   dS )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   r3   r8   r9   r:   assertIsNone)r   r3   r=   r>   s       r   test_serializeWithClockz0ReconnectingFactoryTests.test_serializeWithClockd   sU    
 ,..V\(%;%;<<--.....r   c                    t                      }|                    t                      d           |                     |j                   t          j        |          }t          j        |          }|                     |j	                   |                     |j
                   |                     |j        d           |                     |j        |j                   |                     |j                   dS )z
        A L{ReconnectingClientFactory} which is unpickled does not have an
        L{IConnector} and has its reconnecting timing parameters reset to their
        initial values.
        Nr   )r   r.   r   
addCleanupr$   r8   r:   r9   rA   r4   _callIDr;   retriesdelayinitialDelay
assertTruer'   )r   factory
serializedunserializeds       r   $test_deserializationResetsParametersz=ReconnectingFactoryTests.test_deserializationResetsParameterso   s     ,--&&}===*+++\'**
|J//,0111,.///-q111+W-ABBB344444r   c                     t                      }t                      }||_        |                    t	                      d           |                     t          |j                  d           dS )z
        The clock used by L{ReconnectingClientFactory} can be parametrized, so
        that one can cleanly test reconnections.
        N   )r   r   r3   r%   r   r;   lencalls)r   r3   rJ   s      r   test_parametrizedClockz/ReconnectingFactoryTests.test_parametrizedClock   s_    
 +--$$]__d;;;U[))1-----r   N)
r   r   r   r   r)   r6   r?   rB   rM   rR   r   r   r   r   r      s|         + + +.!4 !4 !4FD D D	/ 	/ 	/5 5 5$
. 
. 
. 
. 
.r   r   )r   r8   twisted.internet.protocolr   r   twisted.internet.taskr   twisted.trial.unittestr   r   r   r   r   r   <module>rV      s    
  I I I I I I I I ' ' ' ' ' ' + + + + + +	 	 	 	 	 	 	 	o. o. o. o. o.x o. o. o. o. o.r   