ó
0”Nc           @   s1  d  Z  d d l m Z m Z m Z d d l m Z d d l m Z d d l m	 Z	 d d l m
 Z
 d d l m Z m Z m Z m Z m Z d d l m Z 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 „  ƒ  YZ d e j  f d „  ƒ  YZ  d e j f d „  ƒ  YZ! d e j f d „  ƒ  YZ" d e j e j# f d „  ƒ  YZ$ 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) S(*   s   
Test code for policies.
iÿÿÿÿ(   t	   Interfacet
   implementst   implementedBy(   t   StringIO(   t   unittest(   t   StringTransport(   t    StringTransportWithDisconnection(   t   protocolt   reactort   addresst   defert   task(   t   policiest   SimpleProtocolc           B   s<   e  Z d  Z Z d Z d „  Z d „  Z d „  Z d „  Z RS(   i    t    c         C   s"   t  j ƒ  |  _ t  j ƒ  |  _ d  S(   N(   R
   t   Deferredt
   dConnectedt   dDisconnected(   t   self(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   __init__   s    c         C   s   d |  _  |  j j d ƒ d  S(   Ni   R   (   t	   connectedR   t   callback(   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   connectionMade   s    	c         C   s   d |  _  |  j j d ƒ d  S(   Ni   R   (   t   disconnectedR   R   (   R   t   reason(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   connectionLost"   s    	c         C   s   |  j  | 7_  d  S(   N(   t   buffer(   R   t   data(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   dataReceived&   s    (	   t   __name__t
   __module__R   R   R   R   R   R   R   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR      s   
			t   SillyFactoryc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   t   p(   R   R    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR   -   s    c         C   s   |  j  S(   N(   R    (   R   t   addr(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   buildProtocol0   s    (   R   R   R   R"   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR   +   s   	t   EchoProtocolc           B   s2   e  Z e Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   s   t  |  _ d  S(   N(   t   Truet   paused(   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   pauseProducing7   s    c         C   s   t  |  _ d  S(   N(   t   FalseR%   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   resumeProducing:   s    c         C   s   d  S(   N(    (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   stopProducing=   s    c         C   s   |  j  j | ƒ d  S(   N(   t	   transportt   write(   R   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR   @   s    (   R   R   R'   R%   R&   R(   R)   R   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR#   4   s
   			t   Serverc           B   s   e  Z d  Z e Z RS(   s8   
    A simple server factory using L{EchoProtocol}.
    (   R   R   t   __doc__R#   R   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR,   E   s   t   TestableThrottlingFactoryc           B   s    e  Z d  Z d „  Z d „  Z RS(   sH   
    L{policies.ThrottlingFactory} using a L{task.Clock} for tests.
    c         O   s#   t  j j |  | | Ž | |  _ d S(   s˜   
        @param clock: object providing a callLater method that can be used
            for tests.
        @type clock: C{task.Clock} or alike.
        N(   R   t   ThrottlingFactoryR   t   clock(   R   R0   t   argst   kwargs(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR   R   s    c         C   s   |  j  j | | ƒ S(   s0   
        Forward to the testable clock.
        (   R0   t	   callLater(   R   t   periodt   func(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR3   \   s    (   R   R   R-   R   R3   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR.   M   s   	
t   TestableTimeoutFactoryc           B   s    e  Z d  Z d „  Z d „  Z RS(   sE   
    L{policies.TimeoutFactory} using a L{task.Clock} for tests.
    c         O   s#   t  j j |  | | Ž | |  _ d S(   s˜   
        @param clock: object providing a callLater method that can be used
            for tests.
        @type clock: C{task.Clock} or alike.
        N(   R   t   TimeoutFactoryR   R0   (   R   R0   R1   R2   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR   i   s    c         C   s   |  j  j | | ƒ S(   s0   
        Forward to the testable clock.
        (   R0   R3   (   R   R4   R5   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR3   s   s    (   R   R   R-   R   R3   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR6   d   s   	
t   WrapperTestCasec           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s>   
    Tests for L{WrappingFactory} and L{ProtocolWrapper}.
    c         C   sP   t  ƒ  } t j | ƒ } | j t j d d d ƒ ƒ } |  j | j j | ƒ d S(   sf   
        Make sure protocol.factory is the wrapped factory, not the wrapping
        factory.
        t   TCPs	   127.0.0.1i#   N(	   R,   R   t   WrappingFactoryR"   R	   t   IPv4Addresst   assertIdenticalt   wrappedProtocolt   factory(   R   t   ft   wfR    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_protocolFactoryAttribute   s    	c            s   d t  f d „  ƒ  Y‰  d d ‡  f d †  ƒ  Y} t t j ƒ t j ƒ  } t j t j d ƒ | ƒ } | j | ƒ  ƒ |  j	 ˆ  j
 | j ƒ ƒ d S(   s²   
        The transport wrapper passed to the wrapped protocol's
        C{makeConnection} provides the same interfaces as are provided by the
        original transport.
        t   IStubTransportc           B   s   e  Z RS(    (   R   R   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyRB      s   t   StubTransportc              s   e  Z e ˆ  ƒ RS(    (   R   R   R   (    (   RB   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyRC   “   s   N(    (   R    R   R   t   ProtocolWrapperR   t   ProtocolR:   t   Nonet   makeConnectiont
   assertTruet
   providedByR*   (   R   RC   t   protot   wrapper(    (   RB   s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_transportInterfacesŠ   s    
c         C   s2   t  ƒ  } t j | ƒ } |  j d | j ƒ  ƒ d S(   sƒ   
        L{WrappingFactory.logPrefix} is customized to mention both the original
        factory and the wrapping factory.
        s   Server (WrappingFactory)N(   R,   R   R:   t   assertEqualt	   logPrefix(   R   t   serverR>   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_factoryLogPrefix¦   s    	c         C   sH   d t  f d „  ƒ  Y} | ƒ  } t j | ƒ } |  j d | j ƒ  ƒ d S(   s—   
        If the wrapped factory doesn't have a L{logPrefix} method,
        L{WrappingFactory.logPrefix} falls back to the factory class name.
        t	   NoFactoryc           B   s   e  Z RS(    (   R   R   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyRQ   µ   s   s   NoFactory (WrappingFactory)N(   t   objectR   R:   RM   RN   (   R   RQ   RO   R>   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_factoryLogPrefixFallback°   s    	c         C   sP   t  ƒ  } t j | ƒ } | j t j d d d ƒ ƒ } |  j d | j ƒ  ƒ d S(   s{   
        L{ProtocolWrapper.logPrefix} is customized to mention both the original
        protocol and the wrapper.
        R9   s	   127.0.0.1i#   s   EchoProtocol (ProtocolWrapper)N(   R,   R   R:   R"   R	   R;   RM   RN   (   R   RO   R>   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_protocolLogPrefix½   s    		c         C   so   d t  f d „  ƒ  Y} t ƒ  } | | _ t j | ƒ } | j t j d d d ƒ ƒ } |  j d | j	 ƒ  ƒ d S(   s™   
        If the wrapped protocol doesn't have a L{logPrefix} method,
        L{ProtocolWrapper.logPrefix} falls back to the protocol class name.
        t
   NoProtocolc           B   s   e  Z RS(    (   R   R   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyRU   Ï   s   R9   s	   127.0.0.1i#   s   NoProtocol (ProtocolWrapper)N(
   RR   R,   R   R   R:   R"   R	   R;   RM   RN   (   R   RU   RO   R>   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_protocolLogPrefixFallbackÊ   s    			(	   R   R   R-   RA   RL   RP   RS   RT   RV   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR8   {   s   			
		R:   c           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   | S(   N(    (   t   sR?   R    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   <lambda>Ý   s    c         C   s$   t  j j |  ƒ |  j j d  ƒ d  S(   N(   R   R:   t   startFactoryt   deferredR   RF   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyRY   ß   s    (   R   R   R   RY   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR:   Ü   s   	t   ThrottlingTestCasec           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s2   
    Tests for L{policies.ThrottlingFactory}.
    c   
         sm  t  ƒ  } g  t d ƒ D] } t ƒ  ^ q \ ‰ ‰ ‰ ‰ t j | d ƒ ‰  t ˆ  ƒ } t j ƒ  | _ t	 j
 d | d d ƒ‰ ˆ j ƒ  j ‰ ‡ ‡ ‡ ‡ f d †  } ‡  ‡ ‡ ‡ ‡ f d †  } ‡ f d †  } ‡ ‡ f d	 †  } ‡ ‡ f d
 †  } ‡ ‡ ‡ f d †  }	 | j j | ƒ | j j | ƒ | j j | ƒ | j j | ƒ | j j | ƒ | j j |	 ƒ | j S(   sQ   
        Full test using a custom server limiting number of connections.
        i   i   i    t	   interfaces	   127.0.0.1c            sX   t  j d ˆ  t ˆ ƒ ƒ ˆ j j ‡ ‡  f d †  ƒ ˆ j j ‡ ‡  f d †  ƒ ˆ j S(   Ns	   127.0.0.1c            s   t  j d ˆ t ˆ  ƒ ƒ S(   Ns	   127.0.0.1(   R   t
   connectTCPR   (   t   r(   t   c2t   n(    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyRX   û   s    c            s   t  j d ˆ t ˆ  ƒ ƒ S(   Ns	   127.0.0.1(   R   R]   R   (   R^   (   t   c3R`   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyRX   ý   s    (   R   R]   R   R   t   addCallbackR   (   t   results(   R`   R_   Ra   t   c1(    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   _connect123ø   s    		c            s“   ˆ j  g  ˆ ˆ ˆ f D] } | j ^ q d d d g ƒ ˆ j  g  ˆ ˆ ˆ f D] } | j ^ qN d d d g ƒ ˆ j  t ˆ  j j ƒ  ƒ d ƒ |  S(   Ni   i    i   (   RM   R   R   t   lent	   protocolst   keys(   Rc   t   c(   t   tServerR   Ra   R_   Rd   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt	   _check123   s    88c            s   ˆ  j  j ƒ  ˆ  j S(   N(   R*   t   loseConnectionR   (   Rc   (   Rd   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   _lose1  s    c            s    t  j d ˆ t ˆ  ƒ ƒ ˆ  j S(   Ns	   127.0.0.1(   R   R]   R   R   (   Rc   (   t   c4R`   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt	   _connect4  s    c            s*   ˆ  j  ˆ j d ƒ ˆ  j  ˆ j d ƒ |  S(   Ni   i    (   RM   R   R   (   Rc   (   R   Rn   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   _check4  s    c            sL   x! ˆ ˆ f D] } | j  j ƒ  q Wt j t j ˆ  j ƒ ˆ j ˆ j g ƒ S(   N(   R*   Rl   R
   t   DeferredListt   maybeDeferredt   stopListeningR   (   Rc   Ri   (   R    R_   Rn   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   _cleanup  s    (   R,   t   rangeR   R   R/   R:   R
   R   RZ   R   t	   listenTCPt   getHostt   portRb   (
   R   RO   t   it   wrapTServerRe   Rk   Rm   Ro   Rp   Rt   (    (   Rj   R   Ra   R_   Rd   Rn   R`   R    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt
   test_limitê   s(    	.c         C   s3  t  ƒ  } t t j ƒ  | d d ƒ} | j t j d d d ƒ ƒ } t ƒ  } | | _ | j	 | ƒ | j
 | _ | j d ƒ | j d ƒ |  j | j ƒ  d ƒ |  j | j d	 ƒ |  j | j
 j ƒ | j j d
 ƒ |  j | j d ƒ |  j | j
 j ƒ | j j d
 ƒ |  j | j d ƒ |  j | j
 j ƒ d S(   se   
        Check the writeLimit parameter: write data, and check for the pause
        status.
        t
   writeLimiti
   R9   s	   127.0.0.1i    t
   0123456789t
   abcdefghijt   0123456789abcdefghiji   gÍÌÌÌÌÌð?N(   R,   R.   R   t   ClockR"   R	   R;   R   R   RG   R=   t   producerR   RM   t   valuet   writtenThisSecondt   assertFalseR%   R0   t   advanceRH   (   R   RO   Rj   Rx   t   tr(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_writeLimit%  s$    			c         C   sÍ  t  ƒ  } t t j ƒ  | d d ƒ} | j t j d d d ƒ ƒ } t ƒ  } | | _ | j	 | ƒ | j
 d ƒ | j
 d ƒ |  j | j ƒ  d ƒ |  j | j d	 ƒ | j j d
 ƒ |  j | j d ƒ |  j | j d ƒ | j j d
 ƒ |  j | j d ƒ |  j | j d ƒ | j ƒ  | j
 d ƒ | j
 d ƒ |  j | j ƒ  d ƒ |  j | j d	 ƒ | j j d
 ƒ |  j | j d ƒ |  j | j d ƒ | j j d
 ƒ |  j | j d ƒ |  j | j d ƒ d S(   sb   
        Check the readLimit parameter: read data and check for the pause
        status.
        t	   readLimiti
   R9   s	   127.0.0.1i    R}   R~   R   i   gÍÌÌÌÌÌð?R%   t	   producingN(   R,   R.   R   R€   R"   R	   R;   R   R   RG   R   RM   R‚   t   readThisSecondR0   R…   t   producerStatet   clear(   R   RO   Rj   Rx   R†   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_readLimitD  s6    			
(   R   R   R-   R{   R‡   R   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR[   å   s   	;	t   TimeoutTestCasec           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s/   
    Tests for L{policies.TimeoutFactory}.
    c         C   s’   t  j ƒ  |  _ t j ƒ  } t | _ t |  j | d ƒ |  _ |  j j t	 j
 d d d ƒ ƒ |  _ t ƒ  |  _ |  j |  j _ |  j j |  j ƒ d S(   sq   
        Create a testable, deterministic clock, and a set of
        server factory/protocol/transport.
        i   R9   s	   127.0.0.1i90  N(   R   R€   R0   R   t   ServerFactoryR   R6   R>   R"   R	   R;   RJ   R   R*   RG   (   R   t   wrappedFactory(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   setUpr  s    		c         C   se   |  j  j d d d d d g ƒ |  j |  j j j ƒ |  j  j d d g ƒ |  j |  j j j ƒ d S(   s¶   
        Make sure that when a TimeoutFactory accepts a connection, it will
        time out that connection if no data is read or written within the
        timeout period.
        g        g      à?g      ð?gš™™™™™Ù?gš™™™™™É?N(   R0   t   pumpt   failIfRJ   R=   R   t
   failUnless(   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_timeout‚  s    c         C   sä   |  j  j d d d g ƒ |  j |  j j j ƒ |  j j d ƒ |  j  j d d d g ƒ |  j |  j j j ƒ |  j j d g d ƒ |  j  j d d d g ƒ |  j |  j j j ƒ |  j  j d d g ƒ |  j |  j j j ƒ d S(	   s’   
        Make sure that writing data to a transport from a protocol
        constructed by a TimeoutFactory resets the timeout countdown.
        g        g      à?g      ð?s   bytes bytes bytest   bytesi   g       @N(	   R0   R’   R“   RJ   R=   R   R+   t   writeSequenceR”   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_sendAvoidsTimeout‘  s    c         C   s¡   |  j  j d d d g ƒ |  j |  j j j ƒ |  j j d ƒ |  j  j d d d g ƒ |  j |  j j j ƒ |  j  j d d d g ƒ |  j |  j j j ƒ d S(   sR   
        Make sure that receiving data also resets the timeout countdown.
        g        g      ð?g      à?s   bytes bytes bytesN(   R0   R’   R“   RJ   R=   R   R   R”   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_receiveAvoidsTimeout®  s    (   R   R   R-   R‘   R•   R˜   R™   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyRŽ   m  s
   			t   TimeoutTesterc           B   sS   e  Z d  Z d Z e Z d „  Z d „  Z d „  Z d d „ Z
 d „  Z d „  Z RS(	   s”   
    A testable protocol with timeout facility.

    @ivar timedOut: set to C{True} if a timeout has been detected.
    @type timedOut: C{bool}
    i   c         C   s   | |  _  d S(   sF   
        Initialize the protocol with a C{task.Clock} object.
        N(   R0   (   R   R0   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR   Î  s    c         C   s   |  j  |  j ƒ d S(   s3   
        Upon connection, set the timeout.
        N(   t
   setTimeoutt   timeOut(   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR   Õ  s    c         C   s!   |  j  ƒ  t j j |  | ƒ d S(   s,   
        Reset the timeout on data.
        N(   t   resetTimeoutR   RE   R   (   R   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR   Ü  s    
c         C   s   |  j  d ƒ d S(   sD   
        On connection lost, cancel all timeout operations.
        N(   R›   RF   (   R   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR   ä  s    c         C   s   t  |  _ d S(   sX   
        Flags the timedOut variable to indicate the timeout of the connection.
        N(   R$   t   timedOut(   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   timeoutConnectionë  s    c         O   s   |  j  j | | | | Ž S(   sD   
        Override callLater to use the deterministic clock.
        (   R0   R3   (   R   t   timeoutR5   R1   R2   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR3   ò  s    N(   R   R   R-   Rœ   R'   Rž   R   R   R   RF   R   RŸ   R3   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyRš   Ä  s   				t   TestTimeoutc           B   sM   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s-   
    Tests for L{policies.TimeoutMixin}.
    c         C   s%   t  j ƒ  |  _ t |  j ƒ |  _ d S(   sY   
        Create a testable, deterministic clock and a C{TimeoutTester} instance.
        N(   R   R€   R0   Rš   RJ   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR‘   ÿ  s    c         C   s0   |  j  j d ƒ |  j t |  j j ƒ d ƒ d S(   sg   
        Test that the callLater of the clock is used instead of
        C{reactor.callLater}.
        i
   i   N(   RJ   R›   RM   Rf   R0   t   calls(   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_overriddenCallLater  s    c         C   so   |  j  j t ƒ  ƒ |  j j d d d d g ƒ |  j |  j  j ƒ |  j j d d g ƒ |  j |  j  j ƒ d S(   sq   
        Check that the protocol does timeout at the time specified by its
        C{timeOut} attribute.
        i    g      à?g      ð?N(   RJ   RG   R   R0   R’   R“   Rž   R”   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR•     s
    c         C   s®   |  j  j t ƒ  ƒ |  j j d d d d g ƒ |  j |  j  j ƒ |  j  j d ƒ |  j j d d d d g ƒ |  j |  j  j ƒ |  j j d d g ƒ |  j |  j  j ƒ d S(   sV   
        Check that receiving data is delaying the timeout of the connection.
        i    g      à?g      ð?s   hello thereN(	   RJ   RG   R   R0   R’   R“   Rž   R   R”   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_noTimeout  s    c         C   s›   d |  j _ |  j j t ƒ  ƒ |  j j d ƒ |  j |  j j d ƒ |  j j d d g ƒ |  j	 |  j j
 ƒ |  j j d d g ƒ |  j |  j j
 ƒ d S(   sy   
        Check that setting a new value for timeout cancel the previous value
        and install a new timeout.
        i   i    gÍÌÌÌÌÌì?gš™™™™™É?N(   RF   RJ   Rœ   RG   R   R›   RM   R0   R’   R“   Rž   R”   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_resetTimeout-  s    c         C   sx   d |  j  _ |  j  j t ƒ  ƒ |  j  j d ƒ |  j |  j  j d ƒ |  j j d d d d g ƒ |  j	 |  j  j
 ƒ d S(   sO   
        Setting the timeout to C{None} cancel any timeout operations.
        i   i    N(   RJ   Rœ   RG   R   R›   RF   RM   R0   R’   R“   Rž   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_cancelTimeout>  s    c         C   sŠ   d |  j  _ |  j |  j  j d ƒ d ƒ |  j |  j  j d ƒ d ƒ |  j |  j  j d ƒ d ƒ |  j |  j  j d ƒ |  j  j d ƒ d S(   sM   
        setTimeout should return the value of the previous timeout.
        i   i
   i   N(   RJ   Rœ   RM   R›   RF   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_returnL  s    (
   R   R   R-   R‘   R£   R•   R¤   R¥   R¦   R§   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR¡   ú  s   							t$   LimitTotalConnectionsFactoryTestCasec           B   s    e  Z d  Z d „  Z d „  Z RS(   s/   Tests for policies.LimitTotalConnectionsFactoryc         C   s³   t  j ƒ  } t j | _ |  j d | j ƒ | j d  ƒ } |  j d | j ƒ | j d  ƒ } |  j d | j ƒ | j d  ƒ |  j d | j ƒ | j d  ƒ |  j d | j ƒ d  S(   Ni    i   i   (	   R   t   LimitTotalConnectionsFactoryR   RE   RM   t   connectionCountR"   RF   R   (   R   R>   t   p1t   p2(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   testConnectionCounting^  s    c            s6  t  j ƒ  ‰  t j ˆ  _ d ˆ  _ ˆ  j d  ƒ } |  j d  | ƒ |  j d ˆ  j	 ƒ |  j d  ˆ  j d  ƒ ƒ |  j d ˆ  j	 ƒ d t j f ‡  f d †  ƒ  Y} | ˆ  _
 t ˆ  _ ˆ  j d  ƒ } | j d  ƒ |  j t ˆ  j ƒ |  j d ˆ  j	 ƒ | j d  ƒ |  j d ˆ  j	 ƒ | j d  ƒ |  j d ˆ  j	 ƒ d  S(   Ni   t   OverflowProtocolc              s   e  Z ‡  f d  †  Z RS(   c            s   t  ˆ  _ d  S(   N(   R$   t
   overflowed(   R   (   R>   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR   „  s    (   R   R   R   (    (   R>   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR®   ƒ  s   i   i    (   R   R©   R   RE   t   connectionLimitR"   RF   t   assertNotEqualRM   Rª   t   overflowProtocolR'   R¯   RG   R$   R   (   R   R    R®   t   op(    (   R>   s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   testConnectionLimitingr  s&    			(   R   R   R-   R­   R´   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR¨   \  s   	t   WriteSequenceEchoProtocolc           B   s   e  Z d  „  Z RS(   c         C   s?   | j  d ƒ d k r+ |  j j | g ƒ n t j |  | ƒ d  S(   Ns   vector!iÿÿÿÿ(   t   findR*   R—   R#   R   (   R   R–   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR   ™  s    (   R   R   R   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyRµ   ˜  s   t   TestLoggingFactoryc           B   s   e  Z d Z d  „  Z RS(   c         C   s.   |  j  d  k s t d ƒ ‚ t ƒ  |  _  |  j  S(   Ns   open() called too many times(   t   openFileRF   t   AssertionErrorR   (   R   t   name(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   open¡  s    N(   R   R   RF   R¸   R»   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR·   Ÿ  s   t   LoggingFactoryTestCasec           B   s    e  Z d  Z d „  Z d „  Z RS(   s6   
    Tests for L{policies.TrafficLoggingFactory}.
    c         C   sY  t  ƒ  } t | _ t ƒ  } t | d ƒ } | j d ƒ } | | _ | j | ƒ | j j ƒ  } |  j	 d | k d | f ƒ |  j
 | j ƒ  ƒ | j d ƒ | j j ƒ  } |  j d | ƒ |  j d | ƒ |  j | j ƒ  d ƒ | j ƒ  | j d	 ƒ | j j ƒ  } |  j d
 | ƒ |  j | j ƒ  d	 ƒ | j ƒ  | j j ƒ  } |  j d | ƒ d S(   sQ   
        Check the output produced by L{policies.TrafficLoggingFactory}.
        t   tests   1.2.3.4i.  t   *s   * not found in %rs   here are some bytess   C 1: 'here are some bytes's   S 1: 'here are some bytes's"   prepare for vector! to the extremes,   SV 1: ['prepare for vector! to the extreme']t   ConnectionDoneN(   s   1.2.3.4i.  (   R,   Rµ   R   R   R·   R"   RG   R¸   t   getvalueR”   R“   R‚   R   t   assertInRM   RŒ   Rl   (   R   R   t   tR?   R    t   v(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_thingsGetLogged­  s.    				

c         C   s•   t  ƒ  } t | d ƒ } |  j | j d ƒ | j d	 ƒ |  j | j d ƒ d | _ | j d
 ƒ |  j | j d ƒ | j ƒ  |  j | j d ƒ d S(   sG   
        Test counter management with the resetCounter method.
        R½   i    s   1.2.3.4i.  i   i/  i   N(   s   1.2.3.4i.  (   s   1.2.3.4i/  (   R,   R·   RM   t   _counterR"   RF   R¸   t   resetCounter(   R   R   R?   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_counterÐ  s    		
(   R   R   R-   RÄ   RÇ   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR¼   ¨  s   	#N(+   R-   t   zope.interfaceR    R   R   R   t   twisted.trialR   t   twisted.test.proto_helpersR   R   t   twisted.internetR   R   R	   R
   R   t   twisted.protocolsR   RE   R   t   ClientFactoryR   R#   R   R,   R/   R.   R7   R6   t   TestCaseR8   R:   R[   RŽ   t   TimeoutMixinRš   R¡   R¨   Rµ   t   TrafficLoggingFactoryR·   R¼   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   <module>   s.   (	a	ˆW6b<	