ó
[³XMc           @   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   s    e  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    
(   R   R   R-   RA   RL   (    (    (    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.pyRO   ª   s    (   R   R   R   RO   (    (    (    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.pyRN   Æ   s    c            s   t  j d ˆ t ˆ  ƒ ƒ S(   Ns	   127.0.0.1(   R   RS   R   (   RT   (   t   c3RV   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyRN   È   s    (   R   RS   R   R   t   addCallbackR   (   t   results(   RV   RU   RW   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   (   t   assertEqualsR   R   t   lent	   protocolst   keys(   RY   t   c(   t   tServerR   RW   RU   RZ   (    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   (   RY   (   RZ   (    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   RS   R   R   (   RY   (   t   c4RV   (    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    (   R\   R   R   (   RY   (   R   Re   (    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*   Rc   R
   t   DeferredListt   maybeDeferredt   stopListeningR   (   RY   R`   (   R    RU   Re   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   _cleanupß   s    (   R,   t   rangeR   R   R/   R:   R
   R   RP   R   t	   listenTCPt   getHostt   portRX   (
   R   t   servert   it   wrapTServerR[   Rb   Rd   Rf   Rg   Rk   (    (   Ra   R   RW   RU   RZ   Re   RV   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   R\   t   valuet   writtenThisSecondt   assertFalseR%   R0   t   advanceRH   (   R   Rp   Ra   Ro   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    Ru   Rv   Rw   i   gÍÌÌÌÌÌð?R%   t	   producingN(   R,   R.   R   Rx   R"   R	   R;   R   R   RG   R   R\   Rz   t   readThisSecondR0   R}   t   producerStatet   clear(   R   Rp   Ra   Ro   R~   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_readLimit  s6    			
(   R   R   R-   Rs   R   R…   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyRQ   °   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   Rx   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   setUp=  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_timeoutM  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_receiveAvoidsTimeouty  s    (   R   R   R-   R‰   R   R   R‘   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR†   8  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   Rx   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“   R\   R]   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“   R\   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   R\   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”   R\   R“   RF   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_return  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   t   assertEqualt   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   O  s    (   R   R   R   (    (   R>   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR§   N  s   i   i    (   R   R¡   R   RE   t   connectionLimitR"   RF   t   assertNotEqualR¢   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   testConnectionLimiting=  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   d  s    (   R   R   R   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR®   c  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   openl  s    N(   R   R   RF   R±   R´   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyR°   j  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‹   Rz   R   t   assertInR\   R„   Rc   (   R   Rˆ   t   tR?   R    t   v(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   test_thingsGetLoggedx  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°   R¢   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  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:   RQ   R†   t   TimeoutMixinR’   R™   R    R®   t   TrafficLoggingFactoryR°   Rµ   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_policies.pyt   <module>   s.   (	,	ˆW6b<	