
    Yf$                     ^   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
mZ ddlmZmZ ddlmZ dd	lmZ  G d
 de          Z G d de          Z G d de          Z G d de          Z e                                e                                            e                                e                                            e                                e                                            e                                e                                           dS )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)UnsupportedAddressFamily)IReactorSocket)DatagramProtocolServerFactory)ReactorBuilderneedsRunningReactor)err)platformc                       e Zd ZdZegZd ZdS )&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}.
    c                     |                                  }|                     t          j        t          |                     dS )zf
        The reactor instance returned by C{buildReactor} provides
        L{IReactorSocket}.
        N)buildReactor
assertTruer   verifyObjectr   )selfreactors     S/var/www/html/env/lib/python3.11/site-packages/twisted/internet/test/test_socket.pytest_providerz4IReactorSocketVerificationTestsBuilder.test_provider-   s:    
 ##%%+NGDDEEEEE    N)__name__
__module____qualname____doc__r   requiredInterfacesr    r   r   r   r      s=           ))F F F F Fr   r   c                   *    e Zd ZdZegZd Zd Zd ZdS )!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}.
    c                    |                                  }t          j                    }|                                }|                                 |                     t          j        |j        |t          j        t                                }t          j
                    r-|                     |j        d         t          j                   dS |                     |j        d         t          j                   dS )z
        An implementation of L{IReactorSocket.adoptStreamPort} raises
        L{socket.error} if passed an integer which is not associated with a
        socket.
        r   N)r   socketfilenocloseassertRaiseserroradoptStreamPortAF_INETr   r   	isWindowsassertEqualargserrnoWSAENOTSOCKEBADFr   r   prober!   excs        r   test_invalidDescriptorz8AdoptStreamPortErrorsTestsBuilder.test_invalidDescriptorB   s     ##%%L#NOO
 
  	7SXa[%*;<<<<<SXa[%+66666r   c                 b   |                                  }t          j                    }|                    d           |                    d           |                     |j                   d}|                     t          |j        |	                                |t                                 dS )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
addCleanupr"   r#   r   r%   r!   r   r   r   port	arbitrarys       r   test_invalidAddressFamilyz;AdoptStreamPortErrorsTestsBuilder.test_invalidAddressFamilyZ   s     ##%%}		"###A
###	$#KKMMOO	
 	
 	
 	
 	
r   c                 f                                      t          j                                         j                                       d                               d                               d                                                               j	        t                                }|                                 fd}                    |                               t          d           t          fd                                            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.
        r2   r3   Fc                 (                        t          j        j                  }t	          j                    r-                    |j        d         t          j	                   d S                     |j        d         t          j
                   d S )Nr   )r#   r    r$   acceptr   r'   r(   r)   r*   WSAEWOULDBLOCKEAGAINignoredr/   
portSocketr   s     r   stoppedzFAdoptStreamPortErrorsTestsBuilder.test_stopOnlyCloses.<locals>.stopped   sy     ##FL*2CDDC!## <  !e.BCCCCC  !el;;;;;r   z"Failed to accept on original port.c                  4                          fd          S )Nc                 ,                                     S NstoprB   r   s    r   <lambda>zYAdoptStreamPortErrorsTestsBuilder.test_stopOnlyCloses.<locals>.<lambda>.<locals>.<lambda>       7<<>> r   addCallbackdr   s   r   rK   zGAdoptStreamPortErrorsTestsBuilder.test_stopOnlyCloses.<locals>.<lambda>       Q]]+I+I+I+IJJ r   N)r   r    r7   r"   r5   r6   setblockingr%   r!   familyr   stopListeningrN   
addErrbackr
   r	   runr   r9   rD   rP   rC   r   s   `  @@@r   test_stopOnlyClosesz5AdoptStreamPortErrorsTestsBuilder.test_stopOnlyClosesq   s6    ##%%]__

()))()))!u%%% &&!2MOO
 
   	< 	< 	< 	< 	< 	< 	
g	S>???JJJJJ	
 	
 	
 	r   N	r   r   r   r   r   r   r0   r;   rX   r   r   r   r   r   6   sV          ))7 7 70
 
 
.( ( ( ( (r   r   c                       e Zd ZdZegZd ZdS )'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}.
    c                    |                                  }t          j                    }|                     |j                   d}|                     t
          |j        |                                |t                                 dS )z
        An implementation of L{IReactorSocket.adoptStreamConnection} raises
        L{UnsupportedAddressFamily} if passed an address family it does not
        support.
        r4   N)	r   r    r7   r"   r#   r   adoptStreamConnectionr!   r   )r   r   
connectionr:   s       r   r;   zAAdoptStreamConnectionErrorsTestsBuilder.test_invalidAddressFamily   s~     ##%%]__

()))	$)OO	
 	
 	
 	
 	
r   N)r   r   r   r   r   r   r;   r   r   r   r[   r[      s8          ))
 
 
 
 
r   r[   c                   *    e Zd ZdZegZd Zd Zd ZdS )#AdoptDatagramPortErrorsTestsBuilderzR
    Builder for testing L{IReactorSocket.adoptDatagramPort} implementations.
    c                    |                                  }t          j                    }|                                }|                                 |                     t          j        |j        |t          j        t                                }t          j
                    r-|                     |j        d         t          j                   dS |                     |j        d         t          j                   dS )z
        An implementation of L{IReactorSocket.adoptDatagramPort} raises
        L{socket.error} if passed an integer which is not associated with a
        socket.
        r   N)r   r    r!   r"   r#   r$   adoptDatagramPortr&   r   r   r'   r(   r)   r*   r+   r,   r-   s        r   r0   z:AdoptDatagramPortErrorsTestsBuilder.test_invalidDescriptor   s     ##%%L%N
 
  	7SXa[%*;<<<<<SXa[%+66666r   c                 :   |                                  }t          j        t          j        t          j                  }|                     |j                   d}|                     t          |j        |	                                |t                                 dS )z
        An implementation of L{IReactorSocket.adoptDatagramPort} raises
        L{UnsupportedAddressFamily} if passed an address family it does not
        support.
        r4   N)r   r    r&   
SOCK_DGRAMr7   r"   r#   r   rb   r!   r   r8   s       r   r;   z=AdoptDatagramPortErrorsTestsBuilder.test_invalidAddressFamily   s     ##%%}V^V->??
###	$%KKMM	
 	
 	
 	
 	
r   c                 h                                      t          j        t          j        t          j                                       j                                       d                               d                               	                                j
        t                                }|                                 fd}                    |                               t          d           t!          fd                                            dS )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.
        r2   Fc                 *                        t          j        j        d          }t	          j                    r-                    |j        d         t          j	                   d S                     |j        d         t          j
                   d S )Nr3   r   )r#   r    r$   recvfromr   r'   r(   r)   r*   r?   r@   rA   s     r   rD   zHAdoptDatagramPortErrorsTestsBuilder.test_stopOnlyCloses.<locals>.stopped	  s{     ##FL*2EqIIC!## <  !e.BCCCCC  !el;;;;;r   z Failed to read on original port.c                  4                          fd          S )Nc                 ,                                     S rG   rH   rJ   s    r   rK   z[AdoptDatagramPortErrorsTestsBuilder.test_stopOnlyCloses.<locals>.<lambda>.<locals>.<lambda>  rL   r   rM   rO   s   r   rK   zIAdoptDatagramPortErrorsTestsBuilder.test_stopOnlyCloses.<locals>.<lambda>  rQ   r   N)r   r    r&   rd   r7   r"   r5   rR   rb   r!   rS   r   rT   rN   rU   r
   r	   rV   rW   s   `  @@@r   rX   z7AdoptDatagramPortErrorsTestsBuilder.test_stopOnlyCloses   s0    ##%%]6>63DEE

()))()))u%%% ((!24D4F4F
 
   	< 	< 	< 	< 	< 	< 	
g	S<===JJJJJ	
 	
 	
 	r   NrY   r   r   r   r`   r`      sV          ))7 7 70
 
 
*& & & & &r   r`   )r   r*   r    zope.interfacer   twisted.internet.errorr   twisted.internet.interfacesr   twisted.internet.protocolr   r   #twisted.internet.test.reactormixinsr   r	   twisted.python.logr
   twisted.python.runtimer   r   r   r[   r`   globalsupdatemakeTestCaseClassesr   r   r   <module>rt      s      ! ! ! ! ! ! ; ; ; ; ; ; 6 6 6 6 6 6 E E E E E E E E S S S S S S S S " " " " " " + + + + + +F F F F F^ F F F8c c c c c c c cL 
  
  
  
  
n  
  
  
FZ Z Z Z Z. Z Z Zz 		  7KKMM N N N 		  2FFHH I I I 		  8LLNN O O O 		  4HHJJ K K K K Kr   