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_socket.cpython-38.pyc
U


W[q$�@sdZddlZddlZddlmZddlmZddlmZddl	m
Z
ddlmZm
Z
ddlmZmZdd	lmZdd
lmZGdd�de�ZGd
d�de�ZGdd�de�ZGdd�de�Ze��e���e��e���e��e���e��e���dS)aD
Tests for implementations of L{IReactorSocket}.

Generally only tests for failure cases are found here.  Success cases for
this interface are tested elsewhere.  For example, the success case for
I{AF_INET} is in L{twisted.internet.test.test_tcp}, since that case should
behave exactly the same as L{IReactorTCP.listenTCP}.
�N)�verify)�err)�IReactorSocket)�UnsupportedAddressFamily)�DatagramProtocol�
ServerFactory)�ReactorBuilder�needsRunningReactor)�_PY3)�platformc@seZdZdZegZdd�ZdS)�&IReactorSocketVerificationTestsBuilderaO
    Builder for testing L{IReactorSocket} implementations for required
    methods and method signatures.

    L{ReactorBuilder} already runs L{IReactorSocket.providedBy} to
    ensure that these tests will only be run on reactor classes that
    claim to implement L{IReactorSocket}.

    These tests ensure that reactors which claim to provide the
    L{IReactorSocket} interface actually have all the required methods
    and that those methods have the expected number of arguments.

    These tests will be skipped for reactors which do not claim to
    provide L{IReactorSocket}.
    cCs|��}|�t�t|��dS)zf
        The reactor instance returned by C{buildReactor} provides
        L{IReactorSocket}.
        N)�buildReactorZ
assertTruerZverifyObjectr)�self�reactor�r�C/usr/lib/python3/dist-packages/twisted/internet/test/test_socket.py�
test_provider/s
�z4IReactorSocketVerificationTestsBuilder.test_providerN)�__name__�
__module__�__qualname__�__doc__r�requiredInterfacesrrrrrrsrc@s.eZdZdZegZdd�Zdd�Zdd�ZdS)	�!AdoptStreamPortErrorsTestsBuilderas
    Builder for testing L{IReactorSocket.adoptStreamPort} implementations.

    Generally only tests for failure cases are found here.  Success cases for
    this interface are tested elsewhere.  For example, the success case for
    I{AF_INET} is in L{twisted.internet.test.test_tcp}, since that case should
    behave exactly the same as L{IReactorTCP.listenTCP}.
    cCst|��}t��}|��}|��|�tj|j|tjt��}t	�
�r\tr\|�|j
dtj�n|�|j
dtj�dS)z�
        An implementation of L{IReactorSocket.adoptStreamPort} raises
        L{socket.error} if passed an integer which is not associated with a
        socket.
        rN)r
�socket�fileno�close�assertRaises�error�adoptStreamPort�AF_INETrr�	isWindowsr
�assertEqual�args�errno�WSAENOTSOCK�EBADF�rrZprober�excrrr�test_invalidDescriptorEs�z8AdoptStreamPortErrorsTestsBuilder.test_invalidDescriptorcCsR|��}t��}|�d�|�d�|�|j�d}|�t|j|�	�|t
��dS)z�
        An implementation of L{IReactorSocket.adoptStreamPort} raises
        L{UnsupportedAddressFamily} if passed an address family it does not
        support.
        �z	127.0.0.1r��N)r
r�bind�listen�
addCleanuprrrrrr�rr�port�	arbitraryrrr�test_invalidAddressFamilyZs

�z;AdoptStreamPortErrorsTestsBuilder.test_invalidAddressFamilycs�����t������j���d���d���d�������j	t
��}|�����fdd�}��|���
td�t���fdd�����d	S)
a9
        When the L{IListeningPort} returned by
        L{IReactorSocket.adoptStreamPort} is stopped using
        C{stopListening}, the underlying socket is closed but not
        shutdown.  This allows another process which still has a
        reference to it to continue accepting connections over it.
        r)r*FcsJ��tj�j�}t��r2tr2��|jdt	j
�n��|jdt	j�dS)Nr)rrrZacceptrr r
r!r"r#�WSAEWOULDBLOCK�EAGAIN��ignoredr'��
portSocketrrr�stopped�szFAdoptStreamPortErrorsTestsBuilder.test_stopOnlyCloses.<locals>.stoppedz"Failed to accept on original port.cs���fdd��S)Ncs���S�N��stop�r6�rrr�<lambda>��zYAdoptStreamPortErrorsTestsBuilder.test_stopOnlyCloses.<locals>.<lambda>.<locals>.<lambda>��addCallbackr��drrrr?�r@zGAdoptStreamPortErrorsTestsBuilder.test_stopOnlyCloses.<locals>.<lambda>N)r
rr.rr,r-�setblockingrr�familyr�
stopListeningrB�
addErrbackrr	�run�rr0r9r�rDr8rrr�test_stopOnlyClosesns(


�	
�z5AdoptStreamPortErrorsTestsBuilder.test_stopOnlyClosesN�	rrrrrrr(r2rLrrrrr:s
rc@seZdZdZegZdd�ZdS)�'AdoptStreamConnectionErrorsTestsBuildera}
    Builder for testing L{IReactorSocket.adoptStreamConnection}
    implementations.

    Generally only tests for failure cases are found here.  Success cases for
    this interface are tested elsewhere.  For example, the success case for
    I{AF_INET} is in L{twisted.internet.test.test_tcp}, since that case should
    behave exactly the same as L{IReactorTCP.listenTCP}.
    cCs>|��}t��}|�|j�d}|�t|j|��|t��dS)z�
        An implementation of L{IReactorSocket.adoptStreamConnection} raises
        L{UnsupportedAddressFamily} if passed an address family it does not
        support.
        r+N)	r
rr.rrrZadoptStreamConnectionrr)rrZ
connectionr1rrrr2�s�zAAdoptStreamConnectionErrorsTestsBuilder.test_invalidAddressFamilyN)rrrrrrr2rrrrrN�s	rNc@s.eZdZdZegZdd�Zdd�Zdd�ZdS)	�#AdoptDatagramPortErrorsTestsBuilderzR
    Builder for testing L{IReactorSocket.adoptDatagramPort} implementations.
    cCst|��}t��}|��}|��|�tj|j|tjt��}t	�
�r\tr\|�|j
dtj�n|�|j
dtj�dS)z�
        An implementation of L{IReactorSocket.adoptDatagramPort} raises
        L{socket.error} if passed an integer which is not associated with a
        socket.
        rN)r
rrrrr�adoptDatagramPortrrrr r
r!r"r#r$r%r&rrrr(�s�z:AdoptDatagramPortErrorsTestsBuilder.test_invalidDescriptorcCsF|��}t�tjtj�}|�|j�d}|�t|j|�	�|t
��dS)z�
        An implementation of L{IReactorSocket.adoptDatagramPort} raises
        L{UnsupportedAddressFamily} if passed an address family it does not
        support.
        r+N)r
rr�
SOCK_DGRAMr.rrrrPrrr/rrrr2�s�z=AdoptDatagramPortErrorsTestsBuilder.test_invalidAddressFamilycs�����t�tjtj�����j���d���d�����	��j
t��}|�����fdd�}��
|���td�t���fdd�����dS)	a7
        When the L{IListeningPort} returned by
        L{IReactorSocket.adoptDatagramPort} is stopped using
        C{stopListening}, the underlying socket is closed but not
        shutdown.  This allows another process which still has a
        reference to it to continue reading and writing to it.
        r)FcsL��tj�jd�}t��r4tr4��|jdt	j
�n��|jdt	j�dS)Nr*r)rrrZrecvfromrr r
r!r"r#r3r4r5r7rrr9�szHAdoptDatagramPortErrorsTestsBuilder.test_stopOnlyCloses.<locals>.stoppedz Failed to read on original port.cs���fdd��S)Ncs���Sr:r;r=r>rrr?r@z[AdoptDatagramPortErrorsTestsBuilder.test_stopOnlyCloses.<locals>.<lambda>.<locals>.<lambda>rArrCrrr?r@zIAdoptDatagramPortErrorsTestsBuilder.test_stopOnlyCloses.<locals>.<lambda>N)r
rrrQr.rr,rErPrrFrrGrBrHrr	rIrJrrKrrL�s&

�
�z7AdoptDatagramPortErrorsTestsBuilder.test_stopOnlyClosesNrMrrrrrO�s
rO)rr#rZzope.interfacerZtwisted.python.logrZtwisted.internet.interfacesrZtwisted.internet.errorrZtwisted.internet.protocolrrZ#twisted.internet.test.reactormixinsrr	Ztwisted.python.compatr
Ztwisted.python.runtimerrrrNrO�globals�updateZmakeTestCaseClassesrrrr�<module>s"	] W