ó
S+šNc           @   s¦  d  Z  d d l 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 ƒ rs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   unittest(   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   assertEqualt   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   R6   (    (   R   R5   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    (   R1   R   R   R3   (   R4   (   R   t   port1R9   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR6   Œ   s    c            s   ˆ  j  ˆ j d ƒ d  S(   Ni   (   R1   R   (   R4   (   R   R9   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt	   cbStopped   s    (   R   R   R   R   R   R7   R8   (   R   R   R6   R<   (    (   R   R9   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(   R3   (   R4   t   port(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR6   ž   s    c            s;   t  j ƒ  } ˆ  _ t j d ˆ  d d ƒ} | j ˆ | ƒ S(   Ni    R.   s	   127.0.0.1(   R   R   R   R   R7   R8   (   R4   R   R5   (   R9   R6   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR<   ¡   s    (   R   R   R   R   R   R7   R8   (   R   R   R5   R<   (    (   R6   R9   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(
   R1   R0   t	   transportR   t   assertRaisesR   t   CannotListenErrorR   R7   R>   (   R4   t   server2(   R   R9   R>   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR6   ²   s    	c            s
   ˆ  j  ƒ  S(   N(   R3   (   R4   (   R>   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt
   cbFinished»   s    (   R   R   R   R   R   R7   R8   (   R   R   R6   RD   (    (   R   R9   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   R7   t   port2(   R4   (   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   R8   R@   t   writet   pop(   R4   t   nextClientWrite(   R9   RG   t   cbClientSendt   clientWrites(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRQ   á   s
    t   fireOnOneErrback(   RK   (   RL   N(   R@   t   connectR0   R>   R   R   R   RN   t   hostR   t   DeferredListt   True(   R4   t   cAddrt   sAddrt
   serverSend(   R9   RG   (   RQ   RR   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(   NRJ   RK   RL   RM   (   R@   R0   R1   R   RU   R>   (   R4   RX   RY   t
   clientAddr(   R   R9   RG   (    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(   NRS   (   R   RV   R   R3   RF   RW   (   R4   (   R   R;   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRD     s    (   R   R   R   R   R   R7   R'   R8   (   R   t   serverStartedRI   R   R[   R]   RD   (    (   RH   R   RG   R9   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.1RS   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   R@   RT   t   rangeRN   t   strt   assertFailureR   R%   (   R4   R&   t   i(   R   R9   RG   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR6     s    c            s1   t  j t  j ˆ j ƒ t  j ˆ  j ƒ g d t ƒS(   NRS   (   R   RV   R   R3   RW   (   R4   (   RF   R>   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRD   ,  s    (
   R'   R   R   R   R   R7   R   RV   RW   R8   (   R   RH   R^   R   R6   RD   (    (   R   R9   RG   RF   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   R7   RA   t
   ValueErrorR@   RT   t   RuntimeErrorR3   (   R   RG   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(   R1   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(    (   Rk   (   t   result(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   <lambda>a  s    (   R   R   R3   t   addBoth(   Rn   (   R>   (   Rn   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   Rj   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(   Rv   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   ebPacketTimeout•  s    	gš™™™™™¹?s&   Timed out in testDatagramReceivedErrorN(   t   failR!   t   failIfIdenticalR@   R   Ra   RO   R   R   R+   RN   RU   R>   t   addCallbackst
   addErrbackR   Rs   R   t   TimeoutError(   Rt   t   packetDeferredRy   R{   (   Ru   R   Rv   R   t   attemptsRG   Rx   (   Rw   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRv   q  s$    	(	   R   R   R8   R*   R   R7   Rp   R0   R`   (   R   Rm   Rq   (    (   Ru   Rv   R   R‚   RG   Rx   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(   Rk   (   R   t   portNoR5   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   stoppedListeningµ  s    (   R'   R   R7   Ra   R0   R>   R„   R…   R†   R   R   R3   R8   (   R   RG   Rˆ   R   (    (   R‡   R   R5   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   socketRN   t   flushWarningst   test_NoWarningOnBroadcastR1   Rj   (   R   RŠ   R5   t   warnings(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyR’   ¼  s    (   R   R   R:   R=   R?   RE   R_   Rd   Rh   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   R9   R   R7   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>   R3   (   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    (   R9   R@   t   connectionLostR   Rs   R   R   (   R4   (   R   t   finished(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   pktReceì  s    c            s   ˆ  j  ƒ  d  S(   N(   Ri   (   R4   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   flushErrorsõ  s    t    i@   s	   127.0.0.1(	   R   R   R9   R   R8   R@   RN   R0   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   R9   R    RG   R   t   listenMulticastR;   RF   R@   RT   R0   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;   R3   RF   (   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   (   RG   R9   R1   R@   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(   NRJ   s   225.0.0.250(   R   R9   R   R@   RN   R>   (   R4   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    RJ   s   225.0.0.250(   R1   Rj   R9   R   R@   t   setLoopbackModet   getLoopbackModeRN   R>   R   R   Rs   R   R   (   R4   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   (   R1   Rj   R9   R   (   R4   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt
   cbNoPacket6  s    (   R1   R9   R@   R¦   R0   t	   joinGroupR8   (   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(   R1   RG   R@   t   getOutgoingInterfaceR9   (   R4   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   cbInterfacesJ  s    (   R1   RG   R@   R¬   R9   t   setOutgoingInterfaceR   R8   (   R   t   d1t   d2Rn   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(   RG   R@   t
   leaveGroup(   R4   (   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(   R9   R@   R©   (   R4   (   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(   R9   R@   R²   (   R4   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   serverJoineda  s    (   RG   R@   R©   R8   (   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(   Rb   RG   R@   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   R9   R   R@   RN   R>   (   R4   R   (   RM   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(   R1   R9   R   (   R4   (   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(    (   Rk   (   t   passthrough(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRo   Œ  s    (   R   R3   R8   (   R¹   Rn   (   R5   (   R¹   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyt   cleanupŠ  s    (   R   R   RŸ   R9   R@   R0   R©   R8   (   R   Rª   R¤   R§   Rº   (    (   RM   R   R   R5   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 ƒ‰ d ‰ t ˆ j j j	 ˆ ƒ ˆ j	 ˆ ƒ ˆ j	 ˆ ƒ g ƒ } ‡  ‡ ‡ ‡ 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 ˆ ˆ  f ƒ t | | g ƒ S(   Ns   hello world(   R   R   R@   RN   R   (   R4   R¯   R°   (   t   portnot   theGroupt   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(   R1   R   (   R4   (   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(    (   Rk   (   R¹   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRo   ¸  s    (   R   R   R3   R8   (   R¹   Rn   (   t
   secondPortt	   firstPort(   R¹   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_udp.pyRº   ´  s
    (   R   R   RŸ   RW   R0   R>   R   R9   R@   R©   R8   Rp   (   R   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    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À			