§
    ÈtºfW&  ã                  ó  — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZmZmZ dd	lmZ  G d
„ de¦  «        Z ee¦  «         G d„ d¦  «        ¦   «         Z G d„ de¦  «        Z G d„ de¦  «        ZdS )z"
Tests for L{twisted.test.iosim}.
é    )Úannotations)ÚLiteral)Úimplementer)ÚIPushProducer)ÚProtocol)ÚClock)ÚFakeTransportÚconnectÚconnectedServerAndClient)ÚTestCasec                  ó*   — e Zd ZdZdd„Zdd„Zdd„ZdS )	ÚFakeTransportTestsz%
    Tests for L{FakeTransport}.
    ÚreturnÚNonec                ó6  — t          t          ¦   «         d¦  «        }t          t          ¦   «         d¦  «        }|                      |j        t          ¦  «         |                      |j        t          ¦  «         |                      |j        |j        ¦  «         dS )ze
        Each L{FakeTransport} receives a serial number that uniquely identifies
        it.
        TFN)r	   ÚobjectÚassertIsInstanceÚserialÚintÚassertNotEqual)ÚselfÚaÚbs      úV/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/test/test_iosim.pyÚtest_connectionSerialz(FakeTransportTests.test_connectionSerial   sz   € õ
 �&™(œ( DÑ)Ô)ˆÝ�&™(œ( EÑ*Ô*ˆØ×Ò˜aœh­Ñ,Ô,Ð,Ø×Ò˜aœh­Ñ,Ô,Ð,Ø×Ò˜AœH a¤hÑ/Ô/Ð/Ð/Ð/ó    c                óò   — t          t          ¦   «         d¦  «        }|                     d¦  «         |                     g d¢¦  «         |                      d                     |j        ¦  «        d¦  «         dS )zl
        L{FakeTransport.writeSequence} will write a sequence of L{bytes} to the
        transport.
        Fó   a)ó   bó   có   dr   s   abcdN)r	   r   ÚwriteÚwriteSequenceÚassertEqualÚjoinÚstream©r   r   s     r   Útest_writeSequencez%FakeTransportTests.test_writeSequence$   si   € õ
 �&™(œ( EÑ*Ô*ˆà	�Š�‰ŒˆØ	�ŠÐ*Ð*Ð*Ñ+Ô+Ð+à×Ò˜Ÿš !¤(Ñ+Ô+¨WÑ5Ô5Ð5Ð5Ð5r   c                ó  — t          t          ¦   «         d¦  «        }|                     d¦  «         |                     ¦   «          |                     d¦  «         |                      d                     |j        ¦  «        d¦  «         dS )zˆ
        L{FakeTransport.write} will accept writes after transport was closed,
        but the data will be silently discarded.
        Fs   befores   afterr   N)r	   r   r"   ÚloseConnectionr$   r%   r&   r'   s     r   Útest_writeAfterClosez'FakeTransportTests.test_writeAfterClose0   sw   € õ
 �&™(œ( EÑ*Ô*ˆØ	�Š�	ÑÔÐØ	×ÒÑÔÐØ	�Š�ÑÔÐà×Ò˜Ÿš !¤(Ñ+Ô+¨YÑ7Ô7Ð7Ð7Ð7r   N©r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r(   r+   © r   r   r   r      sZ   € € € € € ðð ð	0ð 	0ð 	0ð 	0ð
6ð 
6ð 
6ð 
6ð
8ð 
8ð 
8ð 
8ð 
8ð 
8r   r   c                  ó.   — e Zd ZdZdZd	d„Zd	d„Zd	d„ZdS )
ÚStrictPushProducerzƒ
    An L{IPushProducer} implementation which produces nothing but enforces
    preconditions on its state transition methods.
    Úrunningr   r   c                óH   — | j         dk    rt          d¦  «        ‚d| _         d S )NÚstoppedz)Cannot stop already-stopped IPushProducer©Ú_stateÚ
ValueError©r   s    r   ÚstopProducingz StrictPushProducer.stopProducingF   s)   € ØŒ;˜)Ò#Ð#ÝÐHÑIÔIÐIØˆŒˆˆr   c                óZ   — | j         dk    rt          d| j         › d�¦  «        ‚d| _         d S )Nr4   zCannot pause ú IPushProducerÚpausedr7   r:   s    r   ÚpauseProducingz!StrictPushProducer.pauseProducingK   s6   € ØŒ;˜)Ò#Ð#ÝÐH¨T¬[ÐHÐHÐHÑIÔIÐIØˆŒˆˆr   c                óZ   — | j         dk    rt          d| j         › d�¦  «        ‚d| _         d S )Nr>   zCannot resume r=   r4   r7   r:   s    r   ÚresumeProducingz"StrictPushProducer.resumeProducingP   s6   € ØŒ;˜(Ò"Ð"ÝÐI¨d¬kÐIÐIÐIÑJÔJÐJØˆŒˆˆr   Nr,   )r-   r.   r/   r0   r8   r;   r?   rA   r1   r   r   r3   r3   =   sa   € € € € € ðð ð
 €Fð ð  ð  ð  ð
ð ð ð ð
 ð  ð  ð  ð  ð  r   r3   c                  óª   — e Zd ZdZdd„Zdd„Zdd„Zdd„Zdd
„Zdd„Z	dd„Z
dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„ZdS )ÚStrictPushProducerTestsz*
    Tests for L{StrictPushProducer}.
    r   r3   c                ó   — t          ¦   «         S )zp
        @return: A new L{StrictPushProducer} which has not been through any state
            changes.
        )r3   r:   s    r   Ú_initialz StrictPushProducerTests._initial[   s   € õ
 "Ñ#Ô#Ð#r   c                óJ   — t          ¦   «         }|                     ¦   «          |S )z@
        @return: A new, stopped L{StrictPushProducer}.
        )r3   r;   ©r   Úproducers     r   Ú_stoppedz StrictPushProducerTests._stoppedb   s&   € õ &Ñ'Ô'ˆØ×ÒÑ Ô Ð Øˆr   c                óJ   — t          ¦   «         }|                     ¦   «          |S )z?
        @return: A new, paused L{StrictPushProducer}.
        )r3   r?   rG   s     r   Ú_pausedzStrictPushProducerTests._pausedj   s&   € õ &Ñ'Ô'ˆØ×ÒÑ!Ô!Ð!Øˆr   c                ór   — t          ¦   «         }|                     ¦   «          |                     ¦   «          |S )zY
        @return: A new L{StrictPushProducer} which has been paused and resumed.
        )r3   r?   rA   rG   s     r   Ú_resumedz StrictPushProducerTests._resumedr   s8   € õ &Ñ'Ô'ˆØ×ÒÑ!Ô!Ð!Ø× Ò Ñ"Ô"Ð"Øˆr   rH   r   c                ó<   — |                       |j        d¦  «         dS )z©
        Assert that the given producer is in the stopped state.

        @param producer: The producer to verify.
        @type producer: L{StrictPushProducer}
        r6   N©r$   r8   rG   s     r   ÚassertStoppedz%StrictPushProducerTests.assertStopped{   ó"   € ð 	×Ò˜œ¨)Ñ4Ô4Ð4Ð4Ð4r   c                ó<   — |                       |j        d¦  «         dS )z¨
        Assert that the given producer is in the paused state.

        @param producer: The producer to verify.
        @type producer: L{StrictPushProducer}
        r>   NrO   rG   s     r   ÚassertPausedz$StrictPushProducerTests.assertPaused„   s"   € ð 	×Ò˜œ¨(Ñ3Ô3Ð3Ð3Ð3r   c                ó<   — |                       |j        d¦  «         dS )z©
        Assert that the given producer is in the running state.

        @param producer: The producer to verify.
        @type producer: L{StrictPushProducer}
        r4   NrO   rG   s     r   ÚassertRunningz%StrictPushProducerTests.assertRunning�   rQ   r   c                ój   — |                       t          |                      ¦   «         j        ¦  «         dS )zz
        L{StrictPushProducer.stopProducing} raises L{ValueError} if called when
        the producer is stopped.
        N)ÚassertRaisesr9   rI   r;   r:   s    r   Útest_stopThenStopz)StrictPushProducerTests.test_stopThenStop–   s+   € ð
 	×Ò�* d§m¢m¡o¤oÔ&CÑDÔDÐDÐDÐDr   c                ój   — |                       t          |                      ¦   «         j        ¦  «         dS )z{
        L{StrictPushProducer.pauseProducing} raises L{ValueError} if called when
        the producer is stopped.
        N)rW   r9   rI   r?   r:   s    r   Útest_stopThenPausez*StrictPushProducerTests.test_stopThenPause�   s+   € ð
 	×Ò�* d§m¢m¡o¤oÔ&DÑEÔEÐEÐEÐEr   c                ój   — |                       t          |                      ¦   «         j        ¦  «         dS )z|
        L{StrictPushProducer.resumeProducing} raises L{ValueError} if called when
        the producer is stopped.
        N)rW   r9   rI   rA   r:   s    r   Útest_stopThenResumez+StrictPushProducerTests.test_stopThenResume¤   s+   € ð
 	×Ò�* d§m¢m¡o¤oÔ&EÑFÔFÐFÐFÐFr   c                ó€   — |                       ¦   «         }|                     ¦   «          |                      |¦  «         dS )zn
        L{StrictPushProducer} is stopped if C{stopProducing} is called on a paused
        producer.
        N)rK   r;   rP   rG   s     r   Útest_pauseThenStopz*StrictPushProducerTests.test_pauseThenStop«   s=   € ð
 —<’<‘>”>ˆØ×ÒÑ Ô Ð Ø×Ò˜8Ñ$Ô$Ð$Ð$Ð$r   c                ón   — |                       ¦   «         }|                      t          |j        ¦  «         dS )zs
        L{StrictPushProducer.pauseProducing} raises L{ValueError} if called on a
        paused producer.
        N)rK   rW   r9   r?   rG   s     r   Útest_pauseThenPausez+StrictPushProducerTests.test_pauseThenPause´   s0   € ð
 —<’<‘>”>ˆØ×Ò�* hÔ&=Ñ>Ô>Ð>Ð>Ð>r   c                ó€   — |                       ¦   «         }|                     ¦   «          |                      |¦  «         dS )zp
        L{StrictPushProducer} is resumed if C{resumeProducing} is called on a
        paused producer.
        N)rK   rA   rU   rG   s     r   Útest_pauseThenResumez,StrictPushProducerTests.test_pauseThenResume¼   s=   € ð
 —<’<‘>”>ˆØ× Ò Ñ"Ô"Ð"Ø×Ò˜8Ñ$Ô$Ð$Ð$Ð$r   c                ó€   — |                       ¦   «         }|                     ¦   «          |                      |¦  «         dS )zo
        L{StrictPushProducer} is stopped if C{stopProducing} is called on a
        resumed producer.
        N)rM   r;   rP   rG   s     r   Útest_resumeThenStopz+StrictPushProducerTests.test_resumeThenStopÅ   ó=   € ð
 —=’=‘?”?ˆØ×ÒÑ Ô Ð Ø×Ò˜8Ñ$Ô$Ð$Ð$Ð$r   c                ó€   — |                       ¦   «         }|                     ¦   «          |                      |¦  «         dS )zo
        L{StrictPushProducer} is paused if C{pauseProducing} is called on a
        resumed producer.
        N)rM   r?   rS   rG   s     r   Útest_resumeThenPausez,StrictPushProducerTests.test_resumeThenPauseÎ   ó=   € ð
 —=’=‘?”?ˆØ×ÒÑ!Ô!Ð!Ø×Ò˜(Ñ#Ô#Ð#Ð#Ð#r   c                ón   — |                       ¦   «         }|                      t          |j        ¦  «         dS )zu
        L{StrictPushProducer.resumeProducing} raises L{ValueError} if called on a
        resumed producer.
        N)rM   rW   r9   rA   rG   s     r   Útest_resumeThenResumez-StrictPushProducerTests.test_resumeThenResume×   ó0   € ð
 —=’=‘?”?ˆØ×Ò�* hÔ&>Ñ?Ô?Ð?Ð?Ð?r   c                ó€   — |                       ¦   «         }|                     ¦   «          |                      |¦  «         dS )zn
        L{StrictPushProducer} is stopped if C{stopProducing} is called in the
        initial state.
        N)rE   r;   rP   rG   s     r   Ú	test_stopz!StrictPushProducerTests.test_stopß   re   r   c                ó€   — |                       ¦   «         }|                     ¦   «          |                      |¦  «         dS )zn
        L{StrictPushProducer} is paused if C{pauseProducing} is called in the
        initial state.
        N)rE   r?   rS   rG   s     r   Ú
test_pausez"StrictPushProducerTests.test_pauseè   rh   r   c                ón   — |                       ¦   «         }|                      t          |j        ¦  «         dS )zz
        L{StrictPushProducer} raises L{ValueError} if C{resumeProducing} is called
        in the initial state.
        N)rE   rW   r9   rA   rG   s     r   Útest_resumez#StrictPushProducerTests.test_resumeñ   rk   r   N)r   r3   )rH   r3   r   r   r,   )r-   r.   r/   r0   rE   rI   rK   rM   rP   rS   rU   rX   rZ   r\   r^   r`   rb   rd   rg   rj   rm   ro   rq   r1   r   r   rC   rC   V   s°  € € € € € ðð ð$ð $ð $ð $ðð ð ð ðð ð ð ðð ð ð ð5ð 5ð 5ð 5ð4ð 4ð 4ð 4ð5ð 5ð 5ð 5ðEð Eð Eð EðFð Fð Fð FðGð Gð Gð Gð%ð %ð %ð %ð?ð ?ð ?ð ?ð%ð %ð %ð %ð%ð %ð %ð %ð$ð $ð $ð $ð@ð @ð @ð @ð%ð %ð %ð %ð$ð $ð $ð $ð@ð @ð @ð @ð @ð @r   rC   c                  ó2   — e Zd ZdZdd„Zdd„Zdd„Zdd	„Zd
S )ÚIOPumpTestsz
    Tests for L{IOPump}.
    ÚmodeúLiteral['server', 'client']r   r   c                óh  — t          ¦   «         }t          |d¬¦  «        }t          ¦   «         }t          |d¬¦  «        }t          ||||d¬¦  «        }t          ¦   «         }||dœ|         }|                     |d¬¦  «         |                     ¦   «          |                      d|j        ¦  «         dS )	aÌ  
        Connect a couple protocol/transport pairs to an L{IOPump} and then pump
        it.  Verify that a streaming producer registered with one of the
        transports does not receive invalid L{IPushProducer} method calls and
        ends in the right state.

        @param mode: C{u"server"} to test a producer registered with the
            server transport.  C{u"client"} to test a producer registered with
            the client transport.
        T)ÚisServerF)Úgreet)ÚserverÚclient)Ú	streamingr4   N)r   r	   r
   r3   ÚregisterProducerÚpumpr$   r8   )	r   rt   ÚserverProtoÚserverTransportÚclientProtoÚclientTransportr}   rH   Úvictims	            r   Ú_testStreamingProducerz"IOPumpTests._testStreamingProducerÿ   sÌ   € õ ‘j”jˆÝ'¨¸dÐCÑCÔCˆå‘j”jˆÝ'¨¸eÐDÑDÔDˆåØØØØØð
ñ 
ô 
ˆõ &Ñ'Ô'ˆà%Ø%ð
ð 
ð ôˆð 	×Ò °DÐÑ9Ô9Ð9à�	Š	‰ŒˆØ×Ò˜ H¤OÑ4Ô4Ð4Ð4Ð4r   c                ó2   — |                       d¬¦  «         dS )z—
        L{IOPump.pump} does not call C{resumeProducing} on a L{IPushProducer}
        (stream producer) registered with the server transport.
        ry   ©rt   N©rƒ   r:   s    r   Útest_serverStreamingProducerz(IOPumpTests.test_serverStreamingProducer"  ó!   € ð
 	×#Ò#¨Ð#Ñ2Ô2Ð2Ð2Ð2r   c                ó2   — |                       d¬¦  «         dS )z—
        L{IOPump.pump} does not call C{resumeProducing} on a L{IPushProducer}
        (stream producer) registered with the client transport.
        rz   r…   Nr†   r:   s    r   Útest_clientStreamingProducerz(IOPumpTests.test_clientStreamingProducer)  rˆ   r   c                ó  ‡— g Št          ¦   «         }t          t          t          |¬¦  «        \  }}}|                     dˆfd„¦  «         |                      ‰¦  «         |                     ¦   «          |                      ‰¦  «         dS )zE
        L{IOPump.pump} advances time in the given L{Clock}.
        )Úclockr   c                 ó.   •— ‰                       d¦  «        S )NT)Úappend)Útime_passeds   €r   ú<lambda>z/IOPumpTests.test_timeAdvances.<locals>.<lambda>7  s   ø€  ;×#5Ò#5°dÑ#;Ô#;€ r   N)r   r   r   Ú	callLaterÚassertFalser}   Ú
assertTrue)r   rŒ   Ú_r}   r�   s       @r   Útest_timeAdvanceszIOPumpTests.test_timeAdvances0  s„   ø€ ð ˆÝ‘”ˆÝ-­h½ÈÐNÑNÔN‰
ˆˆ1ˆdØ�Š˜Ð;Ð;Ð;Ð;Ñ<Ô<Ð<Ø×Ò˜Ñ%Ô%Ð%Ø�	Š	‰ŒˆØ�Š˜Ñ$Ô$Ð$Ð$Ð$r   N)rt   ru   r   r   r,   )r-   r.   r/   r0   rƒ   r‡   rŠ   r•   r1   r   r   rs   rs   ú   so   € € € € € ðð ð!5ð !5ð !5ð !5ðF3ð 3ð 3ð 3ð3ð 3ð 3ð 3ð
%ð 
%ð 
%ð 
%ð 
%ð 
%r   rs   N)r0   Ú
__future__r   Útypingr   Úzope.interfacer   Útwisted.internet.interfacesr   Útwisted.internet.protocolr   Útwisted.internet.taskr   Útwisted.test.iosimr	   r
   r   Útwisted.trial.unittestr   r   r3   rC   rs   r1   r   r   ú<module>rž      s�  ððð ð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð à &Ð &Ð &Ð &Ð &Ð &à 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø .Ð .Ð .Ð .Ð .Ð .Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OØ +Ð +Ð +Ð +Ð +Ð +ð&8ð &8ð &8ð &8ð &8˜ñ &8ô &8ð &8ðR €ˆ]ÑÔð ð  ð  ð  ð  ñ  ô  ñ Ôð ð0a@ð a@ð a@ð a@ð a@˜hñ a@ô a@ð a@ðH@%ð @%ð @%ð @%ð @%�(ñ @%ô @%ð @%ð @%ð @%r   