ó
[³XMc           @   s¬  d  Z  d d l m Z m Z d d l m Z m Z m Z d d l m	 Z	 m
 Z
 m Z m Z m Z m Z d d l m Z d f  d „  ƒ  YZ d e e	 j f d	 „  ƒ  YZ d
 e e	 j f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e	 j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ e j e
 e ƒ ryd e _  d e _  n  e j! e
 e ƒ r˜d e _  n  d „  Z" e" ƒ  d S(   sG   
Tests for implementations of L{IReactorUDP} and L{IReactorMulticast}.
iÿÿÿÿ(   t   unittestt   util(   t   Deferredt   gatherResultst   maybeDeferred(   t   protocolt   reactort   errort   defert
   interfacest   udp(   t   runtimet   Mixinc           B   s5   e  Z d  Z d  Z d Z d „  Z d „  Z d „  Z RS(   i    c         C   s   g  |  _  d  S(   N(   t   packets(   t   self(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   __init__   s    c         C   s?   d |  _  |  j d  k	 r; |  j d  } |  _ | j d  ƒ n  d  S(   Ni   (   t   startedt   startedDeferredt   Nonet   callback(   R   t   d(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   startProtocol   s    	c         C   s   d |  _  d  S(   Ni   (   t   stopped(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   stopProtocol    s    N(	   t   __name__t
   __module__R   R   R   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR      s   		t   Serverc           B   s   e  Z d Z d  Z d „  Z RS(   i    c         C   sL   |  j  j | | f ƒ |  j d  k	 rH |  j d  } |  _ | j d  ƒ n  d  S(   N(   R   t   appendt   packetReceivedR   R   (   R   t   datat   addrR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   datagramReceived)   s    N(   R   R   R   R   t   refusedR   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR   $   s   t   Clientc           B   s/   e  Z d Z d  Z d „  Z d „  Z d „  Z RS(   i    c         C   sF   |  j  j | ƒ |  j d  k	 rB |  j d  } |  _ | j d  ƒ n  d  S(   N(   R   R   R   R   R   (   R   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR   6   s    c         C   s?   |  j  d  k	 r2 |  j  d  } |  _  | j | ƒ n  | |  _ d  S(   N(   R   R   t   errbackt   failure(   R   R#   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   connectionFailed<   s    c         C   sH   |  j  d  k	 r; |  j  d  } |  _  | j t j d ƒ ƒ n  d |  _ d  S(   Nt   yupi   (   R   R   R"   R   t   ConnectionRefusedErrorR    (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   connectionRefusedB   s    N(   R   R   R   R   R    R   R$   R'   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR!   1   s
   		t
   GoodClientc           B   s   e  Z d  „  Z RS(   c         C   sH   |  j  d  k	 r; |  j  d  } |  _  | j t j d ƒ ƒ n  d |  _ d  S(   NR%   i   (   R   R   R"   R   R&   R    (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR'   K   s    (   R   R   R'   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR(   I   s   t   BadClientErrorc           B   s   e  Z d  Z RS(   sf   
    Raised by BadClient at the end of every datagramReceived call to try and
    screw stuff up.
    (   R   R   t   __doc__(    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR)   S   s   t	   BadClientc           B   s&   e  Z d  Z d Z d „  Z d „  Z RS(   s   
    A DatagramProtocol which always raises an exception from datagramReceived.
    Used to test error handling behavior in the reactor for that method.
    c         C   s   | |  _  d S(   se   
        Set the Deferred which will be called back when datagramReceived is
        called.
        N(   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   setDeferredb   s    c         C   sB   |  j  d  k	 r2 |  j  d  } |  _  | j | ƒ n  t d ƒ ‚ d  S(   Ns   Application code is very buggy!(   R   R   R   R)   (   R   t   bytesR   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR   j   s    N(   R   R   R*   R   R   R,   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR+   [   s   	t   UDPTestCasec           B   sb   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(
   c            sS   t  ƒ  } t j ƒ  } | _ t j d | d d ƒ‰ ‡  ‡ f d †  } | j | ƒ S(   su   
        The C{type} of the host address of a listening L{DatagramProtocol}'s
        transport is C{"UDP"}.
        i    t	   interfaces	   127.0.0.1c            s)   ˆ j  ƒ  } ˆ  j | j d ƒ ˆ j ƒ  S(   Nt   UDP(   t   getHostt   assertEqualst   typet   stopListening(   t   ignoredR   (   R   t   p(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt	   cbStarted|   s    (   R   R   R   R   R   t	   listenUDPt   addCallback(   R   t   serverR   R7   (    (   R   R6   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   test_oldAddresst   s
    	c            sq   t  ƒ  ‰ t j ƒ  } ˆ _ t j d ˆ d d ƒ‰ ‡  ‡ ‡ f d †  } ‡  ‡ f d †  } | j | ƒ j | ƒ S(   s±   
        The L{DatagramProtocol}'s C{startProtocol} and C{stopProtocol}
        methods are called when its transports starts and stops listening,
        respectively.
        i    R/   s	   127.0.0.1c            s0   ˆ  j  ˆ j d ƒ ˆ  j  ˆ j d ƒ ˆ j ƒ  S(   Ni   i    (   R2   R   R   R4   (   R5   (   R   t   port1R:   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR7   Œ   s    c            s   ˆ  j  ˆ j d ƒ d  S(   Ni   (   R2   R   (   R5   (   R   R:   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt	   cbStopped   s    (   R   R   R   R   R   R8   R9   (   R   R   R7   R=   (    (   R   R:   R<   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   test_startStopƒ   s    	c            s_   t  ƒ  ‰ t j ƒ  } ˆ _ t j d ˆ d d ƒ} d „  ‰  ‡ ‡  f d †  } | j ˆ  | ƒ S(   sr   
        Re-listening with the same L{DatagramProtocol} re-invokes the
        C{startProtocol} callback.
        i    R/   s	   127.0.0.1c         S   s
   | j  ƒ  S(   N(   R4   (   R5   t   port(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR7   ž   s    c            s;   t  j ƒ  } ˆ  _ t j d ˆ  d d ƒ} | j ˆ | ƒ S(   Ni    R/   s	   127.0.0.1(   R   R   R   R   R8   R9   (   R5   R   R6   (   R:   R7   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR=   ¡   s    (   R   R   R   R   R   R8   R9   (   R   R   R6   R=   (    (   R7   R:   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   test_rebind•   s    		c            sv   t  ƒ  ‰ t j ƒ  } ˆ _ t j d ˆ d d ƒ‰ ‡  ‡ ‡ f d †  } | j | ƒ ‡ f d †  } | j | ƒ | S(   s   
        A L{CannotListenError} exception is raised when attempting to bind a
        second protocol instance to an already bound port
        i    R/   s	   127.0.0.1c            sW   ˆ  j  ˆ j ƒ  ˆ j j ƒ  ƒ t ƒ  } ˆ  j t j t j ˆ j ƒ  j	 | d d ƒd  S(   NR/   s	   127.0.0.1(
   R2   R1   t	   transportR   t   assertRaisesR   t   CannotListenErrorR   R8   R?   (   R5   t   server2(   R   R:   R?   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR7   ²   s    	c            s
   ˆ  j  ƒ  S(   N(   R4   (   R5   (   R?   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt
   cbFinished»   s    (   R   R   R   R   R   R8   R9   (   R   R   R7   RE   (    (   R   R:   R?   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   test_bindError©   s    	c            sØ   t  ƒ  ‰ t j ƒ  } ˆ _ t j d ˆ d d ƒ‰ t ƒ  ‰ t j ƒ  ‰  ˆ _ ‡ ‡ ‡  f d †  } | j | ƒ } ‡ ‡ f d †  } | j | ƒ ‡ ‡ ‡ f d †  } | j | ƒ ‡ ‡ f d †  } | j | ƒ | S(   sŽ   
        Datagrams can be sent with the transport's C{write} method and
        received via the C{datagramReceived} callback method.
        i    R/   s	   127.0.0.1c            s   t  j d ˆ d d ƒˆ  _ ˆ S(   Ni    R/   s	   127.0.0.1(   R   R8   t   port2(   R5   (   R   t   clientt   clientStarted(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   cbServerStartedÍ   s    c            sÇ   ˆ j  j d ˆ j  j ƒ  j ƒ ˆ j  j ƒ  } ˆ j  j ƒ  } t j ƒ  } ˆ _ ˆ j  j d | j | j f ƒ d d	 d | j | j f f g ‰ ‡ ‡ ‡  ‡ f d †  ‰  t j
 ˆ  d  ƒ | g d t ƒS(
   Ns	   127.0.0.1t   hellot   at   bt   cc            sG   ˆ rC t  j ƒ  } ˆ  _ | j ˆ ƒ ˆ j j ˆ j d ƒ Œ  | Sd  S(   Ni    (   R   R   R   R9   RA   t   writet   pop(   R5   t   nextClientWrite(   R:   RH   t   cbClientSendt   clientWrites(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRR   á   s
    t   fireOnOneErrback(   RL   (   RM   N(   RA   t   connectR1   R?   R   R   R   RO   t   hostR   t   DeferredListt   True(   R5   t   cAddrt   sAddrt
   serverSend(   R:   RH   (   RR   RS   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   cbClientStartedÓ   s    
		c            sŠ   ˆ j  j ƒ  } ˆ j  j ƒ  } ˆ  j ˆ j d | j | j f f g ƒ | j | j f } ˆ  j ˆ j d | f d | f d | f g ƒ d  S(   NRK   RL   RM   RN   (   RA   R1   R2   R   RV   R?   (   R5   RY   RZ   t
   clientAddr(   R   R:   RH   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   cbSendsFinishedò   s    		c            s4   t  j t  j ˆ j ƒ t  j ˆ  j j ƒ g d t ƒS(   NRT   (   R   RW   R   R4   RG   RX   (   R5   (   R   R<   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRE     s    (   R   R   R   R   R   R8   R(   R9   (   R   t   serverStartedRJ   R   R\   R^   RE   (    (   RI   R   RH   R:   R<   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   test_sendPacketsÁ   s    		c            sÈ   t  ƒ  ‰ t j ƒ  } ˆ _ t j d ˆ d d ƒ‰ t ƒ  ‰ t j ƒ  } ˆ _ t j d ˆ d d ƒ‰ t j | | g d t ƒ} ‡  ‡ ‡ f d †  } | j	 | ƒ ‡ ‡ f d †  } | j	 | ƒ | S(   sÎ   
        A L{ConnectionRefusedError} exception is raised when a connection
        attempt is actively refused by the other end.

        Note: This test assumes no one is listening on port 80 UDP.
        i    R/   s	   127.0.0.1RT   c            s   t  j ƒ  } ˆ _ ˆ j j d d ƒ xC t d ƒ D]5 } ˆ j j t | ƒ ƒ ˆ j j t | ƒ d ƒ q3 Wˆ  j | t	 j
 ƒ S(   Ns	   127.0.0.1iP   i
   (   s	   127.0.0.1iP   (   R   R   R   RA   RU   t   rangeRO   t   strt   assertFailureR   R&   (   R5   R'   t   i(   R   R:   RH   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR7     s    c            s1   t  j t  j ˆ j ƒ t  j ˆ  j ƒ g d t ƒS(   NRT   (   R   RW   R   R4   RX   (   R5   (   RG   R?   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRE   ,  s    (
   R(   R   R   R   R   R8   R   RW   RX   R9   (   R   RI   R_   R   R7   RE   (    (   R   R:   RH   RG   R?   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   test_connectionRefused  s    			c         C   sv   t  ƒ  } t j d | d d ƒ} |  j t | j j d d ƒ | j j d d ƒ |  j t | j j d d ƒ | j ƒ  S(   s  
        A call to the transport's connect method fails with a L{ValueError}
        when a non-IP address is passed as the host value.

        A call to a transport's connect method fails with a L{RuntimeError}
        when the transport is already connected.
        i    R/   s	   127.0.0.1t	   localhostiP   (	   R(   R   R8   RB   t
   ValueErrorRA   RU   t   RuntimeErrorR4   (   R   RH   R?   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   test_badConnect6  s    	

c            s¯   t  j ƒ  ‰ ‡ f d †  } ˆ j | ƒ t ƒ  ‰ t j d ˆ d d ƒ‰ ‡ f d †  } ˆ j | ƒ ˆ j ƒ  ‰ t d ƒ ‰ g  ‰  ‡  ‡ ‡ ‡ ‡ ‡ ‡ f d †  ‰ ˆ ƒ  ˆ S(   sr   
        When datagramReceived raises an exception it is logged but the port
        is not disconnected.
        c            s9   ˆ  j  t ƒ } ˆ  j t | ƒ d d t | ƒ f ƒ d S(   s…   
            Flush the exceptions which the reactor should have logged and make
            sure they're actually there.
            i   s'   Incorrectly found %d errors, expected 2N(   t   flushLoggedErrorsR)   R2   t   len(   t   ignt   errs(   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   cbCompletedP  s    i    R/   s	   127.0.0.1c            s"   t  j ˆ j ƒ j ‡  f d †  ƒ S(   sƒ   
            Disconnect the port we started and pass on whatever was given to us
            in case it was a Failure.
            c            s   ˆ  S(   N(    (   Rl   (   t   result(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   <lambda>a  s    (   R   R   R4   t   addBoth(   Ro   (   R?   (   Ro   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt	   cbCleanup\  s    i<   c             sý   ˆ s. y ˆ j  d ƒ Wq. ˆ j ƒ  q. Xn  ˆ j ˆ j d d ƒ t ˆ j d ƒ ƒ }  t j ƒ  } ˆ j	 | ƒ ˆ j j
 |  ˆ j ˆ j f ƒ ‡ ‡ ‡  ‡ f d †  } ‡ f d †  } | j | | ƒ | j ˆ j ƒ t j d | j t j d ƒ ƒ ‰  d S(	   s6  
            Send one packet to the listening BadClient.  Set up a 0.1 second
            timeout to do re-transmits in case the packet is dropped.  When two
            packets have been received by the BadClient, stop sending and let
            the finalDeferred's callbacks do some assertions.
            s   Not enough packets receiveds   UDP Protocol lost its transporti    c            sM   ˆ j  ƒ  ˆ  j |  ƒ t ˆ  ƒ d k rB t j d ˆ j d ƒ n ˆ ƒ  d S(   s…   
                A packet arrived.  Cancel the timeout for it, record it, and
                maybe finish the test.
                i   i    N(   t   cancelR   Rk   R   t	   callLaterR   R   (   t   packet(   t   succeededAttemptst   makeAttemptt   timeoutCallt   finalDeferred(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   cbPacketReceived…  s
    
c            s   ˆ  ƒ  d S(   sÄ  
                The packet wasn't received quickly enough.  Try sending another
                one.  It doesn't matter if the packet for which this was the
                timeout eventually arrives: makeAttempt throws away the
                Deferred on which this function is the errback, so when
                datagramReceived callbacks, so it won't be on this Deferred, so
                it won't raise an AlreadyCalledError.
                N(    (   t   err(   Rw   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   ebPacketTimeout•  s    	gš™™™™™¹?s&   Timed out in testDatagramReceivedErrorN(   t   failR"   t   failIfIdenticalRA   R   Rb   RP   R   R   R,   RO   RV   R?   t   addCallbackst
   addErrbackR   Rt   R   t   TimeoutError(   Ru   t   packetDeferredRz   R|   (   Rv   R   Rw   R   t   attemptsRH   Ry   (   Rx   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRw   q  s$    	(	   R   R   R9   R+   R   R8   Rq   R1   Ra   (   R   Rn   Rr   (    (   Rv   Rw   R   Rƒ   RH   Ry   R?   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   test_datagramReceivedErrorI  s    	
!7c            sŠ   t  ƒ  } t j d | ƒ ‰ t ˆ j ƒ  j ƒ ‰  ˆ j t ˆ ƒ j ˆ  ƒ d k ƒ ‡ ‡  ‡ f d †  } t	 j
 ˆ j ƒ } | j | ƒ | S(   s”   
        The port number being listened on can be found in the string
        returned from calling repr() on L{twisted.internet.udp.Port}.
        i    iÿÿÿÿc            s&   ˆ  j  t ˆ ƒ j ˆ ƒ d k ƒ d  S(   Niÿÿÿÿ(   t   failIft   reprt   find(   Rl   (   R   t   portNoR6   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   stoppedListeningµ  s    (   R(   R   R8   Rb   R1   R?   R…   R†   R‡   R   R   R4   R9   (   R   RH   R‰   R   (    (   Rˆ   R   R6   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   test_portRepr¬  s    	"c         C   ss   d d d „  ƒ  Y} t  j d t ƒ  ƒ } | ƒ  | _ | j d d	 ƒ |  j |  j g ƒ } |  j t | ƒ d ƒ d S(
   si  
        C{'<broadcast>'} is an alternative way to say C{'255.255.255.255'}
        ({socket.gethostbyname("<broadcast>")} returns C{'255.255.255.255'}),
        so because it becomes a valid IP address, no deprecation warning about
        passing hostnames to L{twisted.internet.udp.Port.write} needs to be
        emitted by C{write()} in this case.
        t
   fakeSocketc           B   s   e  Z d  „  Z RS(   c         S   s   d  S(   N(    (   R   t   foot   bar(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   sendtoÅ  s    (   R   R   RŽ   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR‹   Ä  s   i    t   tests   <broadcast>iÒ  N(    (   s   <broadcast>iÒ  (	   R
   t   PortR   t   socketRO   t   flushWarningst   test_NoWarningOnBroadcastR2   Rk   (   R   R‹   R6   t   warnings(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR“   ¼  s    (   R   R   R;   R>   R@   RF   R`   Re   Ri   R„   RŠ   R“   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR.   r   s   					J	+		c	t   ReactorShutdownInteractionc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s!   Test reactor shutdown interactionc         C   s.   t  ƒ  |  _ t j d |  j d d ƒ|  _ d S(   s   Start a UDP porti    R/   s	   127.0.0.1N(   R   R:   R   R8   R?   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   setUpÔ  s    c         C   s   |  j  j ƒ  S(   s   Stop the UDP port(   R?   R4   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   tearDownÙ  s    c            s   t  j ƒ  ‰ t  j ƒ  } ˆ  j _ ‡  ‡ f d †  } | j | ƒ ‡  f d †  } ˆ j | ƒ ˆ  j j j d d d ˆ  j j j ƒ  j f ƒ ˆ S(   s0   Test reactor shutdown while in a recvfrom() loopc            s*   ˆ  j  j j ƒ  t j d ˆ j d  ƒ d  S(   Ni    (   R:   RA   t   connectionLostR   Rt   R   R   (   R5   (   R   t   finished(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   pktReceì  s    c            s   ˆ  j  ƒ  d  S(   N(   Rj   (   R5   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   flushErrorsõ  s    t    i@   s	   127.0.0.1(	   R   R   R:   R   R9   RA   RO   R1   R?   (   R   t   prRš   R›   (    (   R   R™   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt    testShutdownFromDatagramReceivedÝ  s    (   R   R   R*   R–   R—   Rž   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR•   Ñ  s   		t   MulticastTestCasec           B   sŸ   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e	 j
 j ƒ  rp e	 j
 j ƒ  rp d e _ n  d „  Z d	 „  Z e	 j
 j ƒ  r d
 e _ n  RS(   c         C   sq   t  ƒ  |  _ t ƒ  |  _ t j d |  j ƒ |  _ t j d |  j ƒ |  _ |  j j j	 d |  j j j
 ƒ  j ƒ d  S(   Ni    s	   127.0.0.1(   R   R:   R!   RH   R   t   listenMulticastR<   RG   RA   RU   R1   R?   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR–     s    c         C   s(   t  t |  j j ƒ t |  j j ƒ g ƒ S(   N(   R   R   R<   R4   RG   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR—     s    c         C   sc   x\ |  j  |  j f D]H } |  j | j j ƒ  d ƒ | j j d ƒ |  j | j j ƒ  d ƒ q Wd  S(   Ni   i   (   RH   R:   R2   RA   t   getTTLt   setTTL(   R   t   o(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   testTTL  s    c            s¡   ˆ j  ˆ j j j ƒ  d ƒ ˆ j j j ƒ  ‰  ˆ j j j d ƒ } ‡  ‡ f d †  } | j | ƒ ‡  ‡ f d †  } | j | ƒ ‡ f d †  } | j | ƒ | S(   sv   
        Test that after loopback mode has been set, multicast packets are
        delivered to their sender.
        i   s   225.0.0.250c            s6   t  ƒ  } ˆ j _ ˆ j j j d d ˆ  j f ƒ | S(   NRK   s   225.0.0.250(   R   R:   R   RA   RO   R?   (   R5   R   (   R   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   cbJoined$  s    c            s   ˆ j  t ˆ j j ƒ d ƒ ˆ j j j d ƒ ˆ j ˆ j j j ƒ  d ƒ ˆ j j j d d ˆ  j	 f ƒ t
 ƒ  } t j d | j d  ƒ | S(   Ni   i    RK   s   225.0.0.250(   t   assertEqualRk   R:   R   RA   t   setLoopbackModeR2   t   getLoopbackModeRO   R?   R   R   Rt   R   R   (   R5   R   (   R   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   cbPacket*  s    	c            s    ˆ  j  t ˆ  j j ƒ d ƒ d  S(   Ni   (   R¦   Rk   R:   R   (   R5   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt
   cbNoPacket6  s    (   R2   R:   RA   R¨   R1   t	   joinGroupR9   (   R   t   joinedR¥   R©   Rª   (    (   R   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   test_loopback  s    
c            s”   ˆ  j  ˆ  j j j ƒ  d ƒ ˆ  j  ˆ  j j j ƒ  d ƒ ˆ  j j j d ƒ } ˆ  j j j d ƒ } t | | g ƒ } ‡  f d †  } | j | ƒ | S(   sK   
        Test C{getOutgoingInterface} and C{setOutgoingInterface}.
        s   0.0.0.0s	   127.0.0.1c            s<   ˆ  j  ˆ  j j j ƒ  d ƒ ˆ  j  ˆ  j j j ƒ  d ƒ d  S(   Ns	   127.0.0.1(   R¦   RH   RA   t   getOutgoingInterfaceR:   (   R5   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   cbInterfacesJ  s    (   R¦   RH   RA   R®   R:   t   setOutgoingInterfaceR   R9   (   R   t   d1t   d2Ro   R¯   (    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   test_interface=  s    c            sm   ˆ  j  j j d ƒ } ‡  f d †  } | j | ƒ ‡  f d †  } | j | ƒ ‡  f d †  } | j | ƒ | S(   sE   
        Test that multicast a group can be joined and left.
        s   225.0.0.250c            s   ˆ  j  j j d ƒ S(   Ns   225.0.0.250(   RH   RA   t
   leaveGroup(   R5   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   clientJoinedY  s    c            s   ˆ  j  j j d ƒ S(   Ns   225.0.0.250(   R:   RA   R«   (   R5   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt
   clientLeft]  s    c            s   ˆ  j  j j d ƒ S(   Ns   225.0.0.250(   R:   RA   R´   (   R5   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   serverJoineda  s    (   RH   RA   R«   R9   (   R   R   Rµ   R¶   R·   (    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   test_joinLeaveS  s    c         C   s"   |  j  |  j j j d ƒ t j ƒ S(   sŠ   
        Test that an attempt to join an address which is not a multicast
        address fails with L{error.MulticastJoinError}.
        s	   127.0.0.1(   Rc   RH   RA   R«   R   t   MulticastJoinError(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   test_joinFailureh  s    s   Windows' multicast is wonkyc            s    t  ƒ  ‰  t j d ˆ  ƒ ‰ ˆ j j j ƒ  ‰ ˆ j j j d ƒ } ‡  ‡ ‡ f d †  } | j | ƒ ‡ f d †  } | j | ƒ ‡ f d †  } | j | ƒ | S(   sn   
        Test that a multicast group can be joined and messages sent to and
        received from it.
        i    s   225.0.0.250c            s3   t  ƒ  } ˆ j _ ˆ  j j d d ˆ j f ƒ | S(   Ns   hello worlds   225.0.0.250(   R   R:   R   RA   RO   R?   (   R5   R   (   RN   R   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR¥   €  s    c            s"   ˆ  j  ˆ  j j d d d ƒ d  S(   Ni    s   hello world(   R2   R:   R   (   R5   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR©   †  s    c            s)   t  ˆ j ƒ } | j ‡  f d †  ƒ | S(   Nc            s   ˆ  S(   N(    (   Rl   (   t   passthrough(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRp   Œ  s    (   R   R4   R9   (   R»   Ro   (   R6   (   R»   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   cleanupŠ  s    (   R   R   R    R:   RA   R1   R«   R9   (   R   R¬   R¥   R©   R¼   (    (   RN   R   R   R6   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   test_multicastu  s    	c            sÍ   t  ƒ  ‰ t j d ˆ d t ƒ‰ ˆ j ƒ  j ‰  t  ƒ  ‰ t j ˆ  ˆ d t ƒ‰ ˆ j j j d ƒ } ‡  ‡ ‡ f d †  } | j	 | ƒ ‡ ‡ ‡ f d †  } | j	 | ƒ ‡ ‡ f d †  } | j
 | ƒ | S(   s¢   
        Test that multiple sockets can listen on the same multicast port and
        that they both receive multicast messages directed to that address.
        i    t   listenMultiples   225.0.0.250c            sI   t  ƒ  } ˆ _ t  ƒ  } ˆ _ ˆ j j d d ˆ  f ƒ t | | g ƒ S(   Ns   hello worlds   225.0.0.250(   R   R   RA   RO   R   (   R5   R±   R²   (   t   portnot   firstClientt   secondClient(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR·   ¤  s    c            s:   ˆ  j  ˆ j d d d ƒ ˆ  j  ˆ j d d d ƒ d  S(   Ni    s   hello world(   R2   R   (   R5   (   R   RÀ   RÁ   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt
   gotPackets«  s    c            s>   t  t ˆ j ƒ t ˆ j ƒ g ƒ } | j ‡  f d †  ƒ | S(   Nc            s   ˆ  S(   N(    (   Rl   (   R»   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRp   ´  s    (   R   R   R4   R9   (   R»   Ro   (   t
   secondPortt	   firstPort(   R»   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR¼   °  s
    (   R   R   R    RX   R1   R?   R:   RA   R«   R9   Rq   (   R   R¬   R·   RÂ   R¼   (    (   R¿   RÃ   R   RÀ   RÁ   RÄ   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   test_multiListen“  s    		sj   on non-linux platforms it appears multiple processes can listen, but not multiple sockets in same process?(   R   R   R–   R—   R¤   R­   R³   R¸   Rº   R   t   platformt	   isWindowst   isVistat   todoR½   RÅ   t   skip(    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRŸ     s   	
			"						%s!   This reactor does not support UDPs'   This reactor does not support multicastc          C   s   d d  l  }  |  j j d ƒ rŒ t d ƒ j ƒ  } | j d ƒ rŒ | j ƒ  d } | j d ƒ d  d d g k r‰ t j j	 } d | _
 q‰ qŒ n  d  S(   Niÿÿÿÿs   /proc/versions   Linux versioni   t   .t   2s&   figure out why this fails in linux 2.2(   t   ost   patht   existst   opent   readt
   startswitht   splitRŸ   t   testInterfacet   im_funcRÉ   (   RÍ   t   st   f(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   checkForLinux22Ã  s    N(#   R*   t   twisted.trialR    R   t   twisted.internet.deferR   R   R   t   twisted.internetR   R   R   R   R	   R
   t   twisted.pythonR   R   t   DatagramProtocolR   t   ConnectedDatagramProtocolR!   R(   t	   ExceptionR)   R+   t   TestCaseR.   R•   RŸ   t   IReactorUDPR   RÊ   t   IReactorMulticastRØ   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   <module>   s*   .
ÿ `1»			