
    Yf                        d Z ddlmZ ddlm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  ee           G d	 d
                      Z eee            ee           G d de                      Z eee           dS )z$
Utilities for Twisted.names tests.
    )	randrange)implementer)verifyClass)IPv4Address)succeed)IReactorUDPIUDPTransport)Clockc                   >    e Zd ZdZd Zd Zd Zd
dZd Zd Z	d	 Z
dS )MemoryDatagramTransporta  
    This L{IUDPTransport} implementation enforces the usual connection rules
    and captures sent traffic in a list for later inspection.

    @ivar _host: The host address to which this transport is bound.
    @ivar _protocol: The protocol connected to this transport.
    @ivar _sentPackets: A C{list} of two-tuples of the datagrams passed to
        C{write} and the addresses to which they are destined.

    @ivar _connectedTo: L{None} if this transport is unconnected, otherwise an
        address to which all traffic is supposedly sent.

    @ivar _maxPacketSize: An C{int} giving the maximum length of a datagram
        which will be successfully handled by C{write}.
    c                 L    || _         || _        g | _        d | _        || _        d S N)_host	_protocol_sentPackets_connectedTo_maxPacketSize)selfhostprotocolmaxPacketSizes       N/var/www/html/env/lib/python3.11/site-packages/twisted/names/test/test_util.py__init__z MemoryDatagramTransport.__init__&   s.    
! +    c                 &    t          dg| j        R  S )z_
        Return the address which this transport is pretending to be bound
        to.
        UDP)r   r   r   s    r   getHostzMemoryDatagramTransport.getHost-   s    
 5.4:....r   c                 D    | j         t          d          ||f| _         dS )z>
        Connect this transport to the given address.
        NzAlready connected)r   
ValueError)r   r   ports      r   connectzMemoryDatagramTransport.connect4   s.     (0111!4Lr   Nc                     || j         }|t          d          t          |          | j        k    rt          d          | j                            ||f           dS )z*
        Send the given datagram.
        NzNeed an addresszPacket too big)r   r    lenr   r   append)r   datagramaddrs      r   writezMemoryDatagramTransport.write<   sj     <$D<.///x==4...-...  (D!122222r   c                 R    | j                                          t          d          S )z+
        Shut down this transport.
        N)r   stopProtocolr   r   s    r   stopListeningz%MemoryDatagramTransport.stopListeningH   s$     	##%%%t}}r   c                     dS zC
        Dummy implementation to satisfy L{IUDPTransport}.
        N )r   enableds     r   setBroadcastAllowedz+MemoryDatagramTransport.setBroadcastAllowedO   	     	r   c                     dS r-   r.   r   s    r   getBroadcastAllowedz+MemoryDatagramTransport.getBroadcastAllowedU   r1   r   r   )__name__
__module____qualname____doc__r   r   r"   r(   r+   r0   r3   r.   r   r   r   r      s          , , ,/ / /) ) )
3 
3 
3 
3        r   r   c                        e Zd ZdZd ZddZdS )MemoryReactoraO  
    An L{IReactorTime} and L{IReactorUDP} provider.

    Time is controlled deterministically via the base class, L{Clock}.  UDP is
    handled in-memory by connecting protocols to instances of
    L{MemoryDatagramTransport}.

    @ivar udpPorts: A C{dict} mapping port numbers to instances of
        L{MemoryDatagramTransport}.
    c                 <    t          j        |            i | _        d S r   )r
   r   udpPortsr   s    r   r   zMemoryReactor.__init__l   s    tr        c                     |dk    r	 t          dd          }|| j        vrn|| j        v rt          d          t          ||f||          }|| j        |<   |                    |           |S )zR
        Pretend to bind a UDP port and connect the given protocol to it.
        r   T   i   zAddress in use)r   r;   r    r   makeConnection)r   r!   r   	interfacer   	transports         r   	listenUDPzMemoryReactor.listenUDPp   s     199 E**t},, 4=  -...+Y,=xWW	'd	***r   N)r<   r=   )r4   r5   r6   r7   r   rC   r.   r   r   r9   r9   _   sA        	 	       r   r9   N)r7   randomr   zope.interfacer   zope.interface.verifyr   twisted.internet.addressr   twisted.internet.deferr   twisted.internet.interfacesr   r	   twisted.internet.taskr
   r   r9   r.   r   r   <module>rK      sN   
       & & & & & & - - - - - - 0 0 0 0 0 0 * * * * * * B B B B B B B B ' ' ' ' ' ' ]D D D D D D D DN M2 3 3 3 [    E   B K ' ' ' ' 'r   