
    Yf6                     
   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
 ddlmZ ddlmZmZ ddlmZmZmZ ddlmZ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# ddl$m%Z% ddl&m'Z'm(Z( ddl)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1  G d de-j2                  Z3 G d de-j4                  Z5 eej6                   G d d                      Z7 G d d          Z8d Z9 G d d          Z: G d de#          Z;ddZ< G d  d!e-j=                  Z> G d" d#e-j=                  Z? G d$ d%e-j@                  ZA G d& d'e-jB                  ZC e-jD        eAeC            G d( d)e-j@                  ZEd* ZF e-jG        eEeF            G d+ d,e-j=                  ZH G d- d.e-jI                  ZJ G d/ d0e-j=                  ZK G d1 d2e-jI                  ZL G d3 d4e-jM                  ZN e-jD        eLeN            G d5 d6e-jM                  ZO e-jD        eJeO            G d7 d8e-j=                  ZP G d9 d:e-j=                  ZQ G d; d<e-j=                  ZR G d= d>e-j=                  ZS G d? d@e-j@        e-jB                  ZT e-jD        eTeT            G dA dBe-j@        e-jB                  ZU e-jD        eUeU            G dC dDe-jI        e-jM                  ZV e-jD        eVeV            G dE dFe-jW                  ZX G dG dHe-jW                  ZY G dI dJe1jZ                  Z[ G dK dLe-j\                  Z] G dM dNe1j^                  Z_ G dO dPe1j^                  Z`dQZadabdacdR Zd G dS dTe-j=                  Ze G dU dVe-j=                  Zf G dW dXe1j^                  Zg G dY dZe.jh                  Zi G d[ d\e.jj                  Zk G d] d^e-j=                  Zl e-jD        eiek            G d_ d`e1j^                  Zm G da dben          Zo G dc dde-j@                  Zp G de dfe-j=                  Zq G dg dhe/jr                  Zs ee-jt                   G di dje-j4                              Zu G dk dl          Zv G dm dne-j2                  Zw G do dpev          Zx G dq dre1j^                  Zy G ds dte1j^                  Zz ee-jt                   G du dv                      Z{ G dw dxe1j^                  Z| G dy dze          Z} ee}           G d{ d|                      Z~ G d} d~e1j^                  Z G d de1j^                  ZdS )z
Tests for Perspective Broker module.

TODO: update protocol level tests to use new connection API, leaving
only specific tests for old API.
    N)deque)BytesIO)Dict)	Interfaceimplementer)checkerscredentialsportal)UnauthorizedLoginUnhandledCredentials)addressmainprotocolreactor)DeferredgatherResultssucceed)ConnectionRefusedError)_FakeConnector)WrappingFactory)failurelog)	iterbytes)jellypbpublishutil)unittestc                       e Zd Zd ZdS )Dummyc                 4    t          |t                    rdS dS )Nzhello world!zgoodbye, cruel world!)
isinstanceDummyPerspectiveselfusers     M/var/www/html/env/lib/python3.11/site-packages/twisted/spread/test/test_pb.pyview_doNothingzDummy.view_doNothing(   s     d,-- 	+!>**    N)__name__
__module____qualname__r(    r)   r'   r    r    '   s#        + + + + +r)   r    c                       e Zd ZdZd ZdS )r#   zE
    An L{IPerspective} avatar which will be used in some tests.
    c                     t                      S N)r    r%   s    r'   perspective_getDummyViewPointz.DummyPerspective.perspective_getDummyViewPoint4   s    wwr)   N)r*   r+   r,   __doc__r2   r-   r)   r'   r#   r#   /   s-             r)   r#   c                       e Zd Zd ZdS )
DummyRealmc                 V    |D ]%}|t           j        u r|t          |          d fc S &d S )Nc                      d S r0   r-   r-   r)   r'   <lambda>z*DummyRealm.requestAvatar.<locals>.<lambda>=   s    $ r)   )r   IPerspectiver#   )r%   avatarIdmind
interfacesifaces        r'   requestAvatarzDummyRealm.requestAvatar:   sO     	G 	GE''.x88,,FFFF (	G 	Gr)   N)r*   r+   r,   r>   r-   r)   r'   r5   r5   8   s(        G G G G Gr)   r5   c                   *    e Zd ZdZd Zd Zd Zd ZdS )IOPumpz
    Utility to pump data between clients and servers for protocol testing.

    Perhaps this is a utility worthy of being in protocol.py?
    c                 >    || _         || _        || _        || _        d S r0   )clientserverclientIOserverIO)r%   rB   rC   rD   rE   s        r'   __init__zIOPump.__init__G   s"      r)   c                     d| _         t          j                    dz   }| j         sJ|                                 r8t          j                    |k    rdS | j         s|                                 4dS dS dS dS )z
        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.
        F   N)_stoptimepump)r%   timeouts     r'   flushzIOPump.flushM   s     
)++/* 	 	y{{W$$ * 	 	 	 	 	 	 	 	 	 	r)   c                     d| _         dS )zd
        Stop a running L{flush} operation, even if data remains to be
        transferred.
        TN)rI   r1   s    r'   stopzIOPump.stopZ   s    
 


r)   c                    | j                             d           | j                            d           | j                                         }| j                                        }| j                             d           | j                            d           | j                                          | j                                         | j        j                                         | j        j                                         t          |          D ]}| j        
                    |           t          |          D ]}| j        
                    |           |s|rdS dS )zX
        Move data back and forth.

        Returns whether any data was moved.
        r      )rD   seekrE   readtruncaterB   	transport_checkProducerrC   r   dataReceived)r%   cDatasDatabytes       r'   rK   zIOPump.pumpa   sQ    	11""$$""$$11      ,,...,,...e$$ 	+ 	+DK$$T****e$$ 	+ 	+DK$$T**** 	E 	11r)   N)r*   r+   r,   r3   rF   rM   rO   rK   r-   r)   r'   r@   r@   @   sZ         ! ! !        r)   r@   c                    d}                     |          }|                     |          }t                      }t                      }|                    t          j        |                     |                    t          j        |                     t          ||||          }d }	fd}
|                     |	|           |                     |	|           |                     |
           |                                 |||fS )al  
    Create a server and a client and connect the two with an
    L{IOPump}.

    @param test: the test case where the client and server will be
        used.
    @type test: L{twisted.trial.unittest.TestCase}

    @param clientFactory: The factory that creates the client object.
    @type clientFactory: L{twisted.spread.pb.PBClientFactory}

    @param serverFactory: The factory that creates the server object.
    @type serverFactory: L{twisted.spread.pb.PBServerFactory}

    @return: a 3-tuple of (client, server, pump)
    @rtype: (L{twisted.spread.pb.Broker}, L{twisted.spread.pb.Broker},
        L{IOPump})
    )	127.0.0.1c                 z    | j         s3|                     t          j        t          j                             d S d S r0   )disconnectedconnectionLostr   Failurer   CONNECTION_DONE)brokers    r'   maybeDisconnectz/connectServerAndClient.<locals>.maybeDisconnect   sA    " 	I!!'/$2F"G"GHHHHH	I 	Ir)   c                  n                          d t          j        t          j                             d S )N)	connectorreason)clientConnectionLostr   r`   r   ra   )clientFactorys   r'   disconnectClientFactoryz7connectServerAndClient.<locals>.disconnectClientFactory   s>    
 	**7?43G#H#H 	+ 	
 	
 	
 	
 	
r)   )buildProtocolStringIOmakeConnectionr   FileWrapperr@   
addCleanuprK   )testrh   serverFactoryaddrclientBrokerserverBrokerclientTransportserverTransportrK   rc   ri   s    `         r'   connectServerAndClientrv   {   s   & D ..t44L ..t44LjjOjjO 4_ E EFFF 4_ E EFFF,oOODI I I
 
 
 
 
 	OOO\222OOO\222OO+,,,IIKKKt++r)   c                   $    e Zd ZdZd Zd Zd ZdS )_ReconnectingFakeConnectorStatez
    Manages connection notifications for a
    L{_ReconnectingFakeConnector} instance.

    @ivar notifications: pending L{Deferreds} that will fire when the
        L{_ReconnectingFakeConnector}'s connect method is called
    c                 ,    t                      | _        d S r0   )r   notificationsr1   s    r'   rF   z(_ReconnectingFakeConnectorState.__init__   s    "WWr)   c                 V    t                      }| j                            |           |S )z
        Connection notification.

        @return: A L{Deferred} that fires when this instance's
            L{twisted.internet.interfaces.IConnector.connect} method
            is called.
        @rtype: L{Deferred}
        )r   rz   
appendleft)r%   notifiers     r'   notifyOnConnectz/_ReconnectingFakeConnectorState.notifyOnConnect   s)     ::%%h///r)   c                 ~    | j         r5| j                                                             |            | j         3dS dS )z1
        Fire all pending notifications.
        N)rz   popcallbackr1   s    r'   	notifyAllz)_ReconnectingFakeConnectorState.notifyAll   sS       	4""$$--d333   	4 	4 	4 	4 	4r)   N)r*   r+   r,   r3   rF   r~   r   r-   r)   r'   rx   rx      sK         % % %  4 4 4 4 4r)   rx   c                   ,     e Zd ZdZ fdZ fdZ xZS )_ReconnectingFakeConnectorzc
    A fake L{IConnector} that can fire L{Deferred}s when its
    C{connect} method is called.
    c                 X    t                                          |           || _        dS )a  
        @param address: An L{IAddress} provider that represents this
            connector's destination.
        @type address: An L{IAddress} provider.

        @param state: The state instance
        @type state: L{_ReconnectingFakeConnectorState}
        N)superrF   _state)r%   r   state	__class__s      r'   rF   z#_ReconnectingFakeConnector.__init__   s(     	!!!r)   c                 z    t                                                       | j                                         dS )zM
        A C{connect} implementation that calls C{reconnectCallback}
        N)r   connectr   r   )r%   r   s    r'   r   z"_ReconnectingFakeConnector.connect   s3     	r)   )r*   r+   r,   r3   rF   r   __classcell__)r   s   @r'   r   r      s[         

 
 
 
 
                 r)   r   c                     |pt                      }t          j        d          }t          j        t          j        ||g                    }t          j                    }t          | ||          S )z
    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).
       guest)guest)	r5   r   'InMemoryUsernamePasswordDatabaseDontUser   PBServerFactoryr
   PortalPBClientFactoryrv   )ro   realmcheckerrp   rh   s        r'   connectedServerAndClientr      sc     !Z\\E>XNNNG&v}UWI'F'FGGM&((M!$}EEEr)   c                       e Zd Zd Zd ZdS )SimpleRemotec                     || _         |dz   S NrQ   )argr%   r   s     r'   remote_thunkzSimpleRemote.remote_thunk       Qwr)   c                     t                      r0   )	Exceptionr   s     r'   remote_knuthzSimpleRemote.remote_knuth   s    kkr)   N)r*   r+   r,   r   r   r-   r)   r'   r   r      s2              r)   r   c                       e Zd Zd ZdS )NestedRemotec                     t                      S r0   )r   r1   s    r'   remote_getSimplezNestedRemote.remote_getSimple  s    ~~r)   N)r*   r+   r,   r   r-   r)   r'   r   r     s#            r)   r   c                       e Zd Zd ZdS )
SimpleCopyc                 6    d| _         ddi| _        dg| _        d S NrQ   HelloWorldro   xyzr1   s    r'   rF   zSimpleCopy.__init__  "    7#r)   Nr*   r+   r,   rF   r-   r)   r'   r   r     #            r)   r   c                       e Zd ZdS )SimpleLocalCopyNr*   r+   r,   r-   r)   r'   r   r             Dr)   r   c                   8    e Zd ZU dZi Zeed f         ed<   d ZdS )SimpleFactoryCopyz]
    @cvar allIDs: hold every created instances of this class.
    @type allIDs: C{dict}
    allIDsc                 2    || _         | t          j        |<   d S r0   )idr   r   )r%   r   s     r'   rF   zSimpleFactoryCopy.__init__  s    '+ $$$r)   N)	r*   r+   r,   r3   r   r   int__annotations__rF   r-   r)   r'   r   r     sL          
 .0FD))*///, , , , ,r)   r   c                    |                      dd          }|t          dt          |                      |t          j        vrt          dt          j                   t          j        |         }|st          d          |S )zl
    Factory of L{SimpleFactoryCopy}, getting a created instance given the
    C{id} found in C{state}.
    r   Nz&factory copy state has no 'id' member zfactory class has no ID: z&factory method found no object with id)getRuntimeErrorreprr   r   )r   stateIdinsts      r'   createFactoryCopyr   !  s    
 iid##GQDKKQQRRR'...Q7H7OQQRRR#G,D ECDDDKr)   c                       e Zd Zd Zd ZdS )
NestedCopyc                     t                      S r0   )r   r1   s    r'   remote_getCopyzNestedCopy.remote_getCopy5  s    ||r)   c                      t          |          S r0   )r   )r%   values     r'   remote_getFactoryzNestedCopy.remote_getFactory8  s     '''r)   N)r*   r+   r,   r   r   r-   r)   r'   r   r   4  s2          ( ( ( ( (r)   r   c                       e Zd Zd ZdS )SimpleCachec                 6    d| _         ddi| _        dg| _        d S r   r   r1   s    r'   	__init___zSimpleCache.__init___=  r   r)   N)r*   r+   r,   r   r-   r)   r'   r   r   <  r   r)   r   c                       e Zd Zd Zd ZdS )NestedComplicatedCachec                 ,    t                      | _        d S r0   )VeryVeryComplicatedCacheablecr1   s    r'   rF   zNestedComplicatedCache.__init__D  s    -//r)   c                     | j         S r0   )r   r1   s    r'   remote_getCachez&NestedComplicatedCache.remote_getCacheG  s	    vr)   N)r*   r+   r,   rF   r   r-   r)   r'   r   r   C  s2        0 0 0    r)   r   c                   &    e Zd Zd Zd Zd Zd ZdS )r   c                 0    d| _         d| _        d| _        d S )NrQ         r   r   foor1   s    r'   rF   z%VeryVeryComplicatedCacheable.__init__L  s    r)   c                 J    d| _         | j                            dd           d S )N   r   )r   observer
callRemoter1   s    r'   setFoo4z$VeryVeryComplicatedCacheable.setFoo4Q  s'      *****r)   c                 :    || _         | j        | j        | j        dS )Nr   )r   r   r   r   r%   perspectiver   s      r'   getStateToCacheAndObserveForz9VeryVeryComplicatedCacheable.getStateToCacheAndObserveForU  s     V$&:::r)   c                     t          j        d           |                    d           || j        k    r	d | _        d S d S )Nzstopped observingend)r   msgr   r   r   s      r'   stoppedObservingz-VeryVeryComplicatedCacheable.stoppedObservingY  sG    #$$$E"""t}$$ DMMM %$r)   N)r*   r+   r,   rF   r   r   r   r-   r)   r'   r   r   K  sP          
+ + +; ; ;! ! ! ! !r)   r   c                       e Zd Zd Zd ZdS )RatherBaroqueCachec                     || _         d S r0   r   )r%   newFoos     r'   observe_foozRatherBaroqueCache.observe_fooa  s    r)   c                 .    t          j        d           d S )Nzthe end of things)r   r   r1   s    r'   observe_endzRatherBaroqueCache.observe_endd  s    #$$$$$r)   N)r*   r+   r,   r   r   r-   r)   r'   r   r   `  s2          % % % % %r)   r   c                   &    e Zd Zd Zd Zd Zd ZdS )SimpleLocalCachec                 :    | j                             |           d S r0   )__dict__update)r%   r   s     r'   setCopyableStatez!SimpleLocalCache.setCopyableStatel  s    U#####r)   c                     | j         S r0   )checkr1   s    r'   checkMethodzSimpleLocalCache.checkMethodo  
    zr)   c                     | S r0   r-   r1   s    r'   	checkSelfzSimpleLocalCache.checkSelfr  s    r)   c                     dS r   r-   r1   s    r'   r   zSimpleLocalCache.checku  s    qr)   N)r*   r+   r,   r   r   r   r   r-   r)   r'   r   r   k  sP        $ $ $        r)   r   c                        e Zd Zd Zd Zd ZdS )NestedCachec                 ,    t                      | _        d S r0   )r   r   r1   s    r'   rF   zNestedCache.__init__}  s    r)   c                     | j         | j         gS r0   r   r1   s    r'   r   zNestedCache.remote_getCache  s    r)   c                     | j         |u S r0   r  r%   caches     r'   remote_putCachezNestedCache.remote_putCache  s    vr)   N)r*   r+   r,   rF   r   r  r-   r)   r'   r   r   |  sA                   r)   r   c                   &    e Zd Zd Zd Zd Zd ZdS )
Observablec                     g | _         d S r0   )	observersr1   s    r'   rF   zObservable.__init__  s    r)   c                 :    | j                             |           d S r0   )r  appendr%   obss     r'   remote_observezObservable.remote_observe      c"""""r)   c                 :    | j                             |           d S r0   )r  remover  s     r'   remote_unobservezObservable.remote_unobserve  r  r)   c                 H    | j         D ]}|                    d| |           d S )Nnotify)r  r   )r%   objr   s      r'   r  zObservable.notify  s8     	5 	5H$4444	5 	5r)   N)r*   r+   r,   rF   r  r  r  r-   r)   r'   r	  r	    sP          # # ## # #5 5 5 5 5r)   r	  c                   &    e Zd Zd Zd Zd Zd ZdS )DeferredRemotec                     d| _         d S )Nr   runr1   s    r'   rF   zDeferredRemote.__init__  s    r)   c                     || _         |dz   S r   r  r   s     r'   runMezDeferredRemote.runMe  r   r)   c                     J d            )Nr   zshouldn't have been run!r-   r   s     r'   	dontRunMezDeferredRemote.dontRunMe  s    ,,,,qr)   c                 p    t                      }|                    | j        | j                   || _        |S )zo
        Return a L{Deferred} to be fired on client side. When fired,
        C{self.runMe} is called.
        )r   addCallbacksr  r   d)r%   r#  s     r'   remote_doItLaterzDeferredRemote.remote_doItLater  s1    
 JJ	tz4>222r)   N)r*   r+   r,   rF   r  r   r$  r-   r)   r'   r  r    sP            - - -    r)   r  c                       e Zd ZdZdZd ZdS )Observerr   Nc                 ^    || _         | j        dz   | _        |                    d|            d S )NrQ   	unobserve)r  notifiedr   )r%   otherr  s      r'   remote_notifyzObserver.remote_notify  s3    )d+++++r)   )r*   r+   r,   r)  r  r+  r-   r)   r'   r&  r&    s-        H
C, , , , ,r)   r&  c                       e Zd Zd ZdS )NewStyleCopyc                     || _         d S r0   )s)r%   r/  s     r'   rF   zNewStyleCopy.__init__  s    r)   Nr   r-   r)   r'   r-  r-    s#            r)   r-  c                   &    e Zd ZdZdZdZd Zd ZdS )NewStyleCopy2r   rQ   c                 r    t           xj        dz  c_        t                              |           }d|_        |S )NrQ   r   )r1  	allocatedobject__new__r   )r%   r   s     r'   r5  zNewStyleCopy2.__new__  s3    1$~~d##
r)   c                 0    t           xj        dz  c_        d S r   )r1  initializedr1   s    r'   rF   zNewStyleCopy2.__init__  s    !!Q&!!!!r)   N)r*   r+   r,   r3  r7  r   r5  rF   r-   r)   r'   r1  r1    sA        IKE  ' ' ' ' 'r)   r1  c                       e Zd Zd ZdS )NewStyleCacheCopyc                     | j         S r0   )r   r   s      r'   r   z.NewStyleCacheCopy.getStateToCacheAndObserveFor  s
    }r)   N)r*   r+   r,   r   r-   r)   r'   r9  r9    s#            r)   r9  c                       e Zd Zd Zd ZdS )Echoerc                     |S r0   r-   r%   sts     r'   remote_echozEchoer.remote_echo  s    	r)   c                 
    ||fS r0   r-   )r%   r?  kws      r'   remote_echoWithKeywordszEchoer.remote_echoWithKeywords  s    Bxr)   N)r*   r+   r,   r@  rC  r-   r)   r'   r<  r<    s2              r)   r<  c                       e Zd Zd Zd ZdS )CachedReturnerc                     || _         d S r0   r  r  s     r'   rF   zCachedReturner.__init__  s    


r)   c                     | j         S r0   rG  r>  s     r'   remote_giveMeCachez!CachedReturner.remote_giveMeCache  r   r)   N)r*   r+   r,   rF   rI  r-   r)   r'   rE  rE    s2              r)   rE  c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )NewStyleTestsc                    t          j        t                                | _        t          j                    }t          | || j                  \  }| _        | _        |                     |	                                          | _
        dS )zY
        Create a pb server using L{Echoer} protocol and connect a client to it.
        )ro   rh   rp   N)r   r   r<  rp   r   rv   rC   rK   successResultOfgetRootObjectref)r%   rh   rB   s      r'   setUpzNewStyleTests.setUp  sy      /99*,,)?]$BT*
 *
 *
&TY ''(C(C(E(EFFr)   c                 N    dt           _        dt           _        dt           _        dS )zp
        Close client and server connections, reset values of L{NewStyleCopy2}
        class variables.
        r   rQ   N)r1  r3  r7  r   r1   s    r'   tearDownzNewStyleTests.tearDown  s"    
 #$$%!r)   c                      t          d           j                            d          } j                                          fd}|                    |           |S )zY
        Create a new style object, send it over the wire, and check the result.
        r   echoc                                          | t                                         | j        d                               | u            d S )Nr   )assertIsInstancer-  assertEqualr/  assertFalseresorigr%   s    r'   cbz'NewStyleTests.test_newStyle.<locals>.cb  sO    !!#|444SUG,,,SD[)))))r)   r-  rO  r   rK   rM   addCallbackr%   r#  r\  r[  s   `  @r'   test_newStylezNewStyleTests.test_newStyle  ss     G$$H--		* 	* 	* 	* 	* 	*
 	
br)   c                 D    t                                           t           j        d                                t           j        d            j                            d          } j                                          fd}|                    |           |S )zN
        Send a new style object and check the number of allocations.
        rQ   rT  c                                          | t                                         | j        d                               t          j        d                               t          j        d                               |            d S )Nr   r   rQ   )rV  r1  rW  r   r3  r7  assertIsNotrY  s    r'   r\  z$NewStyleTests.test_alloc.<locals>.cb  s    !!#}555SY***]4a888]6:::S$'''''r)   )	r1  rW  r3  r7  rO  r   rK   rM   r^  r_  s   `  @r'   
test_alloczNewStyleTests.test_alloc  s     0!4442A666H--		( 	( 	( 	( 	( 	( 	
br)   c                      t          d           j                            ddd          } j                                          fd}|                    |           |S )zo
        Create a new style object with keywords,
        send it over the wire, and check the result.
        value1echoWithKeywordsonetwokeyword1keyword2c                 z                        | t                                          | d         t                                          | d         t                                         | d         j        d                               | d                                        | d         ddd           d S )Nr   rQ   rf  rh  ri  rj  )rV  tupler-  dictrW  r/  rc  rY  s    r'   r\  z3NewStyleTests.test_newStyleWithKeywords.<locals>.cb.  s    !!#u---!!#a&,777!!#a&$///SVXx000SVT***SV%U%K%KLLLLLr)   r]  r_  s   `  @r'   test_newStyleWithKeywordsz'NewStyleTests.test_newStyleWithKeywords#  s    
 H%%Huu   
 
 			M 	M 	M 	M 	M 	M 	
br)   N)r*   r+   r,   rP  rR  r`  rd  rp  r-   r)   r'   rK  rK    sb        	G 	G 	G          ,    r)   rK  c                   "    e Zd ZdZdZd Zd ZdS )ConnectionNotifyServerFactoryaj  
    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}
    Nc                 l    t           j                            | |           t                      | _        dS )z)
        Initialize the factory.
        N)r   r   rF   r   connectionMade)r%   roots     r'   rF   z&ConnectionNotifyServerFactory.__init__I  s/     	##D$///&jjr)   c                 d    || _         | j        dc}| _        ||                    d           dS dS )zF
        Store the protocol and fire the connection deferred.
        N)protocolInstancert  r   )r%   r   r#  s      r'   clientConnectionMadez2ConnectionNotifyServerFactory.clientConnectionMadeP  sB     !)!%!4d4=JJt =r)   )r*   r+   r,   r3   rw  rF   rx  r-   r)   r'   rr  rr  :  sD        
 
 ) ) )    r)   rr  c                        e Zd Zd Zd Zd ZdS )NewStyleCachedTestsc                     t                       _        d j        _        t          j        dt          t           j                                       _        t          j	                    }t          j
        d j                                        j        |            fd}|                                                    |          } j        j        j        }t#          ||g          S )zi
        Create a pb server using L{CachedReturner} protocol and connect a
        client to it.
        r   r   	localhostc                     | _         d S r0   )rO  )rO  r%   s    r'   gotRootz*NewStyleCachedTests.setUp.<locals>.gotRooth  s    DHHHr)   )r9  r[  r/  r   	listenTCPrr  rE  rC   r   r   
connectTCPgetHostportrN  r^  factoryrt  r   )r%   rh   r~  d1d2s   `    r'   rP  zNewStyleCachedTests.setUp[  s    
 &''		',^DI-F-FGG
 
 *,,;(;(;(=(=(BMRRR	 	 	 	 	 ((**66w??[ /b"X&&&r)   c                     | j         j        j        j                                         | j        j        j                                         | j                                         S )z6
        Close client and server connections.
        )rC   r  rw  rU   loseConnectionrO  rb   stopListeningr1   s    r'   rR  zNewStyleCachedTests.tearDowno  sN     	,6EEGGG!00222{((***r)   c                       j                             d j                  } fd}|                    |d           |                    |d           |S )z
        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.
        giveMeCachec                                          | t                                         d| j                                       j        |            |r'| _        j                            dj                  S d S )Nr   r  )	rV  r9  rW  r/  rc  r[  rZ  rO  r   )rZ  againr%   s     r'   r\  z2NewStyleCachedTests.test_newStyleCache.<locals>.cb  s    !!#'8999Wce,,,TY,,, E x**=$)DDDE Er)   TF)rO  r   r[  r^  )r%   r#  r\  s   `  r'   test_newStyleCachez&NewStyleCachedTests.test_newStyleCachew  sk     Hty99	E 	E 	E 	E 	E 	
b$	b%   r)   N)r*   r+   r,   rP  rR  r  r-   r)   r'   rz  rz  Z  sA        ' ' '(+ + +    r)   rz  c                   x    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S )BrokerTestsNc                 R    	 t          j        d           d S # t          $ r Y d S w xY w)NNone-None-TESTING.pub)osunlinkOSErrorr1   s    r'   rR  zBrokerTests.tearDown  s@    	I-..... 	 	 	DD	s    
&&c                 6    |                      d|            d S )Nz&This should cause a return value, not fail)r%   errors     r'   thunkErrorBadzBrokerTests.thunkErrorBad  s#    		B5BBCCCCCr)   c                     || _         d S r0   )thunkResultr%   results     r'   thunkResultGoodzBrokerTests.thunkResultGood  s    !r)   c                     d S r0   r-   )r%   tbs     r'   thunkErrorGoodzBrokerTests.thunkErrorGood      r)   c                 6    |                      d|            d S )Nz This should cause an error, not r  r  s     r'   thunkResultBadzBrokerTests.thunkResultBad  s#    		=V==>>>>>r)   c                 r   t          |           \  }}} G d dt          j                  } G d dt          j                  }|                    d |                       |                    d          } |            } |            }|                    d||           |                                 |                                 |                                 |                     |j        |d           | 	                    |
                    d          |
                    d                     d S )	Nro   c                       e Zd Zd ZdS )%BrokerTests.test_reference.<locals>.Xc                     || _         d S r0   )caughtr   s     r'   remote_catchz2BrokerTests.test_reference.<locals>.X.remote_catch  s    !r)   N)r*   r+   r,   r  r-   r)   r'   Xr    s#        " " " " "r)   r  c                       e Zd Zd ZdS )%BrokerTests.test_reference.<locals>.Yc                 2    |                     d|           d S )Ncatchr   r%   abs      r'   remote_throwz2BrokerTests.test_reference.<locals>.Y.remote_throw  s    Wa(((((r)   N)r*   r+   r,   r  r-   r)   r'   Yr    s#        ) ) ) ) )r)   r  r   throwzX should have caught Z)r   r   ReferenceablesetNameForLocalremoteForNamer   rK   assertIsr  rW  remoteMethod)	r%   r   r/  rK   r  r  r   r   r   s	            r'   test_referencezBrokerTests.test_reference  sC   -4888
1d	" 	" 	" 	" 	"  	" 	" 	"	) 	) 	) 	) 	)  	) 	) 	) 	
#qqss###OOC  ACCACC	Wa###						ah#;<<< 	00!..2I2IJJJJJr)   c                    t          |           \  }}}||f||ffD ]\  }}t                      }|                    d|           |                    d          }d| _        |                    d| j        dz
                                | j        | j                   |	                                 |	                                 | 
                    | j        | j        d           d S )Nr  r      thunkrQ   zresult wasn't received.)r   r   r  r  expectedThunkResultr   r"  r  r  rK   rW  r  )r%   r   r/  rK   r   r   r   bars           r'   test_resultzBrokerTests.test_result  s    -4888
1dFQFN 	 	DAq..CeS)))//%((C'(D$NN7D$<q$@AANN$d&8   IIKKKIIKKK $":<U   	 	r)   c                     || _         d S r0   )nestedRemoter  s     r'   refcountResultzBrokerTests.refcountResult  s    "r)   c           
      t   g }g }t          |           \  }}}t                      }|                    d|           |                    d          }t	          t
          j        dz             D ]c}|j        j        s|j        j        r nH|	                    d          
                    |j        |j                   |                                 dt
          j        dz
  }	|                     |j        j        d           |                     t          |          |	d|	 dt          |                      d S )	Nr  r   
   	getSimplerQ   ztransport was not closedz	expected z got )r   r   r  r  ranger   MAX_BROKER_REFSrU   closedr   r"  r  rK   
assertTruerW  len)
r%   ler   r/  rK   r   r   ignoexpecteds
             r'   test_tooManyRefszBrokerTests.test_tooManyRefs  s&   -4888
1dnn	%%%%OOE""",r122 	 	D{! Q[%7 LL%%2218QXFFFIIKKKK%)*,FGGGQ+Nx+N+Nc!ff+N+NOOOOOr)   c                 .   t          |           \  }}}t                      }|                    d|           |                    d          }|                    d                              | j        | j                   |                                 |                                 | 	                    | j
        j        d           | 	                    | j
        j        d         d           | 	                    | j
        j        d         d           d S )	Nr  r   getCopyrQ   r   r   r   ro   )r   r   r  r  r   r"  r  r  rK   rW  r  r   r   r   )r%   r   r/  rK   r   r   s         r'   	test_copyzBrokerTests.test_copy  s    -4888
1dll	%%%%OOE""	Y,,T-A4CUVVV				)+Q///)+G4g>>>)+A.77777r)   c                 r   t          |           \  }}}t                      }t                      }|                    d|           |                    d          }|                    d|           |                                 |                    d           |                                 |                                 |                    d           |                                 |                                 |                     |j	        d           | 
                    |j	        dd           d S )Nr  r  observerQ   r  zdidn't notifyznotified too much)r   r	  r&  r  r  r   rK   r  assertIsNotNoner  rW  )r%   r   r/  rK   r  r  ras          r'   test_observezBrokerTests.test_observe  s    -4888
1d LLJJ	#q!!!__S!!
i###												QUO444#677777r)   c                    t          |           \  }}}t                      }|                    d|           |                    d          }|                                 |                                 g }|                    d                              |j                   |                                 |                                 |                     |j	        d           |j
                            d           |                     |j	        dd           |                                 |                                 |                     |d         dd	           d S )
Nr  r#  	doItLaterzDeferred method run too early.rH   zDeferred method run too late.r      zIncorrect result.)r   r  r  r  rK   r   r^  r  rX  r  r#  r   rW  )r%   r   r/  rK   r#  r  resultss          r'   
test_deferzBrokerTests.test_defer  s'   -4888
1d	#q!!!OOC  					[!!--gn===				 @AAA	Q#BCCC				Q(;<<<<<r)   c                    t          |           \  }}}t                      }|                    d|           |                    d          }|                    d                              | j        | j                   |                                 |                                 | j	        j
        }|                     ||j                   | `	t          j        dk    rt          j                     |                                 |                                 |                                 |                     ||j                   d S )Nr  r   r     )r   r   r  r  r   r"  r  r  rK   r  luidassertInlocalObjectssys
hexversiongccollectassertNotIn)r%   r   r/  rK   r   r  rluids          r'   test_refcountzBrokerTests.test_refcount  s   -4888
1dnn	%%%%ooe$${##00!3	
 	
 	

 					 !&eQ^,,,>Y&&JLLL						/////r)   c                    t          |           \  }}}t                      }t                      }|j        }|                    d|           |                    d|           |                    d          }|                    d          }g }	|                    d                              |	j                  	                    |	j                   |                    d                              |	j                  	                    |	j                   g }
|                    d                              |
j                   |                    d                              |
j                   |
                                 |                     |
d         j        d           |                     |
d         j        d           |                     |
d         j        d           |                                 |
                                 |                     |
d         j        d	           |                     t!          |	          d           |	d         d         }|                     |                                j        |d
           |                     |                                |d           g }|                    d|                              |j                   |
                                 |                     |d                    |                     |                    d          |                    d                     |j        }|
d         j        }|                     ||j        d           ~	~|
                                 ~
~|
                                 t4          j        dk    rt9          j                     |
                                 |                     ||j        d           |                     ||j        d           |                     ||j        d           |                     ||j        d           |                      |j!        d           d S )Nr  r  xxxgetCacher   rQ   r   r   r   zpotential refcounting issuez!other potential refcounting issueputCachezremote cache doesn't have itr  zServer still had it after GCzClient still had it after GCz!Server still had complex after GCz!Client still had complex after GCzobserver was not removed)"r   r   r   r   r  r  r   r^  r  
addErrbackrM   rW  r   r   r   r   r  assertIdenticalr   __self__r   r  r  r  r  remotelyCachedObjectsr  r  r  r  r  locallyCachedObjectsassertIsNoner   )r%   r   r/  rK   r  obj2vcco2o3collcomplexcpcol2r  baroqueLuids                  r'   
test_cachezBrokerTests.test_cache4  s   -4888
1dmm%''f	%%%%	%&&&__U##__U##
j!!--dk::EEdkRRR
j!!--dk::EEdkRRR
j!!--gn===
j!!--gn===

q)))q)))+++

+++TA&&&!WQZNN%r+H	
 	
 	
 	R\\^^R1TUUU
j"%%11$+>>>

Q   44booj6Q6QRRR wajodA35STTT



 >Y&&JLLL

q68VWWWq57UVVV02U	
 	
 	
 	/1T	
 	
 	
 	#,(BCCCCCr)   c                    	 t          j        d           n# t          $ r Y nw xY wt          |           \  }}}t	                      }|                    d|           |                    d          }g }|                    d                              |j	        | j
                   |                                 |                                }|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           t          |           \  }}}|                    d|           |                    d          }|                    d                              |j	        | j
                   |                                 |                                }|                     |j        d           d S )Nr  r  r   getPubrQ   r   )r  r  r  r   GetPublisherr  r  r   r"  r  r  rM   r   rW  activateCalledisActivatedyayIGotPublished_wasCleanWhenLoaded)r%   r   r/  rK   r   r  accumr  s           r'   test_publishablezBrokerTests.test_publishablev  s   	I-.... 	 	 	D	-4888
1dnn	%%%%ooe$$x  --elD<NOOO

iikk+Q///!,,,-q1110!444-4888
1d	%%%%ooe$$x  --elD<NOOO

iikk0!44444s    
$$c                     |j         | _        d S r0   )r   r  )r%   vals     r'   gotCopyzBrokerTests.gotCopy  s    6r)   c                    t          |           \  }}}d}t                      }|                    d|           |                    d          }|                    d|                              | j        | j                   |                                 |                                 |                                 | 	                    | j
        |d| j
                    d S )Nr  c   r   
getFactoryz!ID not correct on factory object )r   r   r  r  r   r"  r  r  rK   rW  r  )r%   r   r/  rK   IDr  r   s          r'   test_factoryCopyzBrokerTests.test_factoryCopy  s    -4888
1dll	%%%%OOE""	\2&&33DL$BUVVV						B0@BB	
 	
 	
 	
 	
r)   )r*   r+   r,   r  rR  r  r  r  r  r  r  r  r  r  r  r  r  r   r	  r  r  r-   r)   r'   r  r    s(       K  D D D" " "  ? ? ?K K K0  (# # #P P P 
8 
8 
88 8 8(= = =$0 0 08@D @D @DD5 5 58" " "
 
 
 
 
r)   r  s  helloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldc                      | a |ad S r0   )callbackArgscallbackKeyword)argsrB  s     r'   finishedCallbackr    s    LOOOr)   c                       e Zd Zd Zd ZdS )	Pagerizerc                 2    |||c| _         | _        | _        d S r0   )r   r  rB  )r%   r   r  rB  s       r'   rF   zPagerizer.__init__  s    ,4dB)ty$'''r)   c                 z    t          j        |t          d| j        g| j        R i | j         d x| _        | _        d S )Nd   )r   StringPager	bigStringr   r  rB  r%   	collectors     r'   remote_getPageszPagerizer.remote_getPages  sT    y#t}	
7;y	
 	
 	
DHG	
 	
 	
 #"	DGGGr)   N)r*   r+   r,   rF   r   r-   r)   r'   r  r    s2        ? ? ?# # # # #r)   r  c                       e Zd ZdZd Zd ZdS )FilePagerizerNc                 @    || _         |||c| _        | _        | _        d S r0   )filenamer   r  rB  )r%   r$  r   r  rB  s        r'   rF   zFilePagerizer.__init__  s#     ,4dB)ty$'''r)   c                     t          j        |t          | j        d          | j        g| j        R i | j        | _        d x| _        | _        d S )Nrb)r   	FilePageropenr$  r   r  rB  pagerr  s     r'   r   zFilePagerizer.remote_getPages  s\    ^tDM400$-
BF)
 
 
OSw
 

 #"	DGGGr)   )r*   r+   r,   r)  rF   r   r-   r)   r'   r"  r"    s7        E? ? ?# # # # #r)   r"  c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	PagingTestsz0
    Test pb objects sending data by pages.
    c                     |                                  | _        t          | j        d          5 }|                    t                     ddd           dS # 1 swxY w Y   dS )z?
        Create a file used to test L{util.FilePager}.
        wbN)mktempr$  r(  writer  )r%   fs     r'   rP  zPagingTests.setUp  s     $-&& 	!GGI	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc                    t          |           \  }}}|                    dt          t          dd                     |                    d          }g }t          j        |d                              |j                   |s|	                                 || 
                    d                    |d                   t          d	           | 
                    t          d
d           | 
                    t          ddid           dS )zg
        Test L{util.StringPager}, passing a callback to fire when all pages
        are sent.
        r  r   hellor  r   getPagesr)   r   'Pages received not equal to pages sent!)r2  Completed callback not invokedr   N)r   r  r  r  r  r   getAllPagesr^  r  rK   rW  joinr  r  r  r%   r   r/  rK   r   r  s         r'   test_pagingWithCallbackz#PagingTests.test_pagingWithCallback  s   
 .4888
1d	%+;WB!O!O!OPPPOOE""J''33AH=== 	IIKKK  	HHQqTNNI'P	
 	
 	
 	z3STTTgr],L	
 	
 	
 	
 	
r)   c                    t          |           \  }}}|                    dt          d                     |                    d          }g }t	          j        |d                              |j                   |s|                                 || 	                    d
                    |d                   t          d           dS )z>
        Test L{util.StringPager} without a callback.
        r  r   Nr4  r)   r   r5  )r   r  r  r  r   r7  r^  r  rK   rW  r8  r  r9  s         r'   test_pagingWithoutCallbackz&PagingTests.test_pagingWithoutCallback  s     .4888
1d	%4111OOE""J''33AH=== 	IIKKK  	HHQqTNNI'P	
 	
 	
 	
 	
r)   c                 R   |                                  }t          |d                                           t          |           \  }}}t	          |d          }|                    d|           |                    d          }g }t          j        |d          	                    |j
                   d}|s'|dk    r!|                                 |dz  }|s|dk    !|s|                     d	           |                     d
                    |d                   d
d           dS )z@
        Test L{util.FilePager}, sending an empty file.
        wr  Nr  r4  r  r   rQ   zgetAllPages timed outr)   r5  )r.  r(  closer   r"  r  r  r   r7  r^  r  rK   r  rW  r8  )	r%   filenameEmptyr   r/  rK   	pagerizerr   r  ttls	            r'   test_emptyFilePagingz PagingTests.test_emptyFilePaging  s(    ]C  &&(((-4888
1d!-66		%+++OOE""J''33AH=== 	aIIKKK1HC  	a  	/II-...!A$.WXXXXXr)   c                 j   t          |           \  }}}t          | j        t          dd          }|                    d|           |                    d          }g }t          j        |d                              |j	                   |s|
                                 ||                     d                    |d                   t          d	           |                     t          d
d           |                     t          ddid           |                     |j        j        g            dS )z
        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.
        r  frodo	   r3  r  r4  r)   r   r5  )rE  r6  r   N)r   r"  r$  r  r  r  r   r7  r^  r  rK   rW  r8  r  r  r  r)  chunksr%   r   r/  rK   rA  r   r  s          r'   test_filePagingWithCallbackz'PagingTests.test_filePagingWithCallback  s2   
 .4888
1d!$-1A7RSTTT		%+++OOE""J''33AH=== 	IIKKK  	HHQqTNNI'P	
 	
 	
 	z3STTTgq\+K	
 	
 	
 	/44444r)   c                    t          |           \  }}}t          | j        d          }|                    d|           |                    d          }g }t          j        |d                              |j                   |s|	                                 || 
                    d                    |d                   t          d           | 
                    |j        j        g            dS )z<
        Test L{util.FilePager} without a callback.
        r  Nr  r4  r)   r   r5  )r   r"  r$  r  r  r   r7  r^  r  rK   rW  r8  r  r)  rG  rH  s          r'   test_filePagingWithoutCallbackz*PagingTests.test_filePagingWithoutCallback%  s     .4888
1d!$-66		%+++OOE""J''33AH=== 	IIKKK  	HHQqTNNI'P	
 	
 	
 	/44444r)   N)
r*   r+   r,   r3   rP  r:  r<  rC  rI  rK  r-   r)   r'   r+  r+    s{           
 
 
(
 
 
Y Y Y(5 5 5,5 5 5 5 5r)   r+  c                       e Zd Zd ZdS )DumbPublishablec                 
    ddiS )Nr  rQ   r-   r1   s    r'   getStateToPublishz!DumbPublishable.getStateToPublish8  s    "A&&r)   N)r*   r+   r,   rO  r-   r)   r'   rM  rM  7  s#        ' ' ' ' 'r)   rM  c                       e Zd Zd ZdS )DumbPubc                     d| _         d S r   )r  r1   s    r'   	activatedzDumbPub.activated=  s    r)   N)r*   r+   r,   rS  r-   r)   r'   rQ  rQ  <  s#                 r)   rQ  c                       e Zd Zd Zd ZdS )r  c                 .    t          d          | _        d S )NTESTING)rM  pubr1   s    r'   rF   zGetPublisher.__init__B  s    "9--r)   c                     | j         S r0   )rW  r1   s    r'   remote_getPubzGetPublisher.remote_getPubE  s	    xr)   N)r*   r+   r,   rF   rY  r-   r)   r'   r  r  A  s2        . . .    r)   r  c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )DisconnectionTestsz'
    Test disconnection callbacks.
    c                 &    t          d|           )NzI shouldn't have been called: r   )r%   r  s     r'   r  zDisconnectionTests.errorQ  s    BDBBCCCr)   c                     d| _         dS )z.
        Called on broker disconnect.
        rQ   N)gotCallbackr1   s    r'   gotDisconnectedz"DisconnectionTests.gotDisconnectedT  s     r)   c                 J    |                      || j                   d| _        dS )z7
        Called on RemoteReference disconnect.
        rQ   N)rW  remoteObjectobjectCallbackr%   os     r'   objectDisconnectedz%DisconnectionTests.objectDisconnectedZ  s+     	D-...r)   c                    t          |           \  }}}|                                 |                    dt                                 |                    d          }g }|                    dt                                                    |j                   |	                                 | 
                    t          |          d           d S )Nr  re  
setBadCopyrQ   )r   rK   r  
BadCopySetr  r   BadCopyabler  r  rM   rW  r  )r%   r   r/  rK   gr  s         r'   test_badSerializationz(DisconnectionTests.test_badSerializationa  s    -4888
1d			#z||,,,OOC  	\;==11<<QXFFF

Q#####r)   c                    t          |           \  }}}|                                 |                    dt                                 |                    d          }|                                 |                                 |                                 |                    | j                   |                     | j        |j                   |	                    | j                   | 
                    | j        |j                   |                    | j                   |                     |j        |j                   |                     | j        |j                   |	                    | j                   | 
                    |j        |j                   | 
                    | j        |j                   |                    | j                   |                    | j                   || _        |                    t#          j        t&          j                             |                     | j                   |                     | j                   d S )Nr  re  )r   rK   r  r   r  notifyOnDisconnectr  r  disconnectsdontNotifyOnDisconnectr  _disconnecteddisconnectCallbacksr`  rf  rb  r_   r   r`   r   ra   r  r_  rc  )r%   r   r/  rK   rs        r'   test_disconnectionz%DisconnectionTests.test_disconnectionk  s   -4888
1d			#|~~... OOC  						 	
TZ(((dj!-000	  ,,,Q]333	TZ(((aoq}555dj!"7888	  ,,,!-888Q%:;;; 	
T1222	T4555 	
)=>>???()))+,,,,,r)   N)	r*   r+   r,   r3   r  r`  rf  rl  rt  r-   r)   r'   r[  r[  L  sl         D D D       $ $ $!- !- !- !- !-r)   r[  c                       e Zd ZdS )FreakOutNr   r-   r)   r'   rv  rv    r   r)   rv  c                       e Zd Zd ZdS )rj  c                     t                      r0   )rv  )r%   ps     r'   getStateToCopyForzBadCopyable.getStateToCopyFor  s    jjr)   N)r*   r+   r,   rz  r-   r)   r'   rj  rj    s#            r)   rj  c                       e Zd Zd ZdS )ri  c                     d S r0   r-   )r%   bcs     r'   remote_setBadCopyzBadCopySet.remote_setBadCopy  s    tr)   N)r*   r+   r,   r~  r-   r)   r'   ri  ri    s#            r)   ri  c                   &    e Zd ZdZd ZddZd ZdS )LocalRemoteTestr   c                     |dz   S r   r-   )r%   r   s     r'   	sync_add1zLocalRemoteTest.sync_add1      1ur)   rQ   c                     ||z   S r0   r-   )r%   r   r   s      r'   	async_addzLocalRemoteTest.async_add  r  r)   c                     t                      r0   r]  r1   s    r'   
async_failzLocalRemoteTest.async_fail  s    nnr)   N)r   rQ   )r*   r+   r,   reportAllTracebacksr  r  r  r-   r)   r'   r  r    sL                 r)   r  c                   8    e Zd ZdZdxZZd Zd Zd Zd Z	d Z
dS )	MyPerspectivez
    @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}
    Fc                     || _         d S r0   r:   r%   r:   s     r'   rF   zMyPerspective.__init__  s     r)   c                     | j         S )zT
        Return the avatar identifier which was used to access this avatar.
        r  r1   s    r'   perspective_getAvatarIdz%MyPerspective.perspective_getAvatarId  s     }r)   c                     t                      S r0   )MyViewr1   s    r'   perspective_getViewPointz&MyPerspective.perspective_getViewPoint  s    xxr)   c                     ||z   S )z
        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  s      r'   perspective_addzMyPerspective.perspective_add  s     1ur)   c                     d| _         d S NT	loggedOutr1   s    r'   logoutzMyPerspective.logout      r)   N)r*   r+   r,   r3   loggedInr  rF   r  r  r  r  r-   r)   r'   r  r    su          ! Hy! ! !          r)   r  c                        e Zd ZdZeZdZd ZdS )	TestRealma  
    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}.
    Nc                    |t           j        k    sJ |dk    sJ |t          j        u rt           j        t	                      d fS |                     |          | _        d| j        _        t           j        | j        | j        j        fS )z
        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.
        BRAINS!c                      d S r0   r-   r-   r)   r'   r8   z)TestRealm.requestAvatar.<locals>.<lambda>  s    d r)   T)	r   r9   r   	ANONYMOUSr<  perspectiveFactorylastPerspectiver  r  )r%   r:   r;   	interfaces       r'   r>   zTestRealm.requestAvatar  s     BO++++y    x)))?FHHll::#'#:#:8#D#DD ,0D )OT%94;O;VWWr)   )r*   r+   r,   r3   r  r  r  r>   r-   r)   r'   r  r    s?        
 
 'OX X X X Xr)   r  c                       e Zd Zd ZdS )r  c                 ,    t          |t                    S r0   )r"   r  r$   s     r'   
view_checkzMyView.view_check  s    $...r)   N)r*   r+   r,   r  r-   r)   r'   r  r    s#        / / / / /r)   r  c                       e Zd ZdZd Zd ZdS )
LeakyRealmz]
    A realm which hangs onto a reference to the mind object in its logout
    function.
    c                     || _         dS )z
        Create a L{LeakyRealm}.

        @param mindEater: a callable that will be called with the C{mind}
        object when it is available
        N)
_mindEater)r%   	mindEaters     r'   rF   zLeakyRealm.__init__  s     $r)   c                     |                                 |                     |          t          j        fdfS )Nc                  0                                      fS r0   )r  )r;   persps   r'   r8   z*LeakyRealm.requestAvatar.<locals>.<lambda>  s    u||~~0F r)   )r  r  r   r9   )r%   r:   r;   r  r  s     ` @r'   r>   zLeakyRealm.requestAvatar  sE    ''11(F(F(F(F(FGGr)   N)r*   r+   r,   r3   rF   r>   r-   r)   r'   r  r    sA         
$ $ $H H H H Hr)   r  c                       e Zd ZdZd ZdS )NewCredLeakTestsz/
    Tests to try to trigger memory leaks.
    c                    	 d _          fd}t           t          |                    \  }	g |                    d          }|                    dd          }d }|                    |           	fd}|                    |                                                                 d	g           t          j	                      
                                                                 dS )
z
        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.
        Nc                 :    t          j        |           _        d S r0   )weakrefrO  mindRef)r;   r%   s    r'   
setMindRefz4NewCredLeakTests.test_logoutLeak.<locals>.setMindRef  s    ";t,,DLLLr)   )ro   r   ru  loginr   c                 |    | \  }}t                      }|                    dt          j        |d          |          S )Nrespondr   )r   r   r   r  )r   	challenge
challengerr;   s       r'   
cbResponsez4NewCredLeakTests.test_logoutLeak.<locals>.cbResponse$  s@    $%!Iz>>D((2:i::D  r)   c                                                                           d                               t          j        t          d                               d S )NrQ   boom)rO   r  r_   r   r`   r   )_connectionBrokenrK   rs   s    r'   r_   z8NewCredLeakTests.test_logoutLeak.<locals>.connectionLost-  sP    IIKKK##A&&&''V8L8L(M(MNNNNNr)   rQ   )r  r   r  r  r   r^  rM   rW  r  r  r  )
r%   r  rr   ru  r#  r  r_   r  rK   rs   s
   `      @@@r'   test_logoutLeakz NewCredLeakTests.test_logoutLeak  s9    	- 	- 	- 	- 	- ,DZ
33,
 ,
 ,
(lD
 ))&11OOGX..	 	 	 	
j!!!	O 	O 	O 	O 	O 	O 	O
 	
n%%% 	

)A3///
 	
$,,..)))))r)   N)r*   r+   r,   r3   r  r-   r)   r'   r  r  	  s-         .* .* .* .* .*r)   r  c                       e Zd ZdZd ZddZ ej        ej	                  f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S )NewCredTestsz=
    Tests related to the L{twisted.cred} support in PB.
    c                     t                      | _        t          j        | j                  | _        t	          | j                  | _        t          j                    | _        dS )z
        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.
        N)	r  r   r
   r   rr  rp   r   r   rh   r1   s    r'   rP  zNewCredTests.setUpD  sK     [[
mDJ//:4;GG/11r)   Nc                 F   t          | | j        | j                  \  | _        | _        | _        t                      | _        t          t          j
        ddd          | j                  | _        | j                                                            | j                   dS )a  
        Connect a client obtained from C{clientFactory} and a server
        obtained from the current server factory via an L{IOPump},
        then assign them to the appropriate instance variables

        @ivar clientFactory: the broker client factory
        @ivar clientFactory: L{pb.PBClientFactory} instance

        @ivar client: the client broker
        @type client: L{pb.Broker}

        @ivar server: the server broker
        @type server: L{pb.Broker}

        @ivar pump: the IOPump connecting the client and server
        @type pump: L{IOPump}

        @ivar connector: A connector whose connect method recreates
            the above instance variables
        @type connector: L{twisted.internet.base.IConnector}
        TCPr\   i  N)rv   rh   rp   rB   rC   rK   rx   connectorStater   r   IPv4Addressre   r~   r^  establishClientAndServer)r%   _ignoreds     r'   r  z%NewCredTests.establishClientAndServerO  s    , /E$$d&8/
 /
+T[$) >??3{D994;N
 
 	++--99$:WXXXXXr)   c                     |                      | j        j        j                   | j                            |           | j                            | j        |           dS )a  
        Asserts that the client broker's transport was closed and then
        mimics the event loop by calling the broker's connectionLost
        callback with C{reason}, followed by C{self.clientFactory}'s
        C{clientConnectionLost}

        @param reason: (optional) the reason to pass to the client
            broker's connectionLost callback
        @type reason: L{Failure}
        N)r  rB   rU   r  r_   rh   rg   re   )r%   rf   s     r'   completeClientLostConnectionz)NewCredTests.completeClientLostConnectiono  sW     	-4555 	""6***//GGGGGr)   c                                                          j                                        } fd} fd}|                    |           |                    |           |S )z
        Assert that L{PBClientFactory.getRootObject}'s Deferred fires with
        a L{RemoteReference}, and that disconnecting it runs its
        disconnection callbacks.
        c                 H                         | t          j                   | S r0   )rV  r   RemoteReference)rootObjr%   s    r'   gotRootObjectz6NewCredTests.test_getRootObject.<locals>.gotRootObject  s!    !!'2+=>>>Nr)   c                     t                      }|                     |j                   j                                                                          |S r0   )r   rn  r   rh   
disconnectr  )r  disconnectedDeferredr%   s     r'   r  z3NewCredTests.test_getRootObject.<locals>.disconnect  sR    #+:: &&';'DEEE))+++--///''r)   r  rh   rN  r^  )r%   rootObjDeferredr  r  s   `   r'   test_getRootObjectzNewCredTests.test_getRootObject  s     	%%''',::<<	 	 	 	 		( 	( 	( 	( 	( 	##M222##J///r)   c                                                          j                                        } fd}|                    |          S )z
        Test that when a connection is lost, calling a method on a
        RemoteReference obtained from it raises L{DeadReferenceError}.
        c                      t                      }                     |j                    fd}|                    |           j                                                                          |S )Nc                 T                         t          j        j        d           d S )Nmethod)assertRaisesr   DeadReferenceErrorr   )ignr  r%   s    r'   lostConnectionzSNewCredTests.test_deadReferenceError.<locals>.gotRootObject.<locals>.lostConnection  s'    !!""79KXVVVVVr)   )r   rn  r   r^  rh   r  r  )r  r  r  r%   s   `  r'   r  z;NewCredTests.test_deadReferenceError.<locals>.gotRootObject  s    #+:: &&';'DEEEW W W W W W !,,^<<<))+++--///''r)   r  )r%   r  r  s   `  r'   test_deadReferenceErrorz$NewCredTests.test_deadReferenceError  sZ    
 	%%''',::<<	( 	( 	( 	( 	( **=999r)   c                       G d dt           j                  } |             _                                           j                                        } fd}|                    |          S )z
        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.
        c                       e Zd ZdZd ZdS )=NewCredTests.test_clientConnectionLost.<locals>.ReconnectOnceFc                     | j          }d| _         t          j                            | |||          }|r|                                 |S r  )reconnectedAlreadyr   r   rg   r   )r%   re   rf   reconnectingr  s        r'   rg   zRNewCredTests.test_clientConnectionLost.<locals>.ReconnectOnce.clientConnectionLost  sW    #'#::*.'+@@)V\    (%%'''r)   N)r*   r+   r,   r  rg   r-   r)   r'   ReconnectOncer    s)        !&    r)   r  c                 "                        | t          j                   t                      }|                     |j                   j                                                                          fd}|	                    |          S )Nc                 j    j                                         }fd}|                    |          S )Nc                                          | t          j                   t                      }|                     |j                   j                                                                          |S r0   )	rV  r   r  r   rn  r   rh   r  r  )anotherRootObjr#  r%   s     r'   gotAnotherRootObjectzqNewCredTests.test_clientConnectionLost.<locals>.gotRootObject.<locals>.disconnected.<locals>.gotAnotherRootObject  sg    )).":LMMM 

A"55ajAAA&1133355777Hr)   )rh   rN  r^  )r  r#  r  r%   s      r'   r^   zSNewCredTests.test_clientConnectionLost.<locals>.gotRootObject.<locals>.disconnected  sE    &4466     }}%9:::r)   )
rV  r   r  r   rn  r   rh   r  r  r^  )r  r#  r^   r%   s      r'   r  z=NewCredTests.test_clientConnectionLost.<locals>.gotRootObject  s    !!'2+=>>>

A&&qz222))+++--///; ; ; ; ; ==...r)   )r   r   rh   r  rN  r^  )r%   r  r  r  s   `   r'   test_clientConnectionLostz&NewCredTests.test_clientConnectionLost  s    	 	 	 	 	B. 	 	 	 +]__%%''',::<<	/ 	/ 	/ 	/ 	/0 **=999r)   c                 *   |                                   | j                            d          }|                    t	          j        t                                           |                    t          j	        t          j                             dS )z
        Test that if a Broker loses its connection without receiving any bytes,
        it doesn't raise any exceptions or log any errors.
        )r\   i90  N)r  rp   rj   rl   r   rm   rk   r_   r   r`   r   ra   )r%   serverProtos     r'   test_immediateClosez NewCredTests.test_immediateClose  sw    
 	%%'''(667KLL""8#7

#C#CDDD""7?43G#H#HIIIIIr)   c                    t          j                    }|                    t          j        dd                    }|                    dt          j        t          d                               | 	                    |t                    S )z
        L{PBClientFactory.login} returns a L{Deferred} which is errbacked
        with the L{ConnectionRefusedError} if the underlying connection is
        refused.
           foo   barNz!Test simulated refused connection)
r   r   r  r	   UsernamePasswordclientConnectionFailedr   r`   r   assertFailure)r%   rh   loginDeferreds      r'   test_loginConnectionRefusedz(NewCredTests.test_loginConnectionRefused  s     *,,%++(88
 
 	,,O&'JKK 	
 	
 	
 !!-1GHHHr)   c                 ^     j                             t          j        d                     t	          j        dd          }d}t                       j                            ||          } fd} fd}|	                    |           |	                    |            fd}|	                    |            
                                  j                                         t          j                      j                                                             d           |S )	z
        Test that login can be performed with IUsernamePassword credentials and
        that when the connection is dropped the avatar is logged out.
           passr&      userr  c                                          j        j        j                                       | t
          j                   S r0   )r  r   r  r  rV  r   r  )r   loginCompletedr%   s    r'   cbLoginz.NewCredTests.test_loginLogout.<locals>.cbLogin  s<    OODJ6?@@@!!+r/ABBB!!r)   c                 b    j                                                                           d S r0   )rh   r  r  ignoredr%   s    r'   cbDisconnectz3NewCredTests.test_loginLogout.<locals>.cbDisconnect  s0    ))+++--/////r)   c                 P                         j        j        j                   d S r0   )r  r   r  r  r  s    r'   cbLogoutz/NewCredTests.test_loginLogout.<locals>.cbLogout&  s#    OODJ6@AAAAAr)   N)r
   registerCheckerr   r   r	   r  r   rh   r  r^  r  rK   rM   r  r  r   )r%   credsr;   r#  r  r  r  r  s   `      @r'   test_loginLogoutzNewCredTests.test_loginLogout  sX   
 	##<'JJJ	
 	
 	
 ,Wg>> !$$UD11	" 	" 	" 	" 	" 	"
	0 	0 	0 	0 	0 	
g	l###	B 	B 	B 	B 	B 	
h%%'''	 	
	%%%r)   c                 B    t                       G fddt          j                  }| j        _         j                            t          j        d                      j	        
                    t          j        dd          d          }fd}|                    |            fd}|                    |                                              j                                         t#          j                      j                                         |S )	z
        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.
        c                   $    e Zd ZdZd Z fdZdS )=NewCredTests.test_logoutAfterDecref.<locals>.EventPerspectivezQ
            An avatar which fires a Deferred when it is logged out.
            c                     d S r0   r-   r  s     r'   rF   zFNewCredTests.test_logoutAfterDecref.<locals>.EventPerspective.__init__C  s    r)   c                 2                         d            d S r0   )r   )r%   r  s    r'   r  zDNewCredTests.test_logoutAfterDecref.<locals>.EventPerspective.logoutF  s    ""4(((((r)   N)r*   r+   r,   r3   rF   r  r  s   r'   EventPerspectiver  >  sG           ) ) ) ) ) ) )r)   r  r  r   r  r  c                     S r0   r-   )avatarr  s    r'   
cbLoggedInz7NewCredTests.test_logoutAfterDecref.<locals>.cbLoggedInS  s     r)   c                 R                         j        j        j        i            d S r0   )rW  rp   rw  _localCleanupr  s    r'   cbLoggedOutz8NewCredTests.test_logoutAfterDecref.<locals>.cbLoggedOutZ  s+     T/@NPRSSSSSr)   )r   r   Avatarr   r  r
   r  r   r   rh   r  r	   r  r^  r  rK   rM   r  r  )r%   r  r#  r  r  r  s   `    @r'   test_logoutAfterDecrefz#NewCredTests.test_logoutAfterDecref6  sQ    JJ			) 		) 		) 		) 		) 		) 		)ry 		) 		) 		) )9
%##<HHH	
 	
 	
 $$(88)
 
	 	 	 	 	
 	
j!!!	T 	T 	T 	T 	T
 	
k"""%%''' 		 	
	r)   c                      j                             t          j        dd                      j                            t          j        dd          d          } j                            t          j        dd          d          }t          ||g          }d }|	                    |            fd}|	                    |            
                                  j                                         |S )	z
        Two different correct login attempts can be made on the same root
        object at the same time and produce two different resulting avatars.
        r  s   quux)r   bazr  r     bazc                 z    | \  }}t          |                    d          |                    d          g          S )NgetAvatarId)r   r   )r  firstseconds      r'   r  z5NewCredTests.test_concurrentLogin.<locals>.cbLoggedIn}  sA    $OUF !!-00&2C2CM2R2RS  r)   c                 j    | \  }}                     |d                                |d           d S )Nr  r  )rW  )r   r  r  r%   s      r'   cbAvatarIdsz6NewCredTests.test_concurrentLogin.<locals>.cbAvatarIds  s>    ME6UF+++VV,,,,,r)   )r
   r  r   r   rh   r  r	   r  r   r^  r  rK   rM   )r%   
firstLoginsecondLoginr#  r  r  s   `     r'   test_concurrentLoginz!NewCredTests.test_concurrentLoginl  s   
 	##<WUUU	
 	
 	
 '--(88)
 

 (..(999
 
 :{344	 	 	 	
j!!!	- 	- 	- 	- 	-
 	
k"""%%'''	r)   c                 2     j                             t          j        d                      j                            t          j        dd                    } j                            t          j        dd                    }                     |t                                          |t                     t          ||g          } fd}|                    |                                              j                                         |S )zz
        Test that a login attempt with an invalid user or invalid password
        fails in the appropriate way.
        r  r  s
   nosuchuserr  s	   wrongpassc                                          t                    }                    t          |          d           d S )Nr   )flushLoggedErrorsr   rW  r  ignoreerrorsr%   s     r'   cleanupz;NewCredTests.test_badUsernamePasswordLogin.<locals>.cleanup  s9    ++,=>>FS[[!,,,,,r)   )r
   r  r   r   rh   r  r	   r  r  r   r   r^  r  rK   rM   )r%   r   r!  r#  r)  s   `    r'   test_badUsernamePasswordLoginz*NewCredTests.test_badUsernamePasswordLogin  s   
 	##<'JJJ	
 	
 	
 '--(@@
 

 (..(,??
 
 	:'8999;(9::::{344	- 	- 	- 	- 	- 	
g%%'''	r)   c                 t   | j                             t          j                               | j                            t          j                    d          }d }|                    |           |                    | j	        d           | 
                                 | j                                         |S )z
        Verify that a PB server using a portal configured with a checker which
        allows IAnonymous credentials can be logged into using IAnonymous
        credentials.
        r  c                 .    |                      dd          S NrT  {   r  r   s    r'   r  z4NewCredTests.test_anonymousLogin.<locals>.cbLoggedIn      ))&#666r)   r.  )r
   r  r   AllowAnonymousAccessrh   r  r	   	Anonymousr^  rW  r  rK   rM   )r%   r#  r  s      r'   test_anonymousLoginz NewCredTests.test_anonymousLogin  s     	##H$A$C$CDDD$$[%:%<%<iHH	7 	7 	7 	
j!!!	d&,,,%%'''	r)   c                 ~     j                             t          j        d                      j                            t          j                    d          }                     |t                      fd}|
                    |                                              j                                         |S )zg
        Verify that without an anonymous checker set up, anonymous login is
        rejected.
        passr  r  c                                          t                    }                    t          |          d           d S r   )r%  r   rW  r  r&  s     r'   r)  z=NewCredTests.test_anonymousLoginNotPermitted.<locals>.cleanup  s9    ++,@AAFS[[!,,,,,r)   )r
   r  r   r   rh   r  r	   r2  r  r   r^  r  rK   rM   )r%   r#  r)  s   `  r'   test_anonymousLoginNotPermittedz,NewCredTests.test_anonymousLoginNotPermitted  s    
 	##<&III	
 	
 	
 $$[%:%<%<iHH12333	- 	- 	- 	- 	- 	
g%%'''	r)   c                    | j                             t          j                               | j                             t          j        d                     | j                            t          j                    d          }d }|	                    |           |	                    | j
        d           |                                  | j                                         |S )z
        Like L{test_anonymousLogin} but against a portal with a checker for
        both IAnonymous and IUsernamePassword.
        r  r  r  c                 .    |                      dd          S r-  r  r/  s    r'   r  zENewCredTests.test_anonymousLoginWithMultipleCheckers.<locals>.cbLogin  r0  r)   r.  )r
   r  r   r1  r   rh   r  r	   r2  r^  rW  r  rK   rM   r%   r#  r  s      r'   'test_anonymousLoginWithMultipleCheckersz4NewCredTests.test_anonymousLoginWithMultipleCheckers  s    
 	##H$A$C$CDDD##<'JJJ	
 	
 	
 $$[%:%<%<iHH	7 	7 	7 	
g	d&,,,%%'''	r)   c                    | j                             t          j                               | j                             t          j        d                     | j                            t          j        dd          d          }d }|	                    |           |	                    | j
        d           |                                  | j                                         |S )z
        Like L{test_anonymousLoginWithMultipleCheckers} but check that
        username/password authentication works.
        r  r  r  r  c                 0    |                      ddd          S )Naddr     r  r/  s    r'   r  zINewCredTests.test_authenticatedLoginWithMultipleCheckers.<locals>.cbLogin  s    ))%b999r)   r.  )r
   r  r   r1  r   rh   r  r	   r  r^  rW  r  rK   rM   r:  s      r'   +test_authenticatedLoginWithMultipleCheckersz8NewCredTests.test_authenticatedLoginWithMultipleCheckers  s    
 	##H$A$C$CDDD##<'JJJ	
 	
 	
 $$('::I
 
	: 	: 	: 	
g	d&,,,%%'''	r)   c                    | j                             t          j        d                     | j                            t          j        dd          d          }d }|                    |           d }|                    |           |                    | j	                   | 
                                 | j                                         |S )zb
        Verify that a viewpoint can be retrieved after authenticating with
        cred.
        r  r  r  r  c                 ,    |                      d          S )NgetViewPointr  r/  s    r'   r  z'NewCredTests.test_view.<locals>.cbLogin  s    )).999r)   c                 ,    |                      d          S )Nr   r  )	viewpoints    r'   cbViewz&NewCredTests.test_view.<locals>.cbView  s    ''000r)   )r
   r  r   r   rh   r  r	   r  r^  r  r  rK   rM   )r%   r#  r  rF  s       r'   	test_viewzNewCredTests.test_view
  s    
 	##<'JJJ	
 	
 	
 $$('::I
 
	: 	: 	: 	
g	1 	1 	1 	
f	do&&&%%'''	r)   r0   )r*   r+   r,   r3   rP  r  r   r`   r   ra   r  r  r  r  r  r  r  r  r"  r*  r3  r7  r;  r@  rG  r-   r)   r'   r  r  ?  sN        	2 	2 	2Y Y Y YB %W_T%9::H H H H(  6: : :01: 1: 1:fJ J JI I I$/ / /b4 4 4l# # #J  >  (  ,  .  2    r)   r  c                        e Zd Zd Zd Zd ZdS )NonSubclassingPerspectivec                     d S r0   r-   r  s     r'   rF   z"NonSubclassingPerspective.__init__*  r  r)   c                     |                     ||           }|                     ||           }|                    |||f          S r0   )unserialize	serialize)r%   rb   messager  kwargss        r'   perspectiveMessageReceivedz4NonSubclassingPerspective.perspectiveMessageReceived.  sG    !!$--##FD11$ 7888r)   c                     d| _         d S r  r  r1   s    r'   r  z NonSubclassingPerspective.logout4  r  r)   N)r*   r+   r,   rF   rP  r  r-   r)   r'   rI  rI  (  sA          9 9 9    r)   rI  c                       e Zd ZdZd Zd ZdS )NSPTestsz
    Tests for authentication against a realm where the L{IPerspective}
    implementation is not a subclass of L{Avatar}.
    c                 J   t                      | _        t          | j        _        t	          j        | j                  | _        t          j                    | _        | j        	                    dd           | j        
                    | j                   t          t          j        | j                            | _        t          j        d| j        d          | _        |                     | j        j                   | j                                        j        | _        d S )Nr  r  r   r\   )r  )r  r   rI  r  r
   r   r   r   r   addUserr  r   r   r   r  r   r  r  rn   r  r  portnor1   s    r'   rP  zNSPTests.setUp>  s    [[
(A
%mDJ//GIIWg...##DL111&r'9$+'F'FGG%aMMM		/000i'')).r)   c                 Z    t          j                                        t          j        dd          d          }t          j        d j                   |                    d            |                     j	        dddd	if            fd
}|                    |           |S )z
        An L{IPerspective} implementation which does not subclass
        L{Avatar} can expose remote methods for the client to call.
        r  r  r  r\   c                 2    |                      ddd          S )NANYTHINGherer  )r  r  )ry  s    r'   r8   z#NSPTests.test_NSP.<locals>.<lambda>R  s    ZU K K r)   rY  )rZ  r  r  c                                                       j        j        D ]}|j                                         d S r0   )r  r  	protocolsrU   r  )r  ry  r  r%   s     r'   r)  z"NSPTests.test_NSP.<locals>.cleanupU  sJ       \+ - -**,,,,- -r)   )
r   r   r  r	   r  r   r  rV  r^  rW  )r%   r#  r)  r  s   `  @r'   test_NSPzNSPTests.test_NSPJ  s    
 $&&MM+6wHH)TT;W===	KKLLL	d&Y(OPPP	- 	- 	- 	- 	- 	-
 	
gr)   N)r*   r+   r,   r3   rP  r]  r-   r)   r'   rS  rS  8  s<         

/ 
/ 
/    r)   rS  c                       e Zd ZdZd Zd ZdS )
IForwardedzA
    Interface used for testing L{util.LocalAsyncForwarder}.
    c                      dS )z,
        Simple synchronous method.
        Nr-   r-   r)   r'   	forwardMezIForwarded.forwardMec        r)   c                      dS )z-
        Simple asynchronous method.
        Nr-   r-   r)   r'   forwardDeferredzIForwarded.forwardDeferredh  rb  r)   N)r*   r+   r,   r3   ra  rd  r-   r)   r'   r_  r_  ^  s<           
    r)   r_  c                   ,    e Zd ZdZdZdZd Zd Zd ZdS )	Forwardedz
    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}
    Fc                     d| _         dS )z6
        Set a local flag to test afterwards.
        TN)	forwardedr1   s    r'   ra  zForwarded.forwardMe|  s     r)   c                     d| _         dS )zv
        Set a local flag to test afterwards. This should not be called as it's
        not in the interface.
        TN)unforwardedr1   s    r'   dontForwardMezForwarded.dontForwardMe  s    
  r)   c                      t          d          S )z0
        Asynchronously return C{True}.
        T)r   r1   s    r'   rd  zForwarded.forwardDeferred  s     t}}r)   N)	r*   r+   r,   r3   rh  rj  ra  rk  rd  r-   r)   r'   rf  rf  n  sW          IK           r)   rf  c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )SpreadUtilTestsz+
    Tests for L{twisted.spread.util}.
    c                 v    t                      }|                     |                    dd          d           dS )zk
        Call a synchronous method of a L{util.LocalAsRemote} object and check
        the result.
        add1r   r   N)r  rW  r   rd  s     r'   	test_synczSpreadUtilTests.test_sync  s9    
 fa00!44444r)   c                     t                      }t                      }|                    ddd          }|                     |t                     |                    | j        d           |S )zm
        Call an asynchronous method of a L{util.LocalAsRemote} object and check
        the result.
        r>  r   r   )r   r  )r  r   rV  r   r^  rW  )r%   re  r#  s      r'   
test_asynczSpreadUtilTests.test_async  sc    
 LLQL''a***	d&***r)   c                      t                      }|                    d          } fd}|                     fd|           |S )zG
        Test an asynchronous failure on a remote method call.
        r  c                 |                         | t          j                   |                     t                     d S r0   )rV  r   r`   trapr   )r0  r%   s    r'   ebz*SpreadUtilTests.test_asyncFail.<locals>.eb  s3    !!!W_555FF<     r)   c                 .                         d          S )Nzsupposed to failr  )rZ  r%   s    r'   r8   z0SpreadUtilTests.test_asyncFail.<locals>.<lambda>  s    499-?#@#@ r)   )r  r   r"  )r%   re  r#  rw  s   `   r'   test_asyncFailzSpreadUtilTests.test_asyncFail  s_     LL  	! 	! 	! 	! 	! 	
@@@@"EEEr)   c                     t                      }|                    d          }|                      |d          d           dS )zM
        Test the C{remoteMethod} facility of L{util.LocalAsRemote}.
        rp  r   r   N)r  r  rW  )r%   re  ms      r'   test_remoteMethodz!SpreadUtilTests.test_remoteMethod  sD     NN6""1q!!!!!r)   c                    t                      }t          j        |t                    }|                    d           |                     |j                   |                    d           |                     |j                   |                    d          }g }|	                    |j
                   |                     |d         d           dS )ze
        Test a call to L{util.LocalAsyncForwarder} using L{Forwarded} local
        object.
        ra  rk  rd  r   rQ   N)rf  r   LocalAsyncForwarderr_  r   r  rh  rX  rj  r^  r  rW  )r%   r0  lfrrr  s        r'   test_localAsyncForwarderz(SpreadUtilTests.test_localAsyncForwarder  s    
 KK%a44
k"""$$$
o&&&''']],--
qx   1q!!!!!r)   N)	r*   r+   r,   r3   rq  rs  ry  r|  r  r-   r)   r'   rn  rn    si         5 5 5
 
 
  " " "" " " " "r)   rn  c                   *    e Zd ZdZd Zd Zd Zd ZdS )PBWithSecurityOptionsTestsz&
    Test security customization.
    c                     t          j                    }|                    d          }|                     |j        t
          j                   dS )zl
        By default, client broker should use C{jelly.globalSecurity} as
        security settings.
        N)r   r   rj   r  securityr   globalSecurityr%   r  rb   s      r'   !test_clientDefaultSecurityOptionsz<PBWithSecurityOptionsTests.test_clientDefaultSecurityOptions  sD    
 $&&&&t,,fou';<<<<<r)   c                     t          j        t                                }|                    d          }|                     |j        t          j                   dS )zl
        By default, server broker should use C{jelly.globalSecurity} as
        security settings.
        N)r   r   r<  rj   r  r  r   r  r  s      r'   !test_serverDefaultSecurityOptionsz<PBWithSecurityOptionsTests.test_serverDefaultSecurityOptions  sJ    
 $VXX..&&t,,fou';<<<<<r)   c                     t          j                    }t          j        |          }|                    d          }|                     |j        |           dS )zs
        Check that the security settings are passed from the client factory to
        the broker object.
        r  N)r   SecurityOptionsr   r   rj   r  r  r%   r  r  rb   s       r'    test_clientSecurityCustomizationz;PBWithSecurityOptionsTests.test_clientSecurityCustomization  sT    
 (**$h777&&t,,fox00000r)   c                     t          j                    }t          j        t	                      |          }|                    d          }|                     |j        |           dS )zs
        Check that the security settings are passed from the server factory to
        the broker object.
        r  N)r   r  r   r   r<  rj   r  r  r  s       r'    test_serverSecurityCustomizationz;PBWithSecurityOptionsTests.test_serverSecurityCustomization  sZ    
 (**$VXXAAA&&t,,fox00000r)   N)r*   r+   r,   r3   r  r  r  r  r-   r)   r'   r  r    sZ         = = == = =1 1 11 1 1 1 1r)   r  r0   )r3   r  r  r  rJ   r  collectionsr   ior   rk   typingr   zope.interfacer   r   twisted.credr   r	   r
   twisted.cred.errorr   r   twisted.internetr   r   r   r   twisted.internet.deferr   r   r   twisted.internet.errorr   twisted.internet.testingr   twisted.protocols.policiesr   twisted.pythonr   r   twisted.python.compatr   twisted.spreadr   r   r   r   twisted.trialr   Viewabler    r  r#   IRealmr5   r@   rv   rx   r   r   r  r   r   Copyabler   
RemoteCopyr   setUnjellyableForClassr   r   setUnjellyableFactoryForClassr   	Cacheabler   r   r   RemoteCacher   r   r   r	  r  r&  r-  r1  r9  Rootr<  rE  SynchronousTestCaserK  r   rr  TestCaserz  r  r  r  r  r  r  r"  r+  PublishablerM  RemotePublishedrQ  r  r[  r   rv  rj  ri  LocalAsRemoter  r9   r  r  r  r  r  r  rI  rS  r_  rf  rn  r  r-   r)   r'   <module>r     s    
			 				 



         " " " " " "       1 1 1 1 1 1 1 1 6 6 6 6 6 6 6 6 6 6 F F F F F F F F = = = = = = = = = = = = C C C C C C C C C C 9 9 9 9 9 9 3 3 3 3 3 3 6 6 6 6 6 6 ' ' ' ' ' ' ' ' + + + + + + 3 3 3 3 3 3 3 3 3 3 3 3 " " " " " "+ + + + +BK + + +    ry    V]G G G G G G G G8 8 8 8 8 8 8 8v0, 0, 0,f4 4 4 4 4 4 4 4B               4F F F F    2#       2#   
       	 	 	 	 	bm 	 	 	  *o 6 6 6
, 
, 
, 
, 
, 
, 
, 
,    !  !24E F F F( ( ( ( (! ( ( (    ",       R-   ! ! ! ! !2< ! ! !*% % % % % % % %  68J K K K    r~     +'7 8 8 8    ""   5 5 5 5 5! 5 5 5    R%   ,, , , , ,r , , ,    2;   
  , 5 5 5' ' ' ' 'BK ' ' '  - 7 7 7    bn   
  +-> ? ? ?    RW       RW   O O O O OH0 O O Od    B$6   @4 4 4 4 4(+ 4 4 4nR
 R
 R
 R
 R
(# R
 R
 R
j 	  # # # # #  # # ## # # # #B$ # # #i5 i5 i5 i5 i5(# i5 i5 i5X' ' ' ' 'g) ' ' '
         g%      
    2#     /7 3 3 3@- @- @- @- @-* @- @- @-F	 	 	 	 	y 	 	 	    "+   
    !   

 
 
 
 
d( 
 
 
 R_         BI      FX X X X X X X XB/ / / / /R[ / / /
H H H H H H H H*3* 3* 3* 3* 3*x( 3* 3* 3*lf f f f f8$ f f fR R_       # # # # #x  # # #L         Z       B=" =" =" =" ="h' =" =" ="@)1 )1 )1 )1 )1!2 )1 )1 )1 )1 )1r)   