Ë
    oj×  ã                   ób   — 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
y)
z&
Test code for basic Factory classes.
é    N)ÚProtocolÚReconnectingClientFactory)ÚClock)ÚTestCasec                   ó   — e Zd ZdZd„ Zd„ Zy)ÚFakeConnectorzP
    A fake connector class, to be used to mock connections failed or lost.
    c                  ó   — y ©N© ©Úselfs    ú=/usr/lib/python3/dist-packages/twisted/test/test_factories.pyÚstopConnectingzFakeConnector.stopConnecting   ó   € Øó    c                  ó   — y 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                   ó4   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	y)	ÚReconnectingFactoryTestsz1
    Tests for L{ReconnectingClientFactory}.
    c                 óè   —  G d„ d«      }t        «       }t        |_        |j                  d«       |j	                  «        |j                   |«       d«       | j                  |j                  «       y)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y)ú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Ð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óAr   r!   N)r   r   ÚprotocolÚbuildProtocolÚ
stopTryingÚclientConnectionLostÚassertFalseÚcontinueTrying)r   r!   Úcs      r   Útest_stopTryingWhenConnectedz5ReconnectingFactoryTests.test_stopTryingWhenConnected!   s\   € ÷	Añ 	Aô &Ó'ˆÜˆŒ
à	�‰˜Ôà	�‰ŒØ	×ÑÑ1Ó3°TÔ:Ø×Ñ˜×)Ñ)Õ*r   c                 ó.  ‡—  G ˆfd„dt         «      }t        «       Št        «       ‰_         |«       ‰_        ‰j                  «        | j                  ‰j                  j                  «       | j                  ‰j                  j                  «       «       y)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y)ú[ReconnectingFactoryTests.test_stopTryingDoesNotReconnect.<locals>.FactoryAwareFakeConnectorFc                 ó*   •— ‰j                  | d«       y)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Õ4r   c                 ó   — d| _         y)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,   >   s   ø„ Ø"ˆNô5ó+r   r2   N)	r   r   r   ÚclockÚ	connectorr$   r&   r1   ÚgetDelayedCalls)r   r2   r/   s     @r   Útest_stopTryingDoesNotReconnectz8ReconnectingFactoryTests.test_stopTryingDoesNotReconnect8   sl   ø€ ö	+¬ô 	+ô" &Ó'ˆÜ“'ˆŒñ 0Ó1ˆŒØ	�‰Œð 	×Ñ˜Ÿ™×3Ñ3Ô4Ø×Ñ˜Ÿ™×0Ñ0Ó2Õ3r   c                 ó´   — t        «       }t        j                  t        j                  |«      «      }| j	                  |j
                  |j
                  «       y)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[   s?   € ô
 -Ó.ˆÜŸ™¤V§\¡\°(Ó%;Ó<ˆØ×Ñ˜×*Ñ*¨M×,BÑ,BÕCr   c                 óÀ   — t        «       }t        «       }||_        t        j                  t        j
                  |«      «      }| j                  |j                  «       y)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   sE   € ô
 “ˆÜ,Ó.ˆØˆŒÜŸ™¤V§\¡\°(Ó%;Ó<ˆØ×Ñ˜-×-Ñ-Õ.r   c                 óü  — t        «       }|j                  t        «       d«       | j                  |j                  «       t        j                  |«      }t        j                  |«      }| j                  |j                  «       | j                  |j                  «       | j                  |j                  d«       | j                  |j                  |j                  «       | j                  |j                   «       y)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Ñ0Ô1Ø×Ñ˜,×.Ñ.Ô/Ø×Ñ˜×-Ñ-¨qÔ1Ø×Ñ˜×+Ñ+¨W×-AÑ-AÔBØ�‰˜×3Ñ3Õ4r   c                 ó¸   — t        «       }t        «       }||_        |j                  t	        «       d«       | j                  t        |j                  «      d«       y)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�   sE   € ô
 “ˆÜ+Ó-ˆØˆŒà×$Ñ$¤]£_°dÔ;Ø×Ñœ˜UŸ[™[Ó)¨1Õ-r   N)
r   r   r   r   r)   r6   r?   rB   rM   rR   r   r   r   r   r      s'   „ ñò+ò.!4òFDò	/ò5ó$
.r   r   )r   r8   Útwisted.internet.protocolr   r   Útwisted.internet.taskr   Útwisted.trial.unittestr   r   r   r   r   r   ú<module>rV      s0   ðñó
 ç IÝ 'Ý +÷	ñ 	ôo.˜xõ o.r   