ó
    Ö›‘h=.  ã                   ó^  • S r SSKrSSKJr  SSKJr  SSKJrJr  SSK	J
r
  SSKJr  SSKJr  Sr SS	KJr  SS
KJr  SSKJr  SSKJr   " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg! \ a    Sr Nof = f)z>
Tests for L{twisted.internet.posixbase} and supporting code.
é    N)ÚDeferred)ÚIReadDescriptor)ÚPosixReactorBaseÚ_Waker)ÚServerFactory)Úplatform)ÚTestCase)Úunix)ÚClientProtoz)Platform does not support AF_UNIX sockets)Úreactor)ÚPortc                   ó8   ^ • \ rS rSrSrU 4S jrU 4S jrSrU =r$ )ÚWarningCheckerTestCaseé   z_
A test case that will make sure that no warnings are left unchecked at the end of a test run.
c                 óÞ   >• [         TU ]  5         [        R                  R	                  SS5      R                  5       S:X  a,  [        R                  " 5       (       a  U R                  5         g g g )NÚCIÚ Útrue)	ÚsuperÚsetUpÚosÚenvironÚgetÚlowerr   Ú	isWindowsÚflushWarnings)ÚselfÚ	__class__s    €ÚhC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/internet/test/test_posixbase.pyr   ÚWarningCheckerTestCase.setUp    sQ   ø€ Ü‰‰Œô �:‰:�>‰>˜$ Ó#×)Ñ)Ó+¨vÓ5¼(×:LÒ:L×:NÑ:NØ×ÑÕ ð ;OÐ5ó    c                 ó"  >•  [         TU ]  5         U R                  5       n[        R                  R                  SS5      R                  5       S:X  a  [        R                  " 5       (       a  g U R                  [        U5      SSU 35        g ! U R                  5       n[        R                  R                  SS5      R                  5       S:X  a  [        R                  " 5       (       a     g U R                  [        U5      SSU 35        f = f)Nr   r   r   r   z'Warnings found at the end of the test:
)r   ÚtearDownr   r   r   r   r   r   r   ÚassertEqualÚlen)r   Úwarningsr   s     €r   r#   ÚWarningCheckerTestCase.tearDown+   sÛ   ø€ ð	Ü‰GÑÔà×)Ñ)Ó+ˆHÜ�z‰z�~‰~˜d BÓ'×-Ñ-Ó/°6Ó9¼h×>PÒ>P×>RÑ>Rð Ø×ÑÜ�H“˜qÐ$LÈXÈJÐ"Wõøð ×)Ñ)Ó+ˆHÜ�z‰z�~‰~˜d BÓ'×-Ñ-Ó/°6Ó9¼h×>PÒ>P×>RÑ>Rò Ø×ÑÜ�H“˜qÐ$LÈXÈJÐ"Wõús   ƒB ÂADÃ. D© )	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r#   Ú__static_attributes__Ú__classcell__)r   s   @r   r   r      s   ø† ñõ	!÷ó r!   r   c                   ó2   • \ rS rSrS rS rS rS rS rSr	g)	ÚTrivialReactoré=   c                 óL   • 0 U l         0 U l        [        R                  " U 5        g ©N)Ú_readersÚ_writersr   Ú__init__©r   s    r   r7   ÚTrivialReactor.__init__>   s   € ØˆŒØˆŒÜ×!Ò! $Õ'r!   c                 ó"   • SU R                   U'   g ©NT©r5   ©r   Úreaders     r   Ú	addReaderÚTrivialReactor.addReaderC   ó   € Ø $ˆ�‰�fÒr!   c                 ó   • U R                   U	 g r4   r<   r=   s     r   ÚremoveReaderÚTrivialReactor.removeReaderF   ó   € Ø�M‰M˜&Ñ!r!   c                 ó"   • SU R                   U'   g r;   ©r6   ©r   Úwriters     r   Ú	addWriterÚTrivialReactor.addWriterI   rA   r!   c                 ó   • U R                   U	 g r4   rG   rH   s     r   ÚremoveWriterÚTrivialReactor.removeWriterL   rE   r!   )r5   r6   N)
r)   r*   r+   r,   r7   r?   rC   rJ   rM   r.   r(   r!   r   r1   r1   =   s   † ò(ò
%ò"ò%õ"r!   r1   c                   ó0   • \ rS rSrSrS rS rS rS rSr	g)	ÚPosixReactorBaseTestséP   z 
Tests for L{PosixReactorBase}.
c                 óÜ   • U R                  UR                  [        5        U R                  UR                  UR                  5        U R                  UR                  UR
                  5        g r4   )ÚassertIsInstanceÚwakerr   ÚassertInÚ_internalReadersr5   ©r   r   s     r   Ú_checkWakerÚ!PosixReactorBaseTests._checkWakerU   sF   € Ø×Ñ˜gŸm™m¬VÔ4Ø�‰�g—m‘m W×%=Ñ%=Ô>Ø�‰�g—m‘m W×%5Ñ%5Õ6r!   c                 ó:   • [        5       nU R                  U5        g)zg
When L{PosixReactorBase} is instantiated, it creates a waker and adds
it to its internal readers set.
N)r1   rX   rW   s     r   Útest_wakerIsInternalReaderÚ0PosixReactorBaseTests.test_wakerIsInternalReaderZ   s   € ô
 !Ó"ˆØ×Ñ˜Õ!r!   c                 ób  • [        5       n[        5       nUR                  R                  U5        UR                  " U5        UR
                  " UR                  UR                  5        U R                  U5        U R                  X!R                  5        U R                  X!R                  5        g)zs
Any L{IReadDescriptor}s in L{PosixReactorBase._internalReaders} are
left alone by L{PosixReactorBase._removeAll}.
N)
r1   ÚobjectrV   Úaddr?   Ú
_removeAllr5   r6   rX   rU   )r   r   Úextras      r   Ú"test_removeAllSkipsInternalReadersÚ8PosixReactorBaseTests.test_removeAllSkipsInternalReadersb   sƒ   € ô
 !Ó"ˆÜ“ˆØ× Ñ ×$Ñ$ UÔ+Ø×Ò˜%Ô Ø×Ò˜7×+Ñ+¨W×-=Ñ-=Ô>Ø×Ñ˜Ô!Ø�‰�e×5Ñ5Ô6Ø�‰�e×-Ñ-Õ.r!   c                 óz  • [        5       n[        5       n[        5       nUR                  " U5        UR                  " U5        UR                  " UR
                  UR                  5      nU R                  [        U5      X#15        U R                  X!R
                  5        U R                  X1R                  5        g)zn
L{PosixReactorBase._removeAll} returns a list of removed
L{IReadDescriptor} and L{IWriteDescriptor} objects.
N)
r1   r^   r?   rJ   r`   r5   r6   r$   ÚsetÚassertNotIn)r   r   r>   rI   Úremoveds        r   Ú'test_removeAllReturnsRemovedDescriptorsÚ=PosixReactorBaseTests.test_removeAllReturnsRemovedDescriptorsp   s“   € ô
 !Ó"ˆÜ“ˆÜ“ˆØ×Ò˜&Ô!Ø×Ò˜&Ô!Ø×$Ò$ W×%5Ñ%5°w×7GÑ7GÓHˆØ×Ñœ˜W›¨Ð'7Ô8Ø×Ñ˜×!1Ñ!1Ô2Ø×Ñ˜×!1Ñ!1Õ2r!   r(   N)
r)   r*   r+   r,   r-   rX   r[   rb   rh   r.   r(   r!   r   rP   rP   P   s   † ñò7ò
"ò/õ3r!   rP   c                   ó>   • \ rS rSrSr\" \\5      (       d  SrS r	Sr
g)ÚTCPPortTestsé€   z)
Tests for L{twisted.internet.tcp.Port}.
zNon-posixbase reactorc                 ó�   • [        S[        5       5      nSUl        S Ul        U R	                  UR                  5       [        5      $ )zk
L{Port.stopListening} returns a L{Deferred} which errbacks if
L{Port.connectionLost} raises an exception.
i90  Tc                 ó   • SS-  $ )Né   r   r(   )Úreasons    r   Ú<lambda>Ú8TCPPortTests.test_connectionLostFailed.<locals>.<lambda>�   s   € ¨Q°!ªVr!   )r   r   Ú	connectedÚconnectionLostÚassertFailureÚstopListeningÚZeroDivisionError)r   Úports     r   Útest_connectionLostFailedÚ&TCPPortTests.test_connectionLostFailedˆ   s>   € ô
 �Eœ=›?Ó+ˆØˆŒÙ3ˆÔØ×!Ñ! $×"4Ñ"4Ó"6Ô8IÓJÐJr!   r(   N)r)   r*   r+   r,   r-   Ú
isinstancer   r   Úskipry   r.   r(   r!   r   rk   rk   €   s"   † ññ �gÐ/×0Ñ0Ø&ˆõKr!   rk   c                   óT   • \ rS rSrSrS rS\SS4S jrS\SS4S jrS	 r	S
 r
S rSrg)ÚTimeoutReportReactoré“   zÐ
A reactor which is just barely runnable and which cannot monitor any
readers or writers, and which fires a L{Deferred} with the timeout
passed to its C{doIteration} method as soon as that method is invoked.
c                 ó\   • [         R                  " U 5        [        5       U l        SU l        g )Néd   )r   r7   r   ÚiterationTimeoutÚnowr8   s    r   r7   ÚTimeoutReportReactor.__init__š   s!   € Ü×!Ò! $Ô'Ü (£
ˆÔØˆ�r!   r>   ÚreturnNc                 ó   • g)z
Ignore the reader.  This is necessary because the waker will be
added.  However, we won't actually monitor it for any events.
Nr(   r=   s     r   r?   ÚTimeoutReportReactor.addReaderŸ   ó   � r!   c                 ó   • g)z
See L{addReader}.
Nr(   r=   s     r   rC   Ú!TimeoutReportReactor.removeReader¥   rˆ   r!   c                 ó   • / $ )z�
There are no readers or writers, so there is nothing to remove.
This will be called when the reactor stops, though, so it must be
implemented.
r(   r8   s    r   Ú	removeAllÚTimeoutReportReactor.removeAllª   s	   € ð ˆ	r!   c                 ó   • U R                   $ )z`
Override the real clock with a deterministic one that can be easily
controlled in a unit test.
)rƒ   r8   s    r   ÚsecondsÚTimeoutReportReactor.seconds²   s   € ð
 �x‰xˆr!   c                 óT   • U R                   nUb  S U l         UR                  U5        g g r4   )r‚   Úcallback)r   ÚtimeoutÚds      r   ÚdoIterationÚ TimeoutReportReactor.doIteration¹   s+   € Ø×!Ñ!ˆØ‰=Ø$(ˆDÔ!Ø�J‰J�wÕð r!   )r‚   rƒ   )r)   r*   r+   r,   r-   r7   r   r?   rC   rŒ   r�   r•   r.   r(   r!   r   r~   r~   “   sA   † ñòð
 ð °Dô ð ?ð °tô ò
òõ r!   r~   c                   óH   • \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSrg)ÚIterationTimeoutTestséÀ   z�
Tests for the timeout argument L{PosixReactorBase.run} calls
L{PosixReactorBase.doIteration} with in the presence of various delayed
calls.
c                 ó¼   ^• / nTR                   R                  UR                  5        TR                   R                  U4S j5        TR                  " 5         US   $ )Nc                 ó&   >• TR                   " 5       $ r4   )Ústop)Úignoredr   s    €r   rq   Ú>IterationTimeoutTests._checkIterationTimeout.<locals>.<lambda>Ê   s   ø€ ¸W¿\º\¼^r!   r   )r‚   ÚaddCallbackÚappendÚrun©r   r   r“   s    ` r   Ú_checkIterationTimeoutÚ,IterationTimeoutTests._checkIterationTimeoutÇ   sH   ø€ ØˆØ× Ñ ×,Ñ,¨W¯^©^Ô<Ø× Ñ ×,Ñ,Ô-KÔLØ�ŠŒØ�q‰zÐr!   c                 ó\   • [        5       nU R                  U5      nU R                  U5        g)zT
If there are no delayed calls, C{doIteration} is called with a
timeout of L{None}.
N)r~   r£   ÚassertIsNoner¢   s      r   Útest_noCallsÚ"IterationTimeoutTests.test_noCallsÎ   s*   € ô
 'Ó(ˆØ×-Ñ-¨gÓ6ˆØ×Ñ˜'Õ"r!   c                 ó†   • [        5       nUR                  " SS 5        U R                  U5      nU R                  US5        g)z¡
If there is a delayed call, C{doIteration} is called with a timeout
which is the difference between the current time and the time at
which that call is to run.
r�   c                  ó   • g r4   r(   r(   r!   r   rq   Ú8IterationTimeoutTests.test_delayedCall.<locals>.<lambda>Þ   ó   €  tr!   N©r~   Ú	callLaterr£   r$   r¢   s      r   Útest_delayedCallÚ&IterationTimeoutTests.test_delayedCall×   s<   € ô 'Ó(ˆØ×Ò˜#™|Ô,Ø×-Ñ-¨gÓ6ˆØ×Ñ˜ #Õ&r!   c                 ó°   • [        5       nUR                  " SS 5        U=R                  S-  sl        U R                  U5      nU R	                  US5        g)z�
If a delayed call is scheduled and then some time passes, the
timeout passed to C{doIteration} is reduced by the amount of time
which passed.
r�   c                  ó   • g r4   r(   r(   r!   r   rq   Ú7IterationTimeoutTests.test_timePasses.<locals>.<lambda>é   r¬   r!   é   éK   N)r~   r®   rƒ   r£   r$   r¢   s      r   Útest_timePassesÚ%IterationTimeoutTests.test_timePassesâ   sJ   € ô 'Ó(ˆØ×Ò˜#™|Ô,Ø�Š�rÑ�Ø×-Ñ-¨gÓ6ˆØ×Ñ˜ "Õ%r!   c                 óÖ   • [        5       nUR                  " SS 5        UR                  " SS 5        UR                  " SS 5        U R                  U5      nU R                  US5        g)z¼
If there are several delayed calls, C{doIteration} is called with a
timeout which is the difference between the current time and the
time at which the earlier of the two calls is to run.
é2   c                  ó   • g r4   r(   r(   r!   r   rq   ÚAIterationTimeoutTests.test_multipleDelayedCalls.<locals>.<lambda>õ   ó   €  dr!   é
   c                  ó   • g r4   r(   r(   r!   r   rq   r»   ö   r¼   r!   r�   c                  ó   • g r4   r(   r(   r!   r   rq   r»   ÷   r¬   r!   Nr­   r¢   s      r   Útest_multipleDelayedCallsÚ/IterationTimeoutTests.test_multipleDelayedCallsî   s\   € ô 'Ó(ˆØ×Ò˜"™lÔ+Ø×Ò˜"™lÔ+Ø×Ò˜#™|Ô,Ø×-Ñ-¨gÓ6ˆØ×Ñ˜ "Õ%r!   c                 óÒ   • [        5       nUR                  " SS 5      nU=R                  S-  sl        UR                  S5        U R	                  U5      nU R                  US5        g)z 
If a delayed call is reset, the timeout passed to C{doIteration} is
based on the interval between the time when reset is called and the
new delay of the call.
r¹   c                  ó   • g r4   r(   r(   r!   r   rq   Ú=IterationTimeoutTests.test_resetDelayedCall.<locals>.<lambda>  ó   € ¨Tr!   r´   é   N)r~   r®   rƒ   Úresetr£   r$   ©r   r   Úcallr“   s       r   Útest_resetDelayedCallÚ+IterationTimeoutTests.test_resetDelayedCallû   sW   € ô 'Ó(ˆØ× Ò  ¡\Ó2ˆØ�Š�rÑ�Ø�
‰
�2ŒØ×-Ñ-¨gÓ6ˆØ×Ñ˜ "Õ%r!   c                 óÒ   • [        5       nUR                  " SS 5      nU=R                  S-  sl        UR                  S5        U R	                  U5      nU R                  US5        g)zÉ
If a delayed call is re-delayed, the timeout passed to
C{doIteration} is based on the remaining time before the call would
have been made and the additional amount of time passed to the delay
method.
r¹   c                  ó   • g r4   r(   r(   r!   r   rq   Ú=IterationTimeoutTests.test_delayDelayedCall.<locals>.<lambda>  rÅ   r!   r½   é   é<   N)r~   r®   rƒ   Údelayr£   r$   rÈ   s       r   Útest_delayDelayedCallÚ+IterationTimeoutTests.test_delayDelayedCall  sW   € ô 'Ó(ˆØ× Ò  ¡\Ó2ˆØ�Š�rÑ�Ø�
‰
�2ŒØ×-Ñ-¨gÓ6ˆØ×Ñ˜ "Õ%r!   c                 ó¤   • [        5       nUR                  " SS 5      nUR                  5         U R                  U5      nU R	                  U5        g)zX
If the only delayed call is canceled, L{None} is the timeout passed
to C{doIteration}.
r¹   c                  ó   • g r4   r(   r(   r!   r   rq   Ú>IterationTimeoutTests.test_cancelDelayedCall.<locals>.<lambda>  rÅ   r!   N)r~   r®   Úcancelr£   r¦   rÈ   s       r   Útest_cancelDelayedCallÚ,IterationTimeoutTests.test_cancelDelayedCall  sE   € ô
 'Ó(ˆØ× Ò  ¡\Ó2ˆØ�‰ŒØ×-Ñ-¨gÓ6ˆØ×Ñ˜'Õ"r!   r(   N)r)   r*   r+   r,   r-   r£   r§   r¯   r¶   rÀ   rÊ   rÒ   rØ   r.   r(   r!   r   r˜   r˜   À   s/   † ñòò#ò	'ò
&ò&ò&ò&õ	#r!   r˜   c                   ó.   • \ rS rSrSr\b  \rS rS rSr	g)ÚConnectedDatagramPortTestsi"  z'
Test connected datagram UNIX sockets.
Nc                 ó~   ^ • U 4S jn[         R                  " S[        5       5      nXl        UR	                  S5        g)zw
L{ConnectedDatagramPort} does not call the deprecated C{loseConnection}
in L{ConnectedDatagramPort.connectionFailed}.
c                  ó(   >• T R                  S5        g)z\
Dummy C{loseConnection} method. C{loseConnection} is deprecated and
should not get called.
z7loseConnection is deprecated and should not get called.N)Úfailr8   s   €r   ÚloseConnectionÚ`ConnectedDatagramPortTests.test_connectionFailedDoesntCallLoseConnection.<locals>.loseConnection0  s   ø€ ð
 �I‰IÐOÕPr!   NÚgoodbye)r
   ÚConnectedDatagramPortr   rß   ÚconnectionFailed)r   rß   rx   s   `  r   Ú-test_connectionFailedDoesntCallLoseConnectionÚHConnectedDatagramPortTests.test_connectionFailedDoesntCallLoseConnection*  s3   ø€ õ	Qô ×)Ò)¨$´³Ó>ˆØ,ÔØ×Ñ˜iÕ(r!   c                 óÂ   ^ • ST l         U 4S jn[        R                  " S[        5       5      nXl        UR                  S5        T R                  T R                   5        g)z¡
L{ConnectedDatagramPort} calls L{ConnectedDatagramPort.stopListening}
instead of the deprecated C{loseConnection} in
L{ConnectedDatagramPort.connectionFailed}.
Fc                  ó   >• ST l         g)z 
Dummy C{stopListening} method.
TN©Úcalledr8   s   €r   rv   ÚYConnectedDatagramPortTests.test_connectionFailedCallsStopListening.<locals>.stopListeningC  s   ø€ ð ˆD�Kr!   Nrá   )ré   r
   râ   r   rv   rã   Ú
assertTrue)r   rv   rx   s   `  r   Ú'test_connectionFailedCallsStopListeningÚBConnectedDatagramPortTests.test_connectionFailedCallsStopListening;  sK   ø€ ð ˆŒõ	ô ×)Ò)¨$´³Ó>ˆØ*ÔØ×Ñ˜iÔ(Ø�‰˜Ÿ™Õ$r!   rè   )
r)   r*   r+   r,   r-   ÚskipSocketsr|   rä   rì   r.   r(   r!   r   rÛ   rÛ   "  s   † ñð ÑØˆò)õ"%r!   rÛ   c                   ó   • \ rS rSrS rSrg)Ú
WakerTestsiO  c                 óê   • [        5       nU R                  5       nU R                  [        U5      SU5        UR	                  S5        U R                  5       nU R                  [        U5      SU5        g)z8
No warnings are generated when constructing the waker.
r   N)r   r   r$   r%   rt   )r   rT   r&   s      r   Ú test_noWakerConstructionWarningsÚ+WakerTests.test_noWakerConstructionWarningsP  sc   € ô “ˆà×%Ñ%Ó'ˆØ×Ñœ˜X›¨¨8Ô4ð 	×Ñ˜TÔ"Ø×%Ñ%Ó'ˆØ×Ñœ˜X›¨¨8Õ4r!   r(   N)r)   r*   r+   r,   rò   r.   r(   r!   r   rð   rð   O  s   † õ5r!   rð   ) r-   r   Útwisted.internet.deferr   Útwisted.internet.interfacesr   Útwisted.internet.posixbaser   r   Útwisted.internet.protocolr   Útwisted.python.runtimer   Útwisted.trial.unittestr	   rî   Útwisted.internetr
   Útwisted.test.test_unixr   ÚImportErrorr   Útwisted.internet.tcpr   r   r1   rP   rk   r~   r˜   rÛ   rð   r(   r!   r   Ú<module>rþ      sÀ   ðñó 
å +Ý 7ß ?Ý 3Ý +Ý +à€ð>Ý%Ý2õ %Ý %ô˜Xô ôD"Ð%ô "ô&-3Ð2ô -3ô`KÐ)ô Kô&* Ð+ô * ôZ_#Ð2ô _#ôD*%Ð!7ô *%ôZ5Ð'õ 5øðw	 ó >Ø=‚Kð>ús   °B! Â!B,Â+B,