
[XMc           @   s   d  Z  d d l m Z d d l m Z m Z m Z m Z m Z 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 m Z d d l m Z m Z d e f d	     YZ d
 e f d     YZ d S(   s*   
Tests for L{twisted.test.proto_helpers}.
i(   t   verifyObject(	   t
   ITransportt   IPushProducert	   IConsumert   IReactorTCPt   IReactorSSLt   IReactorUNIXt   IAddresst   IListeningPortt
   IConnector(   t   IPv4Address(   t   TestCase(   t   StringTransportt   MemoryReactort   RaisingMemoryReactor(   t   ClientFactoryt   Factoryt   StringTransportTestsc           B   s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   sB   
    Tests for L{twisted.test.proto_helpers.StringTransport}.
    c         C   s   t    |  _ d  S(   N(   R   t	   transport(   t   self(    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt   setUp   s    c         C   sO   |  j  t t |  j   |  j  t t |  j   |  j  t t |  j   d S(   sq   
        L{StringTransport} instances provide L{ITransport}, L{IPushProducer},
        and L{IConsumer}.
        N(   t
   assertTrueR    R   R   R   R   (   R   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt   test_interfaces   s    c         C   sU   t    } t    } |  j j | |  |  j |  j j |  |  j |  j j |  d S(   sz   
        L{StringTransport.registerProducer} records the arguments supplied to
        it as instance attributes.
        N(   t   objectR   t   registerProducert   assertIdenticalt   producert	   streaming(   R   R   R   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt   test_registerProducer&   s
    		c         C   sh   t    } |  j j | t  |  j t |  j j t    t  |  j |  j j |  |  j	 |  j j
  d S(   sy   
        L{StringTransport.registerProducer} raises L{RuntimeError} if a
        producer is already registered.
        N(   R   R   R   t   Truet   assertRaisest   RuntimeErrort   FalseR   R   R   R   (   R   R   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt   test_disallowedRegisterProducer2   s    	c         C   s   t    } t    } |  j j | t  |  j j   |  j |  j j d  |  j j | t  |  j |  j j |  |  j	 |  j j
  d S(   s   
        L{StringTransport.unregisterProducer} causes the transport to forget
        about the registered producer and makes it possible to register a new
        one.
        N(   R   R   R   R    t   unregisterProducerR   R   t   NoneR   R   R   (   R   t   oldProducert   newProducer(    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt   test_unregisterProducer?   s    		c         C   s   |  j  t |  j j  d S(   s   
        L{StringTransport.unregisterProducer} raises L{RuntimeError} if called
        when no producer is registered.
        N(   R   R   R   R"   (   R   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt   test_invalidUnregisterProducerO   s    c         C   s   |  j  |  j j d  d S(   sO   
        L{StringTransport.producerState} is initially C{'producing'}.
        t	   producingN(   t   assertEqualR   t   producerState(   R   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt   test_initialProducerStateW   s    c         C   s'   |  j  j   |  j |  j  j d  d S(   sy   
        L{StringTransport.pauseProducing} changes the C{producerState} of the
        transport to C{'paused'}.
        t   pausedN(   R   t   pauseProducingR)   R*   (   R   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt   test_pauseProducing^   s    c         C   s4   |  j  j   |  j  j   |  j |  j  j d  d S(   s}   
        L{StringTransport.resumeProducing} changes the C{producerState} of the
        transport to C{'producing'}.
        R(   N(   R   R-   t   resumeProducingR)   R*   (   R   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt   test_resumeProducingg   s    c         C   s'   |  j  j   |  j |  j  j d  d S(   s{   
        L{StringTransport.stopProducing} changes the C{'producerState'} of the
        transport to C{'stopped'}.
        t   stoppedN(   R   t   stopProducingR)   R*   (   R   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt   test_stopProducingq   s    c         C   s'   |  j  j   |  j t |  j  j  d S(   su   
        L{StringTransport.pauseProducing} raises L{RuntimeError} if the
        transport has been stopped.
        N(   R   R2   R   R   R-   (   R   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt    test_stoppedTransportCannotPausez   s    c         C   s'   |  j  j   |  j t |  j  j  d S(   sv   
        L{StringTransport.resumeProducing} raises L{RuntimeError} if the
        transport has been stopped.
        N(   R   R2   R   R   R/   (   R   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt!   test_stoppedTransportCannotResume   s    c         C   s'   |  j  j   |  j t |  j  j  d S(   sz   
        L{StringTransport.pauseProducing} raises L{RuntimeError} if the
        transport is being disconnected.
        N(   R   t   loseConnectionR   R   R-   (   R   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt&   test_disconnectingTransportCannotPause   s    c         C   s'   |  j  j   |  j t |  j  j  d S(   s{   
        L{StringTransport.resumeProducing} raises L{RuntimeError} if the
        transport is being disconnected.
        N(   R   R6   R   R   R/   (   R   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt'   test_disconnectingTransportCannotResume   s    c         C   s7   |  j  |  j j  |  j j   |  j |  j j  d S(   sv   
        L{StringTransport.loseConnection} toggles the C{disconnecting} instance
        variable to C{True}.
        N(   t   assertFalseR   t   disconnectingR6   R   (   R   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt$   test_loseConnectionSetsDisconnecting   s    c         C   s)   t    } |  j t |  j   |  d S(   s   
        If a host address is passed to L{StringTransport.__init__}, that
        value is returned from L{StringTransport.getHost}.
        N(   R   R   R   t   getHost(   R   t   address(    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt   test_specifiedHostAddress   s    	c         C   s,   t    } |  j t d |  j   |  d S(   s   
        If a peer address is passed to L{StringTransport.__init__}, that
        value is returned from L{StringTransport.getPeer}.
        t   peerAddressN(   R   R   R   t   getPeer(   R   R=   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt   test_specifiedPeerAddress   s    	c         C   s#   t    j   } |  j | t  d S(   s   
        If no host address is passed to L{StringTransport.__init__}, an
        L{IPv4Address} is returned from L{StringTransport.getHost}.
        N(   R   R<   t   assertIsInstanceR
   (   R   R=   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt   test_defaultHostAddress   s    c         C   s#   t    j   } |  j | t  d S(   s   
        If no peer address is passed to L{StringTransport.__init__}, an
        L{IPv4Address} is returned from L{StringTransport.getPeer}.
        N(   R   R@   RB   R
   (   R   R=   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt   test_defaultPeerAddress   s    (   t   __name__t
   __module__t   __doc__R   R   R   R!   R&   R'   R+   R.   R0   R3   R4   R5   R7   R8   R;   R>   RA   RC   RD   (    (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyR      s(   		
								
											
			
		t   ReactorTestsc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   sA   
    Tests for L{MemoryReactor} and L{RaisingMemoryReactor}.
    c         C   s4   t    } t t |  t t |  t t |  d S(   st   
        L{MemoryReactor} provides all of the attributes described by the
        interfaces it advertises.
        N(   R   R    R   R   R   (   R   t   memoryReactor(    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt   test_memoryReactorProvides   s    	c         C   s4   t    } t t |  t t |  t t |  d S(   s{   
        L{RaisingMemoryReactor} provides all of the attributes described by the
        interfaces it advertises.
        N(   R   R    R   R   R   (   R   t   raisingReactor(    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt   test_raisingReactorProvides   s    	c         C   s   t    } x | j d d t    | j d d t   d  g D]R } t t |  | j   } t t |  |  j	 | j
 d  |  j	 | j d  q= W| j d t    } t t |  | j   } t t |  |  j	 | j d  d S(   s  
        L{MemoryReactor.connectTCP}, L{MemoryReactor.connectSSL}, and
        L{MemoryReactor.connectUNIX} will return an L{IConnector} whose
        C{getDestination} method returns an L{IAddress} with attributes which
        reflect the values passed.
        s   test.example.comi   s
   /fake/pathN(   R   t
   connectTCPR   t
   connectSSLR#   R    R	   t   getDestinationR   t   assertEqualst   hostt   portt   connectUNIXt   name(   R   RI   t	   connectorR=   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt   test_connectDestination   s     		c         C   s   t    } x | j d t    | j d t   d  g D]R } t t |  | j   } t t |  |  j	 | j
 d  |  j	 | j d  q7 W| j d t    } t t |  | j   } t t |  |  j	 | j d  d S(   s  
        L{MemoryReactor.listenTCP}, L{MemoryReactor.listenSSL} and
        L{MemoryReactor.listenUNIX} will return an L{IListeningPort} whose
        C{getHost} method returns an L{IAddress}; C{listenTCP} and C{listenSSL}
        will have a default host of C{'0.0.0.0'}, and a port that reflects the
        value passed, and C{listenUNIX} will have a name that reflects the path
        passed.
        i2   s   0.0.0.0s   /path/to/socketN(   R   t	   listenTCPR   t	   listenSSLR#   R    R   R<   R   RP   RQ   RR   t
   listenUNIXRT   (   R   RI   RR   R=   (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt   test_listenDefaultHost  s    		(   RE   RF   RG   RJ   RL   RV   RZ   (    (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyRH      s
   			N(   RG   t   zope.interface.verifyR    t   twisted.internet.interfacesR   R   R   R   R   R   R   R   R	   t   twisted.internet.addressR
   t   twisted.trial.unittestR   t   twisted.test.proto_helpersR   R   R   t   twisted.internet.protocolR   R   R   RH   (    (    (    sE   /usr/lib/python2.7/dist-packages/twisted/test/test_stringtransport.pyt   <module>   s   @