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: //lib/python3/dist-packages/twisted/internet/test/__pycache__/test_stdio.cpython-38.pyc
U


W[1�@spdZddlmZmZddlmZddlmZddlm	Z	e�
�sLddlmZGdd�de�Z
e��e
���d	S)
z&
Tests for L{twisted.internet.stdio}.
�)�absolute_import�division)�platform)�ReactorBuilder)�Protocol)�
StandardIOc@s\eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Ze�
�rXdZdS)�StdioFilesTestszI
    L{StandardIO} supports reading and writing to filesystem files.
    cCs4|��}t|d���t|d�|_|�|jj�dS)N�wbzrb+)�mktemp�open�close�	extraFile�
addCleanup)�self�path�r�B/usr/lib/python3/dist-packages/twisted/internet/test/test_stdio.py�setUpszStdioFilesTests.setUpc	s�|���G�fdd�dt�}|��}t|d��}|�d�W5QRXt|d��0}|�}t||��|j���d�|���W5QRX|�	|j
d�dS)zc
        Adding a filesystem file reader to a reactor will make sure it is
        polled.
        cseZdZdZ�fdd�ZdS)z4StdioFilesTests.test_addReader.<locals>.DataProtocol�cs$|j|7_|jdkr ���dS)N�hello!)�data�stop)rr��reactorrr�dataReceived(s
zAStdioFilesTests.test_addReader.<locals>.DataProtocol.dataReceivedN)�__name__�
__module__�__qualname__rrrrrr�DataProtocol&srr	r�rb��stdin�stdoutrN)�buildReactorrr
r�writer�filenor
�
runReactor�assertEqualr)rrr�f�protocolrrr�test_addReaders

�zStdioFilesTests.test_addReaderc	s�|���G�fdd�dt�}|��}t|d��R}|�}t||��|j���d�|j�d�|j�d�|j�	�|�
��W5QRXt|d��}|�|��d�W5QRXd	S)
zc
        Adding a filesystem file writer to a reactor will make sure it is
        polled.
        cseZdZ�fdd�ZdS)z:StdioFilesTests.test_addWriter.<locals>.DisconnectProtocolcs���dS)N)r)r�reasonrrr�connectionLostHszIStdioFilesTests.test_addWriter.<locals>.DisconnectProtocol.connectionLostN)rrrr,rrrr�DisconnectProtocolGsr-r	�r"r!r�hellos, worldrshello, worldN)
r#rr
rrr%r
�	transportr$ZloseConnectionr&r'�read)rr-rr(r)rrr�test_addWriter@s
�
zStdioFilesTests.test_addWriterc	Cs�|��}|�|j|�|��}t|d���t|d��P}tt�|��|j	��|d�}|�
|j|���|j�
�|�|j|���W5QRXdS)zq
        Removing a filesystem file reader from a reactor will make sure it is
        no longer polled.
        r	rr N)r#r�unbuildReactorr
rrrrr%r
�assertIn�_reader�
getReadersZstopReading�assertNotIn�rrrr(�stdiorrr�test_removeReader]s�
z!StdioFilesTests.test_removeReadercCs�|��}|�|j|�t|��d�|_}t�}t||��|j	��|d�}|j
�d�|�|j
|���|j
��|�|j
|���dS)zq
        Removing a filesystem file writer from a reactor will make sure it is
        no longer polled.
        r	r.r/N)r#rr3rr
r(rrr%r
r0r$r4�_writer�
getWritersZstopWritingr7)rrr(r)r9rrr�test_removeWriterrs
�
z!StdioFilesTests.test_removeWritercCs�|��}|�|j|�|��}t|d���t|d�|_}tt�|�	�|j
�	�|d�}|��}|�|j
|�|�|j
|���dS)zk
        Calling C{removeAll} on a reactor includes descriptors that are
        filesystem files.
        r	rr N)r#rr3r
rrr(rrr%r
Z	removeAllr4r5r7r6)rrrr(r9Zremovedrrr�test_removeAll�s�zStdioFilesTests.test_removeAllc	Cst|��}|�|j|�|��}t|d���t|d��4}tt�|��|j	��|d�}|�
|j|���W5QRXdS)zW
        C{reactor.getReaders} includes descriptors that are filesystem files.
        r	rr N)
r#rr3r
rrrrr%r
r4r5r6r8rrr�test_getReaders�s�zStdioFilesTests.test_getReaderscCsx|��}|�|j|�t|��d�|_}tt�|��|j	��|d�}|�
|j|���|j�
�|�|j|���dS)zW
        C{reactor.getWriters} includes descriptors that are filesystem files.
        r	r.N)r#rr3rr
r(rrr%r
r7r;r<ZstartWritingr4)rrr(r9rrr�test_getWriters�s�
zStdioFilesTests.test_getWriterszoStandardIO does not accept stdout as an argument to Windows. Testing redirection to a file is therefore harder.N)rrr�__doc__rr*r2r:r=r>r?r@r�	isWindows�skiprrrrrs!rN)rAZ
__future__rrZtwisted.python.runtimerZ#twisted.internet.test.reactormixinsrZtwisted.internet.protocolrrBZtwisted.internet.stdiorr�globals�updateZmakeTestCaseClassesrrrr�<module>s5