
    Yf                         d 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 n# e$ r dZY nw xY w G d	 d
          Z ee d           G d de
                      ZdS )z-
Tests for L{twisted.internet.epollreactor}.
    )skipIfConnectionDone)_ContinuousPolling)Clock)TestCase)epollreactorNc                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )
DescriptorzF
    Records reads and writes, as if it were a C{FileDescriptor}.
    c                     g | _         d S N)eventsselfs    Y/var/www/html/env/lib/python3.11/site-packages/twisted/internet/test/test_epollreactor.py__init__zDescriptor.__init__   s        c                     dS )N    r   s    r   filenozDescriptor.fileno   s    qr   c                 :    | j                             d           d S )Nreadr   appendr   s    r   doReadzDescriptor.doRead    s    6"""""r   c                 :    | j                             d           d S )Nwriter   r   s    r   doWritezDescriptor.doWrite#   s    7#####r   c                 n    |                     t                     | j                            d           d S )Nlost)trapr   r   r   )r   reasons     r   connectionLostzDescriptor.connectionLost&   s0    N###6"""""r   N)	__name__
__module____qualname____doc__r   r   r   r   r$   r   r   r   r   r      si             # # #$ $ $# # # # #r   r   z(epoll not supported in this environment.c                   `    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd ZdS )ContinuousPollingTestsza
    L{_ContinuousPolling} can be used to read and write from C{FileDescriptor}
    objects.
    c                    t          t                                }|                     |j                   t	                      }|                     |                    |                     |                    |           |                     |j                   | 	                    |j        j
                   |                     |j        j        |j                   | 	                    |                    |                     dS )zi
        Adding a reader when there was previously no reader starts up a
        C{LoopingCall}.
        N)r   r   assertIsNone_loopobjectassertFalse	isReading	addReaderassertIsNotNone
assertTruerunningassertIsclock_reactorr   pollerreaders      r   test_addReaderz%ContinuousPollingTests.test_addReader2       
 $EGG,,&,'''))&11222   V\***,---fl(&/:::((0011111r   c                    t          t                                }|                     |j                   t	                      }|                     |                    |                     |                    |           |                     |j                   | 	                    |j        j
                   |                     |j        j        |j                   | 	                    |                    |                     dS )zi
        Adding a writer when there was previously no writer starts up a
        C{LoopingCall}.
        N)r   r   r,   r-   r.   r/   	isWriting	addWriterr2   r3   r4   r5   r6   r7   r   r9   writers      r   test_addWriterz%ContinuousPollingTests.test_addWriterA   r<   r   c                    t          t                                }t                      }|                    |           |                    |           |                     |j                   |                     |j        	                                g            | 
                    |                    |                     dS )z=
        Removing a reader stops the C{LoopingCall}.
        N)r   r   r.   r1   removeReaderr,   r-   assertEqualr7   getDelayedCallsr/   r0   r8   s      r   test_removeReaderz(ContinuousPollingTests.test_removeReaderP        $EGG,,   F###&,'''88::B???))&1122222r   c                    t          t                                }t                      }|                    |           |                    |           |                     |j                   |                     |j        	                                g            | 
                    |                    |                     dS )z=
        Removing a writer stops the C{LoopingCall}.
        N)r   r   r.   r?   removeWriterr,   r-   rE   r7   rF   r/   r>   r@   s      r   test_removeWriterz(ContinuousPollingTests.test_removeWriter\   rH   r   c                     t          t                                }|                    t                                 |                    t                                 dS )zM
        Removing unknown readers and writers silently does nothing.
        N)r   r   rJ   r.   rD   )r   r9   s     r   test_removeUnknownz)ContinuousPollingTests.test_removeUnknownh   sK     $EGG,,FHH%%%FHH%%%%%r   c                    t          t                                }t                      }|                    |           |                     |j                   |                    t                                 |                     |j                   |                    t                                 |                     |j                   |                    t                                 |                    |           |                     |j                   |                     |j        j	                   | 
                    t          |j                                                  d           dS )za
        Adding multiple readers and writers results in a single
        C{LoopingCall}.
        r   N)r   r   r.   r?   r2   r-   r1   rJ   r3   r4   rE   lenr7   rF   r@   s      r   test_multipleReadersAndWritersz5ContinuousPollingTests.test_multipleReadersAndWritersp   s/   
 $EGG,,   V\***"""V\***"""V\***"""F###V\***,---V_<<>>??CCCCCr   c                    t                      }t          |          }t                      }|                    |           |                     |j        g            |                    d           |                     |j        dg           |                    d           |                     |j        ddg           |                    d           |                     |j        g d           dS )za
        Adding a reader causes its C{doRead} to be called every 1
        milliseconds.
        gh㈵>r   )r   r   r   N)r   r   r   r1   rE   r   advancer   reactorr9   descs       r   test_readerPollingz)ContinuousPollingTests.test_readerPolling   s    
 ''#G,,||b)))   vh///   vv&6777   &>&>&>?????r   c                    t                      }t          |          }t                      }|                    |           |                     |j        g            |                    d           |                     |j        dg           |                    d           |                     |j        ddg           |                    d           |                     |j        g d           dS )zb
        Adding a writer causes its C{doWrite} to be called every 1
        milliseconds.
        MbP?r   )r   r   r   N)r   r   r   r?   rE   r   rR   rS   s       r   test_writerPollingz)ContinuousPollingTests.test_writerPolling   s    
 ''#G,,||b)))wi000w&8999&A&A&ABBBBBr   c                 .   t                      }t          |          }t                      }d |_        |                    |           |                     |j        g            |                    d           |                     |j        dg           dS )zu
        If a C{doRead} returns a value indicating disconnection,
        C{connectionLost} is called on it.
        c                      t                      S r   r   r   r   r   <lambda>zBContinuousPollingTests.test_connectionLostOnRead.<locals>.<lambda>   s    n.. r   rX   r!   N)r   r   r   r   r1   rE   r   rR   rS   s       r   test_connectionLostOnReadz0ContinuousPollingTests.test_connectionLostOnRead   s    
 ''#G,,||..b)))vh/////r   c                 .   t                      }t          |          }t                      }d |_        |                    |           |                     |j        g            |                    d           |                     |j        dg           dS )zv
        If a C{doWrite} returns a value indicating disconnection,
        C{connectionLost} is called on it.
        c                      t                      S r   r   r   r   r   r\   zCContinuousPollingTests.test_connectionLostOnWrite.<locals>.<lambda>   s    ~// r   rX   r!   N)r   r   r   r   r?   rE   r   rR   rS   s       r   test_connectionLostOnWritez1ContinuousPollingTests.test_connectionLostOnWrite   s    
 ''#G,,||//b)))vh/////r   c                    t          t                                }t                      }t                      }t                      }|                    |           |                    |           |                    |           |                    |           |                                }|                     |                                g            |                     |                                g            |                     t          |          d           |                     t          |          |||h           dS )zv
        L{_ContinuousPolling.removeAll} removes all descriptors and returns
        the readers and writers.
           N)r   r   r.   r1   r?   	removeAllrE   
getReaders
getWritersrO   set)r   r9   r:   rA   bothremoveds         r   test_removeAllz%ContinuousPollingTests.test_removeAll   s   
 $EGG,,xx      ""$$**,,b111**,,b111Wq)))W'=>>>>>r   c                     t          t                                }t                      }|                    |           |                     ||                                           dS )zb
        L{_ContinuousPolling.getReaders} returns a list of the read
        descriptors.
        N)r   r   r.   r1   assertInrd   r8   s      r   test_getReadersz&ContinuousPollingTests.test_getReaders   X    
 $EGG,,   ff//1122222r   c                     t          t                                }t                      }|                    |           |                     ||                                           dS )zc
        L{_ContinuousPolling.getWriters} returns a list of the write
        descriptors.
        N)r   r   r.   r?   rk   re   r@   s      r   test_getWritersz&ContinuousPollingTests.test_getWriters   rm   r   N)r%   r&   r'   r(   r;   rB   rG   rK   rM   rP   rV   rY   r]   r`   ri   rl   ro   r   r   r   r*   r*   +   s         
2 2 22 2 2
3 
3 
3
3 
3 
3& & &D D D&@ @ @"C C C"0 0 00 0 0? ? ?&3 3 33 3 3 3 3r   r*   )r(   unittestr   twisted.internet.errorr   twisted.internet.posixbaser   twisted.internet.taskr   twisted.trial.unittestr   twisted.internetr	   ImportErrorr   r*   r   r   r   <module>rw      s-          1 1 1 1 1 1 9 9 9 9 9 9 ' ' ' ' ' ' + + + + + +-------   LLL# # # # # # # #, LDEEz3 z3 z3 z3 z3X z3 z3 FEz3 z3 z3s   ) 33