Ë
    oj1  ã                   óê   — d Z 	 ddl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  G d	„ d
«      Z G d„ de
«      Z e«       j'                  ej)                  «       «       y# e$ r dZY Œiw xY w)z6
Tests for implementations of L{IReactorWin32Events}.
é    N)ÚverifyObject)ÚDeferred)ÚIReactorWin32Events)ÚReactorBuilder)ÚFailure)ÚgetThreadIDÚisInIOThreadc                   óD   — e Zd ZdZdZdxZxZZd„ Zd„ Z	d„ Z
d„ Zd„ Zd	„ Zy)
ÚListeneraÔ  
    L{Listener} is an object that can be added to a L{IReactorWin32Events}
    reactor to receive callback notification when a Windows event is set.  It
    records what thread its callback is invoked in and fires a Deferred.

    @ivar success: A flag which is set to C{True} when the event callback is
        called.

    @ivar logThreadID: The id of the thread in which the C{logPrefix} method is
        called.

    @ivar eventThreadID: The id of the thread in which the event callback is
        called.

    @ivar connLostThreadID: The id of the thread in which the C{connectionLost}
        method is called.

    @ivar _finished: The L{Deferred} which will be fired when the event callback
        is called.
    FNc                 ó   — || _         y ©N)Ú	_finished)ÚselfÚfinisheds     úH/usr/lib/python3/dist-packages/twisted/internet/test/test_win32events.pyÚ__init__zListener.__init__/   s	   € Ø!ˆ�ó    c                 ó"   — t        «       | _        y)Nr   )r   ÚlogThreadID©r   s    r   Ú	logPrefixzListener.logPrefix2   s   € Ü&›=ˆÔØr   c                 óf   — d| _         t        «       | _        | j                  j	                  d «       y )NT)Úsuccessr   ÚeventThreadIDr   Úcallbackr   s    r   ÚoccurredzListener.occurred6   s%   € ØˆŒÜ(›]ˆÔØ�‰×Ñ Õ%r   c                 ó   — t        d«      ‚)NzSome problem)ÚRuntimeErrorr   s    r   ÚbrokenOccurredzListener.brokenOccurred;   s   € Ü˜>Ó*Ð*r   c                 ó   — t        d«      S )NzEntirely different problem)ÚEnvironmentErrorr   s    r   ÚreturnValueOccurredzListener.returnValueOccurred>   s   € ÜÐ <Ó=Ð=r   c                 óX   — t        «       | _        | j                  j                  |«       y r   )r   ÚconnLostThreadIDr   Úerrback)r   Úreasons     r   ÚconnectionLostzListener.connectionLostA   s   € Ü +£ˆÔØ�‰×Ñ˜vÕ&r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r$   r   r   r   r   r"   r'   © r   r   r   r      s<   „ ñð* €GØ59Ð9€KÐ9�-Ð"2ò"òò&ò
+ò>ó'r   r   c                   ó:   — e Zd ZdZegZd„ Zd„ Zd„ Zd„ Z	d„ Z
d„ Zy)	ÚWin32EventsTestsBuilderzD
    Builder defining tests relating to L{IReactorWin32Events}.
    c                 óD   — | j                  «       }t        t        |«       y)zn
        An instance of the reactor has all of the methods defined on
        L{IReactorWin32Events}.
        N)ÚbuildReactorr   r   )r   Úreactors     r   Útest_interfacez&Win32EventsTestsBuilder.test_interfaceM   s   € ð
 ×#Ñ#Ó%ˆÜÔ(¨'Õ2r   c                 óê  ‡— t        «       }| j                  «       Št        j                  dddd«      }t	        «       }|j                  ˆfd„«       t        |«      }‰j                  ||d«       ‰j                  t        j                  |«       | j                  ‰«       | j                  |j                  «       | j                  ||j                  «       | j                  ||j                  «       y)zš
        When an event which has been added to the reactor is set, the action
        associated with the event is invoked in the reactor thread.
        NFc                 ó$   •— ‰j                  «       S r   ©Ústop©Úignoredr1   s    €r   ú<lambda>z7Win32EventsTestsBuilder.test_addEvent.<locals>.<lambda>^   s   ø€ ¨W¯\©\«^€ r   r   )r   r0   Ú
win32eventÚCreateEventr   ÚaddCallbackr   ÚaddEventÚcallWhenRunningÚSetEventÚ
runReactorÚ
assertTruer   ÚassertEqualr   r   )r   ÚreactorThreadIDÚeventr   Úlistenerr1   s        @r   Útest_addEventz%Win32EventsTestsBuilder.test_addEventU   sÂ   ø€ ô
 &›-ˆØ×#Ñ#Ó%ˆÜ×&Ñ& t¨U°E¸4Ó@ˆÜ“:ˆØ×ÑÓ;Ô<Ü˜HÓ%ˆØ×Ñ˜ ¨*Ô5Ø×Ñ¤
× 3Ñ 3°UÔ;Ø�‰˜Ô Ø�‰˜×(Ñ(Ô)Ø×Ñ˜¨(×*>Ñ*>Ô?Ø×Ñ˜¨(×*@Ñ*@ÕAr   c                 ó˜  ‡‡— g Šˆˆfd„}| j                  «       Št        j                  dddd«      }t        «       }t	        |«      }|j                  |«       ‰j                  ||d«       ‰j                  t        j                  |«       | j                  ‰«       | j                  |j                  «       | j                  dg‰«       y)z{
        Using L{IReactorWin32Events.addEvent} does not change which thread is
        reported as the I/O thread.
        c                 óX   •— ‰j                  t        «       «       ‰j                  «        y r   )Úappendr	   r6   )r8   r1   Úresultss    €€r   ÚcheckzAWin32EventsTestsBuilder.test_ioThreadDoesNotChange.<locals>.checkn   s   ø€ Ø�N‰Nœ<›>Ô*Ø�L‰L�Nr   NFr   T)r0   r:   r;   r   r   r<   r=   r>   r?   r@   rA   r   rB   )r   rK   rD   r   rE   r1   rJ   s        @@r   Útest_ioThreadDoesNotChangez2Win32EventsTestsBuilder.test_ioThreadDoesNotChangeg   s¬   ù€ ð
 ˆõ	ð ×#Ñ#Ó%ˆÜ×&Ñ& t¨U°E¸4Ó@ˆÜ“:ˆÜ˜HÓ%ˆØ×Ñ˜UÔ#Ø×Ñ˜ ¨*Ô5Ø×Ñ¤
× 3Ñ 3°UÔ;Ø�‰˜Ô Ø�‰˜×(Ñ(Ô)Ø×Ñ˜$˜ Õ)r   c                 ót  ‡— t        «       }| j                  «       Št        j                  dddd«      }g }t	        «       }|j                  |j                  «       |j                  ˆfd„«       t        |«      }‰j                  ||d«       ‰j                  t        j                  |«       | j                  ‰«       | j                  |d   t        «       |d   j                  t        «       | j!                  ||j"                  «       | j!                  dt%        | j'                  t        «      «      «       y)zÕ
        If the event handler raises an exception, the event is removed from the
        reactor and the handler's C{connectionLost} method is called in the I/O
        thread and the exception is logged.
        NFc                 ó$   •— ‰j                  «       S r   r5   r7   s    €r   r9   zBWin32EventsTestsBuilder.test_disconnectedOnError.<locals>.<lambda>Š   ó   ø€ ¨¯©«€ r   r   r   é   )r   r0   r:   r;   r   ÚaddBothrI   r   r=   r>   r?   r@   ÚassertIsInstancer   Útrapr   rB   r$   ÚlenÚflushLoggedErrors©r   rC   rD   Úresultr   rE   r1   s         @r   Útest_disconnectedOnErrorz0Win32EventsTestsBuilder.test_disconnectedOnError}   sö   ø€ ô &›-ˆØ×#Ñ#Ó%ˆÜ×&Ñ& t¨U°E¸4Ó@ˆàˆÜ“:ˆØ×Ñ˜Ÿ™Ô'Ø×ÑÓ7Ô8ä˜HÓ%ˆØ×Ñ˜ Ð*:Ô;Ø×Ñ¤
× 3Ñ 3°UÔ;Ø�‰˜Ô à×Ñ˜f Q™i¬Ô1Øˆq‰	�‰”|Ô$à×Ñ˜¨(×*CÑ*CÔDØ×Ñ˜œC × 6Ñ 6´|Ó DÓEÕFr   c                 ó  ‡— t        «       }| j                  «       Št        j                  dddd«      }g }t	        «       }|j                  |j                  «       |j                  ˆfd„«       t        |«      }‰j                  ||d«       ‰j                  t        j                  |«       | j                  ‰«       | j                  |d   t        «       |d   j                  t        «       | j!                  ||j"                  «       y)zµ
        If the event handler returns a value, the event is removed from the
        reactor and the handler's C{connectionLost} method is called in the I/O
        thread.
        NFc                 ó$   •— ‰j                  «       S r   r5   r7   s    €r   r9   zFWin32EventsTestsBuilder.test_disconnectOnReturnValue.<locals>.<lambda>¤   rO   r   r"   r   )r   r0   r:   r;   r   rQ   rI   r   r=   r>   r?   r@   rR   r   rS   r!   rB   r$   rV   s         @r   Útest_disconnectOnReturnValuez4Win32EventsTestsBuilder.test_disconnectOnReturnValue—   s×   ø€ ô &›-ˆØ×#Ñ#Ó%ˆÜ×&Ñ& t¨U°E¸4Ó@ˆàˆÜ“:ˆØ×Ñ˜Ÿ™Ô'Ø×ÑÓ7Ô8ä˜HÓ%ˆØ×Ñ˜ Ð*?Ô@Ø×Ñ¤
× 3Ñ 3°UÔ;Ø�‰˜Ô à×Ñ˜f Q™i¬Ô1Øˆq‰	�‰Ô'Ô(à×Ñ˜¨(×*CÑ*CÕDr   c                 ó2  — | j                  «       }t        j                  dddd«      }t        «       }t	        |«      }|j                  ||d«       |j                  |j                  «       | j                  |«       | j                  |j                  «       y)z¾
        Event handlers added with L{IReactorWin32Events.addEvent} do not have
        C{connectionLost} called on them if they are still active when the
        reactor shuts down.
        NFr   )r0   r:   r;   r   r   r=   r>   r6   r@   ÚassertIsNoner$   )r   r1   rD   r   rE   s        r   Útest_notDisconnectedOnShutdownz6Win32EventsTestsBuilder.test_notDisconnectedOnShutdown°   s}   € ð ×#Ñ#Ó%ˆÜ×&Ñ& t¨U°E¸4Ó@ˆÜ“:ˆÜ˜HÓ%ˆØ×Ñ˜ ¨*Ô5Ø×Ñ §¡Ô-Ø�‰˜Ô Ø×Ñ˜(×3Ñ3Õ4r   N)r(   r)   r*   r+   r   ÚrequiredInterfacesr2   rF   rL   rX   r[   r^   r,   r   r   r.   r.   F   s3   „ ñð .Ð.Ðò3òBò$*ò,Gò4Eó25r   r.   )r+   r:   ÚImportErrorÚzope.interface.verifyr   Útwisted.internet.deferr   Útwisted.internet.interfacesr   Ú#twisted.internet.test.reactormixinsr   Útwisted.python.failurer   Útwisted.python.threadabler   r	   r   r.   ÚglobalsÚupdateÚmakeTestCaseClassesr,   r   r   ú<module>rj      ss   ðñðÛõ /å +Ý ;Ý >Ý *ß ?÷-'ñ -'ô`w5˜nô w5ñt ƒ	× Ñ Ð(×<Ñ<Ó>Õ ?øðm ò Ø‚Jðús   „A( Á(A2Á1A2