ó
[łXMc           @   s*  d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m	 Z	 d d l
 m Z m Z m Z m Z d d l
 m Z d d l m Z d d	 l m Z m Z d d
 l m Z d d l m Z d d  Z d e j f d     YZ d e j f d     YZ d e f d     YZ d e e j f d     YZ  d e e j! f d     YZ" d e j# f d     YZ$ d   Z% d e j# f d     YZ& d e j' 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- d) e j# f d*     YZ. d+ e j f d,     YZ/ d- e j f d.     YZ0 d/ e j! f d0     YZ1 d1 e j# f d2     YZ2 d3 e j f d4     YZ3 d5 e j f d6     YZ4 d7 e j f d8     YZ5 d9 e5 f d:     YZ6 d; db d<     YZ7 d= e j# e7 f d>     YZ8 d? e j9 f d@     YZ: dA e j; f dB     YZ< dC e j# f dD     YZ= dE e j f dF     YZ> dG e j f dH     YZ? dI e j! f dJ     YZ@ dK e j9 f dL     YZA dM e j; f dN     YZB dO e j# f dP     YZC dQ e f dR     YZD dS e j f dT     YZE dU e j# f dV     YZF dW e j# f dX     YZG dY e j# f dZ     YZH d[ e j# f d\     YZI d] e j# f d^     YZJ d_ e j# f d`     YZK y d d lL ZL Wn eM k
 rn$ XeL jN eL jO  d da ZP eP e8 _Q d S(c   s.   
Tests for implementations of L{IReactorTCP}.
i˙˙˙˙N(   t
   implements(   t   unittest(   t   msg(   t   protocolt   reactort   defert
   interfaces(   t   error(   t   IPv4Address(   t   IHalfCloseableProtocolt   IPullProducer(   t   policies(   t   AccumulatingProtocoli    c            s|   d d l  m } t j       f d   } | j |    f d   }  j |   j |  } | j  j   S(   s¨   
    Poor excuse for an event notification helper.  This polls a condition and
    calls back a Deferred when it is seen to be true.

    Do not use this function.
    i˙˙˙˙(   t   taskc             s#       }  |  r  j  |   n  d  S(   N(   t   callback(   t   res(   t	   predicatet   d(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   check    s    	c            s     j    |  S(   N(   t   stop(   t   result(   t   call(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   %   s    
(	   t   twisted.internetR   R   t   Deferredt   LoopingCallt   addCallbackt   startt
   addErrbackt   errback(   R   t   intervalR   R   R   t   d2(    (   R   R   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt	   loopUntil   s    t   ClosingProtocolc           B   s   e  Z d    Z d   Z RS(   c         C   s   t  d  |  j j   d  S(   Ns   ClosingProtocol.connectionMade(   R   t	   transportt   loseConnection(   t   self(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   connectionMade1   s    
c         C   s   t  d  | j t j  d  S(   Ns   ClosingProtocol.connectionLost(   R   t   trapR   t   ConnectionDone(   R#   t   reason(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   connectionLost5   s    
(   t   __name__t
   __module__R$   R(   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR    /   s   	t   ClosingFactoryc           B   s&   e  Z d  Z d Z d   Z d   Z RS(   s/   
    Factory that closes port immediately.
    c         C   s   |  j  j   |  _ t   S(   N(   t   portt   stopListeningt   _cleanerUpperR    (   R#   t   conn(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   buildProtocolB   s    c         C   s#   |  j  d k r |  j j   S|  j  S(   sL   
        Clean-up for tests to wait for the port to stop listening.
        N(   R.   t   NoneR,   R-   (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   cleanUpG   s    N(   R)   R*   t   __doc__R1   R.   R0   R2   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR+   ;   s   	t   MyProtocolFactoryMixinc           B   s>   e  Z d  Z e Z d Z d Z d Z d Z	 d   Z
 d   Z RS(   s  
    Mixin for factories which create L{AccumulatingProtocol} instances.

    @type protocolFactory: no-argument callable
    @ivar protocolFactory: Factory for protocols - takes the place of the
        typical C{protocol} attribute of factories (but that name is used by
        this class for something else).

    @type protocolConnectionMade: L{NoneType} or L{defer.Deferred}
    @ivar protocolConnectionMade: When an instance of L{AccumulatingProtocol}
        is connected, if this is not C{None}, the L{Deferred} will be called
        back with the protocol instance and the attribute set to C{None}.

    @type protocolConnectionLost: L{NoneType} or L{defer.Deferred}
    @ivar protocolConnectionLost: When an instance of L{AccumulatingProtocol}
        is created, this will be set as its C{closedDeferred} attribute and
        then this attribute will be set to C{None} so the L{defer.Deferred} is
        not used by more than one protocol.

    @ivar protocol: The most recently created L{AccumulatingProtocol} instance
        which was returned from C{buildProtocol}.

    @type called: C{int}
    @ivar called: A counter which is incremented each time C{buildProtocol}
        is called.

    @ivar peerAddresses: A C{list} of the addresses passed to C{buildProtocol}.
    i    c         C   s   g  |  _  d  S(   N(   t   peerAddresses(   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   __init__u   s    c         C   sV   |  j  j |  |  j d 7_ |  j   } |  | _ |  j | _ d |  _ | |  _ | S(   si   
        Create a L{AccumulatingProtocol} and set it up to be able to perform
        callbacks.
        i   N(	   R5   t   appendt   calledt   protocolFactoryt   factoryt   protocolConnectionLostt   closedDeferredR1   R   (   R#   t   addrt   p(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR0   y   s    			N(   R)   R*   R3   R   R9   R1   t   protocolConnectionMadeR;   R   R8   R6   R0   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR4   Q   s   	t   MyServerFactoryc           B   s   e  Z d  Z RS(   sI   
    Server factory which creates L{AccumulatingProtocol} instances.
    (   R)   R*   R3   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR@      s   t   MyClientFactoryc           B   s>   e  Z d  Z d Z d Z d   Z d   Z d   Z d   Z RS(   sI   
    Client factory which creates L{AccumulatingProtocol} instances.
    i    c         C   s/   t  j |   t j   |  _ t j   |  _ d  S(   N(   R4   R6   R   R   t   deferredt   failDeferred(   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6      s    c         C   s&   d |  _  | |  _ |  j j d   d  S(   Ni   (   t   failedR'   RC   R   R1   (   R#   t	   connectorR'   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   clientConnectionFailed   s    		c         C   s   | |  _  |  j j d   d  S(   N(   t
   lostReasonRB   R   R1   (   R#   RE   R'   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   clientConnectionLostĄ   s    	c         C   s   d |  _  d  S(   Ni   (   t   stopped(   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   stopFactoryĽ   s    (	   R)   R*   R3   RD   RI   R6   RF   RH   RJ   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRA      s   			t   ListeningTestCasec           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         C   sN   t    } t j d | d d } |  j | j  |  j t j j |   d S(   sf   
        L{IReactorTCP.listenTCP} returns an object which provides
        L{IListeningPort}.
        i    t	   interfaces	   127.0.0.1N(	   R@   R   t	   listenTCPt
   addCleanupR-   t
   failUnlessR   t   IListeningPortt
   providedBy(   R#   t   ft   p1(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_listenŹ   s    	c            se   t      t j d   d d } | j   j     f d   } t j | j  } | j |  | S(   s  
        The L{IListeningPort} returned by L{IReactorTCP.listenTCP} can be
        stopped with its C{stopListening} method.  After the L{Deferred} it
        (optionally) returns has been called back, the port number can be bound
        to a new server.
        i    RL   s	   127.0.0.1c            s"   t  j    d d } | j   S(   NRL   s	   127.0.0.1(   R   RM   R-   (   t   ignoredR,   (   t   nRR   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   cbStopListeningÂ   s    (	   R@   R   RM   t   getHostR,   R   t   maybeDeferredR-   R   (   R#   R,   RW   R   (    (   RR   RV   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   testStopListeningˇ   s    	c         C   s+   t    } t j d | d d } | j   S(   Ni    RL   s	   127.0.0.1(   R@   R   RM   R-   (   R#   RR   RS   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   testNumberedInterfaceĚ   s    	c            s   t    } t j d |   t  j   j     j t   j    d k      f d   } t	 j
  j  } | j |  S(   Ni    i˙˙˙˙c            s&     j  t   j   d k  d  S(   Ni˙˙˙˙(   t   failIft   reprt   find(   t   ign(   R#   t   portNoR>   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   stoppedListening×   s    (   R@   R   RM   t   strRX   R,   R\   R]   R^   R   RY   R-   R   (   R#   RR   Ra   R   (    (   R`   R#   R>   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   testPortReprŇ   s    	"c            sś   t    } t j   } | _ t j d |     j  j  t   } t j   } | _ t j	 d  j
   j |  }   j | j     f d   } t j | | g  j |  S(   s   
        Check that the repr string of the server transport get the good port
        number if the server listens on 0.
        i    s	   127.0.0.1c            sY   |  \ } }  j    j }   j t | j  d | f  | j j   | j j   d  S(   Ns   <AccumulatingProtocol #0 on %s>(   RX   R,   t   assertEqualsR]   R!   R"   (   t   .0t   serverProtot   clientProtot
   portNumber(   R#   R,   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   ě   s    	(   R@   R   R   R?   R   RM   RN   R-   RA   t
   connectTCPRX   R,   t
   disconnectt   gatherResultsR   (   R#   t   servert   serverConnMadet   clientt   clientConnMadeRE   R   (    (   R#   R,   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_serverReprÝ   s    			c            su   t     t j d  d d    j  j       f d   } d    t j  j  } | j |  | S(   s   
        Stop and then try to restart a L{tcp.Port}: after a restart, the
        server should be able to handle client connections.
        i    RL   s	   127.0.0.1c            s    j    t   } t j    _ t j   | _ t j d  j   j |  }   j	 | j
  t j  j | j g  j   S(   Ns	   127.0.0.1(   t   startListeningRA   R   R   R?   R   Ri   RX   R,   RN   Rj   Rk   R   (   RU   Rn   RE   (   R#   t   serverFactoryt   closeR,   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRW      s    
		c         S   s*   |  \ } } | j  j   | j  j   d  S(   N(   R!   R"   (   Re   Rf   Rg   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs     s    	(   R@   R   RM   RN   R-   R   RY   R   (   R#   RW   R   (    (   R#   Rr   Rs   R,   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_restartListening÷   s    		c         C   sI   t    } d   } | | _ t j d | d d } |  j | j   t  S(   sť   
        If the server factory raises an exception in C{stopFactory}, the
        deferred returned by L{tcp.Port.stopListening} should fail with the
        corresponding error.
        c           S   s   t  d   d  S(   Ns   An error(   t   RuntimeError(    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   raiseException  s    i    RL   s	   127.0.0.1(   R@   RJ   R   RM   t   assertFailureR-   Ru   (   R#   Rr   Rv   R,   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_exceptInStop  s
    			c            s   t     d   } |  _ t j d  d d    j  j       f d   } d      j  j   t  j |  S(   sš   
        Even if the server factory raise an exception in C{stopFactory}, the
        corresponding C{tcp.Port} instance should be in a sane state and can
        be restarted.
        c           S   s   t  d   d  S(   Ns   An error(   Ru   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRv   ,  s    i    RL   s	   127.0.0.1c            s    `   j   t   } t j    _ t j   | _ t j d  j   j	 |  }   j
 | j  t j  j | j g  j   S(   Ns	   127.0.0.1(   RJ   Rq   RA   R   R   R?   R   Ri   RX   R,   RN   Rj   Rk   R   (   RU   Rn   RE   (   R#   Rr   Rs   R,   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRW   2  s    
		c         S   s*   |  \ } } | j  j   | j  j   d  S(   N(   R!   R"   (   Re   Rf   Rg   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs   @  s    	(	   R@   RJ   R   RM   RN   R-   Rw   Ru   R   (   R#   Rv   RW   (    (   R#   Rr   Rs   R,   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_restartAfterExcept%  s    				c            s   t    } t j d | d d } | j   j } | j d  t     t j	   | _
 t j	     _
 t j d |      f d   }   j j |  S(   së   
        If C{connectionLost} is called directly on a port object, it succeeds
        (and doesn't expect the presence of a C{deferred} attribute).

        C{connectionLost} is called by L{reactor.disconnectAll} at shutdown.
        i    RL   s	   127.0.0.1c            s     j  j t j  d  S(   N(   R'   R%   R   t   ConnectionRefusedError(   R_   (   Rn   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   X  s    N(   R@   R   RM   RX   R,   R(   R1   RA   R   R   R?   Ri   RC   R   (   R#   Rr   R,   Rh   R   (    (   Rn   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_directConnectionLostCallH  s    		c         C   sM   t    } d   } | | _ t j d | d d } |  j t | j d  d S(   s  
        If C{connectionLost} is called directory on a port object and that the
        server factory raises an exception in C{stopFactory}, the exception is
        passed through to the caller.

        C{connectionLost} is called by L{reactor.disconnectAll} at shutdown.
        c           S   s   t  d   d  S(   Ns   An error(   Ru   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRv   f  s    i    RL   s	   127.0.0.1N(   R@   RJ   R   RM   t   assertRaisesRu   R(   R1   (   R#   Rr   Rv   R,   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_exceptInConnectionLostCall]  s
    			(   R)   R*   RT   RZ   R[   Rc   Rp   Rt   Rx   Ry   R{   R}   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRK   Ş   s   								#	c         C   sI   d d l  m } d d  l } | j |  z |    Wd  | j d   Xd  S(   Ni˙˙˙˙(   t   spewerWithLinenums(   t   twisted.python.utilR~   t   syst   settraceR1   (   RR   t   spewerR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   callWithSpewn  s    t   LoopbackTestCasec           B   s_   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(
   s$   
    Test loopback connections.
    c            s   t    } t j d | d d   | _   j | j   j   j } t    t j d |       f d   }  j	 j
 |  S(   sz   
        A port created with L{IReactorTCP.listenTCP} can be connected to with
        L{IReactorTCP.connectTCP}.
        i    RL   s	   127.0.0.1c            s:     j   j j    j   j   j j t j  d  S(   N(   t
   assertTrueR   t   madet   disconnectedRG   R%   R   R&   (   t   x(   R#   R,   t   clientF(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR     s    (   R+   R   RM   R,   RN   R2   RX   RA   Ri   RB   R   (   R#   RR   Rh   R   (    (   R#   R,   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_closePortInProtocolFactory{  s    			c         C   s    t  | d d    t j  d  S(   NR%   c         S   s   d  S(   N(   R1   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   <lambda>  s    (   t   getattrR   R&   (   R#   t   obj(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   _trapCnxDone  s    c   
         sť   t    } t j   } | | _ t j d | d d } |  j | j  | j   j	 } t
   } t j   } | | _ t j d | |  t j | | g  }   f d   }	 | j |	  | S(   s   
        Invoke the given callback with a client protocol and a server protocol
        which have been connected to each other.
        i    RL   s	   127.0.0.1c            s7   |  \ } }   | |  | j  j   | j  j   d  S(   N(   R!   R"   (   Re   t   serverProtocolt   clientProtocol(   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt	   connectedŁ  s    	(   R@   R   R   R?   R   RM   RN   R-   RX   R,   RA   Ri   Rk   R   (
   R#   R   Rr   Rm   R,   Rh   R   Ro   t	   connsMadeR   (    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   _connectedClientAndServerTest  s    				c            s     f d   }   j  |  S(   s  
        The transport of a protocol connected with L{IReactorTCP.connectTCP} or
        L{IReactor.TCP.listenTCP} can have its I{TCP_NODELAY} state inspected
        and manipulated with L{ITCPTransport.getTcpNoDelay} and
        L{ITCPTransport.setTcpNoDelay}.
        c            s   xy |  | g D]k } | j  }   j | j   d  | j d    j | j   d  | j d    j | j   d  q Wd  S(   Ni    i   (   R!   Rd   t   getTcpNoDelayt   setTcpNoDelay(   R   R   R>   R!   (   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   ˛  s    	(   R   (   R#   R   (    (   R#   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_tcpNoDelayŤ  s    c            s     f d   }   j  |  S(   s  
        The transport of a protocol connected with L{IReactorTCP.connectTCP} or
        L{IReactor.TCP.listenTCP} can have its I{SO_KEEPALIVE} state inspected
        and manipulated with L{ITCPTransport.getTcpKeepAlive} and
        L{ITCPTransport.setTcpKeepAlive}.
        c            s   xy |  | g D]k } | j  }   j | j   d  | j d    j | j   d  | j d    j | j   d  q Wd  S(   Ni    i   (   R!   Rd   t   getTcpKeepAlivet   setTcpKeepAlive(   R   R   R>   R!   (   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   Ä  s    	(   R   (   R#   R   (    (   R#   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_tcpKeepAlive˝  s    c            sA   t      t j d d   d d   f d   }   j j |  S(   Ns	   127.0.0.1iE   t   timeouti   c            s     j  j t j  d  S(   N(   R'   R%   R   Rz   (   RU   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   Ó  s    (   RA   R   Ri   RC   R   (   R#   R   (    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   testFailingĎ  s    	c            sâ   g   xG t  d  D]9 } t j   } | j d  | j d   j |  q Wt j   t j t	 t j
        f d         }  j | t j   f d   } | j |   f d   } | j |  | S(	   s   
        Assert that the error number of the ConnectionRefusedError is
        ECONNREFUSED, and not some other socket related error.
        i
   s	   127.0.0.1i    i   c             s`       f d   }   j    } | j   \ } } | j    j | |  } | j |   | S(   Nc            s+   |  j  j    r     S j d  d S(   s\   
                Darn.  Kill it and try again, if there are any tries left.
                s?   Could not fail to connect - could not test errno for that case.N(   R!   R"   t   fail(   t   proto(   t   tryConnectFailuret   serverSocketsR#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   ü  s    (   t   popt   getsocknameRs   Ri   R   (   R   t   serverSockett
   serverHostt
   serverPortt   connectDeferred(   R   R   t   clientCreatorR#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   ű  s    	
c            s     j  |  j t j  d  S(   N(   t   assertEqualt   osErrort   errnot   ECONNREFUSED(   t   exc(   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   connRefused  s    c            s!   x   r   j    j   q W|  S(   N(   R    Rs   (   t   passthrough(   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   cleanup  s    	(   s	   127.0.0.1i    (   t   xranget   sockett   bindt   listenR7   t   randomt   shuffleR   t   ClientCreatorR   t   ProtocolRw   R   Rz   R   t   addBoth(   R#   t   iR˘   t   refusedDeferredRŹ   RŽ   (    (   R   R   R#   RŚ   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt!   test_connectionRefusedErrorNumberŘ  s     	c         C   s&   |  j  t j t j d d t    d S(   su   
        Connecting to a named service which does not exist raises
        L{error.ServiceNameUnknownError}.
        s	   127.0.0.1t   thisbetternotexistN(   R|   R   t   ServiceNameUnknownErrorR   Ri   RA   (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_connectByServiceFail  s    c            sŕ   t     t j   } |  _ t j d  d d }   j | j  | j   j	  t
   } t j   } | | _  f d   }   j t d |  t j d d |  t j | | g  }    f d   } | j |  | S(   s×   
        L{IReactorTCP.connectTCP} accepts the name of a service instead of a
        port number and connects to the port number associated with that
        service, as defined by L{socket.getservbyname}.
        i    RL   s	   127.0.0.1c            s    |  d k r | d k r   Sd S(   Nt   httpt   tcpi
   (    (   t   serviceNamet   protocolName(   Rh   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   fakeGetServicePortByName5  s    t   getservbynameRž   c            s=   |  \ } }  j    j d  | j j   | j j   d  S(   Ns7   Server factory was not called upon to build a protocol.(   R   R8   R!   R"   (   Re   R   R   (   Rr   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   >  s    	(   R@   R   R   R?   R   RM   RN   R-   RX   R,   RA   t   patchR°   Ri   Rk   R   (   R#   Rm   R,   t   clientFactoryRo   RÂ   t   connMadeR   (    (   R#   Rr   Rh   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_connectByService%  s     				(   R)   R*   R3   R   R   R   R   R   R   Rş   R˝   RÇ   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   w  s   								B	t   StartStopFactoryc           B   s&   e  Z d  Z d  Z d   Z d   Z RS(   i    c         C   s(   |  j  s |  j r t  n  d |  _  d  S(   Ni   (   t   startedRI   Ru   (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   startFactoryM  s    	c         C   s)   |  j  s |  j r t  n  d |  _ d  S(   Ni   (   RÉ   RI   Ru   (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRJ   R  s    	(   R)   R*   RÉ   RI   RĘ   RJ   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRČ   H  s   	t   ClientStartStopFactoryc           B   s&   e  Z d  Z d  Z d   Z d   Z RS(   i    c         C   s(   |  j  s |  j r t  n  d |  _  d  S(   Ni   (   RÉ   RI   Ru   (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRĘ   ]  s    	c         C   s)   |  j  s |  j r t  n  d |  _ d  S(   Ni   (   RÉ   RI   Ru   (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRJ   b  s    	(   R)   R*   RÉ   RI   RĘ   RJ   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRË   X  s   	t   FactoryTestCasec           B   s    e  Z d  Z d   Z d   Z RS(   s   Tests for factories.c            s  t     t j d  d d }  j | j   j  j  j f d  t j d  d d } t j d  d d    j  j  j f d  t j	 | j  } t j	 | j  } t j
 | | g  }     f d   } | j |    f d   } | j |  | S(	   s  
        The factory passed to L{IReactorTCP.listenTCP} should be started only
        when it transitions from being used on no ports to being used on one
        port and should be stopped only when it transitions from being used on
        one port to being used on no ports.
        i    RL   s	   127.0.0.1i   c            s&     j   j  j f d   j   S(   Ni   i    (   i   i    (   R§   RÉ   RI   R-   (   RU   (   R#   t   p3RR   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   cbClosed  s    c            s      j   j  j f d  d  S(   Ni   (   i   i   (   Rd   RÉ   RI   (   RU   (   R#   RR   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   cbClosedAll  s    (   i   i    (   i   i    (   RČ   R   RM   RN   R-   R§   RÉ   RI   R   RY   Rk   R   (   R#   RS   t   p2t   d1R   R<   RÎ   RĎ   (    (   RÍ   RR   R#   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_serverStartStopk  s    	c            s   t    } t j d | d d } | | _ |  j | j  | j   j } t     t j d |    |  j	   j
  t   f d    S(   s   
        The factory passed to L{IReactorTCP.connectTCP} should be started when
        the connection attempt starts and stopped when it is over.
        i    RL   s	   127.0.0.1c              s     j  S(   N(   RI   (    (   R:   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   ¤  s    (   R+   R   RM   R,   RN   R2   RX   RË   Ri   R   RÉ   R   (   R#   RR   R>   Rh   (    (   R:   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_clientStartStop  s    			(   R)   R*   R3   RŇ   RÓ   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRĚ   h  s   	+t   ConnectorTestCasec           B   s#   e  Z d    Z d   Z d   Z RS(   c            s0  t    } t j d | d d } | | _  j | j  | j   j } g   g    t       f d    _  j	  _
 t j d |     j t j j     j   }  j | j d   j | j d   j | j |  t  f d    }      f d   } | j |  | S(   sU  
        L{IReactorTCP.connectTCP} returns an object which provides
        L{IConnector}.  The destination of the connector is the address which
        was passed to C{connectTCP}.  The same connector object is passed to
        the factory's C{startedConnecting} method as to the factory's
        C{clientConnectionLost} method.
        i    RL   s	   127.0.0.1c            s    j  |     j  |  f S(   N(   R7   (   RE   R'   (   t   seenFailurest   seenConnectors(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   ˝  s   t   TCPc              s     j  S(   N(   RI   (    (   RĹ   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   Č  s    c            s.    d j  t j   j     g  d  S(   Ni    (   R%   R   R&   R§   (   RU   (   RÖ   R#   RE   RŐ   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   clientFactoryStoppedÉ  s    (   R+   R   RM   R,   RN   R2   RX   RË   RH   R7   t   startedConnectingRi   R   R   t
   IConnectorRQ   t   getDestinationRd   t   typet   hostR   R   (   R#   Rr   t   tcpPortRh   t   destR   RŘ   (    (   RŐ   RÖ   R#   RE   RĹ   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_connectorIdentityŞ  s(    			c            s˘   t    } t j d | d d }   j | j  | j   j } d   } t    |  _ t j	 d |   t
  f d    }    f d   } | j |  S(   sÇ   
        Calling L{IConnector.stopConnecting} in C{Factory.startedConnecting}
        results in C{Factory.clientConnectionFailed} being called with
        L{error.UserError} as the reason.
        i    RL   s	   127.0.0.1c         S   s   |  j    d  S(   N(   t   stopConnecting(   RE   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRŮ   Ű  s    c              s     j  S(   N(   RI   (    (   RĹ   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   â  s    c            s*     j   j d   j j t j  d  S(   Ni   (   Rd   RD   R'   R%   R   t	   UserError(   RU   (   R#   RĹ   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   ă  s    (   R@   R   RM   RN   R-   RX   R,   RË   RŮ   Ri   R   R   (   R#   Rr   RŢ   Rh   RŮ   R   R   (    (   R#   RĹ   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_userFailĐ  s    				c            sŤ   t    } t j d | d d } | | _   j | j  | j   j } t    d   } |  _ t j	 d |   t
  f d    }    f d   } | j |  S(   s   
        Calling L{IConnector.connect} in C{Factory.clientConnectionLost} causes
        a new connection attempt to be made.
        i    RL   s	   127.0.0.1c         S   s   |  j    d  S(   N(   t   connect(   RE   R'   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRH   ö  s    c              s     j  S(   N(   RD   (    (   RĹ   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   ű  s    c            sO    j  }   j | j | j f d   j j t j    j  j d  d  S(   Ni   (   i   i   (	   R   R§   R   t   closedR'   R%   R   Rz   RI   (   RU   R>   (   R#   RĹ   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   reconnectFailedü  s    	(   R+   R   RM   R,   RN   R2   RX   RA   RH   Ri   R   R   (   R#   Rr   RŢ   Rh   RH   R   Rć   (    (   R#   RĹ   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_reconnecté  s    					(   R)   R*   Rŕ   Ră   Rç   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRÔ   ¨  s   	&	t   CannotBindTestCasec           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s]   
    Tests for correct behavior when a reactor cannot bind to the required TCP
    port.
    c         C   sŤ   t    } t j d | d d } |  j | j  | j   j } | j   } |  j | j d  |  j | j	 d  |  j | j |  |  j
 t j t j | | d d d S(   s   
        L{IReactorTCP.listenTCP} raises L{error.CannotListenError} if the
        address to listen on is already in use.
        i    RL   s	   127.0.0.1R×   N(   R@   R   RM   RN   R-   RX   R,   Rd   RÜ   RÝ   R|   R   t   CannotListenError(   R#   RR   RS   RV   Rß   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_cannotBind  s    	c            s2   d d l  m }    f d   } | j  |  S(   sG   Returns closure that when called calls f and then callbacks d.
        i˙˙˙˙(   t   utilc             s     |  |   }   j  d  | S(   Nt    (   R   (   t   argst   kwt   rtn(   R   RR   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   newf$  s    (   t   twisted.pythonRë   t   mergeFunctionMetadata(   R#   R   RR   t   tputilRđ   (    (   R   RR   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   _fireWhenDoneFunc   s    c            sç   t  j   } t   }  j | | j  | _ t j d | d d   j  j     f d   }   f d          f d     f d     f d       f d	     f d
    | j	 |  | S(   sł   
        L{IReactorTCP.connectTCP} calls C{Factory.clientConnectionFailed} with
        L{error.ConnectBindError} if the bind address specified is already in
        use.
        i    RL   s	   127.0.0.1c            sc   t  j   } t   }   j | | j  | _ t j d  j   j | d d | j	  |  | S(   Ns	   127.0.0.1t   bindAddressi    (   s	   127.0.0.1i    (
   R   R   RA   Rô   R0   R   Ri   RX   R,   R   (   t   resultsR   t   cf1(   R#   R>   t   _conmade(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt	   _connect17  s    	c            s>   t  j   }   j | | j j  | j _ | j  |  | S(   N(   R   R   Rô   R   R$   R   (   Rö   R÷   R   (   R#   t   _check1connect2(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRř   @  s
    c            sö    j  | j j d  t j   } t j   } | j j j   j } t   }  j	 | | j
  | _
  j	 | | j  | _ t j d  j   j | d d | f | j  | |  | j   | |  t j | | g  } | j  | |  | S(   Ni   s	   127.0.0.1Rő   (   Rd   R   R   R   R   R!   RX   R,   RA   Rô   RF   RJ   R   Ri   R   t   DeferredList(   Rö   R÷   RŃ   R   R,   t   cf2t   dl(   t   _check2stoppedt   _stopR#   t   _check2failedR>   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRú   G  s    	c            sF     j  | j d  | j j t j    j | j j t j   |  S(   Ni   (   Rd   RD   R'   R%   R   t   ConnectBindErrorR   R   (   Rö   R÷   Rü   (   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   Y  s    c            s     j  | j d  |  S(   Ni   (   Rd   RI   (   Rö   R÷   Rü   (   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRţ   _  s    c            sH   t  j   } | j  |    j | | j  | _ | j j j   | S(   N(   R   R   R   Rô   RJ   R   R!   R"   (   Rö   R÷   Rü   R   (   R#   t   _check1cleanup(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR˙   c  s
    c            s     j  | j d  d  S(   Ni   (   Rd   RI   (   Rö   R÷   (   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR  j  s    (
   R   R   R@   Rô   RĘ   R   RM   RN   R-   R   (   R#   t   theDeferredt   sfRů   (    (   Rţ   R˙   R#   R   R>   Rř   R  Rú   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_clientBind+  s    		(   R)   R*   R3   Rę   Rô   R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRč     s   		t   MyOtherClientFactoryc           B   s   e  Z d    Z RS(   c         C   s   | |  _  t   |  _ |  j S(   N(   t   addressR   R   (   R#   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR0   s  s    	(   R)   R*   R0   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR  r  s   t   LocalRemoteAddressTestCasec           B   s   e  Z d  Z d   Z RS(   so   
    Tests for correct getHost/getPeer values and that the correct address is
    passed to buildProtocol.
    c            sÎ   t    } t j   | _ | j   t j d | d d   j  j   j   j	 } t
    t j   }  _ t j d |       f d   } | j |     f d   } | j |  | S(   s   
        L{IListeningPort.getHost} returns the same address as a client
        connection's L{ITCPTransport.getPeer}.
        i    RL   s	   127.0.0.1c            sB     j   j   g  j    j   j    j j j    d  S(   N(   Rd   RX   R5   R   R!   t   getPeer(   RU   (   R#   RĹ   R,   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR     s    c            s     j     S(   N(   Rj   (   RU   (   RE   t   serverConnectionLost(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRŽ     s    
(   R@   R   R   R;   R   RM   RN   R-   RX   R,   RA   R?   Ri   R   (   R#   Rr   RV   t   onConnectionR   RŽ   (    (   R
  R#   RĹ   R,   RE   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_hostAddress  s    			(   R)   R*   R3   R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR  z  s   t   WriterProtocolc           B   s   e  Z d    Z RS(   c         C   sť   |  j  j d  d d d d g } |  j  j |  |  j  j   } | j d k rh d G| GHd |  j _ n  |  j  j   } | j d k r d	 G| GHd |  j _ n  d |  j _ |  j  j	   d  S(
   Ns   Hello Cleveland!
t   Goodbyes    cruels    worlds   
R×   s    getPeer returned non-TCP socket:i   s    getHost returned non-TCP socket:(
   R!   t   writet   writeSequenceR	  RÜ   R:   t   problemRX   t   doneR"   (   R#   t   seqt   peert   us(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR$   ˘  s    		(   R)   R*   R$   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR  Ą  s   t   ReaderProtocolc           B   s   e  Z d    Z d   Z RS(   c         C   s   |  j  j | 7_ d  S(   N(   R:   t   data(   R#   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   dataReceived¸  s    c         C   s   d |  j  _ d  S(   Ni   (   R:   R  (   R#   R'   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR(   ş  s    (   R)   R*   R  R(   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR  ˇ  s   	t   WriterClientFactoryc           B   s   e  Z d    Z d   Z RS(   c         C   s   d |  _  d |  _ d  S(   Ni    Rě   (   R  R  (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6   ž  s    	c         C   s   t    } |  | _ | |  _ | S(   N(   R  R:   R   (   R#   R=   R>   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR0   Á  s    			(   R)   R*   R6   R0   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR  ˝  s   	t   WriteDataTestCasec           B   s    e  Z d  Z d   Z d   Z RS(   sw   
    Test that connected TCP sockets can actually write data. Try to exercise
    the entire ITransport interface.
    c            sĎ   t  j     t   _  d   _ d   _ t    } t j d | d d }  j | j	  | j
   j } t    t   } t j d | |      f d   } t j | j | j g  } | j |  S(   s   
        L{ITCPTransport.write} and L{ITCPTransport.writeSequence} send bytes to
        the other end of the connection.
        i    RL   s	   127.0.0.1c            sz     j   j d    j   j d k d    j   j d  d j d d d d	 d
 g  }   j   j | k d  d  S(   Ns&   writer didn't finish, it probably diedi    s   writer indicated an errors$   client didn't see connection droppedRě   s   Hello Cleveland!
R  s    cruels    worlds   
s.   client didn't receive all the data it expected(   RO   R  R  t   joinR  (   RU   t   expected(   R#   R   RR   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   Ţ  s    	(   R   t   FactoryR  R  R  t   WiredFactoryR   RM   RN   R-   RX   R,   R  Ri   R   Rk   t   onDisconnectR   (   R#   t   wrappedFR>   RV   t   wrappedClientFR   R   (    (   RR   R#   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_writerÍ  s    					c            s  t  j j d k r$ t j d   n  t  j j d k rH t j d   n  t j     t j    d t j f    f d     Y} t j	   } | | _ t  j
 d | d d	 } |  j | j  | j   } d
 t f d     Y d t j f     f d     Y} t    |  _  j }  f d   } | j |  t d | j | j f  t  j | j | j   t d  |  j | t j  S(   s$  
        A TCP transport which is written to after the connection has been shut
        down should notify its protocol that the connection has been lost, even
        if the TCP transport is not actively being monitored for read events
        (ie, pauseProducing was called on it).
        t   IOCPReactors'  iocpreactor does not, in fact, stop reading immediately after pauseProducing is called. This results in a bonus disconnection notification. Under some circumstances, it might be possible to not receive this notifications (specifically, pauseProducing, deliver some data, proceed with this test).t
   GtkReactors   gtkreactor does not implement unclean disconnection notification correctly.  This might more properly be a todo, but due to technical limitations it cannot be.t   Disconnecterc              s,   e  Z d  Z   f d   Z  f d   Z RS(   sŘ   
            Protocol for the server side of the connection which disconnects
            itself in a callback on clientPaused and publishes notification
            when its connection is actually lost.
            c            s*   t  d    f d   }  j |  d S(   s[   
                Set up a callback on clientPaused to lose the connection.
                s   Disconnector.connectionMadec            s%   t  d    j j   t  d  d  S(   Ns&   Disconnector.connectionMade disconnects   loseConnection called(   R   R!   R"   (   RU   (   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRj   "  s    
N(   R   R   (   R#   Rj   (   t   clientPaused(   R#   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR$     s    
c            s%   t  d    j d  t  d  d S(   st   
                Notify observers that the server side of the connection has
                ended.
                s   Disconnecter.connectionLosts   serverLost called backN(   R   R   R1   (   R#   R'   (   t
   serverLost(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR(   (  s    
(   R)   R*   R3   R$   R(   (    (   R&  R'  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR%    s   i    RL   s	   127.0.0.1t   Infinitec           B   s3   e  Z d  Z e e  d   Z d   Z d   Z RS(   sż   
            A producer which will write to its consumer as long as
            resumeProducing is called.

            @ivar consumer: The L{IConsumer} which will be written to.
            c         S   s   | |  _  d  S(   N(   t   consumer(   R#   R)  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6   A  s    c         S   s(   t  d  |  j j d  t  d  d  S(   Ns   Infinite.resumeProducingR   s*   Infinite.resumeProducing wrote to consumer(   R   R)  R  (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   resumeProducingD  s    
c         S   s   t  d  d  S(   Ns   Infinite.stopProducing(   R   (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   stopProducingI  s    (   R)   R*   R3   R    R
   R6   R*  R+  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR(  8  s
   
		t   UnreadingWriterc              s#   e  Z d  Z     f d   Z RS(   s   
            Trivial protocol which pauses its transport immediately and then
            writes some bytes to it.
            c            sQ   t  d    j j    j d   t  d     f d   }  j |  d  S(   Ns   UnreadingWriter.connectionMades   clientPaused called backc            sD   t  d     j  } t  d    j j | t  t  d  d  S(   Ns$   UnreadingWriter.connectionMade writes5   UnreadingWriter.connectionMade write created producers8   UnreadingWriter.connectionMade write registered producer(   R   R!   t   registerProducert   False(   RU   t   producer(   R#   R(  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR  W  s
    

(   R   R!   t   pauseProducingR   R1   R   (   R#   R  (   R&  R(  R'  (   R#   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR$   R  s    

(   R)   R*   R3   R$   (    (   R(  R&  R'  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR,  M  s   c            s   t  d    j S(   Nt   cbClientLost(   R   RG   (   RU   (   Rn   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR1  n  s    
s   Connecting to %s:%ss   Returning Deferred(   R   t	   __class__R)   R   t   SkipTestR   R   R   Rś   t   ServerFactoryRM   RN   R-   RX   t   objectRA   R9   RB   R   R   RÝ   R,   Ri   Rw   R   t   ConnectionLost(   R#   R%  Rl   R,   R=   R,  RH   R1  (    (   R&  Rn   R(  R'  s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt%   test_writeAfterShutdownWithoutReadingě  s2    	"	%			
(   R)   R*   R3   R"  R7  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR  Ç  s   	t   ConnectionLosingProtocolc           B   s   e  Z d    Z RS(   c         C   sD   |  j  j d  |  j  j   |  j j   |  j j j |  j   d  S(   Nt   1(   R!   R  R"   t   mastert   _connectionMadet   portsR7   (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR$   }  s    (   R)   R*   R$   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR8  |  s   t   NoopProtocolc           B   s   e  Z d    Z d   Z RS(   c         C   s)   t  j   |  _ |  j j j |  j  d  S(   N(   R   R   R   R:  t   serverConnsR7   (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR$     s    c         C   s   |  j  j t  d  S(   N(   R   R   t   True(   R#   R'   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR(     s    (   R)   R*   R$   R(   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR=    s   	t   ConnectionLostNotifyingProtocolc           B   s    e  Z d  Z d   Z d   Z RS(   sc  
    Protocol which fires a Deferred which was previously passed to
    its initializer when the connection is lost.

    @ivar onConnectionLost: The L{Deferred} which will be fired in
        C{connectionLost}.

    @ivar lostConnectionReason: C{None} until the connection is lost, then a
        reference to the reason passed to C{connectionLost}.
    c         C   s   d  |  _ | |  _ d  S(   N(   R1   t   lostConnectionReasont   onConnectionLost(   R#   RB  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6     s    	c         C   s   | |  _  |  j j |   d  S(   N(   RA  RB  R   (   R#   R'   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR(     s    	(   R)   R*   R3   R6   R(   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR@    s   
	t   HandleSavingProtocolc           B   s   e  Z d  Z d   Z RS(   s   
    Protocol which grabs the platform-specific socket handle and
    saves it as an attribute on itself when the connection is
    established.
    c         C   s"   | j    |  _ t j j |  |  S(   s\   
        Save the platform-specific socket handle for future
        introspection.
        (   t	   getHandlet   handleR   Rś   t   makeConnection(   R#   R!   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRF  Ť  s    (   R)   R*   R3   RF  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRC  Ľ  s   t   ProperlyCloseFilesMixinc           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   sA   
    Tests for platform resources properly being cleaned up.
    c         C   s   t     d S(   sÂ   
        Bind a server port to which connections will be made.  The server
        should use the given protocol factory.

        @return: The L{IListeningPort} for the server created.
        N(   t   NotImplementedError(   R#   R  Rh   R:   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   createServerš  s    c         C   s   t     d S(   sĂ   
        Establish a connection to the given address using the given
        L{ClientCreator} instance.

        @return: A Deferred which will fire with the connected protocol instance.
        N(   RH  (   R#   R  Rh   RŚ   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   connectClientĂ  s    c         C   s   t     d S(   s   
        Return the exception class which will be raised when an operation is
        attempted on a closed platform handle.
        N(   RH  (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   getHandleExceptionTypeÍ  s    c         C   s   t  j S(   sn   
        Return the errno expected to result from writing to a closed
        platform socket handle.
        (   RŠ   t   EBADF(   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   getHandleErrorCodeŐ  s    	c            sč   t  j    t j   }  f d   | _  j d d |   t  j      j   } t j t   f d    }  j | j	 | j
 |  }    f d   } | j |   f d   } | j |   f d   } | j |  | S(   sp   
        Test that lost connections properly have their underlying socket
        resources cleaned up.
        c              s
   t     S(   N(   R@  (    (   t   onServerConnectionLost(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   č  s   s	   127.0.0.1i    c              s
   t     S(   N(   RC  (    (   t   onClientConnectionLost(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   ď  s    c            s0   |  j  j d  |  j  j   t j    g  S(   sŚ   
            Disconnect the client.  Return a Deferred which fires when both
            the client and the server have received disconnect notification.
            s0   some bytes to make sure the connection is set up(   R!   R  R"   R   Rk   (   Rn   (   RO  RN  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   clientConnectedó  s
    	c            sz   |  \ } } | j  j t j  | j  j t j    j   }   j   j   | j j d  }   j	 | j
 d |  d S(   sl   
            Verify that the underlying platform socket handle has been
            cleaned up.
            t   bytesi    N(   RA  R%   R   t   ConnectionClosedRM  R|   RK  RE  t   sendR§   Rí   (   Re   Rn   Rl   t   expectedErrorCodet   err(   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   clientDisconnected˙  s    	c            s,   t  j  j  } | j   f d    | S(   sx   
            Shut down the server port.  Return a Deferred which fires when
            this has completed.
            c            s     S(   N(    (   R_   (   R­   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR     s    (   R   RY   R-   R   (   R­   R   (   R¤   (   R­   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRŽ     s    (   R   R   R   R4  RI  RX   Rľ   R   RJ  RÝ   R,   R   Rˇ   (   R#   Rr   t
   serverAddrRŚ   t   clientDeferredRP  RV  RŽ   (    (   RO  R#   RN  R¤   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_properlyCloseFilesá  s"    
(   R)   R*   R3   RI  RJ  RK  RM  RY  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRG  ľ  s   	
	
		t   ProperlyCloseFilesTestCasec           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s   
    Test that the sockets created by L{IReactorTCP.connectTCP} are cleaned up
    when the connection they are associated with is closed.
    c         C   s   t  j | | d | S(   sE   
        Create a TCP server using L{IReactorTCP.listenTCP}.
        RL   (   R   RM   (   R#   R  Rh   R:   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRI    s    c         C   s   | j  | |  S(   sF   
        Create a TCP client using L{IReactorTCP.connectTCP}.
        (   Ri   (   R#   R  Rh   RŚ   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRJ  &  s    c         C   s   t  j S(   sŹ   
        Return L{socket.error} as the expected error type which will be
        raised by a write to the low-level socket object after it has been
        closed.
        (   R°   R   (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRK  -  s    (   R)   R*   R3   RI  RJ  RK  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRZ    s   		t   WiredForDeferredsc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   t  j j |  | |  d  S(   N(   R   t   ProtocolWrapperR6   (   R#   R:   t   wrappedProtocol(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6   8  s    c         C   s'   t  j j |   |  j j j d   d  S(   N(   R   R\  R$   R:   t	   onConnectR   R1   (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR$   ;  s    c         C   s*   t  j j |  |  |  j j j d   d  S(   N(   R   R\  R(   R:   R  R   R1   (   R#   R'   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR(   ?  s    (   R)   R*   R6   R$   R(   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR[  7  s   		R  c           B   s   e  Z e Z d    Z RS(   c         C   s5   t  j j |  |  t j   |  _ t j   |  _ d  S(   N(   R   t   WrappingFactoryR6   R   R   R^  R  (   R#   t   wrappedFactory(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6   H  s    (   R)   R*   R[  R   R6   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR  E  s   t   AddressTestCasec           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   sR   
    Tests for address-related interactions with client and server protocols.
    c         C   s#  d t  j f d     Y} t   |  _ t j   |  _ |  j _ t j   |  _ |  j _	 | |  j  |  _
 t   |  _ t j   |  _ |  j _ t j   |  _ |  j _	 | |  j  |  _ t j d |  j
 d d |  _ t j |  j j   j |  j j   j |  j  |  _ t j |  j |  j g  S(   s9  
        Create a port and connected client/server pair which can be used
        to test factory behavior related to addresses.

        @return: A L{defer.Deferred} which will be called back when both the
            client and server protocols have received their connection made
            callback.
        t   RememberingWrapperc           B   s    e  Z d  Z d   Z d   Z RS(   s  
            Simple wrapper factory which records the addresses which are
            passed to its L{buildProtocol} method and delegates actual
            protocol creation to another factory.

            @ivar addresses: A list of the objects passed to buildProtocol.
            @ivar factory: The wrapped factory to which protocol creation is
                delegated.
            c         S   s   g  |  _  | |  _ d  S(   N(   t	   addressesR:   (   R#   R:   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6   f  s    	c         S   s    |  j  j |  |  j j |  S(   s   
                Append the given address to C{self.addresses} and forward
                the call to C{self.factory}.
                (   Rc  R7   R:   R0   (   R#   R=   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR0   m  s    (   R)   R*   R3   R6   R0   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRb  \  s   		i    RL   s	   127.0.0.1(   R   t   ClientFactoryR@   Rl   R   R   Rm   R?   t   serverConnLostR;   t   serverWrapperRA   Rn   Ro   t   clientConnLostt   clientWrapperR   RM   R,   Ri   RX   RÝ   RE   Rk   (   R#   Rb  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   setUpS  s    	-c         C   s8   |  j  j   t j |  j |  j t j |  j j  g  S(   sf   
        Disconnect the client/server pair and shutdown the port created in
        L{setUp}.
        (	   RE   Rj   R   Rk   Re  Rg  RY   R,   R-   (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   tearDown  s    c         C   s   |  j  j j j   } |  j j j j   } |  j |  j j t	 d | j
 | j  g  |  j |  j j t	 d | j
 | j  g  d S(   se  
        L{ClientFactory.buildProtocol} should be invoked with the address of
        the server to which a connection has been established, which should
        be the same as the address reported by the C{getHost} method of the
        transport of the server protocol and as the C{getPeer} method of the
        transport of the client protocol.
        R×   N(   Rl   R   R!   RX   Rn   R	  R§   Rh  Rc  R   RÝ   R,   (   R#   RŁ   t
   clientPeer(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_buildProtocolClient  s    		c         C   s   |  j  j j j   } |  j j j j   } |  j |  j j t	 d | j
 | j  g  |  j |  j j t	 d | j
 | j  g  d S(   sv  
        L{ServerFactory.buildProtocol} should be invoked with the address of
        the client which has connected to the port the factory is listening on,
        which should be the same as the address reported by the C{getPeer}
        method of the transport of the server protocol and as the C{getHost}
        method of the transport of the client protocol.
        R×   N(   Rn   R   R!   RX   Rl   R	  R§   Rf  Rc  R   RÝ   R,   (   R#   t
   clientHostt
   serverPeer(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_buildProtocolServerŞ  s    		(   R)   R*   R3   Ri  Rj  Rl  Ro  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRa  O  s
   	9		t   LargeBufferWriterProtocolc           B   s   e  Z d    Z RS(   c         C   s7   |  j  j d |  j j  d |  j _ |  j  j   d  S(   Nt   Xi   (   R!   R  R:   t   lenR  R"   (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR$   Ă  s    (   R)   R*   R$   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRp  ž  s   t   LargeBufferReaderProtocolc           B   s   e  Z d    Z d   Z RS(   c         C   s   |  j  j t |  7_ d  S(   N(   R:   Rr  (   R#   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR  Ę  s    c         C   s   d |  j  _ d  S(   Ni   (   R:   R  (   R#   R'   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR(   Ě  s    (   R)   R*   R  R(   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs  É  s   	t   LargeBufferReaderClientFactoryc           B   s   e  Z d    Z d   Z RS(   c         C   s   d |  _  d |  _ d  S(   Ni    (   R  Rr  (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6   Đ  s    	c         C   s   t    } |  | _ | |  _ | S(   N(   Rs  R:   R   (   R#   R=   R>   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR0   Ó  s    			(   R)   R*   R6   R0   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRt  Ď  s   	t   FireOnClosec           B   s   e  Z d  Z d   Z RS(   sa   A wrapper around a protocol that makes it fire a deferred when
    connectionLost is called.
    c         C   s*   t  j j |  |  |  j j j d   d  S(   N(   R   R\  R(   R:   RB   R   R1   (   R#   R'   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR(   Ţ  s    (   R)   R*   R3   R(   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRu  Ú  s   t   FireOnCloseFactoryc           B   s   e  Z e Z d    Z RS(   c         C   s&   t  j j |  |  t j   |  _ d  S(   N(   R   R_  R6   R   R   RB   (   R#   R`  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6   ć  s    (   R)   R*   Ru  R   R6   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRv  ă  s   t   LargeBufferTestCasec           B   s   e  Z d  Z d Z d   Z RS(   s5   Test that buffering large amounts of data works.
    i<   i   c            sŰ   t  j    t  _  d  _ d  _   j  _ t   } t j	 d | d d }   j
 | j  | j   j } t    t   } t j d | |  t j | j | j g  }     f d   } | j |  S(   Ni    RL   s	   127.0.0.1c            sV     j   j d    j   j   j k d  j   j f    j   j d  d  S(   Ns&   writer didn't finish, it probably dieds9   client didn't receive all the data it expected (%d != %d)s$   client didn't see connection dropped(   RO   R  Rr  t   datalen(   RU   (   R#   R   RR   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   ˙  s    (   R   R  Rp  R  R  Rx  Rr  Rv  R   RM   RN   R-   RX   R,   Rt  Ri   R   Rk   RB   R   (   R#   R   R>   RV   R!  R   R   (    (   R#   RR   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt
   testWriterđ  s    				i đ  i  Ŕ(   R)   R*   R3   Rx  Ry  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRw  ë  s   t   MyHCProtocolc           B   s0   e  Z e e  e Z e Z d    Z d   Z RS(   c         C   s&   t  |  _ |  j r" |  j d   n  d  S(   N(   R?  t   readHalfClosedt   writeHalfClosedR(   R1   (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   readConnectionLost  s    		c         C   s&   t  |  _ |  j r" |  j d   n  d  S(   N(   R?  R|  R{  R(   R1   (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   writeConnectionLost  s    		(	   R)   R*   R    R	   R.  R{  R|  R}  R~  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRz  	  s
   
	t   MyHCFactoryc           B   s   e  Z d  Z d Z d   Z RS(   i    c         C   s.   |  j  d 7_  t   } |  | _ | |  _ | S(   Ni   (   R8   Rz  R:   R   (   R#   R=   R>   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR0   "  s
    			N(   R)   R*   R8   R1   R?   R0   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR    s   t   HalfCloseTestCasec           B   sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s   Test half-closing connections.c            s   t      _ } t j d | d d   _    j  j  t  f d    } t j	 t t
    _ | j    f d    | j   j  | S(   Ni    RL   s	   127.0.0.1c              s     j  S(   N(   R   (    (   R>   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   1  s    c            s%    j  j   j   j   j   j  S(   N(   t   cfRi   RX   RÝ   R,   (   t   _(   R>   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   5  s   (   R  RR   R   RM   R>   RN   R-   R   R   Rľ   Rz  R  R   t   _setUp(   R#   RR   R   (    (   R#   R>   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRi  -  s    c            sN   |   _  t j     _   j  _   j   j  j j d  t   f d    S(   Ni   c              s   t    j d d   d  k	 S(   NR   (   R   RR   R1   (    (   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   ?  s    (	   Rn   R   R   t   clientProtoConnectionLostR<   Rd   R!   R   R   (   R#   Rn   (    (   R#   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR  :  s    	c            se     j    j j d    j j j   t j   j j  } | j	   f d    | j	   j
  | S(   Ni    c            s     j  S(   N(   R  (   R_   (   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   E  s    (   Rd   Rn   Rĺ   R!   R"   R   RY   R>   R-   R   t	   _tearDown(   R#   R   (    (   R#   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRj  A  s    c            s     j    j j d    j    j j j d  t j       f d   } |   j j _   j j j j	    j
   f d     S(   Ni   i    c            s    d   j  j _  j d   d  S(   Ni   (   RR   R   Rĺ   R   R1   (   R'   (   R#   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   _connectionLostO  s    c            s     j    j j j d  S(   Ni   (   Rd   RR   R   Rĺ   (   R   (   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   T  s    (   Rd   Rn   Rĺ   RR   R   R   R   R(   R!   R"   R   (   R#   RU   R  (    (   R#   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR  I  s    c            s    j    j    j   j d  t  f d    }  f d   }     f d   }     f d   } | j |  j |  j |  S(   Nt   helloc              s   t    j  d k S(   Ni    (   Rr  t   _tempDataBuffer(    (   t   t(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   ]  s    c            s     j    t   f d    S(   Nc              s     j  S(   N(   t   _writeDisconnected(    (   R  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   `  s    (   t   loseWriteConnectionR   (   RU   (   R  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt	   loseWrite^  s    
c            sL    j   j t   j   j t   j   j t  t   f d    S(   Nc              s
     j  j S(   N(   R   R{  (    (   RR   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   e  s    (   Rd   Rĺ   R.  R|  R?  R{  R   (   RU   (   RR   R#   Rn   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   a  s    c            s    j  j } | d  | d   j d t  j  j    j   j j d   j   j j t   j   j j	 t
  d  S(   Ns    worlds   lalala fooled youi    R  (   R!   R  Rd   Rr  R  R   R  Rĺ   R.  R{  R?  (   RU   t   w(   RR   R#   Rn   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR  f  s    

(   Rn   RR   R!   R  R   R   (   R#   R   R  R   R  (    (   RR   R#   Rn   R  s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   testCloseWriteCloserW  s    			c            si     j    j j j   t j t  f d    t   f d    g  } | j    f d    | S(   Nc              s
     j  j S(   N(   R   R|  (    (   RR   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   u  s    c              s
     j  j S(   N(   Rn   R{  (    (   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   v  s    c            s     j   j j t  S(   N(   Rd   R   R{  R.  (   R  (   R#   RR   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   w  s   (   RR   R   R!   R  R   Rk   R   R   (   R#   R   (    (   R#   RR   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   testWriteCloseNotificationp  s    	(	   R)   R*   R3   Ri  R  Rj  R  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR  *  s   					t   HalfClose2TestCasec           B   s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C   s   t    |  _ } t j   |  j _ t j d | d d |  _ } t j	 t t
  j | j   j | j   j  } | j |  j  | S(   Ni    RL   s	   127.0.0.1(   R@   RR   R   R   R?   R   RM   R>   R   Rľ   R   Ri   RX   RÝ   R,   R   t
   _gotClient(   R#   RR   R>   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRi  ~  s    c         C   s   | |  _  |  j j S(   N(   Rn   RR   R?   (   R#   Rn   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR    s    	c         C   s   |  j  j j   |  j j   S(   N(   Rn   R!   R"   R>   R-   (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRj    s    c            s     j  j j d    j  j j   t j     j j _ } t j     j  _ } | j	   f d    | j	   f d    t j
 | | g  S(   só   
        TCP protocols support half-close connections, but not all of them
        support being notified of write closes.  In this case, test that
        half-closing the connection causes the peer's connection to be
        closed.
        R  c            s     j    j j j d  S(   NR  (   R§   RR   R   R  (   R   (   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR     s    c            s     j    j j j t  S(   N(   R§   RR   R   Rĺ   R?  (   R   (   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   Ą  s    (   Rn   R!   R  R  R   R   RR   R   R<   R   Rk   (   R#   R   R   (    (   R#   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   testNoNotification  s    c            s     j  j j j     j j j d    j j j   t j     j  j _	 } t j     j _	 } | j
   f d    t j | | g  S(   sx   
        If the other side has already closed its connection,
        loseWriteConnection should pass silently.
        Rq  c            s     j    j j j t  S(   N(   t   failUnlessEqualRR   R   Rĺ   R?  (   R   (   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   Ž  s    (   RR   R   R!   R"   Rn   R  R  R   R   R<   R   Rk   (   R#   R   R   (    (   R#   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   testShutdownException¤  s    (   R)   R*   Ri  R  Rj  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR  |  s
   				t   HalfCloseBuggyApplicationTestsc           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   sI   
    Test half-closing connections where notification code has bugs.
    c            s˝   t      _ t j     j _ t j d   j d d   _   j   j j	    j j
   } t j t t  } | j | j | j  }   f d   } | j |  t j   j j | g  S(   s|   
        Set up a server and connect a client to it.  Return a Deferred which
        only fires once this is done.
        i    RL   s	   127.0.0.1c            s   |    _  d  S(   N(   R   (   R   (   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt	   setClientĹ  s    (   R  Rr   R   R   R?   R   RM   R,   RN   R-   RX   R   Rľ   Rz  Ri   RÝ   R   Rk   (   R#   R=   t   creatorRX  R  (    (   R#   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRi  ¸  s    	c         G   s   t  d   d S(   s`   
        Fake implementation of a callback which illegally raises an
        exception.
        s   ONO I AM BUGGY CODEN(   Ru   (   R#   Rí   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   aBugÍ  s    c            sF   t  j   }   j _   j j j     f d   } | j |  | S(   s~   
        Helper for testing that an exception is logged by the time the
        client protocol loses its connection.
        c            s)     j  t  }   j t |  d  d  S(   Ni   (   t   flushLoggedErrorsRu   R§   Rr  (   RU   t   errors(   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   Ü  s    (   R   R   R   R<   R!   R  R   (   R#   Rĺ   R   (    (   R#   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   _notificationRaisesTestŐ  s
    c         C   s   |  j  |  j j _ |  j   S(   să   
        If C{readConnectionLost} raises an exception when the transport
        calls it to notify the protocol of that event, the exception should
        be logged and the protocol should be disconnected completely.
        (   R  Rr   R   R}  R  (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_readNotificationRaisesă  s    c         C   s   |  j  |  j _ |  j   S(   sä   
        If C{writeConnectionLost} raises an exception when the transport
        calls it to notify the protocol of that event, the exception should
        be logged and the protocol should be disconnected completely.
        (   R  R   R~  R  (   R#   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_writeNotificationRaisesí  s    (   R)   R*   R3   Ri  R  R  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR  ł  s   				
t   LogTestCasec           B   s   e  Z d  Z d   Z RS(   s4   
    Test logging facility of TCP base classes.
    c            sż   t    } t   } t j   | _ t j d | d d }   j | j  t j	 | j
   j | j
   j |     j  j    j  j j d     f d   } | j j |  | j S(   sx   
        Check that the log customization of the client transport happens
        once the client is connected.
        i    RL   s	   127.0.0.1t   Uninitializedc            s    j    j j d  d  S(   Ns   AccumulatingProtocol,client(   Rd   R!   t   logstr(   R_   (   RE   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   cb  s    (   R@   RA   R   R   R?   R   RM   RN   R-   Ri   RX   RÝ   R,   Rj   Rd   R!   R   R   (   R#   Rl   Rn   R,   RĄ  (    (   R#   RE   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_logstrClientSetupý  s    		!(   R)   R*   R3   R˘  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR  ř  s   t   PauseProducingTestCasec           B   s5   e  Z d  Z d   Z e j j e  s3 d e _ n  RS(   sG   
    Test some behaviors of pausing the production of a transport.
    c            s¸   t    } t   } t j   | _ t j d | d d }  j | j  t j	 | j
   j | j
   j |  }  j | j     f d   }  f d     | j j |  | j S(   s   
        In C{connectionMade} of a client protocol, C{pauseProducing} used to be
        ignored: this test is here to ensure it's not ignored.
        i    RL   s	   127.0.0.1c            s   |  j  }   j | t j   t j    |  j  j     j | t j   t j    t j   } | j	   t j
 d | j |   | S(   Ni    (   R!   t   assertInR   t
   getReaderst
   getWritersR0  t   assertNotInR   R   R   t	   callLaterR   (   R   t   trR   (   R#   t   checkAfterConnectionMade(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   checkInConnectionMade0  s    	c            s-   |  j  }   j | t j   t j    d  S(   N(   R!   R§  R   RĽ  RŚ  (   R   RŠ  (   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRŞ  <  s    	(   R@   RA   R   R   R?   R   RM   RN   R-   Ri   RX   RÝ   R,   Rj   R   (   R#   Rl   Rn   R,   RE   RŤ  (    (   RŞ  R#   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt#   test_pauseProducingInConnectionMade  s    		!s#   Reactor not providing IReactorFDSet(	   R)   R*   R3   RŹ  R   t   IReactorFDSetRQ   R   t   skip(    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRŁ    s   	%t   CallBackOrderTestCasec           B   s   e  Z d  Z d   Z RS(   s-   
    Test the order of reactor callbacks
    c   	         s*  t    } t j   j   f d    | _ t    t j    _ t j    _  f d   }  j j |  t j d | d d }   j	 | j
  t j | j   j | j   j   }   j	 | j  d   } d   }   f d   } t j  j j |   j j |  g  } | j |  S(	   sl   
        Check that Protocol.connectionLost is called before factory's
        clientConnectionLost
        c            s     j  |  j j  S(   N(   RN   R!   R"   (   R   (   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR   U  s   c            s   t  j d   j j j  d S(   s:   
            protocol.connectionMade callback
            i    N(   R   R¨  R   R!   R"   (   R   (   Rn   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   _cbCM\  s    i    RL   s	   127.0.0.1c         S   s   d S(   s?   
            factory.clientConnectionLost callback
            t   CCL(    (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   _cbCCLk  s    c         S   s   d S(   s:   
            protocol.connectionLost callback
            t   CL(    (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   _cbCLq  s    c            s     j  |  d d g  d  S(   NRł  Rą  (   Rd   (   R   (   R#   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt	   _cbGatherw  s    (   R@   R   R   R   R?   RA   R;   R   RM   RN   R-   Ri   RX   RÝ   R,   Rj   Rk   RB   (	   R#   Rl   R°  R,   RE   R˛  R´  Rľ  R   (    (   R#   Rn   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   test_loseOrderN  s(    		!		(   R)   R*   R3   Rś  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRŻ  I  s   i
   (    (R   R3   R°   Rł   RŠ   t   zope.interfaceR    t   twisted.trialR   t   twisted.python.logR   R   R   R   R   R   R   t   twisted.internet.addressR   t   twisted.internet.interfacesR	   R
   t   twisted.protocolsR   t   twisted.test.proto_helpersR   R   Rś   R    R4  R+   R5  R4   R@   Rd  RA   t   TestCaseRK   R   R   R  RČ   RË   RĚ   RÔ   Rč   R  R  R  R  R  R  R8  R=  R@  RC  RG  RZ  R\  R[  R_  R  Ra  Rp  Rs  Rt  Ru  Rv  Rw  Rz  R  R  R  R  R  RŁ  RŻ  t   resourcet   ImportErrort	   getrlimitt   RLIMIT_NOFILEt	   numRoundst   numberRounds(    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt   <module>   sv   $"8Ä		Ń@]m'
ľ	
e
o	R7E"/8