o
    ¼>h·  ã                   @   s`   d Z ddlmZ ddlmZ ddlmZ e ¡ sddlm	Z	 G dd„ deƒZ
eƒ  e
 ¡ ¡ dS )	z&
Tests for L{twisted.internet.stdio}.
é    )ÚProtocol)ÚReactorBuilder)Úplatform)Ú
StandardIOc                   @   s`   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Ze ¡ r.dZdS dS )ÚStdioFilesTestszI
    L{StandardIO} supports reading and writing to filesystem files.
    c                 C   s4   |   ¡ }t|dƒ ¡  t|dƒ| _|  | jj¡ d S )NÚwbzrb+)ÚmktempÚopenÚcloseÚ	extraFileÚ
addCleanup)ÚselfÚpath© r   ú€/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/internet/test/test_stdio.pyÚsetUp   s   zStdioFilesTests.setUpc                    s¾   |   ¡ ‰ G ‡ fdd„dtƒ}|  ¡ }t|dƒ}| d¡ W d  ƒ n1 s'w   Y  t|dƒ}|ƒ }t|| ¡ | j ¡ ˆ d |  ˆ ¡ W d  ƒ n1 sQw   Y  |  	|j
d¡ dS )zc
        Adding a filesystem file reader to a reactor will make sure it is
        polled.
        c                       s   e Zd ZdZ‡ fdd„ZdS )z4StdioFilesTests.test_addReader.<locals>.DataProtocoló    c                    s(   |  j |7  _ | j dkrˆ  ¡  d S d S )Nó   hello!)ÚdataÚstop)r   r   ©Úreactorr   r   ÚdataReceived&   s   
ÿzAStdioFilesTests.test_addReader.<locals>.DataProtocol.dataReceivedN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   ÚDataProtocol#   s    r   r   r   NÚrb©ÚstdinÚstdoutr   )ÚbuildReactorr   r   r	   Úwriter   Úfilenor   Ú
runReactorÚassertEqualr   )r   r   r   ÚfÚprotocolr   r   r   Útest_addReader   s"   ÿü÷zStdioFilesTests.test_addReaderc                    sÚ   |   ¡ ‰ G ‡ fdd„dtƒ}|  ¡ }t|dƒ.}|ƒ }t|| ¡ | j ¡ ˆ d |j d¡ |j d¡ |j 	¡  |  
ˆ ¡ W d  ƒ n1 sHw   Y  t|dƒ}|  | ¡ d	¡ W d  ƒ dS 1 sfw   Y  dS )
zc
        Adding a filesystem file writer to a reactor will make sure it is
        polled.
        c                       s   e Zd Z‡ fdd„ZdS )z:StdioFilesTests.test_addWriter.<locals>.DisconnectProtocolc                    s   ˆ   ¡  d S )N)r   )r   Úreasonr   r   r   ÚconnectionLostH   s   zIStdioFilesTests.test_addWriter.<locals>.DisconnectProtocol.connectionLostN)r   r   r   r*   r   r   r   r   ÚDisconnectProtocolG   s    r+   r   ©r    r   r   ó   hellos   , worldNr   s   hello, world)r!   r   r   r	   r   r#   r   Ú	transportr"   ÚloseConnectionr$   r%   Úread)r   r+   r   r&   r'   r   r   r   Útest_addWriter@   s&   ü
ò"ÿzStdioFilesTests.test_addWriterc                 C   s˜   |   ¡ }|  ¡ }t|dƒ ¡  t|dƒ.}ttƒ | ¡ | j ¡ |d}|  |j	| 
¡ ¡ |j	 ¡  |  |j	| 
¡ ¡ W d  ƒ dS 1 sEw   Y  dS )zq
        Removing a filesystem file reader from a reactor will make sure it is
        no longer polled.
        r   r   r   N)r!   r   r	   r
   r   r   r#   r   ÚassertInÚ_readerÚ
getReadersÚstopReadingÚassertNotIn©r   r   r   r&   Ústdior   r   r   Útest_removeReader`   s   ü
"öz!StdioFilesTests.test_removeReaderc                 C   sz   |   ¡ }t|  ¡ dƒ | _}tƒ }t|| ¡ | j ¡ |d}|j 	d¡ |  
|j| ¡ ¡ |j ¡  |  |j| ¡ ¡ dS )zq
        Removing a filesystem file writer from a reactor will make sure it is
        no longer polled.
        r   r,   r-   N)r!   r	   r   r&   r   r   r#   r   r.   r"   r2   Ú_writerÚ
getWritersÚstopWritingr6   )r   r   r&   r'   r8   r   r   r   Útest_removeWriterv   s   ÿ
z!StdioFilesTests.test_removeWriterc                 C   sv   |   ¡ }|  ¡ }t|dƒ ¡  t|dƒ | _}ttƒ | ¡ | j ¡ |d}| 	¡ }|  
|j|¡ |  |j| ¡ ¡ dS )zk
        Calling C{removeAll} on a reactor includes descriptors that are
        filesystem files.
        r   r   r   N)r!   r   r	   r
   r&   r   r   r#   r   Ú	removeAllr2   r3   r6   r4   )r   r   r   r&   r8   Úremovedr   r   r   Útest_removeAllŠ   s   üzStdioFilesTests.test_removeAllc                 C   s|   |   ¡ }|  ¡ }t|dƒ ¡  t|dƒ }ttƒ | ¡ | j ¡ |d}|  |j	| 
¡ ¡ W d  ƒ dS 1 s7w   Y  dS )zW
        C{reactor.getReaders} includes descriptors that are filesystem files.
        r   r   r   N)r!   r   r	   r
   r   r   r#   r   r2   r3   r4   r7   r   r   r   Útest_getReaders£   s   ü"øzStdioFilesTests.test_getReadersc                 C   sj   |   ¡ }t|  ¡ dƒ | _}ttƒ | ¡ | j ¡ |d}|  |j	| 
¡ ¡ |j	 ¡  |  |j	| 
¡ ¡ dS )zW
        C{reactor.getWriters} includes descriptors that are filesystem files.
        r   r,   N)r!   r	   r   r&   r   r   r#   r   r6   r:   r;   ÚstartWritingr2   )r   r   r&   r8   r   r   r   Útest_getWriters·   s   ü
zStdioFilesTests.test_getWriterszoStandardIO does not accept stdout as an argument to Windows. Testing redirection to a file is therefore harder.N)r   r   r   Ú__doc__r   r(   r1   r9   r=   r@   rA   rC   r   Ú	isWindowsÚskipr   r   r   r   r      s    $ ÿÿr   N)rD   Útwisted.internet.protocolr   Ú#twisted.internet.test.reactormixinsr   Útwisted.python.runtimer   rE   Útwisted.internet.stdior   r   ÚglobalsÚupdateÚmakeTestCaseClassesr   r   r   r   Ú<module>   s    B