
=Nc           @   s   d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m	 Z	 m
 Z
 d d l m Z d d l m Z d d l m Z m Z m Z m Z d d l m Z m Z m Z d d	 l m Z d d
 l m Z m Z m Z d d l m Z d d l  m! Z! d d l" m# Z# m$ Z$ d d l% m& Z& m' Z' d d l( m) Z) m* Z* m+ Z+ d e j, f d     YZ- d e j. f d     YZ/ d e0 f d     YZ1 d f  d     YZ2 e3 d  Z4 d e j5 f d     YZ6 d e j5 f d     YZ7 d e j8 f d     YZ9 d e j: f d      YZ; e j< e9 e;  d! e j8 f d"     YZ= d#   Z> e j? e= e>  d$ e j5 f d%     YZ@ d& e jA f d'     YZB d( e j5 f d)     YZC d* e jA f d+     YZD d, e jE f d-     YZF e j< eD eF  d. e jE f d/     YZG e j< eB eG  d0 e j5 f d1     YZH d2 e j5 f d3     YZI d4 e j5 f d5     YZJ d6 e j5 f d7     YZK d8 e j8 e j: e0 f d9     YZL e j< eL eL  d: e j8 e j: e0 f d;     YZM e j< eM eM  d< e jA e jE e0 f d=     YZN e j< eN eN  d> e jO f d?     YZP d@ e jO f dA     YZQ dB e jR f dC     YZS dD e jT f dE     YZU dF e jR f dG     YZV dH e jR f dI     YZW dJ dK ZX e3 aY e3 aZ dL   Z[ dM e j5 f dN     YZ\ dO e j5 f dP     YZ] dQ e jR f dR     YZ^ dS e j_ f dT     YZ` dU e ja f dV     YZb dW e j5 f dX     YZc e j< e` eb  dY e jR f dZ     YZd d[ ee f d\     YZf d] e j8 f d^     YZg d_ e j5 f d`     YZh da e ji f db     YZj dc e j. f dd     YZk de e0 f df     YZl dg e j, f dh     YZm di el f dj     YZn dk e jR f dl     YZo dm e jR f dn     YZp do f  dp     YZq dq e jR f dr     YZr ds e
 f dt     YZs du f  dv     YZt dw e jR f dx     YZu dy e jR f dz     YZv d{ e jR f d|     YZw d S(}   s   
Tests for Perspective Broker module.

TODO: update protocol level tests to use new connection API, leaving
only specific tests for old API.
iN(   t   StringIO(   t
   implementst	   Interface(   t   Version(   t   unittest(   t   pbt   utilt   publisht   jelly(   t   protocolt   maint   reactor(   t   ConnectionRefusedError(   t   Deferredt   gatherResultst   succeed(   t   WrappingFactory(   t   loopback(   t   failuret   log(   t   UnauthorizedLogint   UnhandledCredentials(   t   portalt   checkerst   credentialst   Dummyc           B   s   e  Z d    Z RS(   c         C   s   t  | t  r d Sd Sd  S(   Ns   hello world!s   goodbye, cruel world!(   t
   isinstancet   DummyPerspective(   t   selft   user(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   view_doNothing!   s    (   t   __name__t
   __module__R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR       s   R   c           B   s   e  Z d  Z d   Z RS(   sE   
    An L{IPerspective} avatar which will be used in some tests.
    c         C   s   t    S(   N(   R   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   perspective_getDummyViewPoint,   s    (   R   R    t   __doc__R!   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR   (   s   t
   DummyRealmc           B   s   e  Z e e j  d    Z RS(   c         G   s:   x3 | D]+ } | t  j k r | t |  d   f Sq Wd  S(   Nc           S   s   d  S(   N(   t   None(    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   <lambda>7   s    (   R   t   IPerspectiveR   (   R   t   avatarIdt   mindt
   interfacest   iface(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   requestAvatar4   s    (   R   R    R   R   t   IRealmR+   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR#   1   s   t   IOPumpc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s   
    Utility to pump data between clients and servers for protocol testing.

    Perhaps this is a utility worthy of being in protocol.py?
    c         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   t   clientt   servert   clientIOt   serverIO(   R   R.   R/   R0   R1   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   __init__@   s    			c         C   sP   t  |  _ t j   d } x0 |  j rK |  j   rK t j   | k r d Sq Wd S(   s   
        Pump until there is no more input or output or until L{stop} is called.
        This does not run any timers, so don't use it with any code that calls
        reactor.callLater.
        i   N(   t   Falset   _stopt   timet   pump(   R   t   timeout(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   flushG   s
    	c         C   s   t  |  _ d S(   sd   
        Stop a running L{flush} operation, even if data remains to be
        transferred.
        N(   t   TrueR4   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   stopU   s    c         C   s   |  j  j d  |  j j d  |  j  j   } |  j j   } |  j  j d  |  j j d  |  j  j   |  j j   |  j j j   |  j j j   x | D] } |  j j	 |  q Wx | D] } |  j j	 |  q W| s | r d Sd Sd S(   sX   
        Move data back and forth.

        Returns whether any data was moved.
        i    i   N(
   R0   t   seekR1   t   readt   truncateR.   t	   transportt   _checkProducerR/   t   dataReceived(   R   t   cDatat   sDatat   byte(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR6   ]   s"    (   R   R    R"   R2   R8   R:   R6   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR-   :   s
   			c         C   s   |  p t    }  t j   } t j d d  } t j t j |  | g   } | j d  } t	   } t	   } | j
 t j |   | j
 t j |   t | | | |  } | j   | | | f S(   s   
    Connect a client and server L{Broker} together with an L{IOPump}

    @param realm: realm to use, defaulting to a L{DummyRealm}

    @returns: a 3-tuple (client, server, pump).
    t   guests	   127.0.0.1(   s	   127.0.0.1(   R#   R   t   BrokerR   t'   InMemoryUsernamePasswordDatabaseDontUset   PBServerFactoryR   t   Portalt   buildProtocolR    t   makeConnectionR	   t   FileWrapperR-   R8   (   t   realmt   clientBrokert   checkert   factoryt   serverBrokert   clientTransportt   serverTransportR6   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   connectedServerAndClientx   s    		
t   SimpleRemotec           B   s   e  Z d    Z d   Z RS(   c         C   s   | |  _  | d S(   Ni   (   t   arg(   R   RU   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   remote_thunk   s    	c         C   s   t     d  S(   N(   t	   Exception(   R   RU   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   remote_knuth   s    (   R   R    RV   RX   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyRT      s   	t   NestedRemotec           B   s   e  Z d    Z RS(   c         C   s   t    S(   N(   RT   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   remote_getSimple   s    (   R   R    RZ   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyRY      s   t
   SimpleCopyc           B   s   e  Z d    Z RS(   c         C   s)   d |  _  i d d 6|  _ d g |  _ d  S(   Ni   t   Worldt   Hellot   test(   t   xt   yt   z(   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR2      s    	(   R   R    R2   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR[      s   t   SimpleLocalCopyc           B   s   e  Z RS(    (   R   R    (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyRb      s   t   SimpleFactoryCopyc           B   s   e  Z d  Z i  Z d   Z RS(   s]   
    @cvar allIDs: hold every created instances of this class.
    @type allIDs: C{dict}
    c         C   s   | |  _  |  t j | <d  S(   N(   t   idRc   t   allIDs(   R   Rd   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR2      s    	(   R   R    R"   Re   R2   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyRc      s   c         C   s   |  j  d d  } | d k r: t d t |   f   n  | t j k rb t d t j f   n  t j | } | s t d   n  | S(   sl   
    Factory of L{SimpleFactoryCopy}, getting a created instance given the
    C{id} found in C{state}.
    Rd   s(   factory copy state has no 'id' member %ss   factory class has no ID: %ss&   factory method found no object with idN(   t   getR$   t   RuntimeErrort   reprRc   Re   (   t   statet   stateIdt   inst(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   createFactoryCopy   s    t
   NestedCopyc           B   s   e  Z d    Z d   Z RS(   c         C   s   t    S(   N(   R[   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   remote_getCopy   s    c         C   s
   t  |  S(   N(   Rc   (   R   t   value(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   remote_getFactory   s    (   R   R    Rn   Rp   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyRm      s   	t   SimpleCachec           B   s   e  Z d    Z RS(   c         C   s)   d |  _  i d d 6|  _ d g |  _ d  S(   Ni   R\   R]   R^   (   R_   R`   Ra   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt	   __init___   s    	(   R   R    Rr   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyRq      s   t   NestedComplicatedCachec           B   s   e  Z d    Z d   Z RS(   c         C   s   t    |  _ d  S(   N(   t   VeryVeryComplicatedCacheablet   c(   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR2      s    c         C   s   |  j  S(   N(   Ru   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   remote_getCache   s    (   R   R    R2   Rv   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyRs      s   	Rt   c           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s   d |  _  d |  _ d |  _ d  S(   Ni   i   i   (   R_   R`   t   foo(   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR2      s    		c         C   s    d |  _  |  j j d d  d  S(   Ni   Rw   (   Rw   t   observert
   callRemote(   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   setFoo4   s    	c         C   s+   | |  _  i |  j d 6|  j d 6|  j d 6S(   NR_   R`   Rw   (   Rx   R_   R`   Rw   (   R   t   perspectiveRx   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   getStateToCacheAndObserveFor   s    	
c         C   s9   t  j d  | j d  | |  j k r5 d  |  _ n  d  S(   Ns   stopped observingt   end(   R   t   msgRy   Rx   R$   (   R   R{   Rx   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   stoppedObserving   s    (   R   R    R2   Rz   R|   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyRt      s   			t   RatherBaroqueCachec           B   s   e  Z d    Z d   Z RS(   c         C   s   | |  _  d  S(   N(   Rw   (   R   t   newFoo(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   observe_foo   s    c         C   s   t  j d  d  S(   Ns   the end of things(   R   R~   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   observe_end   s    (   R   R    R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR      s   	t   SimpleLocalCachec           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s   |  j  j |  d  S(   N(   t   __dict__t   update(   R   Ri   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   setCopyableState  s    c         C   s   |  j  S(   N(   t   check(   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   checkMethod  s    c         C   s   |  S(   N(    (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt	   checkSelf
  s    c         C   s   d S(   Ni   (    (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR     s    (   R   R    R   R   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR     s   			t   NestedCachec           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   t    |  _ d  S(   N(   Rq   R_   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR2     s    c         C   s   |  j  |  j  g S(   N(   R_   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyRv     s    c         C   s   |  j  | k S(   N(   R_   (   R   t   cache(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   remote_putCache  s    (   R   R    R2   Rv   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR     s   		t
   Observablec           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s   g  |  _  d  S(   N(   t	   observers(   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR2     s    c         C   s   |  j  j |  d  S(   N(   R   t   append(   R   t   obs(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   remote_observe"  s    c         C   s   |  j  j |  d  S(   N(   R   t   remove(   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   remote_unobserve%  s    c         C   s+   x$ |  j  D] } | j d |  |  q
 Wd  S(   Nt   notify(   R   Ry   (   R   t   objRx   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR   (  s    (   R   R    R2   R   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR     s   			t   DeferredRemotec           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s   d |  _  d  S(   Ni    (   t   run(   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR2   .  s    c         C   s   | |  _  | d S(   Ni   (   R   (   R   RU   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   runMe1  s    	c         C   s   d s t  d   d  S(   Ni    s   shouldn't have been run!(   t   AssertionError(   R   RU   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt	   dontRunMe5  s    c         C   s,   t    } | j |  j |  j  | |  _ | S(   so   
        Return a L{Deferred} to be fired on client side. When fired,
        C{self.runMe} is called.
        (   R   t   addCallbacksR   R   t   d(   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   remote_doItLater8  s    		(   R   R    R2   R   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR   -  s   			t   Observerc           B   s   e  Z d  Z d Z d   Z RS(   i    c         C   s-   | |  _  |  j d |  _ | j d |   d  S(   Ni   t	   unobserve(   R   t   notifiedRy   (   R   t   otherR   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   remote_notifyF  s    	N(   R   R    R   R$   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR   C  s   t   NewStyleCopyc           B   s   e  Z d    Z RS(   c         C   s   | |  _  d  S(   N(   t   s(   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR2   M  s    (   R   R    R2   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR   L  s   t   NewStyleCopy2c           B   s,   e  Z d  Z d  Z d Z d   Z d   Z RS(   i    i   c         C   s+   t  j d 7_ t j |   } d | _ | S(   Ni   i   (   R   t	   allocatedt   objectt   __new__Ro   (   R   Rk   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR   W  s    	c         C   s   t  j d 7_ d  S(   Ni   (   R   t   initialized(   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR2   ]  s    (   R   R    R   R   Ro   R   R2   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR   R  s
   	t   NewStyleCacheCopyc           B   s   e  Z d    Z RS(   c         C   s   |  j  S(   N(   R   (   R   R{   Rx   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR|   d  s    (   R   R    R|   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR   c  s   t   Echoerc           B   s   e  Z d    Z RS(   c         C   s   | S(   N(    (   R   t   st(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   remote_echok  s    (   R   R    R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR   j  s   t   CachedReturnerc           B   s   e  Z d    Z d   Z RS(   c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR2   p  s    c         C   s   |  j  S(   N(   R   (   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   remote_giveMeCacher  s    (   R   R    R2   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR   o  s   	t   NewStyleTestCasec           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c            s   t  j t      _ t   j    _ t j d   j    _ t  j	   } t j
 d   j j   j |    f d   } | j   j |  S(   sY   
        Create a pb server using L{Echoer} protocol and connect a client to it.
        i    t	   localhostc            s   |    _  d  S(   N(   t   ref(   R   (   R   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   gotRoot  s    (   R   RG   R   t   serverFactoryR   t   wrapperR   t	   listenTCPR/   t   PBClientFactoryt
   connectTCPt   getHostt   portt   getRootObjectt   addCallback(   R   t   clientFactoryR   (    (   R   s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   setUpw  s    c         C   s_   d t  _ d t  _ d t  _ |  j j j j   x! |  j j	 D] } | j j   q; W|  j
 j   S(   sp   
        Close client and server connections, reset values of L{NewStyleCopy2}
        class variables.
        i    i   (   R   R   R   Ro   R   t   brokerR>   t   loseConnectionR   t	   protocolsR/   t   stopListening(   R   t   proto(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   tearDown  s    			c            sD   t  d     j j d   }    f d   } | j |  | S(   sY   
        Create a new style object, send it over the wire, and check the result.
        Ro   t   echoc            s@     j  t |  t     j |  j d    j |   k  d  S(   NRo   (   t
   failUnlessR   R   t   assertEqualR   t   failIf(   t   res(   R   t   orig(    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   cb  s    (   R   R   Ry   R   (   R   R   R   (    (   R   R   s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_newStyle  s
    c            sg   t       j t  j d    j t  j d    j j d   }    f d   } | j |  | S(   sN   
        Send a new style object and check the number of allocations.
        i   R   c            sf     j  t |  t     j |  j d    j t j d    j t j d    j |   k  d  S(   Ni   i   i   (   R   R   R   R   Ro   R   R   R   (   R   (   R   R   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR     s
    (   R   R   R   R   R   Ry   R   (   R   R   R   (    (   R   R   s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt
   test_alloc  s    	(   R   R    R   R   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR   v  s   			t   ConnectionNotifyServerFactoryc           B   s&   e  Z d  Z d Z d   Z d   Z RS(   sj  
    A server factory which stores the last connection and fires a
    L{Deferred} on connection made. This factory can handle only one
    client connection.

    @ivar protocolInstance: the last protocol instance.
    @type protocolInstance: C{pb.Broker}

    @ivar connectionMade: the deferred fired upon connection.
    @type connectionMade: C{Deferred}
    c         C   s#   t  j j |  |  t   |  _ d S(   s)   
        Initialize the factory.
        N(   R   RG   R2   R   t   connectionMade(   R   t   root(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR2     s    c         C   s<   | |  _  |  j d } |  _ | d k	 r8 | j d  n  d S(   sF   
        Store the protocol and fire the connection deferred.
        N(   t   protocolInstanceR   R$   t   callback(   R   R	   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   clientConnectionMade  s    	N(   R   R    R"   R$   R   R2   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR     s   	t   NewStyleCachedTestCasec           B   s#   e  Z d    Z d   Z d   Z RS(   c            s   t      _ d   j _ t j d t t   j      _ t j	   } t j
 d   j j   j |    f d   } | j   j |  }   j j j } t | | g  S(   si   
        Create a pb server using L{CachedReturner} protocol and connect a
        client to it.
        Ro   i    R   c            s   |    _  d  S(   N(   R   (   R   (   R   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR     s    (   R   R   R   R   R   R   R   R/   R   R   R   R   R   R   R   RO   R   R   (   R   R   R   t   d1t   d2(    (   R   s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR     s    	c         C   s6   |  j  j j j j   |  j j j j   |  j  j   S(   s6   
        Close client and server connections.
        (   R/   RO   R   R>   R   R   R   R   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR     s    c            sK     j  j d   j  }   f d   } | j | t  | j | t  | S(   s   
        A new-style cacheable object can be retrieved and re-retrieved over a
        single connection.  The value of an attribute of the cacheable can be
        accessed on the receiving side.
        t   giveMeCachec            s_     j  |  t    j d |  j    j   j |   | r[ |    _   j j d   j  Sd  S(   NRo   R   (	   t   assertIsInstanceR   R   R   t   assertNotIdenticalR   R   R   Ry   (   R   t   again(   R   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR     s    	(   R   Ry   R   R   R9   R3   (   R   R   R   (    (   R   s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_newStyleCache  s
    (   R   R    R   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR     s   			t   BrokerTestCasec           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 RS(   c         C   s)   y t  j d  Wn t k
 r$ n Xd  S(   Ns   None-None-TESTING.pub(   t   ost   unlinkt   OSError(   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR     s    c         C   s   |  j  d | f  d  S(   Ns(   This should cause a return value, not %s(   t   fail(   R   t   error(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   thunkErrorBad  s    c         C   s   | |  _  d  S(   N(   t   thunkResult(   R   t   result(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   thunkResultGood  s    c         C   s   d  S(   N(    (   R   t   tb(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   thunkErrorGood  s    c         C   s   |  j  d | f  d  S(   Ns"   This should cause an error, not %s(   R   (   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   thunkResultBad   s    c   	      C   s   t    \ } } } d t j f d     Y} d t j f d     Y} | j d |    | j d  } |   } |   } | j d | |  | j   | j   | j   |  j | j | d  |  j	 | j
 d  | j
 d   d  S(   Nt   Xc           B   s   e  Z d    Z RS(   c         S   s   | |  _  d  S(   N(   t   caught(   R   RU   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   remote_catch'  s    (   R   R    R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR   &  s   t   Yc           B   s   e  Z d    Z RS(   c         S   s   | j  d |  d  S(   Nt   catch(   Ry   (   R   t   at   b(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   remote_throw+  s    (   R   R    R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR   *  s   R`   t   throws   X should have caught Z(   RS   R   t   Referenceablet   setNameForLocalt   remoteForNameRy   R6   t   assertIdenticalR   R   t   remoteMethod(	   R   Ru   R   R6   R   R   R`   R_   Ra   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_reference#  s    		


c         C   s   t    \ } } } x | | f | | f f D] \ } } t   } | j d |  | j d  } d |  _ | j d |  j d  j |  j |  j  | j	   | j	   |  j
 |  j |  j d  q+ Wd  S(   NRw   i   t   thunki   s   result wasn't received.(   RS   RT   R   R   t   expectedThunkResultRy   R   R   R   R6   R   R   (   R   Ru   R   R6   R_   R`   Rw   t   bar(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_result;  s    %		

c         C   s   | |  _  d  S(   N(   t   nestedRemote(   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   refcountResultM  s    c   
      C   s   g  } g  } t    \ } } } t   } | j d |  | j d  } x` t t j d  D]K } | j j sx | j j r| Pn  | j	 d  j
 | j | j  | j   qZ Wt j d }	 |  j | j j d  |  j t |  |	 d |	 t |  f  d  S(   NRw   i
   t	   getSimplei   s   transport was not closeds   expected %s got %s(   RS   RY   R   R   t   xrangeR   t   MAX_BROKER_REFSR>   t   closedRy   R   R   R6   t
   assertTrueR   t   len(
   R   t   lt   eRu   R   R6   Rw   R_   t   ignot   expected(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_tooManyRefsP  s    	c         C   s   t    \ } } } t   } | j d |  | j d  } | j d  j |  j |  j  | j   | j   |  j	 |  j
 j d  |  j	 |  j
 j d d  |  j	 |  j
 j d d  d  S(   NRw   t   getCopyi   R]   R\   i    R^   (   RS   Rm   R   R   Ry   R   R   R   R6   R   R   R_   R`   Ra   (   R   Ru   R   R6   Rw   R_   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt	   test_copya  s    	

c         C   s   t    \ } } } t   } t   } | j d |  | j d  } | j d |  | j   | j d  | j   | j   | j d  | j   | j   |  j | j	 d  d  |  j | j	 d d  d  S(   NR   t   observei   i
   s   didn't notifys   notified too much(   RS   R   R   R   R   Ry   R6   R   R   R   R$   R   (   R   Ru   R   R6   R   R   t   ra(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_observen  s    		




c         C   s   t    \ } } } t   } | j d |  | j d  } | j   | j   g  } | j d  j | j  | j   | j   |  j | j	 d  | j
 j d  |  j | j	 d d  | j   | j   |  j | d d d  d  S(	   NR   t	   doItLaters   Deferred method run too early.i   s   Deferred method run too late.i    i   s   Incorrect result.(   RS   R   R   R   R6   Ry   R   R   t   assertFalseR   R   R   R   (   R   Ru   R   R6   R   R  t   results(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt
   test_defer  s     	
 

 

 
c         C   s   t    \ } } } t   } | j d |  | j d  } | j d  j |  j |  j  | j   | j   |  j	 j
 } |  j | | j  |  `	 t j d k r t j   n  | j   | j   | j   |  j | | j  d  S(   NRw   R   i   (   RS   RY   R   R   Ry   R   R   R   R6   R   t   luidt   assertInt   localObjectst   syst
   hexversiont   gct   collectt   assertNotIn(   R   Ru   R   R6   Rw   R   t   rluid(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_refcount  s"    	




c         C   s	  t    \ } } } t   } t   } | j } | j d |  | j d |  | j d  } | j d  } g  }	 | j d  j |	 j  j	 |	 j  | j d  j |	 j  j	 |	 j  g  }
 | j d  j |
 j  | j d  j |
 j  | j
   |  j |
 d j d  |  j |
 d j d  |  j |
 d j d  | j   | j
   |  j |
 d j d  |  j t |	  d  |	 d d } |  j | j   j | d	  |  j | j   | d
  g  } | j d |  j | j  | j
   |  j | d  |  j | j d  | j d   | j } |
 d j } |  j | | j d  ~	 ~ | j
   ~
 ~ | j
   t j d k rt j   n  | j
   |  j | | j d  |  j | | j d  |  j | | j d  |  j | | j d  |  j | j  d  d  d  S(   NR   t   xxxt   getCachei    i   i   i   i   s   potential refcounting issues!   other potential refcounting issuet   putCaches   remote cache doesn't have iti   s   Server still had it after GCs   Client still had it after GCs!   Server still had complex after GCs!   Client still had complex after GCs   observer was not removed("   RS   R   Rs   Ru   R   R   Ry   R   R   t
   addErrbackR8   R   R_   R`   Rw   Rz   R  R   R   t   im_selfR   R  R   R  R  t   remotelyCachedObjectsR  R  R  R  R  t   locallyCachedObjectsRx   R$   (   R   Ru   R   R6   R   t   obj2t   vcct   o2t   o3t   collt   complext   cpt   col2R  t   baroqueLuid(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt
   test_cache  sr    			



	


c         C   sc  y t  j d  Wn t k
 r$ n Xt   \ } } } t   } | j d |  | j d  } g  } | j d  j | j	 |  j
  | j   | j   } |  j | j d  |  j | j d  |  j | j d  |  j | j d  t   \ } } } | j d |  | j d  } | j d  j | j	 |  j
  | j   | j   } |  j | j d  d  S(   Ns   None-None-TESTING.pubRw   t   getPubi   i    (   R   R   R   RS   t   GetPublisherR   R   Ry   R   R   R   R8   t   popR   t   activateCalledt   isActivatedt   yayIGotPublishedt   _wasCleanWhenLoaded(   R   Ru   R   R6   Rw   R   t   accumR   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_publishable  s.    	

c         C   s   | j  |  _ d  S(   N(   Rd   R   (   R   t   val(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   gotCopy  s    c         C   s   t    \ } } } d } t   } | j d |  | j d  } | j d |  j |  j |  j  | j   | j   | j   |  j	 |  j
 | d |  j
 f  d  S(   Nic   Rw   t
   getFactorys#   ID not correct on factory object %s(   RS   Rm   R   R   Ry   R   R8  R   R6   R   R   (   R   Ru   R   R6   t   IDR   R_   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_factoryCopy  s    	


N(   R   R    R$   R   R   R   R   R   R   R   R   R   R	  R  R  R  R  R-  R6  R8  R;  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR     s$   														F		t
   helloworldi2   c          O   s   |  a  | a d  S(   N(   t   callbackArgst   callbackKeyword(   t   argst   kw(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   finishedCallback'  s    t	   Pagerizerc           B   s   e  Z d    Z d   Z RS(   c         O   s!   | | | |  _  |  _ |  _ d  S(   N(   R   R?  R@  (   R   R   R?  R@  (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR2   .  s    c         C   s9   t  j | t d |  j |  j |  j  d  |  _ |  _ d  S(   Nid   (   R   t   StringPagert	   bigStringR   R?  R@  R$   (   R   t	   collector(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   remote_getPages1  s    (   R   R    R2   RF  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyRB  -  s   	t   FilePagerizerc           B   s    e  Z d Z d    Z d   Z RS(   c         O   s*   | |  _  | | | |  _ |  _ |  _ d  S(   N(   t   filenameR   R?  R@  (   R   RH  R   R?  R@  (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR2   :  s    	c         C   sD   t  j | t |  j  |  j |  j |  j  |  _ d  |  _ |  _ d  S(   N(	   R   t	   FilePagert   fileRH  R   R?  R@  t   pagerR$   (   R   RE  (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyRF  >  s    N(   R   R    R$   RK  R2   RF  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyRG  7  s   	t   PagingTestCasec           B   sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s0   
    Test pb objects sending data by pages.
    c         C   s<   |  j    |  _ t |  j d  } | j t  | j   d S(   s?   
        Create a file used to test L{util.FilePager}.
        t   wN(   t   mktempRH  RJ  t   writeRD  t   close(   R   t   fd(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR   J  s    c         C   s   t    \ } } } | j d t t d d d  | j d  } g  } t j | d  j | j  x | sx | j	   qe W|  j
 d j | d  t d  |  j
 t d d	  |  j
 t i d d 6d	  d
 S(   sg   
        Test L{util.StringPager}, passing a callback to fire when all pages
        are sent.
        Rw   t   helloRo   i
   t   getPagest    i    s'   Pages received not equal to pages sent!s   Completed callback not invokedN(   RR  (   RS   R   RB  RA  R   R   t   getAllPagesR   R   R6   R   t   joinRD  R=  R>  (   R   Ru   R   R6   R_   R  (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_pagingWithCallbackT  s    	c         C   s   t    \ } } } | j d t d   | j d  } g  } t j | d  j | j  x | so | j	   q\ W|  j
 d j | d  t d  d S(   s>   
        Test L{util.StringPager} without a callback.
        Rw   RS  RT  i    s'   Pages received not equal to pages sent!N(   RS   R   RB  R$   R   R   RU  R   R   R6   R   RV  RD  (   R   Ru   R   R6   R_   R  (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_pagingWithoutCallbackh  s    	c   
      C   s   |  j    } t | d  } | j   t   \ } } } t | d
  } | j d |  | j d  } g  } t j	 | d  j
 | j  d }	 x+ | r |	 d k r | j   |	 d 8}	 q W|	 s |  j d  n  |  j d j | d  d d	  d
 S(   s@   
        Test L{util.FilePager}, sending an empty file.
        RM  R   RS  i
   i    i   s   getAllPages timed outRT  s'   Pages received not equal to pages sent!N(   RN  RJ  RP  RS   RG  R$   R   R   R   RU  R   R   R6   R   R   RV  (
   R   t   filenameEmptyRQ  Ru   R   R6   t	   pagerizerR_   R  t   ttl(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_emptyFilePagingw  s"    

c         C   s   t    \ } } } t |  j t d d d } | j d |  | j d  } g  } t j | d  j | j	  x | s | j
   qq W|  j d j | d  t d  |  j t d d	  |  j t i d d 6d	  |  j | j j g   d
 S(   s   
        Test L{util.FilePager}, passing a callback to fire when all pages
        are sent, and verify that the pager doesn't keep chunks in memory.
        t   frodoRo   i	   R   RS  RT  i    s'   Pages received not equal to pages sent!s   Completed callback not invokedN(   R]  (   RS   RG  RH  RA  R   R   R   RU  R   R   R6   R   RV  RD  R=  R>  RK  t   chunks(   R   Ru   R   R6   RZ  R_   R  (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_filePagingWithCallback  s     	c         C   s   t    \ } } } t |  j d  } | j d |  | j d  } g  } t j | d  j | j	  x | s{ | j
   qh W|  j d j | d  t d  |  j | j j g   d S(   s<   
        Test L{util.FilePager} without a callback.
        R   RS  RT  i    s'   Pages received not equal to pages sent!N(   RS   RG  RH  R$   R   R   R   RU  R   R   R6   R   RV  RD  RK  R^  (   R   Ru   R   R6   RZ  R_   R  (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_filePagingWithoutCallback  s    	(	   R   R    R"   R   RW  RX  R\  R_  R`  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyRL  E  s   	
				t   DumbPublishablec           B   s   e  Z d    Z RS(   c         C   s   i d d 6S(   Ni   R3  (    (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   getStateToPublish  s    (   R   R    Rb  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyRa    s   t   DumbPubc           B   s   e  Z d    Z RS(   c         C   s   d |  _  d  S(   Ni   (   R1  (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt	   activated  s    (   R   R    Rd  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyRc    s   R/  c           B   s   e  Z d    Z d   Z RS(   c         C   s   t  d  |  _ d  S(   Nt   TESTING(   Ra  t   pub(   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR2     s    c         C   s   |  j  S(   N(   Rf  (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   remote_getPub  s    (   R   R    R2   Rg  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR/    s   	t   DisconnectionTestCasec           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s'   
    Test disconnection callbacks.
    c         G   s   t  d | f   d  S(   Ns    I shouldn't have been called: %s(   Rg   (   R   R?  (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR     s    c         C   s   d |  _  d S(   s.   
        Called on broker disconnect.
        i   N(   t   gotCallback(   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   gotDisconnected  s    c         C   s    |  j  | |  j  d |  _ d S(   s7   
        Called on RemoteReference disconnect.
        i   N(   R   t   remoteObjectt   objectCallback(   R   t   o(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   objectDisconnected  s    c         C   s   t    \ } } } | j   | j d t    | j d  } g  } | j d t    j | j  | j	   |  j
 t |  d  d  S(   NRm  t
   setBadCopyi   (   RS   R6   R   t
   BadCopySetR   Ry   t   BadCopyableR   R   R8   R   R  (   R   Ru   R   R6   t   gR  (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_badSerialization  s    

c         C   s  t    \ } } } | j   | j d t    | j d  } | j   | j   | j   | j |  j  |  j |  j | j  | j	 |  j  |  j
 |  j | j  | j |  j  |  j | j | j  |  j |  j | j  | j	 |  j  |  j
 | j | j  |  j
 |  j | j  | j |  j  | j |  j  | |  _ | j t j t j   |  j |  j  |  j |  j  d  S(   NRm  (   RS   R6   R   RT   R   t   notifyOnDisconnectR   R  t   disconnectst   dontNotifyOnDisconnectR  t   _disconnectedt   disconnectCallbacksRj  Rn  Rk  t   connectionLostR   t   FailureR
   t   CONNECTION_DONER  Ri  Rl  (   R   Ru   R   R6   t   r(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_disconnection  s.    



	(   R   R    R"   R   Rj  Rn  Rs  R}  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyRh    s   				
t   FreakOutc           B   s   e  Z RS(    (   R   R    (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR~    s   Rq  c           B   s   e  Z d    Z RS(   c         C   s   t     d  S(   N(   R~  (   R   t   p(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   getStateToCopyFor  s    (   R   R    R  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyRq    s   Rp  c           B   s   e  Z d    Z RS(   c         C   s   d  S(   N(   R$   (   R   t   bc(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   remote_setBadCopy  s    (   R   R    R  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyRp    s   t   LocalRemoteTestc           B   s/   e  Z d  Z d   Z d  d d  Z d   Z RS(   i    c         C   s   | d S(   Ni   (    (   R   R_   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt	   sync_add1   s    i   c         C   s   | | S(   N(    (   R   R_   R`   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt	   async_add#  s    c         C   s   t     d  S(   N(   Rg   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt
   async_fail&  s    (   R   R    t   reportAllTracebacksR  R  R  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR    s   	t   MyPerspectivec           B   sR   e  Z d  Z e e j  e Z Z d   Z	 d   Z
 d   Z d   Z d   Z RS(   s   
    @ivar loggedIn: set to C{True} when the avatar is logged in.
    @type loggedIn: C{bool}

    @ivar loggedOut: set to C{True} when the avatar is logged out.
    @type loggedOut: C{bool}
    c         C   s   | |  _  d  S(   N(   R'   (   R   R'   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR2   7  s    c         C   s   |  j  S(   sT   
        Return the avatar identifier which was used to access this avatar.
        (   R'   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   perspective_getAvatarId;  s    c         C   s   t    S(   N(   t   MyView(   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   perspective_getViewPointB  s    c         C   s   | | S(   s   
        Add the given objects and return the result.  This is a method
        unavailable on L{Echoer}, so it can only be invoked by authenticated
        users who received their avatar from L{TestRealm}.
        (    (   R   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   perspective_addF  s    c         C   s   t  |  _ d  S(   N(   R9   t	   loggedOut(   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   logoutO  s    (   R   R    R"   R   R   R&   R3   t   loggedInR  R2   R  R  R  R  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR  +  s   
					t	   TestRealmc           B   s#   e  Z d  Z e Z d Z d   Z RS(   s  
    A realm which repeatedly gives out a single instance of L{MyPerspective}
    for non-anonymous logins and which gives out a new instance of L{Echoer}
    for each anonymous login.

    @ivar lastPerspective: The L{MyPerspective} most recently created and
        returned from C{requestAvatar}.

    @ivar perspectiveFactory: A one-argument callable which will be used to
        create avatars to be returned from C{requestAvatar}.
    c         C   s   | t  j k s t  | d k s' t  | t j k rL t  j t   d   f S|  j |  |  _ t |  j _	 t  j |  j |  j j
 f Sd S(   s   
        Verify that the mind and interface supplied have the expected values
        (this should really be done somewhere else, like inside a test method)
        and return an avatar appropriate for the given identifier.
        s   BRAINS!c           S   s   d  S(   N(   R$   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR%   m  s    N(   R   R&   R   R   t	   ANONYMOUSR   t   perspectiveFactoryt   lastPerspectiveR9   R  R  (   R   R'   R(   t	   interface(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR+   d  s    N(   R   R    R"   R  R  R$   R  R+   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR  T  s   R  c           B   s   e  Z d    Z RS(   c         C   s   t  | t  S(   N(   R   R  (   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt
   view_checky  s    (   R   R    R  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR  w  s   t
   LeakyRealmc           B   s    e  Z d  Z d   Z d   Z RS(   s]   
    A realm which hangs onto a reference to the mind object in its logout
    function.
    c         C   s   | |  _  d S(   s   
        Create a L{LeakyRealm}.

        @param mindEater: a callable that will be called with the C{mind}
        object when it is available
        N(   t
   _mindEater(   R   t	   mindEater(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR2     s    c            s8   |  j    |  j |    t j      f d   f S(   Nc              s      j    f S(   N(   R  (    (   t   perspR(   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR%     s    (   R  R  R   R&   (   R   R'   R(   R  (    (   R  R(   s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR+     s    (   R   R    R"   R2   R+   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR  ~  s   	
t   NewCredLeakTestsc           B   s   e  Z d  Z d   Z RS(   s/   
    Tests to try to trigger memory leaks.
    c            s   d   _   f d   } t t |   \ }   g   | j d  } | j d d  } d   } | j |     f d   } | j |   j     j  d g  t	 j
     j   j   d  d S(	   s   
        The server does not leak a reference when the client disconnects
        suddenly, even if the cred logout function forms a reference cycle with
        the perspective.
        c            s   t  j |     _ d  S(   N(   t   weakrefR   t   mindRef(   R(   (   R   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt
   setMindRef  s    R   t   loginRD   c         S   s4   |  \ } } t    } | j d t j | d  |  S(   Nt   respondRD   (   RT   Ry   R   R  (   t   .0t	   challenget
   challengerR(   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt
   cbResponse  s    			c            s7    j     j d    j t j t d    d  S(   Ni   t   boom(   R:   R   Ry  R   Rz  Rg   (   t   _(   RP   t   connectionBrokenR6   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyRy    s    
i   N(   R$   R  RS   R  R   Ry   R   R8   R   R  R  (   R   R  RM   R   R   R  Ry  (    (   R   RP   R6   R  s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_logoutLeak  s    		

(   R   R    R"   R  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR    s   t   NewCredTestCasec           B   s   e  Z d  Z d   Z d   Z e j 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 related to the L{twisted.cred} support in PB.
    c         C   sj   t    |  _ t j |  j  |  _ t |  j  |  _ t j d |  j d d |  _ |  j j	   j |  _
 d S(   s   
        Create a portal with no checkers and wrap it around a simple test
        realm.  Set up a PB server on a TCP port which serves perspectives
        using that portal.
        i    R  s	   127.0.0.1N(   R  RL   R   RH   R   RO   R   R   R   R   t   portno(   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR     s
    c         C   s   |  j  j   S(   s=   
        Shut down the TCP port created by L{setUp}.
        (   R   R   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR     s    c         C   sG   |   } | j    } t j d |  j |  } |  j | j  | | f S(   sG  
        Create a connection to the test server.

        @param clientFactory: the factory class used to create the connection.

        @return: a tuple (C{factory}, C{deferred}), where factory is an
            instance of C{clientFactory} and C{deferred} the L{Deferred} firing
            with the PB root object.
        s	   127.0.0.1(   R   R   R   R  t
   addCleanupt
   disconnect(   R   R   RO   t   rootObjDeferredt	   connector(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   getFactoryAndRootObject  s
    
	c            s1     j    \  }    f d   } | j |  S(   sw   
        Assert only that L{PBClientFactory.getRootObject}'s Deferred fires with
        a L{RemoteReference}.
        c            s:     j  |  t j  t   } |  j | j   j   | S(   N(   R   R   t   RemoteReferenceR   Rt  R   R  (   t   rootObjt   disconnectedDeferred(   R   RO   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   gotRootObject  s
    	
(   R  R   (   R   R  R  (    (   R   RO   s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_getRootObject  s    c            s1     j    \  }    f d   } | j |  S(   s   
        Test that when a connection is lost, calling a method on a
        RemoteReference obtained from it raises DeadReferenceError.
        c            sF   t    }   j | j     f d   } | j |   j   | S(   Nc            s     j  t j  j d  d  S(   Nt   method(   t   assertRaisesR   t   DeadReferenceErrorRy   (   t   ign(   R   R  (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   lostConnection  s    (   R   Rt  R   R   R  (   R  R  R  (   R   RO   (   R  s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR    s    	
(   R  R   (   R   R  R  (    (   R   RO   s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_deadReferenceError  s    c            sM   d t  j f d     Y}   j |  \  }    f d   } | j |  S(   s   
        Test that if the L{reconnecting} flag is passed with a True value then
        a remote call made from a disconnection notification callback gets a
        result successfully.
        t   ReconnectOncec           B   s   e  Z e Z d    Z RS(   c         S   s?   |  j  } t |  _  | r& | j   n  t j j |  | | |  S(   N(   t   reconnectedAlreadyR9   t   connectR   R   t   clientConnectionLost(   R   R  t   reasont   reconnecting(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR    s    
		(   R   R    R3   R  R  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR    s   c            sU     j  |  t j  t   } |  j | j   j      f d   } | j |  S(   Nc            s+    j    }    f d   } | j |  S(   Nc            s:     j  |  t j  t   } |  j | j   j   | S(   N(   R   R   R  R   Rt  R   R  (   t   anotherRootObjR   (   R   RO   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   gotAnotherRootObject/  s
    	
(   R   R   (   R  R   R  (   R   RO   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   disconnected,  s    (   R   R   R  R   Rt  R   R  R   (   R  R   R  (   R   RO   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR  %  s    	
(   R   R   R  R   (   R   R  R  R  (    (   R   RO   s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_clientConnectionLost  s    
c         C   sH   |  j  j d  } | j t j t     | j t j t	 j
   d S(   s   
        Test that if a Broker loses its connection without receiving any bytes,
        it doesn't raise any exceptions or log any errors.
        s	   127.0.0.1i90  N(   s	   127.0.0.1i90  (   RO   RI   RJ   R	   RK   R    Ry  R   Rz  R
   R{  (   R   t   serverProto(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_immediateClose;  s    c         C   sV   t  j   } | j t j d d   } | j d t j t	 d    |  j
 | t	  S(   s   
        L{PBClientFactory.login} returns a L{Deferred} which is errbacked
        with the L{ConnectionRefusedError} if the underlying connection is
        refused.
        Rw   R   s!   Test simulated refused connectionN(   R   R   R  R   t   UsernamePasswordt   clientConnectionFailedR$   R   Rz  R   t   assertFailure(   R   R   t   loginDeferred(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_loginConnectionRefusedE  s    c            s3   t      |  j j j   f d    | j     S(   s   
        Helper method disconnecting the given client factory and returning a
        C{Deferred} that will fire when the server connection has noticed the
        disconnection.
        c              s     j  d   S(   N(   R   R$   (    (   R  (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR%   ]  s    (   R   RO   R   Rt  R  (   R   t   ignoreRO   (    (   R  s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   _disconnectU  s
    	
c            s     j  j t j d d   t j    t j d d  } d }  j | |  }    f d   } | j	 |    f d   } | j	 |  t
 j d   j   }   j | j  | S(   s   
        Test that login can be performed with IUsernamePassword credentials and
        that when the connection is dropped the avatar is logged out.
        R   t   passs   BRAINS!c            s9     j    j j j    j |  t j    j d    S(   N(	   R  RL   R  R  R   R   R  R  R$   (   R{   (   R   RO   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   cbLogint  s    c            s     j    j j j  d  S(   N(   R  RL   R  R  (   t   ignored(   R   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   cbLogoutz  s    s	   127.0.0.1(   R   t   registerCheckerR   RF   R   R   R   R  R  R   R   R   R  R  R  (   R   t   credsR(   R   R  R  R  (    (   R   RO   s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_loginLogoutb  s    	c            s   t     d t j f  f d     Y} |   j _   j j t j d d   t j	   } | j
 t j d d  d  }  f d   } | j |    f d   } | j |  | j   j |  t j d   j |  }   j | j  | S(	   s   
        If a L{RemoteReference} to an L{IPerspective} avatar is decrefed and
        there remain no other references to the avatar on the server, the
        avatar is garbage collected and the logout method called.
        t   EventPerspectivec              s&   e  Z d  Z d   Z   f d   Z RS(   sQ   
            An avatar which fires a Deferred when it is logged out.
            c         S   s   d  S(   N(    (   R   R'   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR2     s    c            s     j  d   d  S(   N(   R   R$   (   R   (   R  (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR    s    (   R   R    R"   R2   R  (    (   R  (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR    s   	Rw   R   s   BRAINS!c            s     S(   N(    (   t   avatar(   R  (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt
   cbLoggedIn  s    c            s     j    j j j i   d  S(   N(   R   RO   R   t   _localCleanup(   R  (   R   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   cbLoggedOut  s    s	   127.0.0.1(   R   R   t   AvatarRL   R  R   R  R   RF   R   R  R   R  R   R  R   R   R  R  R  (   R   R  RO   R   R  R  R  (    (   R   R  s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_logoutAfterDecref  s     	
	c            s     j  j t j d d d d   t j   } | j t j d d  d  } | j t j d d  d  } t	 | | g  } d   } | j
 |    f d   } | j
 |  | j
   j |  t j d   j |  }   j | j  | S(	   s   
        Two different correct login attempts can be made on the same root
        object at the same time and produce two different resulting avatars.
        Rw   R   t   bazt   quuxs   BRAINS!c         S   s.   |  \ } } t  | j d  | j d  g  S(   Nt   getAvatarId(   R   Ry   (   R  t   firstt   second(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR    s    	c            s0   |  \ } }   j  | d    j  | d  d  S(   NRw   R  (   R   (   R  R  R  (   R   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   cbAvatarIds  s    	s	   127.0.0.1(   R   R  R   RF   R   R   R  R   R  R   R   R  R   R   R  R  R  (   R   RO   t
   firstLogint   secondLoginR   R  R  R  (    (   R   s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_concurrentLogin  s"    			c            s     j  j t j d d   t j     j t j d d   }  j t j d d   }   j	 | t
    j	 | t
  t | | g  }    f d   } | j |  t j d   j   }   j | j  | S(   sz   
        Test that a login attempt with an invalid user or invalid password
        fails in the appropriate way.
        R   R  t
   nosuchusert	   wrongpassc            s5     j  t  }   j t |  d    j d    S(   Ni   (   t   flushLoggedErrorsR   R   R  R  R$   (   R  t   errors(   R   RO   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   cleanup  s    s	   127.0.0.1(   R   R  R   RF   R   R   R  R   R  R  R   R   R   R   R   R  R  R  (   R   R  R  R   R  R  (    (   R   RO   s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_badUsernamePasswordLogin  s    	c         C   s   |  j  j t j    t j   } | j t j   d  } d   } | j	 |  | j	 |  j
 d  | j	 |  j |  t j d |  j |  } |  j | j  | S(   s   
        Verify that a PB server using a portal configured with an checker which
        allows IAnonymous credentials can be logged into using IAnonymous
        credentials.
        s   BRAINS!c         S   s   |  j  d d  S(   NR   i{   (   Ry   (   R{   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR    s    i{   s	   127.0.0.1(   R   R  R   t   AllowAnonymousAccessR   R   R  R   t	   AnonymousR   R   R  R   R   R  R  R  (   R   RO   R   R  R  (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_anonymousLogin  s    	c            s     j  j t j d d   t j     j t j   d  }   j	 | t
     f d   } | j |  t j d   j   }   j | j  | S(   sg   
        Verify that without an anonymous checker set up, anonymous login is
        rejected.
        R   R  s   BRAINS!c            s5     j  t  }   j t |  d    j d    S(   Ni   (   R  R   R   R  R  R$   (   R  R  (   R   RO   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR  
  s    s	   127.0.0.1(   R   R  R   RF   R   R   R  R   R  R  R   R   R   R   R  R  R  (   R   R   R  R  (    (   R   RO   s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_anonymousLoginNotPermitted  s    	c         C   s   |  j  j t j    |  j  j t j d d   t j   } | j t j	   d  } d   } | j
 |  | j
 |  j d  | j
 |  j |  t j d |  j |  } |  j | j  | S(   s   
        Like L{test_anonymousLogin} but against a portal with a checker for
        both IAnonymous and IUsernamePassword.
        R   R  s   BRAINS!c         S   s   |  j  d d  S(   NR   i{   (   Ry   (   R{   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR     s    i{   s	   127.0.0.1(   R   R  R   R  RF   R   R   R  R   R  R   R   R  R   R   R  R  R  (   R   RO   R   R  R  (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt'   test_anonymousLoginWithMultipleCheckers  s    		c         C   s   |  j  j t j    |  j  j t j d d   t j   } | j t j	 d d  d  } d   } | j
 |  | j
 |  j d  | j
 |  j |  t j d |  j |  } |  j | j  | S(   s   
        Like L{test_anonymousLoginWithMultipleCheckers} but check that
        username/password authentication works.
        R   R  s   BRAINS!c         S   s   |  j  d d d  S(   Nt   addid   i   (   Ry   (   R{   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR  9  s    i{   s	   127.0.0.1(   R   R  R   R  RF   R   R   R  R   R  R   R   R  R   R   R  R  R  (   R   RO   R   R  R  (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt+   test_authenticatedLoginWithMultipleCheckers-  s    		c         C   s   |  j  j t j d d   t j   } | j t j d d  d  } d   } | j	 |  d   } | j	 |  | j	 |  j
  | j	 |  j |  t j d |  j |  } |  j | j  | S(   sb   
        Verify that a viewpoint can be retrieved after authenticating with
        cred.
        R   R  s   BRAINS!c         S   s   |  j  d  S(   Nt   getViewPoint(   Ry   (   R{   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR  Q  s    c         S   s   |  j  d  S(   NR   (   Ry   (   t	   viewpoint(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   cbViewU  s    s	   127.0.0.1(   R   R  R   RF   R   R   R  R   R  R   R  R  R   R   R  R  R  (   R   RO   R   R  R  R  (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt	   test_viewF  s    			(   R   R    R"   R   R   R   R   R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR    s&   					(	
			!	)						t   NonSubclassingPerspectivec           B   s0   e  Z e e j  d    Z d   Z d   Z RS(   c         C   s   d  S(   N(    (   R   R'   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR2   f  s    c         C   s:   | j  | |   } | j  | |   } | j | | | f  S(   N(   t   unserializet	   serialize(   R   R   t   messageR?  t   kwargs(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   perspectiveMessageReceivedj  s    c         C   s   t  |  _ d  S(   N(   R9   R  (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR  p  s    (   R   R    R   R   R&   R2   R  R  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR  c  s   		t   NSPTestCasec           B   s    e  Z d  Z d   Z d   Z RS(   s   
    Tests for authentication against a realm where the L{IPerspective}
    implementation is not a subclass of L{Avatar}.
    c         C   s   t    |  _ t |  j _ t j |  j  |  _ t j   |  _ |  j j	 d d  |  j j
 |  j  t t j |  j   |  _ t j d |  j d d |  _ |  j |  j j  |  j j   j |  _ d  S(   NR   R  i    R  s	   127.0.0.1(   R  RL   R  R  R   RH   R   RF   RN   t   addUserR  R   R   RG   RO   R   R   R   R  R   R   R  (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR   z  s    c            s   t  j     j t j d d  d  } t j d   j   | j d    | j   j	 d d i d d	 6f     f d
   } | j |  | S(   s   
        An L{IPerspective} implementation which does not subclass
        L{Avatar} can expose remote methods for the client to call.
        R   R  s   BRAINS!s	   127.0.0.1c         S   s   |  j  d d d d S(   Nt   ANYTHINGt   hereR   R  (   Ry   (   R  (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR%     s    R  R  R  R   c            s2    j    x!   j j D] } | j j   q Wd  S(   N(   R  RO   R   R>   R   (   R  R  (   R   RO   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR    s    
(   s   here(
   R   R   R  R   R  R   R   R  R   R   (   R   R   R  (    (   R   RO   s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_NSP  s    	(   R   R    R"   R   R  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR  u  s   	t
   IForwardedc           B   s    e  Z d  Z d   Z d   Z RS(   sA   
    Interface used for testing L{util.LocalAsyncForwarder}.
    c           C   s   d S(   s,   
        Simple synchronous method.
        N(    (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt	   forwardMe  s    c           C   s   d S(   s-   
        Simple asynchronous method.
        N(    (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   forwardDeferred  s    (   R   R    R"   R  R  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR     s   	t	   Forwardedc           B   s?   e  Z d  Z e e  e Z e Z d   Z d   Z	 d   Z
 RS(   s   
    Test implementation of L{IForwarded}.

    @ivar forwarded: set if C{forwardMe} is called.
    @type forwarded: C{bool}
    @ivar unforwarded: set if C{dontForwardMe} is called.
    @type unforwarded: C{bool}
    c         C   s   t  |  _ d S(   s6   
        Set a local flag to test afterwards.
        N(   R9   t	   forwarded(   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR    s    c         C   s   t  |  _ d S(   sv   
        Set a local flag to test afterwards. This should not be called as it's
        not in the interface.
        N(   R9   t   unforwarded(   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   dontForwardMe  s    c         C   s
   t  t  S(   s0   
        Asynchronously return C{True}.
        (   R   R9   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR    s    (   R   R    R"   R   R   R3   R  R  R  R  R  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR    s   
		t   SpreadUtilTestCasec           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s+   
    Tests for L{twisted.spread.util}.
    c         C   s)   t    } |  j | j d d  d  d S(   sk   
        Call a synchronous method of a L{util.LocalAsRemote} object and check
        the result.
        t   add1i   i   N(   R  R   Ry   (   R   Rm  (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt	   test_sync  s    	c         C   sQ   t    } t    } | j d d d d } |  j | t  | j |  j d  | S(   sm   
        Call an asynchronous method of a L{util.LocalAsRemote} object and check
        the result.
        R  i   R`   i   i   (   R  Ry   R   R   R   R   (   R   Rm  R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt
   test_async  s    		c            sD   t    } | j d  }   f d   } | j   f d   |  | S(   sF   
        Test a asynchronous failure on a remote method call.
        R   c            s*     j  t |  t j   |  j t  d  S(   N(   R  R   R   Rz  t   trapRg   (   t   f(   R   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   eb  s    c            s     j  d  S(   Ns   supposed to fail(   R   (   R   (   R   (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR%     s    (   R  Ry   R   (   R   Rm  R   R  (    (   R   s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_asyncFail  s
    	c         C   s2   t    } | j d  } |  j | d  d  d S(   sM   
        Test the C{remoteMethod} facility of L{util.LocalAsRemote}.
        R  i   i   N(   R  R   R   (   R   Rm  t   m(    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_remoteMethod  s    	c         C   s   t    } t j | t  } | j d  |  j | j  | j d  |  j | j  | j d  } g  } | j	 | j
  |  j | d d  d S(   se   
        Test a call to L{util.LocalAsyncForwarder} using L{Forwarded} local
        object.
        R  R  R  i    i   N(   R  R   t   LocalAsyncForwarderR   Ry   R  R  R  R  R   R   R   (   R   R  t   lft   rrR  (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_localAsyncForwarder  s    	(   R   R    R"   R	  R
  R  R  R  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR    s   				t   PBWithSecurityOptionsTestc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s&   
    Test security customization.
    c         C   s5   t  j   } | j d  } |  j | j t j  d S(   sl   
        By default, client broker should use C{jelly.globalSecurity} as
        security settings.
        N(   R   R   RI   R$   R   t   securityR   t   globalSecurity(   R   RO   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt!   test_clientDefaultSecurityOptions  s    c         C   s;   t  j t    } | j d  } |  j | j t j  d S(   sl   
        By default, server broker should use C{jelly.globalSecurity} as
        security settings.
        N(	   R   RG   R   RI   R$   R   R  R   R  (   R   RO   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt!   test_serverDefaultSecurityOptions  s    c         C   sD   t  j   } t j d |  } | j d  } |  j | j |  d S(   ss   
        Check that the security settings are passed from the client factory to
        the broker object.
        R  N(   R   t   SecurityOptionsR   R   RI   R$   R   R  (   R   R  RO   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt    test_clientSecurityCustomization%  s    c         C   sJ   t  j   } t j t   d | } | j d  } |  j | j |  d S(   ss   
        Check that the security settings are passed from the server factory to
        the broker object.
        R  N(	   R   R  R   RG   R   RI   R$   R   R  (   R   R  RO   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt    test_serverSecurityCustomization0  s    (   R   R    R"   R  R  R  R  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR    s
   	
	
	t   DeprecationTestsc           B   s    e  Z d  Z d   Z d   Z RS(   sS   
    Tests for certain deprecations of free-functions in L{twisted.spread.pb}.
    c      	   C   s8   |  j  t d d d d  t j d d d d d d	 d
 S(   s2   
        L{pb.noOperation} is deprecated.
        t   twistedi   i   i    i   R_   i   R`   i   N(   t   callDeprecatedR   R   t   noOperation(   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_noOperationDeprecated@  s    c         C   s)   |  j  t d d d d  t j d  d S(   s5   
        L{pb.printTraceback} is deprecated.
        R  i   i   i    s/   printTraceback deprecation fake traceback valueN(   R  R   R   t   printTraceback(   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   test_printTracebackI  s    (   R   R    R"   R!  R#  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyR  <  s   		(x   R"   R  R   R5   R  R  t	   cStringIOR    t   zope.interfaceR   R   t   twisted.python.versionsR   t   twisted.trialR   t   twisted.spreadR   R   R   R   t   twisted.internetR	   R
   R   t   twisted.internet.errorR   t   twisted.internet.deferR   R   R   t   twisted.protocols.policiesR   t   twisted.protocolsR   t   twisted.pythonR   R   t   twisted.cred.errorR   R   t   twisted.credR   R   R   t   ViewableR   R  R   R   R#   R-   R$   RS   R   RT   RY   t   CopyableR[   t
   RemoteCopyRb   t   setUnjellyableForClassRc   Rl   t   setUnjellyableFactoryForClassRm   t	   CacheableRq   Rs   Rt   t   RemoteCacheR   R   R   R   R   R   R   R   R   t   RootR   R   t   TestCaseR   RG   R   R   R   RD  R=  R>  RA  RB  RG  RL  t   PublishableRa  t   RemotePublishedRc  R/  Rh  RW   R~  Rq  Rp  t   LocalAsRemoteR  R  R  R  R  R  R  R  R  R   R  R  R  R  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/test/test_pb.pyt   <module>	   s   <"		>				"""@!6 
	
rD)#. '!?0