HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/internet/test/__pycache__/test_win32events.cpython-38.pyc
U


W[d�@s�dZzddlZWnek
r(dZYnXddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZdd	lmZGd
d�de�ZGdd
�d
e�Ze��e���dS)z6
Tests for implementations of L{IReactorWin32Events}.
�N)�verifyObject)�Failure)�isInIOThread)�IReactorWin32Events)�Deferred)�ReactorBuilder)�getThreadIDc@sPeZdZdZdZdZZZdd�Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dS)�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.
    FNcCs
||_dS�N)�	_finished)�self�finished�r�H/usr/lib/python3/dist-packages/twisted/internet/test/test_win32events.py�__init__/szListener.__init__cCst�|_dS)Nr	)r�logThreadID�rrrr�	logPrefix3szListener.logPrefixcCsd|_t�|_|j�d�dS)NT)�successr�
eventThreadIDr�callbackrrrr�occurred8szListener.occurredcCstd��dS)NzSome problem)�RuntimeErrorrrrr�brokenOccurred>szListener.brokenOccurredcCstd�S)NzEntirely different problem)�EnvironmentErrorrrrr�returnValueOccurredBszListener.returnValueOccurredcCst�|_|j�|�dSr
)r�connLostThreadIDrZerrback)r�reasonrrr�connectionLostFszListener.connectionLost)�__name__�
__module__�__qualname__�__doc__rrrrrrrrrrrrrrr	sr	c@sFeZdZdZegZdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�ZdS)�Win32EventsTestsBuilderzD
    Builder defining tests relating to L{IReactorWin32Events}.
    cCs|��}tt|�dS)zn
        An instance of the reactor has all of the methods defined on
        L{IReactorWin32Events}.
        N)�buildReactorrr)r�reactorrrr�test_interfaceRsz&Win32EventsTestsBuilder.test_interfacecs�t�}|���t�dddd�}t�}|��fdd��t|�}��||d���tj	|�|�
��|�|j�|�
||j�|�
||j�dS)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.
        NFcs���Sr
��stop�Zignored�r%rr�<lambda>d�z7Win32EventsTestsBuilder.test_addEvent.<locals>.<lambda>r)rr$�
win32event�CreateEventr�addCallbackr	�addEvent�callWhenRunning�SetEvent�
runReactor�
assertTruer�assertEqualrr)r�reactorThreadID�eventr
�listenerrr*r�
test_addEvent[s
z%Win32EventsTestsBuilder.test_addEventcs�g���fdd�}|���t�dddd�}t�}t|�}|�|���||d���tj|�|�	��|�
|j�|�dg��dS)z{
        Using L{IReactorWin32Events.addEvent} does not change which thread is
        reported as the I/O thread.
        cs��t�����dSr
)�appendrr(r)�r%Zresultsrr�checktszAWin32EventsTestsBuilder.test_ioThreadDoesNotChange.<locals>.checkNFrT)
r$r-r.rr	r/r0r1r2r3r4rr5)rr<r7r
r8rr;r�test_ioThreadDoesNotChangens

z2Win32EventsTestsBuilder.test_ioThreadDoesNotChangecs�t�}|���t�dddd�}g}t�}|�|j�|��fdd��t|�}��||d���	tj
|�|���|�|dt
�|d�t�|�||j�|�dt|�t���dS)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.
        NFcs���Sr
r'r)r*rrr+�r,zBWin32EventsTestsBuilder.test_disconnectedOnError.<locals>.<lambda>rr�)rr$r-r.r�addBothr:r	r0r1r2r3�assertIsInstancer�traprr5r�lenZflushLoggedErrors�rr6r7�resultr
r8rr*r�test_disconnectedOnError�s
z0Win32EventsTestsBuilder.test_disconnectedOnErrorcs�t�}|���t�dddd�}g}t�}|�|j�|��fdd��t|�}��||d���	tj
|�|���|�|dt
�|d�t�|�||j�dS)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.
        NFcs���Sr
r'r)r*rrr+�r,zFWin32EventsTestsBuilder.test_disconnectOnReturnValue.<locals>.<lambda>rr)rr$r-r.rr?r:r	r0r1r2r3r@rrArr5rrCrr*r�test_disconnectOnReturnValue�s
z4Win32EventsTestsBuilder.test_disconnectOnReturnValuecCsZ|��}t�dddd�}t�}t|�}|�||d�|�|j�|�|�|�	|j
�dS)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)r$r-r.rr	r0r1r(r3ZassertIsNoner)rr%r7r
r8rrr�test_notDisconnectedOnShutdown�s
z6Win32EventsTestsBuilder.test_notDisconnectedOnShutdownN)rr r!r"rZrequiredInterfacesr&r9r=rErFrGrrrrr#Ls	r#)r"r-�ImportErrorZzope.interface.verifyrZtwisted.python.failurerZtwisted.python.threadablerZtwisted.internet.interfacesrZtwisted.internet.deferrZ#twisted.internet.test.reactormixinsrr�objectr	r#�globals�updateZmakeTestCaseClassesrrrr�<module>s
5{