
JMc           @   sH	  d  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
 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 d l m Z e Z y d d l m Z Wn e k
 r n Xe oe j re Z n  e e k r"d Z n e Z d e j f d     YZ d e j  f d     YZ! d e" f d     YZ# d e" f d     YZ$ d e" f d     YZ% d e j& f d     YZ' d e j( f d     YZ) d e) 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 d+     YZ1 d, e j( f d-     YZ2 d. e j( f d/     YZ3 d0 e j4 f d1     YZ5 d2 e j6 f d3     YZ7 d4 Z8 d5 e" f d6     YZ9 d7 e j  f d8     YZ: d9 e: f d:     YZ; d; e; f d<     YZ< d= e; f d>     YZ= d? e; f d@     YZ> e! e! dA  Z? dB e j f dC     YZ@ dD e j  f dE     YZA dF e jB f dG     YZC dH e jB f dI     YZD dJ eE f dK     YZF dL f  dM     YZG dN e jB f dO     YZH dP e j( f dQ     YZI dR e jJ f dS     YZK dT eK f dU     YZL dV eL f dW     YZM dX e j  f dY     YZN dZ e jB f d[     YZO d\ ZP d] ZQ d^ e jB f d_     YZR d` e jB f da     YZS db f  dc     YZT dd f  de     YZU df eU f dg     YZV dh eU f di     YZW dj eU f dk     YZX dl e: f dm     YZY dn e jB f do     YZZ dp e jB f dq     YZ[ dr e" f ds     YZ\ dt e" f du     YZ] dv e j( f dw     YZ^ dx e^ f dy     YZ_ dz e^ f d{     YZ` d| e j  f d}     YZa d~ e j  f d     YZb d e j  f d     YZc d e jB f d     YZd d   Ze d f  d     YZf d   Zg d   Zh e e k	 reh   Zi n  d ef e jB f d     YZj d e; f d     YZk d ef e jB f d     YZl d ef e jB f d     YZm d e j& f d     YZn d e j( f d     YZo d e j( f d     YZp d e j  f d     YZq d er f d     YZs d eo f d     YZt d e jB f d     YZu d f  d     YZv d e jB ev f d     YZw d e jB ev f d     YZx d e jB ev f d     YZy d e jB ev f d     YZz d e jB ev f d     YZ{ d e jB f d     YZ| d e jB ev f d     YZ} d e jB f d     YZ~ d e jB f d     YZ d e jB f d     YZ e j j e  rD	d Z e eZ _ e ej _ e el _ e em _ n  d S(   s%   
Tests for L{twisted.protocols.amp}.
iN(   t   verifyObject(   t   setIDFunction(   t   filepath(   t   Failure(   t   amp(   t   unittest(   t   protocolt   defert   errort   reactort
   interfaces(   t   iosim(   t   StringTransport(   t   ssls   SSL not availablet	   TestProtoc           B   sA   e  Z d  Z d Z d   Z d   Z d   Z d   Z d   Z RS(   s   
    A trivial protocol for use in testing where a L{Protocol} is expected.

    @ivar instanceId: the id of this instance
    @ivar onConnLost: deferred that will fired when the connection is lost
    @ivar dataToSend: data to send on the protocol
    i    c         C   s2   | |  _  | |  _ t j |  _ t j d t _ d  S(   Ni   (   t
   onConnLostt
   dataToSendR   t   instanceCountt
   instanceId(   t   selfR   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   __init__1   s    		c         C   s    g  |  _  |  j j |  j  d  S(   N(   t   datat	   transportt   writeR   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   connectionMade8   s    	c         C   s   |  j  j |  d  S(   N(   R   t   append(   R   t   bytes(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   dataReceived=   s    c         C   s   |  j  j |  j  d  S(   N(   R   t   callbackR   (   R   t   reason(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   connectionLostA   s    c         C   s   d |  j  f S(   s   
        Custom repr for testing to avoid coupling amp tests with repr from
        L{Protocol}

        Returns a string which contains a unique identifier that can be looked
        up using the instanceId property::

            <TestProto #3>
        s   <TestProto #%d>(   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   __repr__E   s    
(	   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   &   s   				t   SimpleSymmetricProtocolc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   |  j  d d | S(   Nt   hello(   t   callRemoteString(   R   t   text(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt	   sendHelloU   s    c         C   s   t  j d | d  S(   NR$   (   R   t   Box(   R   t   box(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt	   amp_HELLOZ   s    c         C   s   t  j d d  S(   Nt
   howdoyoudot   world(   R   t   QuitBox(   R   R)   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   amp_HOWDOYOUDO]   s    (   R    R!   R'   R*   R.   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR#   S   s   		t   UnfriendlyGreetingc           B   s   e  Z d  Z RS(   s&   Greeting was insufficiently kind.
    (   R    R!   R"   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR/   b   s   t   DeathThreatc           B   s   e  Z d  Z RS(   s&   Greeting was insufficiently kind.
    (   R    R!   R"   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR0   f   s   t   UnknownProtocolc           B   s   e  Z d  Z RS(   s+   Asked to switch to the wrong protocol.
    (   R    R!   R"   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR1   j   s   t   TransportPeerc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   d S(   Nt    (    (   R   t   dt   namet   proto(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   retriever   s    c         C   s   | j  j   S(   N(   R   t   getPeer(   R   t
   notAStringR6   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   fromStringProtou   s    c         C   s   d  S(   N(    (   R   R5   t   stringst   objectsR6   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   toBoxx   s    (   R    R!   R7   R:   R=   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR2   o   s   		t   Helloc        
   B   s   e  Z d  Z d  e j   f d e j d e  f d e j d e  f d e d e  f d e j d e  f d e j d e  f d e j d e  f g Z	 d  e j   f d e j d e  f g Z
 i d e 6Z i d e 6Z RS(	   R$   t   optionalt   printt   fromt	   mixedCases   dash-argt   underscore_argt
   UNFRIENDLYt   DEAD(   R    R!   t   commandNameR   t   Stringt   Booleant   Truet   UnicodeR2   t	   argumentst   responseR/   t   errorsR0   t   fatalErrors(    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR>   }   s   t   NoAnswerHelloc           B   s   e  Z e j Z e Z RS(    (   R    R!   R>   RF   t   Falset   requiresAnswer(    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRO      s   	t   FutureHelloc           B   s   e  Z d  Z d  e j   f d e j d e  f d e j d e  f d e d e  f d e j d e  f g Z	 d  e j   f d e j d e  f g Z
 i d e 6Z RS(   R$   R?   R@   RA   t   bonusRD   (   R    R!   RF   R   RG   RH   RI   RJ   R2   RK   RL   R/   RM   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRR      s   t   WTFc           B   s   e  Z d  Z RS(   s+   
    An example of an invalid command.
    (   R    R!   R"   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRT      s   t   BrokenReturnc           B   s   e  Z d  Z d Z RS(   s\    An example of a perfectly good command, but the handler is going to return
    None...
    t   broken_return(   R    R!   R"   RF   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRU      s   t   Goodbyec           B   s&   e  Z d  e j   f g Z e j Z RS(   t   goodbye(   R    R!   R   RG   RL   R-   t   responseType(    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRW      s   t
   Howdoyoudoc           B   s   e  Z d  Z RS(   R+   (   R    R!   RF   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRZ      s   t   WaitForeverc           B   s   e  Z d  Z RS(   t   wait_forever(   R    R!   RF   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR[      s   t   GetListc           B   sJ   e  Z d  Z d e j   f g Z d e j d e j   f g  f g Z RS(   t   getlistt   lengtht   bodyt   x(   R    R!   RF   R   t   IntegerRK   t   AmpListRL   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR]      s   t   DontRejectMec           B   s_   e  Z d  Z d e j   f d e j d e j   f g d e f g Z d e j   f g Z RS(   t   dontrejectmet	   magicWordt   listR5   R?   RL   (	   R    R!   RF   R   RJ   Rc   RI   RK   RL   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRd      s   -t   SecuredPingc           B   s   e  Z d  e j   f g Z RS(   t   pinged(   R    R!   R   RH   RL   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRh      s   t   TestSwitchProtoc           B   s0   e  Z d  Z d e j   f g Z i d e 6Z RS(   s   Switch-ProtoR5   t   UNKNOWN(   R    R!   RF   R   RG   RK   R1   RM   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRj      s   t   SingleUseFactoryc           B   s)   e  Z d    Z d   Z d Z d   Z RS(   c         C   s   | |  _  |  |  j  _ d  S(   N(   R6   t   factory(   R   R6   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR      s    	c         C   s   |  j  d  } |  _  | S(   N(   R6   t   None(   R   t   addrt   p(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   buildProtocol   s    c         C   s   | |  _  d  S(   N(   t   reasonFailed(   R   t	   connectorR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   clientConnectionFailed   s    	N(   R    R!   R   Rq   Rn   Rr   Rt   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRl      s   		s   gwebol nargot   ThingIDontUnderstandErrorc           B   s   e  Z RS(    (   R    R!   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRu      s   t   FactoryNotifierc           B   s-   e  Z d Z d    Z d   Z e j e  RS(   c         C   sJ   |  j  d  k	 rF |  |  j  _ t |  j  d  rF |  j  j j d   qF n  d  S(   Nt   onMade(   Rm   Rn   t   theProtot   hasattrRw   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR      s    c         C   s<   d d l  m } | j |  j  s1 t d   n  i t d 6S(   Ni(   t   ISSLTransports+   only send secure pings over secure channelsRi   (   t   twisted.internet.interfacesRz   t
   providedByR   R0   RI   (   R   Rz   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   emitpong   s    N(   R    R!   Rn   Rm   R   R}   Rh   t	   responder(    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRv      s   		t   SimpleSymmetricCommandProtocolc           B   s   e  Z d Z d d   Z d   Z d   Z e Z d d d d d d  Z	 e
 j e	  d   Z e j e  d d  Z e j e  d   Z e j e  d   Z e j e  d   Z e j e  e d	  Z d
   Z e j e  d   Z e j e  RS(   c         C   s   t  j j |   | |  _ d  S(   N(   R   t   AMPR   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR      s    c         C   s   |  j  t d | S(   NR$   (   t
   callRemoteR>   (   R   R&   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR'     s    c         C   s   |  j  t d | d | S(   NR$   t   Print(   R   R>   (   R   R&   t   translation(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   sendUnicodeHello  s    c   	      C   s   | |  j  j   k s t  | t k r3 t    n  | j d  rQ t d   n  | d k rl t d   n  t d |  } | d  k	 r | j
 t d |   n  t |  _ | S(   Nt   fucks   Don't be a dick.t   diet   aieeeeeeeeeR$   R   (   R   R8   t   AssertionErrort   THING_I_DONT_UNDERSTANDRu   t
   startswithR/   R0   t   dictRn   t   updateRI   t   greeted(	   R   R$   t   FromR?   R   RB   t   dash_argRC   t   result(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   cmdHello	  s    	c         C   s   i t  d d  g | d 6S(   NRa   i   R`   (   R   (   R   R_   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt
   cmdGetlist  s    c         C   s4   | d  k r d } n d | d d } t d |  S(   Nu   list omittedu   %s acceptedi    R5   RL   (   Rn   R   (   R   Rf   Rg   RL   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   okiwont  s    	c         C   s   t  j   |  _ |  j S(   N(   R   t   Deferredt   waiting(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt	   waitforit%  s    c         C   s   t  d d  S(   NR+   R,   (   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   howdo*  s    c         C   s   t  d d  S(   NRX   t   everyone(   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   saybye.  s    c            sU   | r d } n d } t  |  j t    |  j t t    d | j   f d    S(   Ns   no-protos
   test-protoR5   c            s     S(   N(    (   t   ign(   Rp   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   <lambda>:  s    (   R   R   t   SWITCH_CLIENT_DATAR   Rj   Rl   t   addCallback(   R   t   failR5   (    (   Rp   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   switchToTestProtocol2  s    	c         C   s,   | d k r t  |  j t  St |   d  S(   Ns
   test-proto(   R   R   t   SWITCH_SERVER_DATAR1   (   R   R5   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   switchit<  s    c         C   s   d  S(   N(   Rn   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt	   donothingB  s    N(   R    R!   Rn   t
   maybeLaterR   R'   R   RP   R   R   R>   R~   R   R]   R   Rd   R   R[   R   RZ   R   RW   R   R   Rj   R   RU   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR      s.   						
		t    DeferredSymmetricCommandProtocolc           B   s   e  Z d    Z e j e  RS(   c         C   sG   | d k r7 t  |  j t  |  _ t j   |  _ |  j St |   d  S(   Ns
   test-proto(   R   R   R   t   maybeLaterProtoR   R   R   R1   (   R   R5   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   H  s
    (   R    R!   R   Rj   R~   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   G  s   	t   BadNoAnswerCommandProtocolc           B   s-   e  Z d d d d d d   Z e j e  RS(   c         C   s   d S(   sQ   
        This responder does nothing and forgets to return a dictionary.
        N(    (   R   R$   R   R?   R   RB   R   RC   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   badResponderQ  s    N(   R    R!   Rn   R   RO   R~   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   P  s   t   NoAnswerCommandProtocolc           B   s-   e  Z d d d d d d   Z e j e  RS(   c         C   s   t  d | d  S(   NR$   s	   -noanswer(   R   (   R   R$   R   R?   R   RB   R   RC   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   goodNoAnswerResponderY  s    N(   R    R!   Rn   R   RO   R~   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   X  s   c         O   s   t  j |  | | |  S(   s.   Returns a 3-tuple: (client, server, pump)
    (   R   t   connectedServerAndClient(   t   ServerClasst   ClientClasst   at   kw(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   ^  s    t   TotallyDumbProtocolc           B   s   e  Z d  Z d   Z RS(   R3   c         C   s   |  j  | 7_  d  S(   N(   t   buf(   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   i  s    (   R    R!   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   g  s   t
   LiteralAmpc           B   s   e  Z d    Z d   Z RS(   c         C   s   g  |  _  d  S(   N(   t   boxes(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   m  s    c         C   s   |  j  j |  d  S(   N(   R   R   (   R   R)   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   ampBoxReceivedp  s    (   R    R!   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   l  s   	t   AmpBoxTestsc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   sm   
    Test a few essential properties of AMP boxes, mostly with respect to
    serialization correctness.
    c         C   s2   t  j d d  } |  j t | j    t  d S(   s8   
        Make sure that strs serialize to strs.
        t   keyt   valueN(   R   t   AmpBoxt   assertEqualst   typet	   serializet   str(   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_serializeStr|  s    c         C   s-   t  j i d d 6  } |  j t | j  d S(   sX   
        Verify that TypeError is raised when trying to serialize Unicode keys.
        R   u   keyN(   R   R   t   assertRaisest	   TypeErrorR   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_serializeUnicodeKeyRaises  s    c         C   s)   t  j d d  } |  j t | j  d S(   sb   
        Verify that TypeError is raised when trying to serialize Unicode
        values.
        R   u   valueN(   R   R   R   R   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt    test_serializeUnicodeValueRaises  s    (   R    R!   R"   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   v  s   		t   ParsingTestc           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s   t  j   } |  j | j d  t  |  j | j d  t  |  j t | j d  |  j t | j d  |  j t | j d  |  j | j t  d  |  j | j t  d  d S(   se   
        Verify that the Boolean parser parses 'True' and 'False', but nothing
        else.
        RI   RP   t   ninjat   truet   TRUEN(	   R   RH   R   t
   fromStringRI   RP   R   R   t   toString(   R   t   b(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_booleanValues  s    c         C   sc   t  j |  j    } t j   } | j |  } | j |  } |  j | |  |  j | |  d S(   sL   
        Verify the 'Path' argument can parse and emit a file path.
        N(	   R   t   FilePatht   mktempR   t   PathR   R   t   assertNotIdenticalR   (   R   t   fpRp   t   st   v(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_pathValueRoundTrip  s    c         C   s+   t  j   } |  j t  j | j t  j    S(   sk   
        Test that empty boxes raise an error; they aren't supposed to be sent
        on purpose.
        (   R   R   R   t   NoEmptyBoxesR   R(   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_sillyEmptyThing  s    c      
   C   s  t  d t d t  \ } } } d } d } d } d } d } d }	 d }
 | g | |
 g | | g | | g | | | | g | | | g | | | |	 g |
 | | g g } x[ | D]S } t j   } | j t |   | j |  | j   |  j | j	 d |  q Wd S(   sq   
        Verify that various kinds of data make it through the encode/parse
        round-trip unharmed.
        R   R   t   simplet   testt   ceqs   : t   crtests   testt   lftests   hello
t   newlines   test
one
twot   newline2s   test
one
 twoR`   s   blah

testtestiN(   R   s   test(   R   s   : (   R   s   test(   R   s   hello
(   R   s   test
one
two(   R   s   test
one
 two(   s   bodys   blah

testtest(
   R   R   R   R(   R   R   t   _sendTot   flushR   R   (   R   t   cR   Rp   t   SIMPLEt   CEt   CRt   LFt   NEWLINEt   NEWLINE2t   BODYTESTt   testDataR   t   jb(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_ParsingRoundTrip  s.    			
(   R    R!   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s   				t   FakeLocatorc           B   s    e  Z d  Z d   Z d   Z RS(   sZ   
    This is a fake implementation of the interface implied by
    L{CommandLocator}.
    c         C   s   i  |  _  d S(   sN   
        Remember the given keyword arguments as a set of responders.
        N(   t   commands(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s    c         C   s   |  j  | S(   sz   
        Look up and return a function passed as a keyword argument of the given
        name to the constructor.
        (   R   (   R   RF   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   locateResponder  s    (   R    R!   R"   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s   	t
   FakeSenderc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s\   
    This is a fake implementation of the 'box sender' interface implied by
    L{AMP}.
    c         C   s   g  |  _  g  |  _ d |  _ d S(   sn   
        Create a fake sender and initialize the list of received boxes and
        unhandled errors.
        i    N(   t	   sentBoxest   unhandledErrorst   expectedErrors(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s    		c         C   s   |  j  d 7_  d S(   sB   
        Expect one error, so that the test doesn't fail.
        i   N(   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   expectError   s    c         C   s   |  j  j |  d S(   s6   
        Accept a box, but don't do anything.
        N(   R   R   (   R   R)   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   sendBox  s    c         C   s?   |  j  d 8_  |  j  d k  r+ | j   n |  j j |  d S(   sW   
        Deal with failures by instantly re-raising them for easier debugging.
        i   i    N(   R   t   raiseExceptionR   R   (   R   t   failure(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   unhandledError  s    (   R    R!   R"   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s
   	
		t   CommandDispatchTestsc           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s  
    The AMP CommandDispatcher class dispatches converts AMP boxes into commands
    and responses using Command.responder decorator.

    Note: Originally, AMP's factoring was such that many tests for this
    functionality are now implemented as full round-trip tests in L{AMPTest}.
    Future tests should be written at this level instead, to ensure API
    compatibility and to provide more granular, readable units of test
    coverage.
    c         C   sD   t    |  _ t   |  _ t j |  j  |  _ |  j j |  j  d S(   s-   
        Create a dispatcher to use.
        N(   R   t   locatorR   t   senderR   t   BoxDispatchert
   dispatchert   startReceivingBoxes(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   setUp&  s    c            sj   g      f d   } t  j d d d d d d  } | |  j j d <|  j j |  |  j   | g  d S(   s   
        L{CommandDispatcher.ampBoxReceived} should locate the appropriate
        command in its responder lookup, based on the '_ask' key.
        c            s!     j  |   t j i d d 6 S(   NRX   R$   (   R   R   R(   (   R)   (   t   received(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   thunk6  s    t   _commandR$   t   _asks   test-command-idR,   N(   R   R(   R   R   R   R   R   (   R   R   t   input(    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_receivedAsk0  s    	c         C   sl   t  d  } |  j j   |  j j t |   |  j t |  j j  d  |  j |  j j d j	 |  d S(   sy   
        L{CommandDispatcher} should relay its unhandled errors in responding to
        boxes to its boxSender.
        s   something went wrong, oh noi   i    N(
   t   RuntimeErrorR   R   R   R   R   t   assertEqualt   lenR   R   (   R   t   err(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_sendUnhandledErrorA  s
    c            s   t  d      f d   } | |  j j d <t j d d d d d d  } |  j j   |  j j |  |  j	 t
 |  j j  d  |  j	 |  j j d	 j    d
 S(   sp   
        Errors during serialization ought to be relayed to the sender's
        unhandledError method.
        s   something undefined went wrongc            s&   d t  j f   f d     Y} |   S(   Nt	   BrokenBoxc              s   e  Z   f d    Z RS(   c            s
      d  S(   N(    (   R   R6   (   R  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   U  s    (   R    R!   R   (    (   R  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR  T  s   (   R   R(   (   R   R  (   R  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   S  s    R$   R   R   s   test-command-idR,   i   i    N(   R   R   R   R   R(   R   R   R   R   R   R  R   R   (   R   R   R   (    (   R  s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt    test_unhandledSerializationErrorM  s    	c      	   C   s   |  j  j t d d } |  j |  j j t j d d d d d d  g  g  } | j | j	  |  j | g   |  j  j
 t j i d d 6d d 6d d	 6  |  j | t d d d
 d  g  d S(   s[  
        L{CommandDispatcher.callRemote} should emit a properly formatted '_ask'
        box to its boxSender and record an outstanding L{Deferred}.  When a
        corresponding '_answer' packet is received, the L{Deferred} should be
        fired, and the results translated via the given L{Command}'s response
        de-serialization.
        R$   R,   R   R   t   1t   yayt   ignoredR@   t   _answerR   u   ignoredN(   R   R   R>   R   R   R   R   R   R   R   R   R   (   R   t   Dt   answers(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_callRemoteb  s    (   R    R!   R"   R   R   R  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s   
	
			t   SimpleGreetingc           B   sM   e  Z d  Z d Z d e j   f d e j   f g Z d e j   f g Z RS(   sN   
    A very simple greeting command that uses a few basic argument types.
    R   t   greetingt   cookiet
   cookieplus(	   R    R!   R"   RF   R   RJ   Rb   RK   RL   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR  y  s
   t   TestLocatorc           B   s/   e  Z d  Z d   Z d   Z e j e  Z RS(   sI   
    A locator which implements a responder to the 'simple' command.
    c         C   s   g  |  _  d  S(   N(   t	   greetings(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s    c         C   s'   |  j  j | | f  t d | d  S(   NR  i   (   R  R   R   (   R   R  R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   greetingResponder  s    (   R    R!   R"   R   R  R  R~   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   		t   OverridingLocatorc           B   s&   e  Z d  Z d   Z e j e  Z RS(   sJ   
    A locator which overrides the responder to the 'simple' command.
    c         C   s'   |  j  j | | f  t d | d  S(   sV   
        Return a different cookieplus than L{TestLocator.greetingResponder}.
        R  i   (   R  R   R   (   R   R  R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s    (   R    R!   R"   R  R  R~   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   	t   InheritingLocatorc           B   s   e  Z d  Z RS(   sN   
    This locator should inherit the responder from L{OverridingLocator}.
    (   R    R!   R"   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   t   OverrideLocatorAMPc           B   s2   e  Z d    Z d   Z d   Z e j e  Z RS(   c         C   s<   t  j j |   t   |  _ i |  j d 6|  _ g  |  _ d  S(   Nt   custom(   R   R   R   t   objectt   customRespondert   expectationsR  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s    c         C   s:   | |  j  k r  |  j  | } | St t |   j |  Sd S(   sB   
        Override the deprecated lookupFunction function.
        N(   R  t   superR  t   lookupFunction(   R   R5   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s    c         C   s'   |  j  j | | f  t d | d  S(   NR  i   (   R  R   R   (   R   R  R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s    (   R    R!   R   R  R  R  R~   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   			t   CommandLocatorTestsc           B   sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s   
    The CommandLocator should enable users to specify responders to commands as
    functions that take structured objects, annotated with metadata.
    c            sU   |   } | j  d  } | t j d d d d   }    f d   } | j |  S(   s   
        Check that a locator of type C{locatorClass} finds a responder
        for command named I{simple} and that the found responder answers
        with the C{expected} result to a C{SimpleGreeting<"ni hao", 5>}
        command.
        R   R  s   ni haoR  t   5c            s&    j  |  t j d t      d  S(   NR  (   R   R   R   R   (   t   values(   t   expectedR   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   done  s    (   R   R   R(   R   (   R   t   locatorClassR!  R   t   responderCallableR   R"  (    (   R   R!  s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   _checkSimpleGreeting  s
    	c         C   s   |  j  t d  S(   s   
        A method on a L{CommandLocator} subclass decorated with a L{Command}
        subclass's L{responder} decorator should be returned from
        locateResponder, wrapped in logic to serialize and deserialize its
        arguments.
        i   (   R%  R  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_responderDecorator  s    c         C   s   |  j  t d  S(   s   
        L{CommandLocator} subclasses can override a responder inherited from
        a base class by using the L{Command.responder} decorator to register
        a new responder method.
        i	   (   R%  R  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_responderOverriding  s    c         C   s   |  j  t d  S(   s   
        Responder lookup follows the same rules as normal method lookup
        rules, particularly with respect to inheritance.
        i	   (   R%  R  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_responderInheritance  s    c            s   t       j t d t  f d    }   j  j |    j t d t  f d    } | t j d d d d   }   f d   } | j |  S(	   s0  
        Subclasses which override locateResponder under its old name,
        lookupFunction, should have the override invoked instead.  (This tests
        an AMP subclass, because in the version of the code that could invoke
        this deprecated code path, there was no L{CommandLocator}.)
        s-   Override locateResponder, not lookupFunction.c              s     j  d  S(   NR  (   R   (    (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s    c              s     j  d  S(   NR   (   R   (    (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s    R  s   ni haoR  R  c            s      j  |  t j d d   d  S(   NR  t   8(   R   R   R   (   R   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR"    s    (	   R  t   assertWarnst   PendingDeprecationWarningt   __file__R   R  R   R(   R   (   R   t   customResponderObjectt   normalResponderObjectR   R"  (    (   R   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt%   test_lookupFunctionDeprecatedOverride  s    	c            sd   t       j t d t  f d    } | t j d d d d   }   f d   } | j |  S(   s   
        Invoking locateResponder under its old name, lookupFunction, should
        emit a deprecation warning, but do the same thing.
        s)   Call locateResponder, not lookupFunction.c              s     j  d  S(   NR   (   R  (    (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s    R  s   ni haoR  R  c            s      j  |  t j d d   d  S(   NR  R)  (   R   R   R   (   R   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR"    s    (   R  R*  R+  R,  R   R(   R   (   R   R$  R   R"  (    (   R   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt#   test_lookupFunctionDeprecatedInvoke  s    	(	   R    R!   R"   R%  R&  R'  R(  R/  R0  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   		
				s   Success!s   No, really.  Success.t   BinaryProtocolTestsc           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 d   Z d   Z d   Z d   Z d   Z RS(   s   
    Tests for L{amp.BinaryBoxProtocol}.

    @ivar _boxSender: After C{startReceivingBoxes} is called, the L{IBoxSender}
        which was passed to it.
    c         C   s   g  |  _  g  |  _ d S(   sz   
        Keep track of all boxes received by this test in its capacity as an
        L{IBoxReceiver} implementor.
        N(   R   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   )  s    	c         C   s   | |  _  d S(   sm   
        Implement L{IBoxReceiver.startReceivingBoxes} to just remember the
        value passed in.
        N(   t
   _boxSender(   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   2  s    c         C   s   |  j  j |  d S(   s5   
        A box was received by the protocol.
        N(   R   R   (   R   R)   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   :  s    c         C   s   | |  _  d S(   sD   
        Record the reason that we stopped receiving boxes.
        N(   t
   stopReason(   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   stopReceivingBoxesA  s    c         C   s   d S(   Ns   no peer(    (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR8   I  s    c         C   s   d S(   Ns   no host(    (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   getHostM  s    c         C   s   |  j  j |  d  S(   N(   R   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   Q  s    c         C   s3   t  j |   } | j d  |  j |  j |  d S(   s   
        When L{amp.BinaryBoxProtocol} is connected to a transport, it calls
        C{startReceivingBoxes} on its L{IBoxReceiver} with itself as the
        L{IBoxSender} parameter.
        N(   R   t   BinaryBoxProtocolt   makeConnectionRn   t   assertIdenticalR2  (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_startReceivingBoxesU  s    c         C   sU   d d d     Y} t    } t j |    } | j |  |  j | j   d  d S(   s   
        The L{IBoxReceiver} which is started when L{amp.BinaryBoxProtocol} is
        connected to a transport can call C{sendBox} on the L{IBoxSender}
        passed to it before C{startReceivingBoxes} returns and have that box
        sent.
        t   SynchronouslySendingReceiverc           B   s   e  Z d    Z RS(   c         S   s!   | j  t j i d d 6  d  S(   Nt   bart   foo(   R   R   R(   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   h  s    (   R    R!   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR:  g  s   t    foo bar  N(    (   R   R   R6  R7  R  R   (   R   R:  R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt!   test_sendBoxInStartReceivingBoxes`  s    		c         C   s\   t  j |   } | j d  | j d  | j d  |  j |  j t  j d d  g  d S(   s   
        When a binary box protocol receives:
            * a key
            * a value
            * an empty string
        it should emit a box and send it to its boxReceiver.
        R$   R,   R3   N(   R   R6  t   stringReceivedR   R   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_receiveBoxStateMachines  s
    c         C   sF   t    } t j |   } | j |  | j d  |  j | j  d S(   s   
        L{amp.BinaryBoxProtocol} drops its connection if the length prefix for
        the first a key it receives is larger than 255.
        s    N(   R   R   R6  R7  R   t
   assertTruet   disconnecting(   R   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt$   test_firstBoxFirstKeyExcessiveLength  s
    	c         C   sc   t    } t j |   } | j |  | j d  |  j | j  | j d  |  j | j  d S(   s   
        L{amp.BinaryBoxProtocol} drops its connection if the length prefix for
        a subsequent key in the first box it receives is larger than 255.
        t    k vs    N(   R   R   R6  R7  R   t   assertFalseRB  RA  (   R   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt)   test_firstBoxSubsequentKeyExcessiveLength  s    	c         C   sc   t    } t j |   } | j |  | j d  |  j | j  | j d  |  j | j  d S(   s   
        L{amp.BinaryBoxProtocol} drops its connection if the length prefix for
        the first key in a subsequent box it receives is larger than 255.
        t    k v  s    N(   R   R   R6  R7  R   RE  RB  RA  (   R   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt)   test_subsequentBoxFirstKeyExcessiveLength  s    	c         C   s   t  j |   } | j t    | j d  | j t t j d    |  j	 j
 t  j  |  j |  j	 j j  |  j |  j	 j j  |  j |  j	 j j d  |  j |  j	 j j d  d S(   s   
        If L{amp.BinaryBoxProtocol} disconnects because it received a key
        length prefix which was too large, the L{IBoxReceiver}'s
        C{stopReceivingBoxes} method is called with a L{TooLong} failure.
        s    s   simulated connection doneN(   R   R6  R7  R   R   R   R   R   t   ConnectionDoneR3  t   trapt   TooLongRA  R   t   isKeyRE  t   isLocalR8  Rn   t   keyName(   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_excessiveKeyFailure  s    c         C   sj   t  j |   } | j t  j i d d 6d d 6 j    |  j |  j t  j i d d 6d d 6 g  d S(   s   
        When a binary box protocol receives the serialized form of an AMP box,
        it should emit a similar box to its boxReceiver.
        t	   valueTestt   testKeyt   anotherValuet
   anotherKeyN(   R   R6  R   R(   R   R   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_receiveBoxData  s    c         C   s   d } d | } t    } t j |   } | j |  | j t j i | d 6 j    |  j |  j t j i | d 6 g  |  j	 | j
  d S(	   s   
        An L{amp.BinaryBoxProtocol} can receive serialized AMP boxes with
        values of up to (2 ** 16 - 1) bytes.
        i   i   i   Ra   t   kNi   i  (   R   R   R6  R7  R   R(   R   R  R   RE  RB  (   R   R_   R   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_receiveLongerBoxData  s    
	#&c         C   sy   t  j |   } | j |   t  j i d d 6d d 6 } | j |   | j |  |  j d j |  j  | j    d S(   s   
        When a binary box protocol sends a box, it should emit the serialized
        bytes of that box to its transport.
        RP  RQ  R$   t   someDataR3   N(	   R   R6  R7  R(   R   R   t   joinR   R   (   R   R   t   aBox(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_sendBox  s    c         C   sO   t  j |   } | j |   t t    } | j |  |  j |  j |  d S(   s   
        When a binary box protocol loses its connection, it should notify its
        box receiver that it has stopped receiving boxes.
        N(   R   R6  R7  R   R   R   R8  R3  (   R   R   t   connectionFailure(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt#   test_connectionLostStopSendingBoxes  s
    c            s  t  d d   |   d d     f d     Y} t j |      t j i d d 6d d 6 }   j |   | j   d }   j |  |  j  j	 |   |  j
 d	 j  j  d  |  j
 |  j d g    j d
  |  j
 d	 j  j  d  |  j t j   j |  d S(   s   
        L{BinaryBoxProtocol} has the capacity to switch to a different protocol
        on a box boundary.  When a protocol is in the process of switching, it
        cannot receive traffic.
        s   outgoing datat   SwitchyReceiverc              s,   e  Z e Z d    Z     f d   Z RS(   c         S   s   d  S(   N(    (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s    c            s7    j  |  j d  t |  _   j     j   d  S(   Ns   Should only receive one box!(   RE  t   switchedRI   t   _lockForSwitcht	   _switchTo(   R   R)   (   R   t
   otherProtoR   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s
    	
(   R    R!   RP   R^  R   R   (    (   R   Ra  R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR]    s   	t   lotst   includeR   t   oft     Hello, world!R3   s	   more datat     Hello, world!more dataN(    (   R   Rn   R   R6  R(   R7  R   R   R8  R   R   RX  R   R   t   ProtocolSwitchedR   (   R   R]  t	   anyOldBoxt   moreThanOneBox(    (   R   Ra  R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_protocolSwitch  s     
c         C   sO   t  j |   } | j |   t d d  } | j |  |  j | j g   d S(   s   
        After switching to a different protocol, if no extra bytes beyond
        the switch box were delivered, an empty string is not passed to the
        switched protocol's C{dataReceived} method.
        R3   N(   R   R6  R7  R   Rn   R`  R   R   (   R   R   Ra  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_protocolSwitchEmptyBuffer  s
    c         C   s   t  j |   } | j |   t  j i d d 6 } | j   |  j t  j | j |  | j   | j |  |  j	 d j
 |  j  | j    | j   t d d  } | j |  |  j t  j | j  d S(   s8  
        In order to make sure the protocol never gets any invalid data sent
        into the middle of a box, it must be locked for switching before it is
        switched.  It can only be unlocked if the switch failed, and attempting
        to send a box while it is locked should raise an exception.
        R   t   someR3   s   outgoing dataN(   R   R6  R7  R(   R_  R   Rg  R   t   _unlockFromSwitchR   RX  R   R   R   Rn   R`  (   R   R   t	   sampleBoxRa  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt    test_protocolSwitchInvalidStates#  s    

"
c         C   s   d t  j f d     Y} |   } t j |   } | j |   | j   | j |  t t    } | j	 |  |  j
 | j |  d S(   so   
        When the protocol is switched, it should notify its nested protocol of
        disconnection.
        t   Loserc           B   s   e  Z d Z d    Z RS(   c         S   s   | |  _  d  S(   N(   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   ?  s    N(   R    R!   Rn   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRp  =  s   N(   R   t   ProtocolR   R6  R7  R_  R`  R   R   R   R   R   (   R   Rp  t   connectionLoserR   R[  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt!   test_protocolSwitchLoseConnection8  s    	
c         C   s   d d d     Y} t  j |   } t j   } |   } | j |   | j   | j | |  t t    } | j	 |  |  j
 | j |  d S(   s~   
        When the protocol is switched, it should notify its nested client
        protocol factory of disconnection.
        t   ClientLoserc           B   s   e  Z d Z d    Z RS(   c         S   s   | |  _  d  S(   N(   R   (   R   Rs   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   clientConnectionLostR  s    N(   R    R!   Rn   R   Ru  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRt  P  s   N(    (   R   R6  R   Rq  R7  R_  R`  R   R   R   R   R   (   R   Rt  R   Rr  t   clientLoserR[  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt'   test_protocolSwitchLoseClientConnectionK  s    	
N(   R    R!   R"   R   R   R   Rn   R3  R4  R8   R5  R   R9  R>  R@  RC  RF  RH  RO  RT  RV  RZ  R\  Rj  Rk  Ro  Rs  Rw  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR1  !  s2   																				$			t   AMPTestc           B   sj  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 e e _ 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  e! e" e" d  Z# d   Z$ e! d  Z% d    Z& d!   Z' d"   Z( d#   Z) d$   Z* RS(%   c         C   s   x t  j t  j f t  j t  j f t  j t  j f t  j t  j f t  j t  j f t  j t  j f t  j t  j f g D]/ \ } } |  j	 | j
 |  d | | f  qp Wd S(   s~   
        The classes in the amp module ought to implement the interfaces that
        are declared for their benefit.
        s   %s does not implements(%s)N(   R   t
   IBoxSenderR6  t   IBoxReceiverR   t   IResponderLocatort   CommandLocatort   SimpleStringLocatorR   t
   failUnlesst   implementedBy(   R   t	   interfacet   implementation(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_interfaceDeclarationsb  s    c         C   s]   t    \ } } } g  } d } | j |  j | j  | j   |  j | d d |  d S(   s   
        Verify that a simple command can be sent and its response received with
        the simple low-level string-based API.
        R,   i    R$   N(   R   R'   R   R   R   R   (   R   R   R   Rp   t   Lt   HELLO(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_helloWorldr  s    
c         C   s]   t    \ } } } g  } d } | j |  j | j  | j   |  j | d d |  d S(   s}   
        Verify that mixed-case, underscored and dashed arguments are mapped to
        their python names properly.
        R,   i    R$   N(   R   R'   R   R   R   R   (   R   R   R   Rp   R  R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_wireFormatRoundTrip  s    
c         C   s   t  d t d t  \ } } } g  } d } d } | j | |  j | j  | j   |  j | d d |  |  j | d d |  d S(	   sK   
        Verify that unicode arguments can be encoded and decoded.
        R   R   R,   s   wor\u1234ldi    R$   R   N(   R   R   R   R   R   R   R   (   R   R   R   Rp   R  R  t   HELLO_UNICODE(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_helloWorldUnicode  s    
c         C   s;   t    \ } } } | j d d t } |  j | d  d S(   sm   
        L{BoxDispatcher.callRemoteString} returns C{None} if C{requiresAnswer}
        is C{False}.
        RT   RQ   N(   R   R%   RP   R8  Rn   (   R   R   R   Rp   t   ret(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt(   test_callRemoteStringRequiresAnswerFalse  s    c         C   s   t    \ } } } g  } d   } | j d  j |  j | j  | j   |  j | j   d  d } | j |  j | j  | j   |  j | d d |  d S(   s   
        Verify that unknown commands using low-level APIs will be rejected with an
        error, but will NOT terminate the connection.
        c         S   s   |  j  t j  d S(   s:   
            You can't propagate the error...
            t   OK(   RJ  R   t   UnhandledCommand(   t   e(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   clearAndAdd  s    RT   R  R,   i    R$   N(	   R   R%   t
   addErrbackR   R   R   R   t   popR'   (   R   R   R   Rp   R  R  R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_unknownCommandLow  s    	"

c         C   s   t    \ } } } g  } d   } | j t  j |  j | j  | j   |  j | j   d  d } | j	 |  j | j  | j   |  j | d d |  d S(   s   
        Verify that unknown commands using high-level APIs will be rejected with an
        error, but will NOT terminate the connection.
        c         S   s   |  j  t j  d S(   s:   
            You can't propagate the error...
            R  (   RJ  R   R  (   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s    R  R,   i    R$   N(
   R   R   RT   R  R   R   R   R   R  R'   (   R   R   R   Rp   R  R  R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_unknownCommandHigh  s    	"

c         C   sf   g  } t    j t j d t j   j | j  | d j t j	  |  j
 d t | d j   d S(   s  
        It can be very confusing if you write some code which responds to a
        command, but gets the return value wrong.  Most commonly you end up
        returning None instead of a dictionary.

        Verify that if that happens, the framework logs a useful error.
        R   i    Rn   N(   R   t   dispatchCommandR   R   RU   RF   R  R   RJ  t   BadLocalReturnt   failUnlessInt   reprR   (   R   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_brokenReturnValue  s
    	"c         C   su   t  d t d t  \ } } } g  } d } | j t d | d d j | j  | j   |  j | d d |  d S(	   s   
        Verify that unknown arguments are ignored, and not passed to a Python
        function which can't accept them.
        R   R   R,   R$   RS   s   I'm not in the book!i    N(   R   R   R   RR   R   R   R   R   (   R   R   R   Rp   R  R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_unknownArgument  s    	

c         C   s   |  j  t t t j d    t  |  j  t t t j     t  |  j  t t t j     t  |  j d t t j    k  d S(   sS   
        Verify that the various Box objects repr properly, for debugging.
        R   R   N(	   R   R   R  R   t
   _SwitchBoxR   R-   R   R~  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_simpleReprs  s    %""c            sm   t  d d  } t j     |   _   f d   } |  j t t |   |  j t    d | j	 f  d S(   sQ   
        Verify that L{AMP} objects output their innerProtocol when set.
        s   outgoing datac            s   i d   6j  |  t |    S(   Ni4  (   t   gett   id(   t   obj(   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   fakeID  s    s%   <AMP inner <TestProto #%d> at 0x1234>N(
   R   Rn   R   R   t   innerProtocolt
   addCleanupR   R   R  R   (   R   Ra  R  (    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_innerProtocolInRepr  s    	c            sK   t  j       f d   } |  j t t |   |  j t    d  d S(   sh   
        Verify that L{AMP} objects do not output 'inner' when no innerProtocol
        is set.
        c            s   i d   6j  |  t |    S(   Ni!C  (   R  R  (   R  (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s    s   <AMP at 0x4321>N(   R   R   R  R   R   R  (   R   R  (    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_innerProtocolNotInRepr  s    c         C   s&   |  j  t t t j     t  d S(   s;   
        L{amp._TLSBox.__repr__} returns a string.
        N(   R   R   R  R   t   _TLSBoxR   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_simpleSSLRepr  s    c         C   s   t    \ } } } d d } |  j t j | j d i d | 6 } |  j | j  |  j | j  |  j | j	 d  |  j | j |  |  j t t |   t |   |  j d t |   d S(	   sl   
        Verify that a key that is too long will immediately raise a synchronous
        exception.
        t   Hi   i   R>   t   hiR   Ni   (   R   R   R   RK  R%   RA  RL  RM  R8  RN  Rn   R   R   t   assertInR   R  R  (   R   R   R   Rp   Ra   t   tl(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_keyTooLong#  s    
	"c         C   s   t    \ } } } d d } |  j t j | j |  } | j   |  j | j  |  j | j	  |  j
 | j d  |  j | j |  |  j t t |   t |  k  |  j d t |  k  |  j d t |  k  d S(   ss   
        Verify that attempting to send value longer than 64k will immediately
        raise an exception.
        R  i  i   R$   R   Ni   (   R   R   R   RK  R'   R   t   failIfRL  R~  RM  R   RN  t   failUnlessIdenticalR   R   R  R  (   R   R   R   Rp   Ra   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_valueTooLong5  s    

%c         C   si   t  d t d t  \ } } } g  } d } | j |  j | j  | j   |  j | d d |  d S(   s   
        Verify that a simple command can be sent and its response received with
        the high-level value parsing API.
        R   R   R,   i    R$   N(   R   R   R'   R   R   R   R   (   R   R   R   Rp   R  R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_helloWorldCommandG  s    
c         C   s   g  } t  d t d t  \ } } } d } | j |  j | j  | j   | d j t  |  j t	 | d j
  d  d S(   s   
        Verify that if a known error type is raised and handled, it will be
        properly relayed to the other end of the connection and translated into
        an exception, and no error will be logged.
        R   R   s   fuck youi    s   Don't be a dick.N(   R   R   R'   R  R   R   RJ  R/   R   R   R   (   R   R  R   R   Rp   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_helloErrorHandlingV  s    
c         C   s   g  } t  d t d t  \ } } } d } | j |  j | j  | j   | j   j t  | j |  j | j  | j   | j   j t	 j
  d S(   s
  
        Verify that if a known, fatal error type is raised and handled, it will
        be properly relayed to the other end of the connection and translated
        into an exception, no error will be logged, and the connection will be
        terminated.
        R   R   R   N(   R   R   R'   R  R   R   R  RJ  R0   R   RI  (   R   R  R   R   Rp   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_helloFatalErrorHandlingg  s    

c         C   s   g  } t  d t d t  \ } } } t } | j |  j | j  | j   | j   } | j t	 j
  | j |  j | j  | j   } | j t j  |  j |  j t   d S(   s   
        Verify that if an unknown error type is raised, it will be relayed to
        the other end of the connection and translated into an exception, it
        will be logged, and then the connection will be dropped.
        R   R   N(   R   R   R   R'   R  R   R   R  RJ  R   t   UnknownRemoteErrorR   RI  R~  t   flushLoggedErrorsRu   (   R   R  R   R   Rp   R  t   uret   cl(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_helloNoErrorHandling|  s    
c         C   s   t  d t d t  \ } } } g  } | j t  j | j  | j   |  j | g   | j j	   | j   | j
   j t j  | j j i   | j S(   s   
        Verify that a command that does not get answered until after the
        connection terminates will not cause any errors.
        R   R   (   R   R   R   R[   R  R   R   R   R   t   loseConnectionR  RJ  R   RI  R   R   (   R   R   R   Rp   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_lateAnswer  s    

c         C   sU   t  d t d t  \ } } } d } | j t d | | j   |  j | j  d S(   sG   
        Verify that a command that requires no answer is run.
        R   R   R,   R$   N(   R   R   R   RO   R   R~  R   (   R   R   R   Rp   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_requiresNoAnswer  s    
c         C   s   g  } t  d t d t  \ } } } d } | j t d | | j   |  j |  j t j   d } | j t	 d | j
 | j  | j   | j   j t j  |  j | j  d S(   s]   
        Verify that commands sent after a failed no-answer request do not complete.
        R   R   s   fuck youR$   R,   N(   R   R   R   RO   R   R~  R  R   t   RemoteAmpErrorR>   R  R   R  RJ  R   RI  R  R   (   R   R  R   R   Rp   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_requiresNoAnswerFail  s    

c         C   sg   t  d t d t  \ } } } | j t d d | j   |  j t j  } |  j	 t
 |  d  d S(   s+  
        Verify that responders of requiresAnswer=False commands have to return
        a dictionary anyway.

        (requiresAnswer is a hint from the _client_ - the server may be called
        upon to answer commands in any case, if the client wants to know when
        they complete.)
        R   R   R$   i   N(   R   R   R   R   RO   R   R  R   R  R   R  (   R   R   R   Rp   t   le(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_noAnswerResponderBadAnswer  s    	
c         C   s   t  d t d t  \ } } } g  } | j t d d j | j  | j   |  j t	 |  d  |  j | t
 d d d d  g  d S(	   s   
        Verify that responders with requiresAnswer=False will actually respond
        if the client sets requiresAnswer=True.  In other words, verify that
        requiresAnswer is a hint honored only by the client.
        R   R   R$   s   Hello!i   s   Hello!-noanswerR   N(   R   R   R   R   R>   R   R   R   R   R  R   Rn   (   R   R   R   Rp   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt$   test_noAnswerResponderAskedForAnswer  s    
c         C   s   t  d t d t  \ } } } g  } | j t d d j | j  | j   | j   j d  } |  j	 | i d d 6g d  d S(	   sN   
        Test encoding of an argument that uses the AmpList encoding.
        R   R   R_   i
   R`   i   Ra   N(
   R   R   R   R]   R   R   R   R  R  R   (   R   R   R   Rp   R  R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_ampListCommand  s    
c         C   sv   t  d t d t  \ } } } g  } | j t d d j | j  | j   | j   j d  } |  j	 | d  d S(   s   
        Sending a command with an omitted AmpList argument that is
        designated as optional does not raise an InvalidSignature error.
        R   R   Rf   u   pleaseRL   s   list omittedN(
   R   R   R   Rd   R   R   R   R  R  R   (   R   R   R   Rp   R  RL   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_optionalAmpListOmitted  s    
c         C   s   t  d t d t  \ } } } g  } | j t d d d i d d 6g j | j  | j   | j   j d  } |  j	 | d	  d
 S(   sV   
        Sanity check that optional AmpList arguments are processed normally.
        R   R   Rf   u   pleaseRg   R<  R5   RL   s   foo acceptedN(
   R   R   R   Rd   R   R   R   R  R  R   (   R   R   R   Rp   R  RL   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_optionalAmpListPresent  s    
c         C   s   |  j  t j t  d S(   s~   
        Verify that if we pass an invalid argument list (omitting an argument),
        an exception will be raised.
        N(   R   R   t   InvalidSignatureR>   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_failEarlyOnArgSending  s    c            s   t  j   } t |   t  j   } t |    t d  f d   d   f d    \  } }   f d   }  j   j |  | j    j  j  d S(   s   
        As a debugging aid, a protocol system should raise a
        L{ProtocolSwitched} exception when asked to switch a protocol that is
        already switched.
        R   c              s     S(   N(    (    (   t   serverProto(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   )  s    R   c              s     S(   N(    (    (   t   clientProto(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   *  s    c            s#     j  t j  j  t   _ d  S(   N(   R   R   Rg  R   RI   t   testSucceeded(   R   (   R   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR^  +  s    N(	   R   R   R   R   R   R   R   R~  R  (   R   t   serverDeferredt   clientDeferredR   Rp   R^  (    (   R  R  R   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_doubleProtocolSwitch  s    
c   
         s  t   _ t j    |    t j    |     t d  f d   d   f d    \ } } } | r g  } | j t  j | j  n  | j	   } | r  j
 t j | j d  n   f d       f d   }	 | j |	  | j    j d
 k	 r) j j  j  | j   n  | rq| rT| j j t j d d	   n | j j i   | j   n  | j j   | j    j  j  d
 S(   s   
        Verify that it is possible to switch to another protocol mid-connection and
        send data to it successfully.
        R   c              s     S(   N(    (    (   R  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   @  s    R   c              s     S(   N(    (    (   R  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   A  s    R,   c            sq   |  \ \ } } \ } }   j  |    j  |    j d j |  t    j d j |  t  t   _ d  S(   NR3   (   R~  R   RX  R   R   RI   R  (   t   .0t   serverSuccesst
   serverDatat   clientSuccesst
   clientData(   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   cbConnsLostJ  s    	c            s   t  j    g  j   S(   N(   R   t   DeferredListR   (   R6   (   R  R  R  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   cbSwitchR  s    t   SPURIOUSs,   Here's some traffic in the form of an error.N(   RP   R  R   R   R   R   R[   R  R   R   R   R   Rg  R'   R   R   R   Rn   R   R   R   t   errbackR  R   R  R~  (
   R   t   switchert   spuriousTraffict   spuriousErrorR   R   Rp   t   wfdrt   switchDeferredR  (    (   R  R  R  R   R  R  s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRj  3  s<    	

c         C   s   |  j  d t  S(   s   
        Verify that protocol-switching even works if the value returned from
        the command that does the switch is deferred.
        R  (   Rj  R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_protocolSwitchDeferredj  s    c            s   t  |  _ t j   } | |   t j   } | |    t d  f d   d   f d    \ } } } g  } | j d t  j | j  | j	   | j
   j t  |  j |  j  | j d  j | j  | j	   |  j | j
   d d  d S(	   s   
        Verify that if we try to switch protocols and it fails, the connection
        stays up and we can go back to speaking AMP.
        R   c              s     S(   N(    (    (   R  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   }  s    R   c              s     S(   N(    (    (   R  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   ~  s    R   R,   R$   N(   RP   R  R   R   R   R   RI   R  R   R   R  RJ  R1   R  R'   R   R  (   R   R  R  R  R   R   Rp   R  (    (   R  R  s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_protocolSwitchFailr  s    	

c         C   s   |  j  d t  S(   ss   
        Verify that attempts to send traffic after a switch will not corrupt
        the nested protocol.
        R  (   Rj  RI   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_trafficAfterSwitch  s    c         C   s   |  j  d t d t  S(   sh   
        Returning an error after a protocol switch should record the underlying
        error.
        R  R  (   Rj  RI   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_errorAfterSwitch  s    c         C   s   t  d t d t  \ } } } g  } d } d } | j |  j | j  | j   |  j | j   d |  | j t	  j | j  | j   |  j | j   d |  | j |  j
 | j  | j   j t j  d S(   st   
        Verify that commands with a responseType of QuitBox will in fact
        terminate the connection.
        R   R   R,   R   R$   RX   N(   R   R   R'   R   R   R   R   R  R   RW   R  RJ  R   RI  (   R   R   R   Rp   R  R  t   GOODBYE(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_quitBoxQuits  s    

c      
   C   s   t    \ } } } g  } | j | _ | j t d d d d d d d d | j   |  j t |  d	  xI d
 t j f d d d d g D]) \ } } |  j | d j	 |  |  q W| d j	 d  |  j | d i   d S(   s   
        Verify that the command dictionaries for a callRemoteN look correct
        after being serialized and parsed.
        R$   s
   hello testRB   s   mixed case arg testR   Ra   RC   t   yi   R   s   dash-argiR   N(   R$   s
   hello test(   RB   s   mixed case arg test(   s   dash-argRa   (   RC   R  (
   R   R   R   R   R>   R   R   R  RF   R  (   R   R   R   Rp   R  RU  R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_basicLiteralEmit  s    
!c            s   g    d t  j f   f d     Y} t d |  \ } } } | j t d d d d d d	 d
 d j   j  | j   |  j t	    d  |  j   d d t
 d d d d d d	 d
 d d d d d d d  f  |  j   d t
 d d d d   d S(   s   
        Verify that a call similar to basicLiteralEmit's is handled properly with
        high-level quoting and passing to Python methods, and that argument
        names are correctly handled.
        t   StructuredHelloc              s$   e  Z   f d    Z e j e  RS(   c            s      j  | | f  t d d  S(   NR$   t   aaa(   R   R   (   R   R   RU  (   R  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   h  s    (   R    R!   R  R>   R~   (    (   R  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   R   R$   s
   hello testRB   s   mixed case arg testR   Ra   RC   R  i   i    R   t   fileR   R?   i   R  N(    (   s   files   file(   R   R   R   R   R>   R   R   R   R   R  R   Rn   (   R   R  R   R   Rp   (    (   R  s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_basicStructuredEmit  s"    
	(+   R    R!   R  R  R  R  R  R  R  R  R  R  R  R  R  t   skipSSLt   skipR  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R   RP   Rj  R  R  R  R  R  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRx  `  sP   					
					
																				5						t!   PretendRemoteCertificateAuthorityc           B   s   e  Z d    Z RS(   c         C   s   t  S(   N(   RI   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   checkIsPretendRemote  s    (   R    R!   R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   t	   IOSimCertc           B   s    e  Z d  Z d   Z d   Z RS(   i    c         G   s   |  S(   N(    (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   options  s    c         C   s%   | |  k s t   |  j d 7_ t S(   s  
        This isn't a real certificate, and wouldn't work on a real socket, but
        iosim specifies a different API so that we don't have to do any crypto
        math to demonstrate that the right functions get called in the right
        places.
        i   (   R   t   verifyCountRI   (   R   t	   otherCert(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   iosimVerify  s    (   R    R!   R  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   	t   OKCertc           B   s   e  Z d    Z RS(   c         C   s   | j    s t  |  S(   N(   R  R   (   R   Ra   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s    (   R    R!   R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   t
   GrumpyCertc           B   s   e  Z d    Z RS(   c         C   s   |  j  d 7_  t S(   Ni   (   R  RP   (   R   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s    (   R    R!   R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   t
   DroppyCertc           B   s   e  Z d    Z d   Z RS(   c         C   s   | |  _  d  S(   N(   t   toDrop(   R   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   	  s    c         C   s    |  j  d 7_  |  j j   t S(   Ni   (   R  R  R  RI   (   R   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s    (   R    R!   R   R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   	t   SecurableProtoc           B   s0   e  Z d Z d    Z d   Z e j j e  RS(   c         C   s
   t    g S(   N(   R  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   verifyFactory  s    c         C   s+   |  j    } |  j   } t d | d |  S(   Nt   tls_localCertificatet   tls_verifyAuthorities(   t   certFactoryR  R   (   R   t   certt   verify(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt
   getTLSVars  s
    N(	   R    R!   Rn   Rm   R  R  R   t   StartTLSR~   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   		t   TLSTestc           B   s2   e  Z d    Z d   Z d   Z d   Z e Z RS(   c            s   t  d t d t  \ } } } t       f d   | _ | j t j d   d t   g g  } | j t  j	 | j
  | j   |  j   j d  g  } | j t  j	 | j
  | j   |  j | d i t d 6 d	 S(
   s   
        Verify that starting TLS and succeeding at handshaking sends all the
        notifications to all the right places.
        R   R   c              s     S(   N(    (    (   t   okc(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   -  s    R  R  i   i    Ri   N(   R   R  R  R  R   R   R  R  Rh   R   R   R   R   R  R  RI   (   R   t   clit   svrRp   R  (    (   R  s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_startingTLS#  s     	

c            s   t  d t d t  \ } } } t       f d   | _ | j t j d   d t   g | j   t	 | _
 |  j t j | j t j d   d t   g d S(   sz   
        Verify that the protocol will complain if we attempt to renegotiate TLS,
        which we don't support.
        R   R   c              s     S(   N(    (    (   R  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   I  s    R  R  N(   R   R  R  R  R   R   R  R  R   RI   t   noPeerCertificateR   t
   OnlyOneTLS(   R   R  R  Rp   (    (   R  s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_startTooManyTimes?  s     	
		c            s   t      t d t d t  \ } } }   f d   | _ | j t j d   | j   |  j   j	 d  | j t
  } | j   |  j | t j  d S(   s   
        Verify that starting TLS and failing on both sides at handshaking sends
        notifications to all the right places and terminates the connection.
        R   R   c              s     S(   N(    (    (   t   badCert(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   c  s    R  i   N(   R  R   R  R  R   R   R  R   R   R  Rh   t   assertFailureR   t   NativeOpenSSLError(   R   R  R  Rp   R4   (    (   R  s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_negotiationFailedX  s    	

c            s   t  d t d t  \ } } } t | j      f d   | _ | j t j d   | j   |  j	   j
 d  | j t  } | j   |  j | t j  d S(   s   
        Verify that starting TLS and failing by way of a lost connection
        notices that it is probably an SSL problem.
        R   R   c              s     S(   N(    (    (   t
   droppyCert(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   z  s    R  i   N(   R   R  R  R   R  R   R   R  R   R   R  Rh   R  R   t   PeerVerifyError(   R   R  R  Rp   R4   (    (   R  s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_negotiationFailedByClosingp  s    

(   R    R!   R  R  R  R  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR  "  s
   				t   TLSNotAvailableTestc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   sP   
    Tests what happened when ssl is not available in current installation.
    c         C   s   t  j |  _ d t  _ d S(   s%   
        Disable ssl in amp.
        N(   R   R   Rn   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s    c         C   s   |  j  t _  d S(   s%   
        Restore ssl module.
        N(   R   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   tearDown  s    c            sg   t  d t d t  \ } } } t       f d   | _ |  j | j t j d   d t   g t	  S(   sg   
        Check that callRemote raises an exception when called with a
        L{amp.StartTLS}.
        R   R   c              s     S(   N(    (    (   R  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s    R  R  (
   R   R  R  R  R  R   R   R  R  R   (   R   R  R  Rp   (    (   R  s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_callRemoteError  s    	c            s   t    } t       f d   | _ t j   } d | d <d | d <g  } | j | _ | j t    | j	 |  |  j
 | i d d 6d d 6d	 d
 6g  d S(   s|   
        When a client with SSL enabled talks to a server without SSL, it
        should return a meaningful error.
        c              s     S(   N(    (    (   R  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s    R  R   R  R   t	   TLS_ERRORt   _error_codet   _errors   TLS not availablet   _error_descriptionN(   R  R  R  R   R(   R   R   R7  R   R   R   (   R   R  R)   R   (    (   R  s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_messageReceivedError  s    		

	
(   R    R!   R"   R   R
  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR	    s
   			t   InheritedErrorc           B   s   e  Z d  Z RS(   s2   
    This error is used to check inheritance.
    (   R    R!   R"   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   t   OtherInheritedErrorc           B   s   e  Z d  Z RS(   s<   
    This is a distinct error for checking inheritance.
    (   R    R!   R"   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   t   BaseCommandc           B   s   e  Z d  Z i d e 6Z RS(   s:   
    This provides a command that will be subclassed.
    t   INHERITED_ERROR(   R    R!   R"   R  RM   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   t   InheritedCommandc           B   s   e  Z d  Z RS(   s`   
    This is a command which subclasses another command but does not override
    anything.
    (   R    R!   R"   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   t   AddErrorsCommandc           B   s0   e  Z d  Z d e j   f g Z i d e 6Z RS(   s]   
    This is a command which subclasses another command but adds errors to the
    list.
    t   othert   OTHER_INHERITED_ERROR(   R    R!   R"   R   RH   RK   R  RM   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   t   NormalCommandProtocolc           B   s$   e  Z d  Z d   Z e j e  RS(   s   
    This is a protocol which responds to L{BaseCommand}, and is used to test
    that inheritance does not interfere with the normal handling of errors.
    c         C   s   t     d  S(   N(   R  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   resp  s    (   R    R!   R"   R  R  R~   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   	t   InheritedCommandProtocolc           B   s$   e  Z d  Z d   Z e j e  RS(   s   
    This is a protocol which responds to L{InheritedCommand}, and is used to
    test that inherited commands inherit their bases' errors if they do not
    respond to any of their own.
    c         C   s   t     d  S(   N(   R  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s    (   R    R!   R"   R  R  R~   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   	t   AddedCommandProtocolc           B   s$   e  Z d  Z d   Z e j e  RS(   s   
    This is a protocol which responds to L{AddErrorsCommand}, and is used to
    test that inherited commands can add their own new types of errors, but
    still respond in the same way to their parents types of errors.
    c         C   s   | r t     n	 t    d  S(   N(   R  R  (   R   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s    (   R    R!   R"   R  R  R~   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   	t   CommandInheritanceTestsc           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   sM   
    These tests verify that commands inherit error conditions properly.
    c   
      K   sP   t  d | d |  \ } } } | j | |  } |  j | |  }	 | j   |	 S(   s~   
        Check that the appropriate kind of error is raised when a given command
        is sent to a given protocol.
        R   R   (   R   R   t   failUnlessFailureR   (
   R   R  R6   t   cmdR   R   R   Rp   R4   t   d2(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt
   errorCheck  s    
c         C   s   |  j  t t t  S(   sx   
        Verify that errors specified in a superclass are respected normally
        even if it has subclasses.
        (   R!  R  R  R  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_basicErrorPropagation)  s    c         C   s   |  j  t t t  S(   sp   
        Verify that errors specified in a superclass command are propagated to
        its subclasses.
        (   R!  R  R  R  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_inheritedErrorPropagation2  s    c         C   s   |  j  t t t d t S(   s   
        Verify that new errors specified in a subclass of an existing command
        are honored even if the superclass defines some errors.
        R  (   R!  R  R  R  RI   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_inheritedErrorAddition;  s    c         C   s   |  j  t t t d t S(   s   
        Verify that errors specified in a command's superclass are respected
        even if that command defines new errors itself.
        R  (   R!  R  R  R  RP   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_additionWithOriginalErrorD  s    (   R    R!   R"   R!  R"  R#  R$  R%  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s   							c         C   s-   |  j  t j t j  | ` | j |   d  S(   N(   RJ  R   t   ConnectionLostRI  R   (   R  R6   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   _loseAndPassM  s    t   LiveFireBasec           B   s    e  Z d  Z d   Z d   Z RS(   s4   
    Utility for connected reactor-using tests.
    c            s  d d l  m } t j     _   j   j _ t j     _   j   j _ t	 j
     j _ t	 j
     j _ | j d   j    _   j   j j  | j d   j j   j   j    _   j   j j    f d   } t	 j   j j   j j g  } | j |  S(   sB   
        Create an amp server and connect a client to it.
        i(   R	   i    s	   127.0.0.1c            s"     j  j   _   j j   _ d  S(   N(   t   clientFactoryRx   R  t   serverFactoryR  (   t   rlst(   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt	   getProtosj  s    (   t   twisted.internetR	   R   t   ServerFactoryR*  R  t   ClientFactoryR)  R  R   R   Rw   t	   listenTCPt
   serverPortR  t   stopListeningt
   connectTCPR5  t   portt
   clientConnt
   disconnectR  R   (   R   R	   R,  t   dl(    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   Y  s"    c         C   s   g  } xj |  j  |  j f D]V } | j d k	 r t j   j t |  } | j | _	 | j j
   | j |  q q Wt j |  j d    S(   sn   
        Cleanup client and server connections, and check the error got at
        C{connectionLost}.
        c         S   s
   |  j  j S(   N(   R   t
   subFailure(   t   first(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s    N(   R  R  R   Rn   R   R   R  R'  R  R   R  R   t   gatherResults(   R   R  t   connR4   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR
  q  s    (   R    R!   R"   R   R
  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR(  T  s   	c         C   s1   d d  l  } | j j |  d  | j j   d  S(   Nis   
(   t   syst   stdoutR   R   (   Ra   R<  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   show  s    c          C   sn   d d l  m }  |  j d d  } |  j j   } | j |  } | j | | d   d  } | j |  } | S(   Ni(   R   t   CNt   sharedc         S   s   t  S(   N(   RI   (   t   dn(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s    i (   R-  R   t   DNt   KeyPairt   generatet   certificateRequestt   signCertificateRequestt   newCertificate(   R   t   sharedDNR   t   crt   sscrdR  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   tempSelfSigned  s    t   LiveFireTLSTestCasec           B   s#   e  Z e Z e Z d    Z e Z RS(   c            sm   t    f d     j _  f d     j _    f d   }   j j t j d  d  g j |  S(   sH  
        Using real, live TLS, actually negotiate a connection.

        This also looks at the 'peerCertificate' attribute's correctness, since
        that's actually loaded using OpenSSL calls, but the main purpose is to
        make sure that we didn't miss anything obvious in iosim about TLS
        negotiations.
        c              s     g S(   N(    (    (   R  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s    c              s     S(   N(    (    (   R  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR     s    c            s7    j         f d   }  j j t  j |  S(   Nc            st    j     j j j     j     j j j     j     j j j     j     j j j    d  S(   N(   t   failUnlessEqualR  t   hostCertificatet   digestt   peerCertificateR  (   t   rslt2(   Ra   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRi     s    (   RO  R  R   Rh   R   (   t   rsltRi   (   R   R  (   Ra   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   secured  s    	R  R  (	   t   tempcertR  R  R  R  R   R   R  R   (   R   RS  (    (   R   R  s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_liveFireCustomTLS  s    
(   R    R!   R  R  R  RU  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRL    s   	 t   SlightlySmartTLSc           B   s'   e  Z d  Z d   Z e j j e  RS(   s_   
    Specific implementation of server side protocol with different
    management of TLS.
    c         C   s   t  d t  S(   sS   
        @return: the global C{tempcert} certificate as local certificate.
        R  (   R   RT  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR    s    (   R    R!   R"   R  R   R  R~   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRV    s   	t   PlainVanillaLiveFirec           B   s#   e  Z e Z e Z d    Z e Z RS(   c            s+     f d   }   j  j t j  j |  S(   s   
        Verify that out of the box, we can start TLS to at least encrypt the
        connection, even if we don't have any certificates to use.
        c            s     j  j t  S(   N(   R  R   Rh   (   R   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRS    s    (   R  R   R   R  R   (   R   RS  (    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_liveFireDefaultTLS  s    (   R    R!   R   R  R  RX  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRW    s   		t   WithServerTLSVerificationc           B   s#   e  Z e Z e Z d    Z e Z RS(   c            s4     f d   }   j  j t j d t g j |  S(   sO   
        Verify that anonymous clients can verify server certificates.
        c            s     j  j t  S(   N(   R  R   Rh   (   R   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRS    s    R  (   R  R   R   R  RT  R   (   R   RS  (    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_anonymousVerifyingClient  s    (	   R    R!   R   R  RV  R  RZ  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRY    s   	
t   ProtocolIncludingArgumentc           B   s    e  Z d  Z d   Z d   Z RS(   s   
    An L{amp.Argument} which encodes its parser and serializer
    arguments *including the protocol* into its parsed and serialized
    forms.
    c         C   s
   | | f S(   s   
        Don't decode anything; just return all possible information.

        @return: A two-tuple of the input string and the protocol.
        (    (   R   t   stringR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR:     s    c         C   s   d t  |  t  |  f S(   s   
        Encode identifying information about L{object} and protocol
        into a string for later verification.

        @type obj: L{object}
        @type protocol: L{amp.AMP}
        s   %s:%s(   R  (   R   R  R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   toStringProto  s    (   R    R!   R"   R:   R]  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR[    s   	t   ProtocolIncludingCommandc           B   s2   e  Z d  Z d e   f g Z d e   f g Z RS(   sf   
    A command that has argument and response schemas which use
    L{ProtocolIncludingArgument}.
    t   weird(   R    R!   R"   R[  RK   RL   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR^  
	  s   t   MagicSchemaCommandc           B   sM   e  Z d  Z d   Z e e  Z d   Z e e  Z d   Z e e  Z RS(   sa   
    A command which overrides L{parseResponse}, L{parseArguments}, and
    L{makeResponse}.
    c         C   s   | | f | _  | S(   s   
        Don't do any parsing, just jam the input strings and protocol
        onto the C{protocol.parseResponseArguments} attribute as a
        two-tuple. Return the original strings.
        (   t   parseResponseArguments(   R   R;   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   parseResponse	  s    c         C   s   | | f | _  | S(   s   
        Don't do any parsing, just jam the input strings and protocol
        onto the C{protocol.parseArgumentsArguments} attribute as a
        two-tuple. Return the original strings.
        (   t   parseArgumentsArguments(   t   clsR;   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   parseArguments$	  s    c         C   s   | | f | _  | S(   s   
        Don't do any serializing, just jam the input strings and protocol
        onto the C{protocol.makeArgumentsArguments} attribute as a
        two-tuple. Return the original strings.
        (   t   makeArgumentsArguments(   Rd  R<   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   makeArguments/	  s    (   R    R!   R"   Rb  t   classmethodRe  Rg  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR`  	  s   			t   NoNetworkProtocolc           B   s'   e  Z d  Z d   Z e j d    RS(   s  
    An L{amp.AMP} subclass which overrides private methods to avoid
    testing the network. It also provides a responder for
    L{MagicSchemaCommand} that does nothing, so that tests can test
    aspects of the interaction of L{amp.Command}s and L{amp.AMP}.

    @ivar parseArgumentsArguments: Arguments that have been passed to any
    L{MagicSchemaCommand}, if L{MagicSchemaCommand} has been handled by
    this protocol.

    @ivar parseResponseArguments: Responses that have been returned from a
    L{MagicSchemaCommand}, if L{MagicSchemaCommand} has been handled by
    this protocol.

    @ivar makeArgumentsArguments: Arguments that have been serialized by any
    L{MagicSchemaCommand}, if L{MagicSchemaCommand} has been handled by
    this protocol.
    c         C   s   t  j |  S(   sJ   
        Return a Deferred which fires with the original strings.
        (   R   t   succeed(   R   RF   R;   RQ   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   _sendBoxCommandN	  s    c         C   s   i  S(   N(    (   R   R_  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   T	  s    (   R    R!   R"   Rk  R`  R~   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRi  ;	  s   	t   MyBoxc           B   s   e  Z d  Z RS(   s!   
    A unique dict subclass.
    (   R    R!   R"   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRl  X	  s   t0   ProtocolIncludingCommandWithDifferentCommandTypec           B   s   e  Z d  Z e Z RS(   sN   
    A L{ProtocolIncludingCommand} subclass whose commandType is L{MyBox}
    (   R    R!   R"   Rl  t   commandType(    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRm  _	  s   t   CommandTestCasec           B   sh   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z RS(   s7   
    Tests for L{amp.Argument} and L{amp.Command}.
    c         C   s#   |  j  t t j t j     d S(   sE   
        L{Argument} instances provide L{amp.IArgumentType}.
        N(   RA  R    R   t   IArgumentTypet   Argument(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_argumentInterfacel	  s    c         C   sI   t    } d } i | d 6} |  j t j | |  i | | f d 6 d S(   s   
        There should be a class method of Command which accepts a
        mapping of argument names to serialized forms and returns a
        similar mapping whose values have been parsed via the
        Command's response schema.
        t   whateverR_  N(   R  R  R^  Rb  (   R   R   R   R;   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_parseResponses	  s    	c            sJ   t     d    j t d   }     f d   } | j |  | S(   s   
        Making a remote call on a L{amp.Command} subclass which
        overrides the C{parseResponse} method should call that
        C{parseResponse} method to get the response.
        t   weeooR_  c            s$     j   j i  d 6 f  d  S(   NR_  (   R   Ra  (   R   (   R   t   clientt   thingy(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   gotResponse	  s    (   Ri  R   R`  R   (   R   RL   Rx  (    (   Rw  R   Rv  s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt!   test_callRemoteCallsParseResponse	  s    	c         C   sI   t    } d } i | d 6} |  j t j | |  i | | f d 6 d S(   s   
        There should be a class method of L{amp.Command} which accepts
        a mapping of argument names to serialized forms and returns a
        similar mapping whose values have been parsed via the
        command's argument schema.
        Rs  R_  N(   R  R  R^  Re  (   R   R   R   R;   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_parseArguments	  s    	c            sY   t        j t j  } t    | t d    } | j     f d    | S(   s   
        Making a remote call on a L{amp.Command} subclass which
        overrides the C{parseArguments} method should call that
        C{parseArguments} method to get the arguments.
        R_  c            s      j   j i  d 6 f  S(   NR_  (   R  Rc  (   R   (   R   R   t   argument(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR   	  s   (   Ri  R   R`  RF   R  R   R   (   R   R~   RL   (    (   R   R   R{  s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt!   test_responderCallsParseArguments	  s    		c         C   s\   t    } t    } i | d 6} |  j t j | |  i d t |  t |  f d 6 d S(   s   
        There should be a class method of L{amp.Command} which accepts
        a mapping of argument names to objects and returns a similar
        mapping whose values have been serialized via the command's
        argument schema.
        R_  s   %d:%dN(   R  R  R^  Rg  R  (   R   R   R{  R<   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_makeArguments	  s    		c         C   sB   t    } i d d 6} t j | |  } |  j t |  t  d S(   s   
        L{amp.Command.makeArguments}'s return type should be the type
        of the result of L{amp.Command.commandType}.
        Rs  R_  N(   R  Rm  Rg  R8  R   Rl  (   R   R   R<   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt!   test_makeArgumentsUsesCommandType	  s
    	c            sM   t     t     j t d  }     f d   } | j |  | S(   s   
        Making a remote call on a L{amp.Command} subclass which
        overrides the C{makeArguments} method should call that
        C{makeArguments} method to get the response.
        R_  c            s$     j   j i  d 6 f  d  S(   NR_  (   R  Rf  (   R   (   R   Rv  R{  (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRx  	  s    (   Ri  R  R   R`  R   (   R   RL   Rx  (    (   R   R{  Rv  s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt!   test_callRemoteCallsMakeArguments	  s    		c         C   s2   |  j  t j t j t d d d t    d  d S(   s   
        L{Command.makeArguments} raises L{amp.InvalidSignature} if the objects
        dictionary passed to it includes a key which does not correspond to the
        Python identifier for a defined argument.
        R$   t   bogusArgumentN(   R   R   R  R>   Rg  R   R  Rn   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_extraArgumentsDisallowed	  s    c      	   C   s3   |  j  t j t j t d d i d d 6 d  d S(   s  
        If a command argument conflicts with a Python keyword, the
        untransformed argument name is not allowed as a key in the dictionary
        passed to L{Command.makeArguments}.  If it is supplied,
        L{amp.InvalidSignature} is raised.

        This may be a pointless implementation restriction which may be lifted.
        The current behavior is tested to verify that such arguments are not
        silently dropped on the floor (the previous behavior).
        R$   t   requireds   print valueR@   N(   R   R   R  R>   Rg  R   Rn   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_wireSpellingDisallowed	  s
    (   R    R!   R"   Rr  Rt  Ry  Rz  R|  R}  R~  R  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRo  h	  s   									t   ListOfTestsMixinc           B   s    e  Z d  Z d   Z d   Z RS(   s  
    Base class for testing L{ListOf}, a parameterized zero-or-more argument
    type.

    @ivar elementType: Subclasses should set this to an L{Argument}
        instance.  The tests will make a L{ListOf} using this.

    @ivar strings: Subclasses should set this to a dictionary mapping some
        number of keys to the correct serialized form for some example
        values.  These should agree with what L{elementType}
        produces/accepts.

    @ivar objects: Subclasses should set this to a dictionary with the same
        keys as C{strings} and with values which are the lists which should
        serialize to the values in the C{strings} dictionary.
    c         C   sh   t  j |  j  } t  j   } x0 |  j D]% } | j | | |  j j   d  q( W|  j | |  j	  d S(   s  
        L{ListOf.toBox} extracts the list of objects from the C{objects}
        dictionary passed to it, using the C{name} key also passed to it,
        serializes each of the elements in that list using the L{Argument}
        instance previously passed to its initializer, combines the serialized
        results, and inserts the result into the C{strings} dictionary using
        the same C{name} key.
        N(
   R   t   ListOft   elementTypeR   R<   R=   t   copyRn   R   R;   (   R   t
   stringListR;   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt
   test_toBox
  s
    	#c         C   sb   t  j |  j  } i  } x0 |  j D]% } | j | |  j j   | d  q" W|  j | |  j  d S(   sX   
        L{ListOf.fromBox} reverses the operation performed by L{ListOf.toBox}.
        N(	   R   R  R  R;   t   fromBoxR  Rn   R   R<   (   R   R  R<   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_fromBox
  s
    #(   R    R!   R"   R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR  	  s   	t   ListOfStringsTestsc           B   s\   e  Z d  Z e j   Z i d d 6d d 6d d 6Z i g  d 6d g d 6d d	 d
 g d 6Z RS(   s:   
    Tests for L{ListOf} combined with L{amp.String}.
    R3   t   emptyt    foot   singlet    bar baz quuxt   multipleR<  R;  t   bazt   quux(   R    R!   R"   R   RG   R  R;   R<   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR  (
  s   

t   ListOfIntegersTestsc           B   s   e  Z d  Z e j   Z d Z i d d 6d d 6d d 6d e f d	 6d
 d 6Z i g  d 6d g d 6d d d g d 6e g d	 6d g d 6Z RS(   s;   
    Tests for L{ListOf} combined with L{amp.Integer}.
    l   ]OSt7s
Xg&}R3   R  t    10R  t    1 20 500R  t    t%dt   huget    -1t   negativei
   i   i   i  il         @[D`Y[[V{!Zyz_dr~saFo$wo536(	   R    R!   R"   R   Rb   R  R  R;   R<   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR  9
  s     


t   ListOfUnicodeTestsc           B   s\   e  Z d  Z e j   Z i d d 6d d 6d d 6Z i g  d 6d g d 6d d	 d
 g d 6Z RS(   s;   
    Tests for L{ListOf} combined with L{amp.Unicode}.
    R3   R  R  R  t    ☃ Hello worldR  u   foou   ☃u   Hellou   world(   R    R!   R"   R   RJ   R  R;   R<   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR  S
  s   

t   ListOfDecimalTestsc           B   s  e  Z d  Z e j   Z i d d 6d d 6d d 6d d 6d	 e j d
  j   e j d  j   f d 6Z i g  d 6e j d  g d 6e j d  e j d  g d 6e j d  e j d  e j d  e j d  e j d  e j d  g d 6e j d
  e j d  g d 6Z	 RS(   s;   
    Tests for L{ListOf} combined with L{amp.Decimal}.
    R3   R  t    1.1R  t    Infinity 	-Infinityt   extremetC    3.141E+5 
0.00003141 3.141E-7 	-3.141E+5 -0.00003141 	-3.141E-7t	   scientistt    %s %st   0e6s   1.5E-9t   engineers   1.1t   Infinitys	   -Infinitys   3.141E5s   3.141e-5s   3.141E-7s   -3.141e5s	   -3.141E-5s	   -3.141e-7(
   R    R!   R"   R   t   DecimalR  t   decimalt   to_eng_stringR;   R<   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR  e
  s.   t   ListOfDecimalNanTestsc           B   sm   e  Z d  Z e j   Z i d d 6Z i e j d  e j d  e j d  e j d  g d 6Z d   Z	 RS(   sS   
    Tests for L{ListOf} combined with L{amp.Decimal} for not-a-number values.
    t    NaN -NaN sNaN -sNaNt   nant   NaNs   -NaNt   sNaNs   -sNaNc         C   s  d   } d   } d   } t  j |  j  } i  } x0 |  j D]% } | j | |  j j   | d	  q= W| d } |  j | | d  o | | d   |  j | | d  o | | d   |  j | | d  o | | d   |  j | | d  o
| | d   d	 S(
   sX   
        L{ListOf.fromBox} reverses the operation performed by L{ListOf.toBox}.
        c         S   s"   d t  |   k o! d t  |   k S(   NR  R  (   R   (   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   is_qnan
  s    c         S   s   d t  |   k S(   NR  (   R   (   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   is_snan
  s    c         S   s   d t  |   k S(   Nt   -(   R   (   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt	   is_signed
  s    R  i    i   i   i   N(   R   R  R  R;   R  R  Rn   RA  (   R   R  R  R  R  R<   R   t   n(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR  
  s    			#
('((
   R    R!   R"   R   R  R  R;   R  R<   R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR  
  s   
t   DecimalTestsc           B   s   e  Z d  Z d   Z RS(   s#   
    Tests for L{amp.Decimal}.
    c         C   sR   t  j   } |  j t | j d  |  j t | j d  |  j t | j d  d S(   s   
        L{amp.Decimal.toString} raises L{ValueError} if passed an object which
        is not an instance of C{decimal.Decimal}.
        s   1.234gX9v?i  N(   R   R  R   t
   ValueErrorR   (   R   R{  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_nonDecimal
  s    (   R    R!   R"   R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR  
  s   t   ListOfDateTimeTestsc           B   s  e  Z d  Z e j   Z i d d 6d d 6d d 6d d 6d	 d
 6Z i e j d d d d d d d e j e j d d d d d d d e j	 d d d  g d 6e j d d d d d d d e j	 d d d  g d 6e j d d d d d d d e j	 d d d  g d 6e j d d d d d d d e j	 d d d  g d 6e j d d d d d d d e j	 d d d  e j d d d d d d d e j	 d d d  g d
 6Z
 RS(   s<   
    Tests for L{ListOf} combined with L{amp.DateTime}.
    tD     2010-12-25T00:00:00.000000-00:00  2010-12-25T00:00:00.000000-00:00t	   christmast"     2010-12-25T00:00:00.000000+01:00s   christmas in eut"     2010-12-25T00:00:00.000000+03:30s   christmas in irant"     2010-12-25T00:00:00.000000-05:00s   christmas in nyctD     2010-12-25T00:00:00.000000+03:19  2010-12-25T00:00:00.000000-06:59s   previous testsi  i   i   i    t   tzinfot   +i   i   i   R  i   i   i   i;   (   R    R!   R"   R   t   DateTimeR  R;   t   datetimet   utct   _FixedOffsetTZInfoR<   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR  
  s,   
$t   ListOfOptionalTestsc           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   so   
    Tests to ensure L{ListOf} AMP arguments can be omitted from AMP commands
    via the 'optional' flag.
    c         C   sE   t  j t  j    } |  j t | j d t  j   i d d 6d  d S(   sn   
        L{ListOf.toBox} raises C{TypeError} when passed a value of C{None}
        for the argument.
        t   omittedN(   R   R  Rb   R   R   R=   R   Rn   (   R   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt1   test_requiredArgumentWithNoneValueRaisesTypeError  s    c         C   sX   t  j t  j   d t } t  j   } | j d | i d d 6d  |  j | i   d S(   s   
        L{ListOf.toBox} silently omits serializing any argument with a
        value of C{None} that is designated as optional for the protocol.
        R?   R  N(   R   R  Rb   RI   R   R=   Rn   R   (   R   R  R;   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt)   test_optionalArgumentWithNoneValueOmitted  s    c         C   sE   t  j t  j    } |  j t | j d t  j   i d d 6d  d S(   s|   
        L{ListOf.toBox} raises C{KeyError} if the argument's key is not
        present in the objects dictionary.
        t   ommitedi    t   someOtherKeyN(   R   R  Rb   R   t   KeyErrorR=   R   Rn   (   R   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt1   test_requiredArgumentWithKeyMissingRaisesKeyError  s    c         C   sB   t  j t  j   d t } | j d t  j   i d d 6d  d S(   s   
        L{ListOf.toBox} silently omits serializing any argument designated
        as optional whose key is not present in the objects dictionary.
        R?   R  i    R  N(   R   R  Rb   RI   R=   R   Rn   (   R   R  (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt*   test_optionalArgumentWithKeyMissingOmitted%  s    c         C   sR   t  j t  j   d t } i  } | j d i  | d  |  j | i d d 6 d S(   s   
        L{ListOf.fromBox} correctly reverses the operation performed by
        L{ListOf.toBox} for optional arguments.
        R?   R  N(   R   R  Rb   RI   R  Rn   R   (   R   R  R<   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt.   test_omittedOptionalArgumentDeserializesAsNone.  s    (   R    R!   R"   R  R  R  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR  
  s   					t   DateTimeTestsc        	   B   sq   e  Z d  Z d Z e j d d d  Z e j d d d d d d d	 e  Z d
   Z	 d   Z
 d   Z d   Z RS(   sO   
    Tests for L{amp.DateTime}, L{amp._FixedOffsetTZInfo}, and L{amp.utc}.
    s    9876-01-23T12:34:56.054321-01:23R  i   i   i&  i   i"   i8   i1  c         C   s&   t  j   } |  j t | j d  d S(   s   
        L{amp.DateTime.fromString} raises L{ValueError} when passed a string
        which does not represent a timestamp in the proper format.
        t   abcN(   R   R  R   R  R   (   R   R4   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_invalidStringB  s    c      
   C   s>   t  j   } |  j t | j t j d d d d d d   d S(   s   
        L{amp.DateTime.toString} raises L{ValueError} when passed a naive
        datetime (a datetime with no timezone information).
        i  i   i   i    N(   R   R  R   R  R   R  (   R   R4   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_invalidDatetimeK  s    c         C   s5   t  j   } | j |  j  } |  j | |  j  d S(   s   
        L{amp.DateTime.fromString} returns a C{datetime.datetime} with all of
        its fields populated from the string passed to it.
        N(   R   R  R   R\  R   R  (   R   R{  R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_fromStringU  s    c         C   s5   t  j   } | j |  j  } |  j | |  j  d S(   s   
        L{amp.DateTime.toString} returns a C{str} in the wire format including
        all of the information from the C{datetime.datetime} passed into it,
        including the timezone offset.
        N(   R   R  R   R  R   R\  (   R   R{  R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_toString_  s    (   R    R!   R"   R\  R   R  R  R  R  R  R  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR  :  s   $			
	
t   FixedOffsetTZInfoTestsc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s=   
    Tests for L{amp._FixedOffsetTZInfo} and L{amp.utc}.
    c         C   s    |  j  t j j d  d  d S(   s8   
        L{amp.utc.tzname} returns C{"+00:00"}.
        s   +00:00N(   R   R   R  t   tznameRn   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_tznamep  s    c         C   s)   |  j  t j j d  t j d   d S(   s:   
        L{amp.utc.dst} returns a zero timedelta.
        i    N(   R   R   R  t   dstRn   R  t	   timedelta(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_dstw  s    c         C   s)   |  j  t j j d  t j d   d S(   s@   
        L{amp.utc.utcoffset} returns a zero timedelta.
        i    N(   R   R   R  t	   utcoffsetRn   R  R  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_utcoffset~  s    c         C   s    |  j  t t j d d d  d S(   s~   
        L{amp._FixedOffsetTZInfo} raises L{ValueError} if passed an offset sign
        other than C{'+'} or C{'-'}.
        t   ?i    N(   R   R  R   R  (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   test_badSign  s    (   R    R!   R"   R  R  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR  k  s
   			s2   This test case requires SSL support in the reactor(   R"   R  R  t   zope.interface.verifyR    t   twisted.python.utilR   t   twisted.pythonR   t   twisted.python.failureR   t   twisted.protocolsR   t   twisted.trialR   R-  R   R   R   R	   R
   t   twisted.testR   t   twisted.test.proto_helpersR   Rn   R   t   ImportErrort	   supportedR  Rq  R   R   R#   t	   ExceptionR/   R0   R1   Rq  R2   t   CommandR>   RO   RR   RT   RU   RW   RZ   R[   R]   Rd   Rh   t   ProtocolSwitchCommandRj   R/  Rl   R   Ru   Rv   R   R   R   R   R   R   R   t   TestCaseR   R   R  R   R   R   R  R|  R  R  R  R  R  R   R   R1  Rx  R  R  R  R  R  R  R  R	  R  R  R  R  R  R  R  R  R  R'  R(  R>  RK  RT  RL  RV  RW  RY  R[  R^  R`  Ri  R   Rl  Rm  Ro  R  R  R  R  R  R  R  R  R  R  R  t   IReactorSSLR|   t   skipMsgR  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt   <module>   s   (		-L	
I)_Y @  	k<
6	.		'
'-,1-;1#			