ó
    ×›‘hb*  ã                  ó  • S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
JrJr  SSKJr  SSKJr  SS	KJrJrJrJrJr  SS
KJr   " S S\5      r\" \5       " S S5      5       r " S S\5      r " S S\5      r " S S\5      rg)z"
Tests for L{twisted.test.iosim}.
é    )Úannotations)ÚLiteral)Úimplementer)ÚIPushProducer)ÚClientFactoryÚFactoryÚProtocol)ÚClock)ÚMemoryReactor)ÚConnectionCompleterÚFakeTransportÚIOPumpÚconnectÚconnectedServerAndClient)ÚTestCasec                  ó6   • \ rS rSrSrSS jrSS jrSS jrSrg)	ÚFakeTransportTestsé   z
Tests for L{FakeTransport}.
c                ó   • [        [        5       S5      n[        [        5       S5      nU R                  UR                  [        5        U R                  UR                  [        5        U R                  UR                  UR                  5        g)zM
Each L{FakeTransport} receives a serial number that uniquely identifies
it.
TFN)r   ÚobjectÚassertIsInstanceÚserialÚintÚassertNotEqual)ÚselfÚaÚbs      Ú[C:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/test/test_iosim.pyÚtest_connectionSerialÚ(FakeTransportTests.test_connectionSerial    s`   € ô
 œ&›( DÓ)ˆÜœ&›( EÓ*ˆØ×Ñ˜aŸh™h¬Ô,Ø×Ñ˜aŸh™h¬Ô,Ø×Ñ˜AŸH™H a§h¡hÕ/ó    c                óÊ   • [        [        5       S5      nUR                  S5        UR                  / SQ5        U R	                  SR                  UR                  5      S5        g)zT
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_writeSequenceÚ%FakeTransportTests.test_writeSequence+   sG   € ô
 œ&›( EÓ*ˆà	�‰�ŒØ	�‰Ò*Ô+à×Ñ˜Ÿ™ !§(¡(Ó+¨WÕ5r!   c                óæ   • [        [        5       S5      nUR                  S5        UR                  5         UR                  S5        U R	                  SR                  UR                  5      S5        g)zp
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_writeAfterCloseÚ'FakeTransportTests.test_writeAfterClose7   sS   € ô
 œ&›( EÓ*ˆØ	�‰�	ÔØ	×ÑÔØ	�‰�Ôà×Ñ˜Ÿ™ !§(¡(Ó+¨YÕ7r!   © N©ÚreturnÚNone)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r-   r1   Ú__static_attributes__r3   r!   r   r   r      s   † ñô	0ô
6÷
8r!   r   c                  ó:   • \ rS rSrSrSrS	S jrS	S jrS	S jrSr	g)
ÚStrictPushProduceréD   zw
An L{IPushProducer} implementation which produces nothing but enforces
preconditions on its state transition methods.
Úrunningc                óH   • U R                   S:X  a  [        S5      eSU l         g )NÚstoppedz)Cannot stop already-stopped IPushProducer©Ú_stateÚ
ValueError©r   s    r   ÚstopProducingÚ StrictPushProducer.stopProducingM   s!   € Ø�;‰;˜)Ó#ÜÐHÓIÐIØˆ�r!   c                ód   • U R                   S:w  a  [        SU R                    S35      eSU l         g )Nr@   zCannot pause ú IPushProducerÚpausedrC   rF   s    r   ÚpauseProducingÚ!StrictPushProducer.pauseProducingR   s-   € Ø�;‰;˜)Ó#Ü˜}¨T¯[©[¨M¸ÐHÓIÐIØˆ�r!   c                ód   • U R                   S:w  a  [        SU R                    S35      eSU l         g )NrK   zCannot resume rJ   r@   rC   rF   s    r   ÚresumeProducingÚ"StrictPushProducer.resumeProducingW   s-   € Ø�;‰;˜(Ó"Ü˜~¨d¯k©k¨]¸.ÐIÓJÐJØˆ�r!   )rD   Nr4   )
r7   r8   r9   r:   r;   rD   rG   rL   rO   r<   r3   r!   r   r>   r>   D   s   † ñð
 €Fô ô
÷
 r!   r>   c                  óÖ   • \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	SS jr
SS	 jrSS
 jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSrg)ÚStrictPushProducerTestsé]   z"
Tests for L{StrictPushProducer}.
c                ó   • [        5       $ )zX
@return: A new L{StrictPushProducer} which has not been through any state
    changes.
)r>   rF   s    r   Ú_initialÚ StrictPushProducerTests._initialb   s   € ô
 "Ó#Ð#r!   c                ó:   • [        5       nUR                  5         U$ )z0
@return: A new, stopped L{StrictPushProducer}.
)r>   rG   ©r   Úproducers     r   Ú_stoppedÚ StrictPushProducerTests._stoppedi   s   € ô &Ó'ˆØ×ÑÔ Øˆr!   c                ó:   • [        5       nUR                  5         U$ )z/
@return: A new, paused L{StrictPushProducer}.
)r>   rL   rX   s     r   Ú_pausedÚStrictPushProducerTests._pausedq   s   € ô &Ó'ˆØ×ÑÔ!Øˆr!   c                óZ   • [        5       nUR                  5         UR                  5         U$ )zI
@return: A new L{StrictPushProducer} which has been paused and resumed.
)r>   rL   rO   rX   s     r   Ú_resumedÚ StrictPushProducerTests._resumedy   s)   € ô &Ó'ˆØ×ÑÔ!Ø× Ñ Ô"Øˆr!   c                ó<   • U R                  UR                  S5        g)z‰
Assert that the given producer is in the stopped state.

@param producer: The producer to verify.
@type producer: L{StrictPushProducer}
rB   N©r)   rD   rX   s     r   ÚassertStoppedÚ%StrictPushProducerTests.assertStopped‚   ó   € ð 	×Ñ˜Ÿ™¨)Õ4r!   c                ó<   • U R                  UR                  S5        g)zˆ
Assert that the given producer is in the paused state.

@param producer: The producer to verify.
@type producer: L{StrictPushProducer}
rK   Nrc   rX   s     r   ÚassertPausedÚ$StrictPushProducerTests.assertPaused‹   s   € ð 	×Ñ˜Ÿ™¨(Õ3r!   c                ó<   • U R                  UR                  S5        g)z‰
Assert that the given producer is in the running state.

@param producer: The producer to verify.
@type producer: L{StrictPushProducer}
r@   Nrc   rX   s     r   ÚassertRunningÚ%StrictPushProducerTests.assertRunning”   rf   r!   c                ó`   • U R                  [        U R                  5       R                  5        g)zb
L{StrictPushProducer.stopProducing} raises L{ValueError} if called when
the producer is stopped.
N)ÚassertRaisesrE   rZ   rG   rF   s    r   Útest_stopThenStopÚ)StrictPushProducerTests.test_stopThenStop�   s    € ð
 	×Ñœ* d§m¡m£o×&CÑ&CÕDr!   c                ó`   • U R                  [        U R                  5       R                  5        g)zc
L{StrictPushProducer.pauseProducing} raises L{ValueError} if called when
the producer is stopped.
N)rn   rE   rZ   rL   rF   s    r   Útest_stopThenPauseÚ*StrictPushProducerTests.test_stopThenPause¤   s    € ð
 	×Ñœ* d§m¡m£o×&DÑ&DÕEr!   c                ó`   • U R                  [        U R                  5       R                  5        g)zd
L{StrictPushProducer.resumeProducing} raises L{ValueError} if called when
the producer is stopped.
N)rn   rE   rZ   rO   rF   s    r   Útest_stopThenResumeÚ+StrictPushProducerTests.test_stopThenResume«   s    € ð
 	×Ñœ* d§m¡m£o×&EÑ&EÕFr!   c                óf   • U R                  5       nUR                  5         U R                  U5        g)zV
L{StrictPushProducer} is stopped if C{stopProducing} is called on a paused
producer.
N)r]   rG   rd   rX   s     r   Útest_pauseThenStopÚ*StrictPushProducerTests.test_pauseThenStop²   s)   € ð
 —<‘<“>ˆØ×ÑÔ Ø×Ñ˜8Õ$r!   c                ód   • U R                  5       nU R                  [        UR                  5        g)z[
L{StrictPushProducer.pauseProducing} raises L{ValueError} if called on a
paused producer.
N)r]   rn   rE   rL   rX   s     r   Útest_pauseThenPauseÚ+StrictPushProducerTests.test_pauseThenPause»   s%   € ð
 —<‘<“>ˆØ×Ñœ* h×&=Ñ&=Õ>r!   c                óf   • U R                  5       nUR                  5         U R                  U5        g)zX
L{StrictPushProducer} is resumed if C{resumeProducing} is called on a
paused producer.
N)r]   rO   rk   rX   s     r   Útest_pauseThenResumeÚ,StrictPushProducerTests.test_pauseThenResumeÃ   s)   € ð
 —<‘<“>ˆØ× Ñ Ô"Ø×Ñ˜8Õ$r!   c                óf   • U R                  5       nUR                  5         U R                  U5        g)zW
L{StrictPushProducer} is stopped if C{stopProducing} is called on a
resumed producer.
N)r`   rG   rd   rX   s     r   Útest_resumeThenStopÚ+StrictPushProducerTests.test_resumeThenStopÌ   ó)   € ð
 —=‘=“?ˆØ×ÑÔ Ø×Ñ˜8Õ$r!   c                óf   • U R                  5       nUR                  5         U R                  U5        g)zW
L{StrictPushProducer} is paused if C{pauseProducing} is called on a
resumed producer.
N)r`   rL   rh   rX   s     r   Útest_resumeThenPauseÚ,StrictPushProducerTests.test_resumeThenPauseÕ   ó)   € ð
 —=‘=“?ˆØ×ÑÔ!Ø×Ñ˜(Õ#r!   c                ód   • U R                  5       nU R                  [        UR                  5        g)z]
L{StrictPushProducer.resumeProducing} raises L{ValueError} if called on a
resumed producer.
N)r`   rn   rE   rO   rX   s     r   Útest_resumeThenResumeÚ-StrictPushProducerTests.test_resumeThenResumeÞ   ó%   € ð
 —=‘=“?ˆØ×Ñœ* h×&>Ñ&>Õ?r!   c                óf   • U R                  5       nUR                  5         U R                  U5        g)zV
L{StrictPushProducer} is stopped if C{stopProducing} is called in the
initial state.
N)rU   rG   rd   rX   s     r   Ú	test_stopÚ!StrictPushProducerTests.test_stopæ   rƒ   r!   c                óf   • U R                  5       nUR                  5         U R                  U5        g)zV
L{StrictPushProducer} is paused if C{pauseProducing} is called in the
initial state.
N)rU   rL   rh   rX   s     r   Ú
test_pauseÚ"StrictPushProducerTests.test_pauseï   r‡   r!   c                ód   • U R                  5       nU R                  [        UR                  5        g)zb
L{StrictPushProducer} raises L{ValueError} if C{resumeProducing} is called
in the initial state.
N)rU   rn   rE   rO   rX   s     r   Útest_resumeÚ#StrictPushProducerTests.test_resumeø   r‹   r!   r3   N)r5   r>   )rY   r>   r5   r6   r4   )r7   r8   r9   r:   r;   rU   rZ   r]   r`   rd   rh   rk   ro   rr   ru   rx   r{   r~   r�   r…   r‰   r�   r�   r“   r<   r3   r!   r   rR   rR   ]   sk   † ñô$ôôôô5ô4ô5ôEôFôGô%ô?ô%ô%ô$ô@ô%ô$÷@r!   rR   c                  ó@   • \ rS rSrSrS	S jrS
S jrS
S jrS
S jrSr	g)ÚIOPumpTestsi  z
Tests for L{IOPump}.
c                ó
  • [        5       n[        USS9n[        5       n[        USS9n[        UUUUSS9n[        5       nUUS.U   nUR	                  USS9  UR                  5         U R                  SUR                  5        g)	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)Ú	streamingr@   N)r	   r   r   r>   ÚregisterProducerÚpumpr)   rD   )	r   ÚmodeÚserverProtoÚserverTransportÚclientProtoÚclientTransportrž   rY   Úvictims	            r   Ú_testStreamingProducerÚ"IOPumpTests._testStreamingProducer  s–   € ô “jˆÜ'¨¸dÑCˆä“jˆÜ'¨¸eÑDˆäØØØØØñ
ˆô &Ó'ˆà%Ø%ñ
ð ñˆð 	×Ñ °DÐÑ9à�	‰	ŒØ×Ñ˜ H§O¡OÕ4r!   c                ó"   • U R                  SS9  g)z
L{IOPump.pump} does not call C{resumeProducing} on a L{IPushProducer}
(stream producer) registered with the server transport.
rš   ©rŸ   N©r¥   rF   s    r   Útest_serverStreamingProducerÚ(IOPumpTests.test_serverStreamingProducer)  ó   € ð
 	×#Ñ#¨Ð#Ò2r!   c                ó"   • U R                  SS9  g)z
L{IOPump.pump} does not call C{resumeProducing} on a L{IPushProducer}
(stream producer) registered with the client transport.
r›   r¨   Nr©   rF   s    r   Útest_clientStreamingProducerÚ(IOPumpTests.test_clientStreamingProducer0  r¬   r!   c                óÚ   ^• / m[        5       n[        [        [        US9u    p#UR                  SU4S j5        U R	                  T5        UR                  5         U R                  T5        g)z5
L{IOPump.pump} advances time in the given L{Clock}.
)Úclockr   c                 ó&   >• T R                  S5      $ )NT)Úappend)Útime_passeds   €r   Ú<lambda>Ú/IOPumpTests.test_timeAdvances.<locals>.<lambda>>  s   ø€  ;×#5Ñ#5°dÔ#;r!   N)r
   r   r	   Ú	callLaterÚassertFalserž   Ú
assertTrue)r   r±   Ú_rž   r´   s       @r   Útest_timeAdvancesÚIOPumpTests.test_timeAdvances7  sU   ø€ ð ˆÜ“ˆÜ-¬h¼ÈÑN‰
ˆˆ1Ø�‰˜Ô;Ô<Ø×Ñ˜Ô%Ø�	‰	ŒØ�‰˜Õ$r!   r3   N)rŸ   zLiteral['server', 'client']r5   r6   r4   )
r7   r8   r9   r:   r;   r¥   rª   r®   r»   r<   r3   r!   r   r–   r–     s   † ñô!5ôF3ô3÷
%r!   r–   c                  ó,   • \ rS rSrSrSS jrSS jrSrg)ÚConnectionCompleterTestsiD  zf
L{ConnectionCompleter} can connect a connecting client and a listening
server in a L{MemoryReactor}.
c                ój   • [        [        5       5      nU R                  UR                  5       S5        g)zd
When no connection for its reactor is pending,
L{ConnectionCompleter.succeedOnce} returns C{None}.
N)r   r   ÚassertIsÚsucceedOnce)r   Úccs     r   Útest_noConnectionÚ*ConnectionCompleterTests.test_noConnectionJ  s%   € ô
 !¤£Ó1ˆØ�‰�b—n‘nÓ&¨Õ-r!   c                ó   • [        5       nUR                  S[        R                  " [        5      5        UR                  SS[        R                  " [        5      5        [        U5      nU R                  UR                  5       [        5        g)zw
When a connection to a matched host and port is pending,
L{ConnectionCompleter} returns an L{IOPump} connecting them.
éP   z	127.0.0.1N)r   Ú	listenTCPr   ÚforProtocolr	   Ú
connectTCPr   r   r   rÁ   r   )r   ÚmemrÂ   s      r   Útest_someConnectionÚ,ConnectionCompleterTests.test_someConnectionR  s`   € ô
 ‹oˆØ�‰�bœ'×-Ò-¬hÓ7Ô8Ø�‰�{ B¬×(AÒ(AÄ(Ó(KÔLÜ  Ó%ˆØ×Ñ˜bŸn™nÓ.´Õ7r!   r3   Nr4   )r7   r8   r9   r:   r;   rÃ   rË   r<   r3   r!   r   r¾   r¾   D  s   † ñô
.÷	8r!   r¾   N)r;   Ú
__future__r   Útypingr   Úzope.interfacer   Útwisted.internet.interfacesr   Útwisted.internet.protocolr   r   r	   Útwisted.internet.taskr
   Útwisted.internet.testingr   Útwisted.test.iosimr   r   r   r   r   Útwisted.trial.unittestr   r   r>   rR   r–   r¾   r3   r!   r   Ú<module>rÖ      sŠ   ðñõ #å å &å 5ß FÑ FÝ 'Ý 2÷õ õ ,ô&8˜ô &8ñR ˆ]Ó÷ ð  ó ð ô0a@˜hô a@ôH@%�(ô @%ôF8˜xõ 8r!   