§
    Ètºf×  ã                   ó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    úZ/var/www/surfInsights/venv3-11/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Ô3°TÑ:Ô:Ð:Ø×Ò˜Ô)Ñ*Ô*Ð*Ð*Ð*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ð !4ðF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   