Ë
    ojý  ã                   óÚ   — 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       ú>/usr/lib/python3/dist-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Ø! 4˜LˆÕ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}   € ð �1Š9ØÜ   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   