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/test/__pycache__/test_fdesc.cpython-38.pyc
U

��W[��@s�dZddlZddlZddlZzddlZWnek
r@dZYnXddlmZddl	m
Z
ddlmZGdd�dej
�ZGd	d
�d
ej
�ZGdd�dej
�ZdS)
z&
Tests for L{twisted.internet.fdesc}.
�Nznot supported on this platform)�fdesc)�untilConcludes)�unittestc@s eZdZdZdd�Zdd�ZdS)�NonBlockingTestszE
    Tests for L{fdesc.setNonBlocking} and L{fdesc.setBlocking}.
    cCsjt��\}}|�tj|�|�tj|�|�t�|tj�tj@�t�	|�|�
t�|tj�tj@�dS)zR
        L{fdesc.setNonBlocking} sets a file description to non-blocking.
        N)�os�pipe�
addCleanup�close�assertFalse�fcntl�F_GETFL�
O_NONBLOCKr�setNonBlocking�
assertTrue��self�r�w�r�9/usr/lib/python3/dist-packages/twisted/test/test_fdesc.py�test_setNonBlockings
z$NonBlockingTests.test_setNonBlockingcCsZt��\}}|�tj|�|�tj|�t�|�t�|�|�t�|tj	�tj
@�dS)zK
        L{fdesc.setBlocking} sets a file description to blocking.
        N)rrrr	rrZsetBlockingr
rrr
rrrr�test_setBlocking(s

z!NonBlockingTests.test_setBlockingN)�__name__�
__module__�__qualname__�__doc__rrrrrrrsrc@speZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�ReadWriteTestsz<
    Tests for L{fdesc.readFromFD}, L{fdesc.writeToFD}.
    cCs,t��\|_|_t�|j�t�|j�dS)zG
        Create a non-blocking pipe that can be used in tests.
        N)rrrrrr�rrrr�setUp:szReadWriteTests.setUpcCsPzt�|j�Wntk
r$YnXzt�|j�Wntk
rJYnXdS)z
        Close pipes.
        N)rr	r�OSErrorrrrrr�tearDownCszReadWriteTests.tearDowncCst�|j|�S)z)
        Write data to the pipe.
        )rZ	writeToFDr)r�drrr�writeQszReadWriteTests.writecCs6g}t�|j|j�}|dkr.|r(|dSdSn|SdS)z*
        Read data from the pipe.
        Nr�)r�
readFromFDr�append)r�l�resrrr�readXszReadWriteTests.readcCsH|�d�}|�|dk�|��}|�t|�|�|�dd|�|�dS)z�
        Test that the number of bytes L{fdesc.writeToFD} reports as written
        with its return value are seen by L{fdesc.readFromFD}.
        shellorN)r"rr(�assertEqual�len)r�n�srrr�test_writeAndReadgs

z ReadWriteTests.test_writeAndReadcCs�dd}|�|�}|�|dk�g}d}d}||ks<|dkrd|�|���|t|d�7}|d7}q,d�|�}|�t|�|�|�|d|�|�dS)	z}
        Similar to L{test_writeAndRead}, but use a much larger string to verify
        the behavior for that case.
        s
0123456879i'r�2����r#N)r"rr%r(r*�joinr))rZorigZwritten�resultZresultlength�irrr�test_writeAndReadLargess


z%ReadWriteTests.test_writeAndReadLargecCs.g}t�|j|j�}|�|g�|�|�dS)z�
        Verify that reading from a file descriptor with no data does not raise
        an exception and does not result in the callback function being called.
        N)rr$rr%r)ZassertIsNone)rr&r2rrr�test_readFromEmpty�sz!ReadWriteTests.test_readFromEmptycCs"t�|j�|�|��tj�dS)z�
        Test that using L{fdesc.readFromFD} on a cleanly closed file descriptor
        returns a connection done indicator.
        N)rr	rr)r(rZCONNECTION_DONErrrr�test_readFromCleanClose�sz&ReadWriteTests.test_readFromCleanClosecCs$t�|j�|�|�d�tj�dS)z�
        Verify that writing with L{fdesc.writeToFD} when the read end is closed
        results in a connection lost indicator.
        �sN)rr	rr)r"r�CONNECTION_LOSTrrrr�test_writeToClosed�sz!ReadWriteTests.test_writeToClosedcCs"t�|j�|�|��tj�dS)z�
        Verify that reading with L{fdesc.readFromFD} when the read end is
        closed results in a connection lost indicator.
        N)rr	rr)r(rr8rrrr�test_readFromInvalid�sz#ReadWriteTests.test_readFromInvalidcCs$t�|j�|�|�d�tj�dS)z�
        Verify that writing with L{fdesc.writeToFD} when the write end is
        closed results in a connection lost indicator.
        r7N)rr	rr)r"rr8rrrr�test_writeToInvalid�sz"ReadWriteTests.test_writeToInvalidcCsftj}dd�}|t_z|�|�d�d�W5|t_Xdd�}|t_z|�|�d�d�W5|t_XdS)z8
        Test error path for L{fdesc.writeTod}.
        cSst�}tj|_|�dS�N)r�errnoZEAGAIN��fd�data�errrrr�eagainWrite�sz4ReadWriteTests.test_writeErrors.<locals>.eagainWriter7rcSst�}tj|_|�dSr<)rr=ZEINTRr>rrr�
eintrWrite�sz3ReadWriteTests.test_writeErrors.<locals>.eintrWriteN)rr"r))rZ
oldOsWriterBrCrrr�test_writeErrors�szReadWriteTests.test_writeErrorsN)rrrrrr r"r(r-r4r5r6r9r:r;rDrrrrr5s					rc@s,eZdZdZdZdd�Zdd�Zdd�Zd	S)
�CloseOnExecTestszL
    Tests for L{fdesc._setCloseOnExec} and L{fdesc._unsetCloseOnExec}.
    z�
import os, errno
try:
    os.write(%d, b'lul')
except OSError as e:
    if e.errno == errno.EBADF:
        os._exit(0)
    os._exit(5)
except:
    os._exit(10)
else:
    os._exit(20)
cCsvt��}|dkr`z&t�tjtjd|j|��fg�Wqrddl}|��t�	d�YqrXnt
tj|d�dSdS)Nrz-c�r0)r�fork�execv�sys�
executable�program�fileno�	traceback�	print_exc�_exitr�waitpid)r�fObj�pidrMrrr�_execWithFileDescriptor�s&z(CloseOnExecTests._execWithFileDescriptorc	CsXt|��d��@}t�|���|�|�}|�t�|��|�	t�
|�d�W5QRXdS)z�
        A file descriptor passed to L{fdesc._setCloseOnExec} is not inherited
        by a new process image created with one of the exec family of
        functions.
        �wbrN)�open�mktempr�_setCloseOnExecrLrSrr�	WIFEXITEDr)�WEXITSTATUS�rrQZstatusrrr�test_setCloseOnExec�s

z$CloseOnExecTests.test_setCloseOnExecc	Csft|��d��N}t�|���t�|���|�|�}|�t�	|��|�
t�|�d�W5QRXdS)z�
        A file descriptor passed to L{fdesc._unsetCloseOnExec} is inherited by
        a new process image created with one of the exec family of functions.
        rT�N)rUrVrrWrLZ_unsetCloseOnExecrSrrrXr)rYrZrrr�test_unsetCloseOnExecs
z&CloseOnExecTests.test_unsetCloseOnExecN)rrrrrKrSr[r]rrrrrE�s

rE)rrrIr=r�ImportError�skipZtwisted.internetrZtwisted.python.utilrZ
twisted.trialrZSynchronousTestCaserrrErrrr�<module>s