
    Vh                         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       y)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
y)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                 J    || _         || _        g | _        d | _        || _        y N)_host	_protocol_sentPackets_connectedTo_maxPacketSize)selfhostprotocolmaxPacketSizes       L/home/dcms/DCMS/lib/python3.12/site-packages/twisted/names/test/test_util.py__init__z MemoryDatagramTransport.__init__&   s(    
! +    c                 .    t        dg| j                   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| _         y)z>
        Connect this transport to the given address.
        NzAlready connected)r   
ValueError)r   r   ports      r   connectzMemoryDatagramTransport.connect4   s(     (011!4Lr   Nc                     || j                   }|t        d      t        |      | j                  kD  rt        d      | j                  j                  ||f       y)z*
        Send the given datagram.
        NzNeed an addresszPacket too big)r   r    lenr   r   append)r   datagramaddrs      r   writezMemoryDatagramTransport.write<   s\     <$$D<.//x=4...-..  (D!12r   c                 L    | j                   j                          t        d      S )z+
        Shut down this transport.
        N)r   stopProtocolr   r   s    r   stopListeningz%MemoryDatagramTransport.stopListeningH   s     	##%t}r   c                      yzC
        Dummy implementation to satisfy L{IUDPTransport}.
        N )r   enableds     r   setBroadcastAllowedz+MemoryDatagramTransport.setBroadcastAllowedO        	r   c                      y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r   r   c                       e Zd ZdZd ZddZy)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 | _        y 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                  |<   |j	                  |       |S )zR
        Pretend to bind a UDP port and connect the given protocol to it.
        r      i   zAddress in use)r   r;   r    r   makeConnection)r   r!   r   	interfacer   	transports         r   	listenUDPzMemoryReactor.listenUDPp   s}     19 E*t}},  4== -..+Y,=xW	'd	*r   N) i    )r4   r5   r6   r7   r   rA   r.   r   r   r9   r9   _   s    	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>rJ      s}   
  & - 0 * B ' ]D D DN M2 3 [E  B K 'r   