ó
    Ö›‘h  ã                   óº  • S r SSKrSSKrSSK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KJ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   SSK!J"r"J#r#J$r$   \" \\5      RQ                  5         Sr)Sr* " S S\5      r. " S S\5      r/g! \% a    \RL                  S:X  a  e Sr' NNf = f! \+ a  r,Sr)\-" \,5      r* Sr,C,NKSr,C,ff = f)z,
Tests for L{twisted.internet.iocpreactor}.
é    N)Úarray)ÚAF_INETÚAF_INET6ÚSOCK_STREAMÚ
SOL_SOCKETÚsocket)Úpack)ÚskipIf)ÚverifyClass)ÚIPushProducer)Úmsg)ÚTestCase)ÚiocpsupportÚtcpÚudp)Ú
FileHandle)ÚSO_UPDATE_ACCEPT_CONTEXT)ÚIReadWriteHandle)ÚEVENTS_PER_LOOPÚ
KEY_NORMALÚIOCPReactorÚwin32z%This test only applies to IOCPReactorFÚ Tc                   óB   • \ rS rSrSrS rS r\" \\	5      S 5       r
Srg)ÚSupportTestsé1   zb
Tests for L{twisted.internet.iocpreactor.iocpsupport}, low-level reactor
implementation helpers.
c           
      ó  • [        SU< 35        [        U[        5      nU R                  UR                  5        UR                  S5        UR                  S5        [        U[        5      nU R                  UR                  5        UR                  S5         UR                  X#R                  5       S   45        [        U[        5      nU R                  UR                  5        [        SS5      nU R!                  S["        R$                  " UR'                  5       UR'                  5       US5      5        [)        [+        S	5      5       H7  n UR-                  [.        [0        [3        S
UR'                  5       5      5          O   U R!                  XR;                  5       SS UR                  5       SS 4["        R<                  " UR'                  5       U5      5        g! [         aE  nU R                  UR                  [        R                  [        R                  45         SnAGNoSnAff = f! [         a0  n	U	R                  [5        [        S5      :w  a  e US:X  a  e  Sn	A	OSn	A	ff = f[6        R8                  " S5        GM=  )a  
Create a C{SOCK_STREAM} connection to localhost using a socket with an
address family of C{family} and assert that the result of
L{iocpsupport.get_accept_addrs} is consistent with the result of
C{socket.getsockname} and C{socket.getpeername}.

A port starts listening (is bound) at the low-level socket without
calling accept() yet.
A client is then connected.
After the client is connected IOCP accept() is called, which is the
target of these tests.

Most of the time, the socket is ready instantly, but sometimes
the socket is not ready right away after calling IOCP accept().
It should not take more than 5 seconds for a socket to be ready, as
the client connection is already made over the loopback interface.

These are flaky tests.
Tweak the failure rate by changing the number of retries and the
wait/sleep between retries.

If you will need to update the retries to wait more than 5 seconds
for the port to be available, then there might a bug in the code and
not the test (or a very, very busy VM running the tests).
z	family = )r   r   é   FNÚBs                                                                                                                                                                                                                                                                   r   é   ÚPÚWSAENOTCONNgš™™™™™É?é   )r   r   r   Ú
addCleanupÚcloseÚbindÚlistenÚsetblockingÚconnectÚgetsocknameÚOSErrorÚassertInÚerrnoÚEINPROGRESSÚEWOULDBLOCKr   ÚassertEqualÚ_iocpÚacceptÚfilenoÚreversedÚrangeÚ
setsockoptr   r   r	   ÚgetattrÚtimeÚsleepÚgetpeernameÚget_accept_addrs)
ÚselfÚfamilyÚ	localhostÚportÚclientÚeÚserverÚbuffÚattemptsRemainingÚsocketErrors
             ÚcC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/internet/test/test_iocp.pyÚ_acceptAddressTestÚSupportTests._acceptAddressTest7   sû  € ô4 	ˆi˜‘zÐ"Ô#Ü�fœkÓ*ˆØ�‰˜Ÿ
™
Ô#Ø�	‰	�'ÔØ�‰�AŒÜ˜¤Ó,ˆØ�‰˜Ÿ™Ô%Ø×Ñ˜5Ô!ð	KØ�N‰N˜I×'7Ñ'7Ó'9¸!Ñ'<Ð=Ô>ô ˜¤Ó,ˆØ�‰˜Ÿ™Ô%Ü�S˜+Ó&ˆØ×Ñ˜œEŸLšL¨¯©«¸¿¹»ÈÈtÓTÔUä!)¬%°«(Ö!3ÐðØ×!Ñ!ÜÔ 8¼$¸sÀDÇKÁKÃMÓ:Rôñ ñ "4ðB 	×ÑØ×'Ñ'Ó)¨"¨1Ð-¨v×/AÑ/AÓ/CÀBÀQÐ/GÐHÜ×"Ò" 6§=¡=£?°DÓ9õ	
øôS ó 	KØ�M‰M˜!Ÿ'™'¤E×$5Ñ$5´u×7HÑ7HÐ#I×JÒJûð	Kûô0 ó 
à×$Ñ$¬´°}Ó(EÓEàð %¨Ó)àô *ûð
úô �JŠJ�s�Os0   Â#G" Å3H4Ç"
H1Ç,:H,È,H1È4
I.È>&I)É)I.c                 ó0   • U R                  [        S5        g)a¹  
L{iocpsupport.get_accept_addrs} returns a three-tuple of address
information about the socket associated with the file descriptor passed
to it.  For a connection using IPv4:

  - the first element is C{AF_INET}
  - the second element is a two-tuple of a dotted decimal notation IPv4
    address and a port number giving the peer address of the connection
  - the third element is the same type giving the host address of the
    connection
z	127.0.0.1N)rG   r   ©r<   s    rF   Útest_ipv4AcceptAddressÚ#SupportTests.test_ipv4AcceptAddress‰   s   € ð 	×Ñ¤¨Õ5ó    c                 ó0   • U R                  [        S5        g)aP  
Like L{test_ipv4AcceptAddress}, but for IPv6 connections.
In this case:

  - the first element is C{AF_INET6}
  - the second element is a two-tuple of a hexadecimal IPv6 address
    literal and a port number giving the peer address of the connection
  - the third element is the same type giving the host address of the
    connection
z::1N)rG   r   rJ   s    rF   Útest_ipv6AcceptAddressÚ#SupportTests.test_ipv6AcceptAddress—   s   € ð 	×Ñ¤¨%Õ0rM   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rG   rK   r
   Úipv6SkipÚipv6SkipReasonrO   Ú__static_attributes__rQ   rM   rF   r   r   1   s.   † ñò
P
òd6ñ ˆH�nÓ%ñ1ó &ó1rM   r   c                   ó,   • \ rS rSrS rS rS rS rSrg)ÚIOCPReactorTestsé¦   c                 óx   • [        5       nUR                  5         U R                  UR                  S5      5        g)zL
Test reactor behavior (doIteration) when there are no pending time
events.
N)r   ÚwakeUpÚassertFalseÚdoIteration)r<   Úirs     rF   Útest_noPendingTimerEventsÚ*IOCPReactorTests.test_noPendingTimerEvents§   s+   € ô
 ‹]ˆØ
�	‰	ŒØ×Ñ˜Ÿ™¨Ó-Õ.rM   c                 ó¸   • U R                  [        [        [        R                  5      5        U R                  [        [        [
        R                  5      5        g)zI
Verify that IOCP socket-representing classes implement IReadWriteHandle
N)Ú
assertTruer   r   r   Ú
Connectionr   ÚPortrJ   s    rF   Útest_reactorInterfacesÚ'IOCPReactorTests.test_reactorInterfaces°   s4   € ð 	�‰œÔ$4´c·n±nÓEÔFØ�‰œÔ$4´c·h±hÓ?Õ@rM   c                 óJ   • U R                  [        [        [        5      5        g)z8
Verify that L{Filehandle} implements L{IPushProducer}.
N)re   r   r   r   rJ   s    rF   Útest_fileHandleInterfacesÚ*IOCPReactorTests.test_fileHandleInterfaces·   s   € ð 	�‰œ¤M´:Ó>Õ?rM   c                 óº  •  " S S5      n[        5       nU" 5       n[        R                  " UR                  U5      n[	        [
        S-   5       H$  nUR                  R                  S[        U5        M&     UR                  S5        U R                  UR                  [
        5        UR                  S5        U R                  UR                  [
        S-   5        g)zn
Verify that we don't lose an event when more than EVENTS_PER_LOOP
events occur in the same reactor iteration
c                   ó$   • \ rS rSrSrS rS rSrg)Ú;IOCPReactorTests.test_maxEventsPerIteration.<locals>.FakeFDéÃ   r   c                 ó   • g)NÚFakeFDrQ   rJ   s    rF   Ú	logPrefixÚEIOCPReactorTests.test_maxEventsPerIteration.<locals>.FakeFD.logPrefixÆ   s   € ØrM   c                 ó.   • U =R                   S-  sl         g )Nr   )Úcounter)r<   ÚrcÚbytesÚevts       rF   ÚcbÚ>IOCPReactorTests.test_maxEventsPerIteration.<locals>.FakeFD.cbÉ   s   € Ø—’ Ñ!–rM   rQ   N)rR   rS   rT   rU   rv   rs   rz   rY   rQ   rM   rF   rr   ro   Ã   s   † ØˆGò õ"rM   rr   r   r   N)r   r1   ÚEventrz   r5   r   r?   Ú	postEventr   r`   r0   rv   )r<   rr   ra   ÚfdÚeventÚ_s         rF   Útest_maxEventsPerIterationÚ+IOCPReactorTests.test_maxEventsPerIteration½   sŸ   € ÷	"ñ 	"ô ‹]ˆÙ‹XˆÜ—’˜BŸE™E 2Ó&ˆÜ”¨Ñ*Ö+ˆAØ�G‰G×Ñ˜a¤¨UÖ3ñ ,à
�‰�tÔØ×Ñ˜Ÿ™¤_Ô5Ø
�‰�qÔØ×Ñ˜Ÿ™¤_°qÑ%8Õ9rM   rQ   N)	rR   rS   rT   rU   rb   rh   rk   r�   rY   rQ   rM   rF   r[   r[   ¦   s   † ò/òAò@õ:rM   r[   )0rV   r-   Úsysr8   r   r   r   r   r   r   Ústructr	   Úunittestr
   Úzope.interface.verifyr   Útwisted.internet.interfacesr   Útwisted.python.logr   Útwisted.trial.unittestr   Útwisted.internet.iocpreactorr   r1   r   r   Ú%twisted.internet.iocpreactor.abstractr   Ú"twisted.internet.iocpreactor.constr   Ú'twisted.internet.iocpreactor.interfacesr   Ú$twisted.internet.iocpreactor.reactorr   r   r   ÚImportErrorÚplatformÚskipr%   rW   rX   r+   rA   Ústrr   r[   rQ   rM   rF   Ú<module>r“      sÒ   ðñó Û 
Û Ý ß EÕ EÝ Ý å -å 5Ý "Ý +ð3ßKÑKÝ@ÝKÝH÷ñ ðÙ
ˆ8�[Ó!×'Ñ'Ô)ð €HØ€Nôr1�8ô r1ôj.:�xõ .:øðM ó 3Ø
‡|�|�wÓØà2‚Dð	3ûð ó Ø€HÙ˜“V…Nûðús*   Á&B! Á/C  Â!B=Â<B=Ã CÃ
CÃC