+
    Dfj6                     &   R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIH	t
 ^ RIHt ^ RIHtHt ^ RIHtHtHt ^ RIHtHt ^ RIHtHtHtHt ^ R	IHtHtHt ^ R
I H!t! ^ RI"H#t# ^ RI$H%t% ^ RI&H't'H(t( ^ RI)H*t* ^ RI+H,t,H-t-H.t.H/t/ ^ RI0H1t1  ! R R]-Pd                  4      t3 ! R R]-Ph                  4      t5]! ]Pl                  4       ! R R4      4       t7 ! R R4      t8R t9 ! R R4      t: ! R R]#4      t;RR lt< ! R R ]-Pz                  4      t> ! R! R"]-Pz                  4      t? ! R# R$]-P                  4      tA ! R% R&]-P                  4      tC]-P                  ! ]A]C4        ! R' R(]-P                  4      tER) tF]-P                  ! ]E]F4        ! R* R+]-Pz                  4      tH ! R, R-]-P                  4      tJ ! R. R/]-Pz                  4      tK ! R0 R1]-P                  4      tL ! R2 R3]-P                  4      tN]-P                  ! ]L]N4        ! R4 R5]-P                  4      tO]-P                  ! ]J]O4        ! R6 R7]-Pz                  4      tP ! R8 R9]-Pz                  4      tQ ! R: R;]-Pz                  4      tR ! R< R=]-Pz                  4      tS ! R> R?]-P                  ]-P                  4      tT]-P                  ! ]T]T4        ! R@ RA]-P                  ]-P                  4      tU]-P                  ! ]U]U4        ! RB RC]-P                  ]-P                  4      tV]-P                  ! ]V]V4        ! RD RE]-P                  4      tX ! RF RG]-P                  4      tY ! RH RI]1P                  4      t[ ! RJ RK]-P                  4      t] ! RL RM]1P                  4      t_ ! RN RO]1P                  4      t`RtaRsbRscRP td ! RQ RR]-Pz                  4      te ! RS RT]-Pz                  4      tf ! RU RV]1P                  4      tg ! RW RX].P                  4      ti ! RY RZ].P                  4      tk ! R[ R\]-Pz                  4      tl]-P                  ! ]i]k4        ! R] R^]1P                  4      tm ! R_ R`]n4      to ! Ra Rb]-P                  4      tp ! Rc Rd]-Pz                  4      tq ! Re Rf]/P                  4      ts]! ]-P                  4       ! Rg Rh]-Ph                  4      4       tu ! Ri Rj4      tv ! Rk Rl]-Pd                  4      tw ! Rm Rn]v4      tx ! Ro Rp]1P                  4      ty ! Rq Rr]1P                  4      tz]! ]-P                  4       ! Rs Rt4      4       t{ ! Ru Rv]1P                  4      t| ! Rw Rx]4      t}]! ]}4       ! Ry Rz4      4       t~ ! R{ R|]1P                  4      t ! R} R~]1P                  4      tR# )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                   &   a  ] tR t^'t o R tRtV tR# )Dummyc                6    \        V\        4      '       d   R # R# )zhello world!zgoodbye, cruel world!)
isinstanceDummyPerspectiveselfusers   &&=/usr/lib/python3/dist-packages/twisted/spread/test/test_pb.pyview_doNothingDummy.view_doNothing(   s    d,--!*     N)__name__
__module____qualname____firstlineno__r'   __static_attributes____classdictcell____classdict__s   @r&   r   r   '   s     + +r)   r   c                   *   a  ] tR t^/t o RtR tRtV tR# )r"   z=
An L{IPerspective} avatar which will be used in some tests.
c                    \        4       # N)r   r$   s   &r&   perspective_getDummyViewPoint.DummyPerspective.perspective_getDummyViewPoint4   s	    wr)   r*   N)r+   r,   r-   r.   __doc__r7   r/   r0   r1   s   @r&   r"   r"   /   s      r)   r"   c                   &   a  ] tR t^8t o R tRtV tR# )
DummyRealmc                b    V F(  pV\         P                  J g   K  V\        V4      R  3u # 	  R# )c                      R # r5   r*   r*   r)   r&   <lambda>*DummyRealm.requestAvatar.<locals>.<lambda>=   s    $r)   N)r   IPerspectiver"   )r$   avatarIdmind
interfacesifaces   &&&* r&   requestAvatarDummyRealm.requestAvatar:   s+    E'.x8,FF  r)   r*   N)r+   r,   r-   r.   rE   r/   r0   r1   s   @r&   r;   r;   8   s     G Gr)   r;   c                   <   a  ] tR t^@t o RtR tR tR tR tRt	V t
R# )IOPumpz
Utility to pump data between clients and servers for protocol testing.

Perhaps this is a utility worthy of being in protocol.py?
c                6    Wn         W n        W0n        W@n        R # r5   )clientserverclientIOserverIO)r$   rJ   rK   rL   rM   s   &&&&&r&   __init__IOPump.__init__G   s      r)   c                    RV n         \        P                  ! 4       ^,           pV P                   '       g7   V P                  4       '       d   \        P                  ! 4       V8  g   KD  R# R# R# )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.
FN)_stoptimepump)r$   timeouts   & r&   flushIOPump.flushM   sE     
))+/***yy{W$ "-*r)   c                    RV n         R# )zL
Stop a running L{flush} operation, even if data remains to be
transferred.
TN)rQ   r6   s   &r&   stopIOPump.stopZ   s    
 
r)   c                   V P                   P                  ^ 4       V P                  P                  ^ 4       V P                   P                  4       pV P                  P                  4       pV P                   P                  ^ 4       V P                  P                  ^ 4       V P                   P	                  4        V P                  P	                  4        V P
                  P                  P                  4        V P                  P                  P                  4        \        V4       F  pV P                  P                  V4       K   	  \        V4       F  pV P
                  P                  V4       K   	  V'       g	   V'       d   ^# ^ # )z@
Move data back and forth.

Returns whether any data was moved.
)rL   seekrM   readtruncaterJ   	transport_checkProducerrK   r   dataReceived)r$   cDatasDatabytes   &   r&   rS   IOPump.pumpa   s	    	11""$""$11  ,,.,,.e$DKK$$T* %e$DKK$$T* %Er)   )rQ   rJ   rL   rK   rM   N)r+   r,   r-   r.   r9   rN   rU   rX   rS   r/   r0   r1   s   @r&   rH   rH   @   s#     ! r)   rH   c                  a RpSP                  V4      pVP                  V4      p\        4       p\        4       pVP                  \        P                  ! V4      4       VP                  \        P                  ! V4      4       \        WEWg4      pR p	V3R lp
V P                  W4       V P                  W4       V P                  V
4       VP                  4        WEV3# )a8  
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})
c                     V P                   '       g6   V P                  \        P                  ! \        P
                  4      4       R # R # r5   )disconnectedconnectionLostr   Failurer   CONNECTION_DONE)brokers   &r&   maybeDisconnect/connectServerAndClient.<locals>.maybeDisconnect   s0    """!!'//$2F2F"GH #r)   c                  r   < S P                  R \        P                  ! \        P                  4      R7       R # )N)	connectorreason)clientConnectionLostr   ri   r   rj   )clientFactorys   r&   disconnectClientFactory7connectServerAndClient.<locals>.disconnectClientFactory   s,    
 	**7??43G3G#H 	+ 	
r)   )	127.0.0.1)buildProtocolStringIOmakeConnectionr   FileWrapperrH   
addCleanuprS   )testrr   serverFactoryaddrclientBrokerserverBrokerclientTransportserverTransportrS   rl   rs   s   &f&        r&   connectServerAndClientr   {   s    & D ..t4L ..t4LjOjO 4 4_ EF 4 4_ EF,oODI
 	OOO2OOO2OO+,IIKt++r)   c                   6   a  ] tR t^t o RtR tR tR tRtV t	R# )_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                $    \        4       V n        R # r5   )r   notificationsr6   s   &r&   rN   (_ReconnectingFakeConnectorState.__init__   s    "Wr)   c                P    \        4       pV P                  P                  V4       V# )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   r   
appendleft)r$   notifiers   & r&   notifyOnConnect/_ReconnectingFakeConnectorState.notifyOnConnect   s$     :%%h/r)   c                    V P                   '       d,   V P                   P                  4       P                  V 4       K=  R# )z!
Fire all pending notifications.
N)r   popcallbackr6   s   &r&   	notifyAll)_ReconnectingFakeConnectorState.notifyAll   s2        ""$--d3 !r)   )r   N)
r+   r,   r-   r.   r9   rN   r   r   r/   r0   r1   s   @r&   r   r      s     %4 4r)   r   c                   B   a a ] tR t^t oRtV 3R ltV 3R ltRtVtV ;t	# )_ReconnectingFakeConnectorzW
A fake L{IConnector} that can fire L{Deferred}s when its
C{connect} method is called.
c                2   < \         SV `  V4       W n        R# )z
@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)superrN   _state)r$   r   state	__class__s   &&&r&   rN   #_ReconnectingFakeConnector.__init__   s     	!r)   c                X   < \         SV `  4        V P                  P                  4        R# )z=
A C{connect} implementation that calls C{reconnectCallback}
N)r   connectr   r   )r$   r   s   &r&   r   "_ReconnectingFakeConnector.connect   s     	r)   )r   )
r+   r,   r-   r.   r9   rN   r   r/   r0   __classcell__)r   r2   s   @@r&   r   r      s     

   r)   r   c                    T;'       g    \        4       p\        P                  ! RR7      p\        P                  ! \
        P                  ! W.4      4      p\        P                  ! 4       p\        WV4      # )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)	r;   r   'InMemoryUsernamePasswordDatabaseDontUser   PBServerFactoryr	   PortalPBClientFactoryr   )r{   realmcheckerr|   rr   s   &&   r&   connectedServerAndClientr      sY     !!Z\E>>XNG&&v}}UI'FGM&&(M!$}EEr)   c                   ,   a  ] tR t^t o R tR tRtV tR# )SimpleRemotec                     Wn         V^,           #    argr$   r   s   &&r&   remote_thunkSimpleRemote.remote_thunk       Qwr)   c                    \        4       hr5   )	Exceptionr   s   &&r&   remote_knuthSimpleRemote.remote_knuth   s
    kr)   r   N)r+   r,   r-   r.   r   r   r/   r0   r1   s   @r&   r   r      s      r)   r   c                   &   a  ] tR tRt o R tRtV tR# )NestedRemotei  c                    \        4       # r5   )r   r6   s   &r&   remote_getSimpleNestedRemote.remote_getSimple  s
    ~r)   r*   N)r+   r,   r-   r.   r   r/   r0   r1   s   @r&   r   r     s      r)   r   c                   &   a  ] tR tRt o R tRtV tR# )
SimpleCopyi  c                6    ^V n         RR/V n        R.V n        R# r   HelloWorldr{   Nxyzr6   s   &r&   rN   SimpleCopy.__init__      7#r)   r   Nr+   r,   r-   r.   rN   r/   r0   r1   s   @r&   r   r           r)   r   c                       ] tR tRtRtR# )SimpleLocalCopyi  r*   Nr+   r,   r-   r.   r/   r*   r)   r&   r   r         r)   r   c                   :   a  ] tR tRt o Rt/ tR tV 3R ltRtV t	R# )SimpleFactoryCopyi  zQ
@cvar allIDs: hold every created instances of this class.
@type allIDs: C{dict}
c                8    Wn         V \        P                  V&   R # r5   )idr   allIDs)r$   r   s   &&r&   rN   SimpleFactoryCopy.__init__  s    '+  $r)   c                :   < V ^8  d   Qh/ S[ S[R3,          ;R&   # )   r   r   )r   int)formatr2   s   "r&   __annotate__SimpleFactoryCopy.__annotate__  s      ))*/ r)   )r   N)
r+   r,   r-   r.   r9   r   rN   __annotate_func__r/   r0   r1   s   @r&   r   r     s     
 .0F,  r)   r   c                   V P                  RR4      pVf   \        R\        V 4       24      hV\        P                  9  d   \        R\        P                   24      h\        P                  V,          pV'       g   \        R4      hV# )z`
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CDK=QRR'...67H7O7O6PQRR##G,DCDDKr)   c                   ,   a  ] tR tRt o R tR tRtV tR# )
NestedCopyi4  c                    \        4       # r5   )r   r6   s   &r&   remote_getCopyNestedCopy.remote_getCopy5  s
    |r)   c                    \        V4      # r5   )r   )r$   values   &&r&   remote_getFactoryNestedCopy.remote_getFactory8  s     ''r)   r*   N)r+   r,   r-   r.   r   r   r/   r0   r1   s   @r&   r   r   4  s     ( (r)   r   c                   &   a  ] tR tRt o R tRtV tR# )SimpleCachei<  c                6    ^V n         RR/V n        R.V n        R# r   r   r6   s   &r&   	__init___SimpleCache.__init___=  r   r)   r   N)r+   r,   r-   r.   r   r/   r0   r1   s   @r&   r   r   <  r   r)   r   c                   ,   a  ] tR tRt o R tR tRtV tR# )NestedComplicatedCacheiC  c                $    \        4       V n        R # r5   )VeryVeryComplicatedCacheablecr6   s   &r&   rN   NestedComplicatedCache.__init__D  s    -/r)   c                    V P                   # r5   r   r6   s   &r&   remote_getCache&NestedComplicatedCache.remote_getCacheG  s    vvr)   r   N)r+   r,   r-   r.   rN   r   r/   r0   r1   s   @r&   r   r   C  s     0 r)   r   c                   8   a  ] tR tRt o R tR tR tR tRtV t	R# )r   iK  c                0    ^V n         ^V n        ^V n        R# r   Nr   r   foor6   s   &r&   rN   %VeryVeryComplicatedCacheable.__init__L  s    r)   c                L    ^V n         V P                  P                  R^4       R# )   r   N)r   observer
callRemoter6   s   &r&   setFoo4$VeryVeryComplicatedCacheable.setFoo4Q  s      *r)   c                Z    W n         R V P                  RV P                  RV P                  /# r   )r  r   r   r   r$   perspectiver  s   &&&r&   getStateToCacheAndObserveFor9VeryVeryComplicatedCacheable.getStateToCacheAndObserveForU  s&     TVVS$&&%::r)   c                    \         P                  ! R 4       VP                  R4       W P                  8X  d
   RV n        R# R# )zstopped observingendN)r   msgr  r  r  s   &&&r&   stoppedObserving-VeryVeryComplicatedCacheable.stoppedObservingY  s3    #$E"}}$ DM %r)   )r   r  r   r   N)
r+   r,   r-   r.   rN   r  r	  r  r/   r0   r1   s   @r&   r   r   K  s     
+;! !r)   r   c                   ,   a  ] tR tRt o R tR tRtV tR# )RatherBaroqueCachei`  c                    Wn         R # r5   r   )r$   newFoos   &&r&   observe_fooRatherBaroqueCache.observe_fooa  s    r)   c                2    \         P                  ! R 4       R# )zthe end of thingsN)r   r  r6   s   &r&   observe_endRatherBaroqueCache.observe_endd  s    #$r)   r  N)r+   r,   r-   r.   r  r  r/   r0   r1   s   @r&   r  r  `  s     % %r)   r  c                   8   a  ] tR tRt o R tR tR tR tRtV t	R# )SimpleLocalCacheik  c                <    V P                   P                  V4       R # r5   )__dict__update)r$   r   s   &&r&   setCopyableState!SimpleLocalCache.setCopyableStatel  s    U#r)   c                    V P                   # r5   checkr6   s   &r&   checkMethodSimpleLocalCache.checkMethodo      zzr)   c                    V # r5   r*   r6   s   &r&   	checkSelfSimpleLocalCache.checkSelfr  s    r)   c                    ^# r   r*   r6   s   &r&   r#  SimpleLocalCache.checku  s    r)   r*   N)
r+   r,   r-   r.   r  r$  r(  r#  r/   r0   r1   s   @r&   r  r  k  s     $ r)   r  c                   2   a  ] tR tRt o R tR tR tRtV tR# )NestedCachei|  c                $    \        4       V n        R # r5   )r   r   r6   s   &r&   rN   NestedCache.__init__}  s    r)   c                2    V P                   V P                   .# r5   r   r6   s   &r&   r   NestedCache.remote_getCache  s    r)   c                    V P                   VJ # r5   r1  r$   caches   &&r&   remote_putCacheNestedCache.remote_putCache  s    vvr)   r1  N)	r+   r,   r-   r.   rN   r   r6  r/   r0   r1   s   @r&   r-  r-  |  s       r)   r-  c                   8   a  ] tR tRt o R tR tR tR tRtV t	R# )
Observablei  c                    . V n         R # r5   	observersr6   s   &r&   rN   Observable.__init__  s	    r)   c                <    V P                   P                  V4       R # r5   )r<  appendr$   obss   &&r&   remote_observeObservable.remote_observe      c"r)   c                <    V P                   P                  V4       R # r5   )r<  remover@  s   &&r&   remote_unobserveObservable.remote_unobserve  rD  r)   c                P    V P                    F  pVP                  R W4       K  	  R# )notifyN)r<  r  )r$   objr  s   && r&   rJ  Observable.notify  s     H$4 'r)   r;  N)
r+   r,   r-   r.   rN   rB  rG  rJ  r/   r0   r1   s   @r&   r9  r9    s     ##5 5r)   r9  c                   8   a  ] tR tRt o R tR tR tR tRtV t	R# )DeferredRemotei  c                    ^ V n         R# )    Nrunr6   s   &r&   rN   DeferredRemote.__init__  s	    r)   c                     Wn         V^,           # r   rQ  r   s   &&r&   runMeDeferredRemote.runMe  r   r)   c                    Q R4       h)rP  zshouldn't have been run!r*   r   s   &&r&   	dontRunMeDeferredRemote.dontRunMe  s    ,,,qr)   c                r    \        4       pVP                  V P                  V P                  4       Wn        V# )zW
Return a L{Deferred} to be fired on client side. When fired,
C{self.runMe} is called.
)r   addCallbacksrU  rX  d)r$   r\  s   & r&   remote_doItLaterDeferredRemote.remote_doItLater  s+    
 J	tzz4>>2r)   )r\  rR  N)
r+   r,   r-   r.   rN   rU  rX  r]  r/   r0   r1   s   @r&   rN  rN    s     - r)   rN  c                   .   a  ] tR tRt o ^ tRtR tRtV tR# )Observeri  Nc                f    W n         V P                  ^,           V n        VP                  RV 4       R# )r   	unobserveN)rK  notifiedr  )r$   otherrK  s   &&&r&   remote_notifyObserver.remote_notify  s'    )d+r)   )rc  rK  )	r+   r,   r-   r.   rc  rK  re  r/   r0   r1   s   @r&   r`  r`    s     H
C, ,r)   r`  c                   &   a  ] tR tRt o R tRtV tR# )NewStyleCopyi  c                    Wn         R # r5   s)r$   rk  s   &&r&   rN   NewStyleCopy.__init__  s    r)   rj  Nr   r1   s   @r&   rh  rh    s      r)   rh  c                   8   a  ] tR tRt o ^ t^ t^tR tR tRt	V t
R# )NewStyleCopy2i  c                x    \         ;P                  ^,          un        \        P                  V 4      p^Vn        V# r   )rn  	allocatedobject__new__r   )r$   r   s   & r&   rr  NewStyleCopy2.__new__  s-    1$~~d#
r)   c                @    \         ;P                  ^,          un        R# r   )rn  initializedr6   s   &r&   rN   NewStyleCopy2.__init__  s    !!Q&!r)   r*   N)r+   r,   r-   r.   rp  ru  r   rr  rN   r/   r0   r1   s   @r&   rn  rn    s#     IKE' 'r)   rn  c                   &   a  ] tR tRt o R tRtV tR# )NewStyleCacheCopyi  c                    V P                   # r5   )r  r  s   &&&r&   r	  .NewStyleCacheCopy.getStateToCacheAndObserveFor  s    }}r)   r*   N)r+   r,   r-   r.   r	  r/   r0   r1   s   @r&   rx  rx    s      r)   rx  c                   ,   a  ] tR tRt o R tR tRtV tR# )Echoeri  c                    V# r5   r*   r$   sts   &&r&   remote_echoEchoer.remote_echo  s    	r)   c                    W3# r5   r*   )r$   r  kws   &&,r&   remote_echoWithKeywordsEchoer.remote_echoWithKeywords  s	    xr)   r*   N)r+   r,   r-   r.   r  r  r/   r0   r1   s   @r&   r|  r|    s      r)   r|  c                   ,   a  ] tR tRt o R tR tRtV tR# )CachedReturneri  c                    Wn         R # r5   r5  r4  s   &&r&   rN   CachedReturner.__init__  s    
r)   c                    V P                   # r5   r  r~  s   &&r&   remote_giveMeCache!CachedReturner.remote_giveMeCache  r&  r)   r  N)r+   r,   r-   r.   rN   r  r/   r0   r1   s   @r&   r  r    s      r)   r  c                   >   a  ] tR tRt o R tR tR tR tR tRt	V t
R# )	NewStyleTestsi  c                   \         P                  ! \        4       4      V n        \         P                  ! 4       p\        WV P                  R7      w  q n        V n        V P                  VP                  4       4      V n
        R# )zI
Create a pb server using L{Echoer} protocol and connect a client to it.
)r{   rr   r|   N)r   r   r|  r|   r   r   rK   rS   successResultOfgetRootObjectref)r$   rr   rJ   s   &  r&   setUpNewStyleTests.setUp  sb      //9**,)?$BTBT*
&TY ''(C(C(EFr)   c                H    ^ \         n        ^ \         n        ^\         n        R# )zX
Close client and server connections, reset values of L{NewStyleCopy2}
class variables.
N)rn  rp  ru  r   r6   s   &r&   tearDownNewStyleTests.tearDown  s    
 #$$%!r)   c                   a a \        R4      oS P                  P                  RS4      pS P                  P	                  4        VV 3R lpVP                  V4       V# )zI
Create a new style object, send it over the wire, and check the result.
r   echoc                    < SP                  V \        4       SP                  V P                  R 4       SP	                  V SJ 4       R# )r   N)assertIsInstancerh  assertEqualrk  assertFalseresorigr$   s   &r&   cb'NewStyleTests.test_newStyle.<locals>.cb  s9    !!#|4SUUG,SD[)r)   rh  r  r  rS   rU   addCallbackr$   r\  r  r  s   f  @r&   test_newStyleNewStyleTests.test_newStyle  sK     G$HH-			*
 	
br)   c                :  a a \        4       oS P                  \         P                  ^4       S P                  \         P                  ^4       S P                  P                  RS4      pS P                  P                  4        VV 3R lpVP                  V4       V# )z>
Send a new style object and check the number of allocations.
r  c                   < SP                  V \        4       SP                  V P                  ^4       SP                  \        P                  ^4       SP                  \        P
                  ^4       SP                  V S4       R# r   N)r  rn  r  r   rp  ru  assertIsNotr  s   &r&   r  $NewStyleTests.test_alloc.<locals>.cb  sc    !!#}5SYY*]44a8]66:S$'r)   )	rn  r  rp  ru  r  r  rS   rU   r  r  s   f  @r&   
test_allocNewStyleTests.test_alloc  st     00!422A6HH-			( 	
br)   c                   a a \        R4      oS P                  P                  RSRRR7      pS P                  P	                  4        VV 3R lpVP                  V4       V# )zW
Create a new style object with keywords,
send it over the wire, and check the result.
value1echoWithKeywordsonetwo)keyword1keyword2c                 Z  < SP                  V \        4       SP                  V ^ ,          \        4       SP                  V ^,          \        4       SP	                  V ^ ,          P
                  R4       SP                  V ^ ,          S4       SP	                  V ^,          RRRR/4       R# )rP  r  r  r  r  r  N)r  tuplerh  dictr  rk  r  r  s   &r&   r  3NewStyleTests.test_newStyleWithKeywords.<locals>.cb.  s    !!#u-!!#a&,7!!#a&$/SVXXx0SVT*SVj%U%KLr)   r  r  s   f  @r&   test_newStyleWithKeywords'NewStyleTests.test_newStyleWithKeywords#  sZ    
 H%HHuu   
 				M 	
br)   )rS   r  rK   r|   N)r+   r,   r-   r.   r  r  r  r  r  r/   r0   r1   s   @r&   r  r    s$     	G  , r)   r  c                   4   a  ] tR tRt o RtRtR tR tRtV t	R# )ConnectionNotifyServerFactoryi:  aJ  
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                b    \         P                  P                  W4       \        4       V n        R# )z
Initialize the factory.
N)r   r   rN   r   connectionMade)r$   roots   &&r&   rN   &ConnectionNotifyServerFactory.__init__I  s"     	##D/&jr)   c                f    Wn         V P                  Ruq n        Ve   VP                  R4       R# R# )z6
Store the protocol and fire the connection deferred.
N)protocolInstancer  r   )r$   r   r\  s   && r&   clientConnectionMade2ConnectionNotifyServerFactory.clientConnectionMadeP  s3     !)!%!4!4d=JJt r)   )r  r  )
r+   r,   r-   r.   r9   r  rN   r  r/   r0   r1   s   @r&   r  r  :  s!     
 ) r)   r  c                   2   a  ] tR tRt o R tR tR tRtV tR# )NewStyleCachedTestsiZ  c                  a  \        4       S n        RS P                  n        \        P                  ! ^ \        \        S P                  4      4      4      S n        \        P                  ! 4       p\        P                  ! RS P                  P                  4       P                  V4       V 3R lpVP                  4       P                  V4      pS P                  P                  P                   p\#        W4.4      # )zQ
Create a pb server using L{CachedReturner} protocol and connect a
client to it.
r   	localhostc                    < V Sn         R # r5   )r  )r  r$   s   &r&   gotRoot*NewStyleCachedTests.setUp.<locals>.gotRooth  s
    DHr)   )rx  r  rk  r   	listenTCPr  r  rK   r   r   
connectTCPgetHostportr  r  factoryr  r   )r$   rr   r  d1d2s   f    r&   r  NewStyleCachedTests.setUp[  s    
 &'			'',^DII-FG
 **,;(;(;(=(B(BMR	 ((*66w?[[  //bX&&r)   c                   V P                   P                  P                  P                  P	                  4        V P
                  P                  P                  P	                  4        V P                   P                  4       # )z&
Close client and server connections.
)rK   r  r  r^   loseConnectionr  rk   stopListeningr6   s   &r&   r  NewStyleCachedTests.tearDowno  sS     	,,66EEG!!002{{((**r)   c                   a  S P                   P                  RS P                  4      pV 3R lpVP                  VR4       VP                  VR4       V# )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                   < SP                  V \        4       SP                  R V P                  4       SP	                  SP
                  V 4       V'       d.   V Sn        SP                  P                  RSP
                  4      # R# )r   r  N)	r  rx  r  rk  r  r  r  r  r  )r  againr$   s   &&r&   r  2NewStyleCachedTests.test_newStyleCache.<locals>.cb  sh    !!#'89Wcee,TYY, xx**=$))DD r)   TF)r  r  r  r  )r$   r\  r  s   f  r&   test_newStyleCache&NewStyleCachedTests.test_newStyleCachew  sH     HHtyy9	E 	
b$	b% r)   )r  r  r  rK   N)	r+   r,   r-   r.   r  r  r  r/   r0   r1   s   @r&   r  r  Z  s     '(+ r)   r  c                      a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tR tR tR tR tR tR tR tR tRtV tR# )BrokerTestsi  Nc                X     \         P                  ! R 4       R#   \         d     R# i ; i)None-None-TESTING.pubN)osunlinkOSErrorr6   s   &r&   r  BrokerTests.tearDown  s&    	II-. 		s    ))c                .    V P                  R V 24       R# )z&This should cause a return value, not Nfail)r$   errors   &&r&   thunkErrorBadBrokerTests.thunkErrorBad  s    		:5'BCr)   c                    Wn         R # r5   )thunkResultr$   results   &&r&   thunkResultGoodBrokerTests.thunkResultGood  s    !r)   c                    R # r5   r*   )r$   tbs   &&r&   thunkErrorGoodBrokerTests.thunkErrorGood      r)   c                .    V P                  R V 24       R# )z This should cause an error, not Nr  r  s   &&r&   thunkResultBadBrokerTests.thunkResultBad  s    		4VH=>r)   c                   \        V R 7      w  rp ! R R\        P                  4      p ! R R\        P                  4      pVP                  RV! 4       4       VP	                  R4      pV! 4       pV! 4       pVP                  RWx4       VP                  4        VP                  4        VP                  4        V P                  VP                  VR4       V P                  VP                  R4      VP                  R4      4       R# )	r{   c                   &   a  ] tR tRt o R tRtV tR# )%BrokerTests.test_reference.<locals>.Xi  c                    Wn         R # r5   caughtr   s   &&r&   remote_catch2BrokerTests.test_reference.<locals>.X.remote_catch  s    !r)   r  N)r+   r,   r-   r.   r  r/   r0   r1   s   @r&   Xr     s     " "r)   r  c                   &   a  ] tR tRt o R tRtV tR# )%BrokerTests.test_reference.<locals>.Yi  c                *    VP                  R V4       R# )catchNr  r$   abs   &&&r&   remote_throw2BrokerTests.test_reference.<locals>.Y.remote_throw  s    Wa(r)   r*   N)r+   r,   r-   r.   r  r/   r0   r1   s   @r&   Yr    s     ) )r)   r  r   throwzX should have caught ZN)r   r   ReferenceablesetNameForLocalremoteForNamer  rS   assertIsr  r  remoteMethod)	r$   r   rk  rS   r  r  r   r   r   s	   &        r&   test_referenceBrokerTests.test_reference  s    -48
d	"   	"	)   	) 	
#qs#OOC CC	Wa#						ahh#;< 	0!..2IJr)   c                   \        V R 7      w  rpW3W!33 F  w  rE\        4       pVP                  RV4       VP                  R4      p^V n        VP                  RV P                  ^,
          4      P                  V P                  V P                  4       VP                  4        VP                  4        V P                  V P                  V P                  R4       K  	  R# )r  r   thunkzresult wasn't received.N)r   r   r  r  expectedThunkResultr  r[  r  r  rS   r  r  )r$   r   rk  rS   r   r   r   bars   &       r&   test_resultBrokerTests.test_result  s    -48
dFQFNDA.CeS)//%(C'(D$NN7D$<$<q$@ANN$$d&8&8 IIKIIK  $":":<U #r)   c                    Wn         R # r5   )nestedRemoter  s   &&r&   refcountResultBrokerTests.refcountResult  s    "r)   c           
        . p. p\        V R 7      w  r4p\        4       pVP                  RV4       VP                  R4      p\	        \
        P                  ^
,           4       F  pVP                  P                  '       g   VP                  P                  '       d    MIVP                  R4      P                  VP                  VP                  4       VP                  4        K  	  \
        P                  ^,
          p	V P                  VP                  P                  R4       V P                  \        V4      V	RV	 R\        V4       24       R# )r  r   	getSimpleztransport was not closedz	expected z got N)r   r   r  r  ranger   MAX_BROKER_REFSr^   closedr  r[  r?  rS   
assertTruer  len)
r$   ler   rk  rS   r   r   ignoexpecteds
   &         r&   test_tooManyRefsBrokerTests.test_tooManyRefs  s    -48
dn	%%OOE"",,r12D{{!!!Q[[%7%7%7LL%22188QXXFIIK	 3
 %%)**,FGQYxjc!fX+NOr)   c                (   \        V R 7      w  rp\        4       pVP                  RV4       VP                  R4      pVP	                  R4      P                  V P                  V P                  4       VP                  4        VP                  4        V P                  V P                  P                  ^4       V P                  V P                  P                  R,          R4       V P                  V P                  P                  ^ ,          R4       R# )r  r   getCopyr   r   r{   N)r   r   r  r  r  r[  r  r  rS   r  r  r   r   r   )r$   r   rk  rS   r   r   s   &     r&   	test_copyBrokerTests.test_copy  s    -48
dl	%%OOE"	Y,,T-A-A4CUCUV				))++Q/))++G4g>))++A.7r)   c                   \        V R 7      w  rp\        4       p\        4       pVP                  RV4       VP	                  R4      pVP                  RV4       VP                  4        VP                  ^4       VP                  4        VP                  4        VP                  ^
4       VP                  4        VP                  4        V P                  VP                  R4       V P                  VP                  ^R4       R# )r  r  observezdidn't notifyznotified too muchN)r   r9  r`  r  r  r  rS   rJ  assertIsNotNonerK  r  )r$   r   rk  rS   r  r  ras   &      r&   test_observeBrokerTests.test_observe  s    -48
d LJ	#q!__S!
i#												QUUO4#67r)   c                r   \        V R 7      w  rp\        4       pVP                  RV4       VP                  R4      pVP	                  4        VP	                  4        . pVP                  R4      P                  VP                  4       VP	                  4        VP	                  4        V P                  VP                  R4       VP                  P                  ^4       V P                  VP                  ^R4       VP	                  4        VP	                  4        V P                  V^ ,          ^R4       R# )r  r\  	doItLaterzDeferred method run too early.zDeferred method run too late.zIncorrect result.N)r   rN  r  r  rS   r  r  r?  r  rR  r\  r   r  )r$   r   rk  rS   r\  r,  resultss   &      r&   
test_deferBrokerTests.test_defer  s    -48
d	#q!OOC 					[!--gnn=				 @A	Q#BC				Q(;<r)   c                x   \        V R 7      w  rp\        4       pVP                  RV4       VP                  R4      pVP	                  R4      P                  V P                  V P                  4       VP                  4        VP                  4        V P                  P                  pV P                  WbP                  4       V =	\        P                  R8  d   \        P                   ! 4        VP                  4        VP                  4        VP                  4        V P#                  WbP                  4       R# )r  r   r%     N)r   r   r  r  r  r[  r"  r  rS   r!  luidassertInlocalObjectssys
hexversiongccollectassertNotIn)r$   r   rk  rS   r   r  rluids   &      r&   test_refcountBrokerTests.test_refcount  s    -48
dn	%%ooe${#00!3!3	

 					 !!&&e^^,>>Y&JJL						/r)   c                f   \        V R 7      w  rp\        4       p\        4       pVP                  pVP	                  RV4       VP	                  RV4       VP                  R4      pVP                  R4      p. p	VP                  R4      P                  V	P                  4      P                  V	P                  4       VP                  R4      P                  V	P                  4      P                  V	P                  4       . p
VP                  R4      P                  V
P                  4       VP                  R4      P                  V
P                  4       VP                  4        V P                  V
^ ,          P                  ^4       V P                  V
^ ,          P                  ^4       V P                  V
^ ,          P                  ^4       VP                  4        VP                  4        V P                  V
^ ,          P                  ^4       V P                  \!        V	4      ^4       V	^ ,          ^ ,          pV P#                  VP%                  4       P&                  VR4       V P#                  VP)                  4       VR4       . pVP                  RV4      P                  VP                  4       VP                  4        V P+                  V^ ,          4       V P                  VP-                  R4      VP-                  R4      4       VP.                  pV
^ ,          P.                  pV P1                  WP2                  R4       ?	?VP                  4        ?
?VP                  4        \4        P6                  R8  d   \8        P:                  ! 4        VP                  4        V P=                  WP2                  R	4       V P=                  WP>                  R
4       V P=                  WP2                  R4       V P=                  WP>                  R4       V PA                  VPB                  R4       R# )r  rK  xxxgetCachezpotential refcounting issuez!other potential refcounting issueputCachezremote cache doesn't have itrA  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 removedN)"r   r-  r   r   r  r  r  r  r?  
addErrbackrU   r  r   r   r   r  r*  assertIdenticalr$  __self__r(  r)  r  rB  rC  remotelyCachedObjectsrE  rF  rG  rH  rI  locallyCachedObjectsassertIsNoner  )r$   r   rk  rS   rK  obj2vcco2o3collcomplexcpcol2rB  baroqueLuids   &              r&   
test_cacheBrokerTests.test_cache4  s   -48
dm%'ff	%%	%&__U#__U#
j!--dkk:EEdkkR
j!--dkk:EEdkkR
j!--gnn=
j!--gnn=

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

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

Q 4booj6QR wwajood335ST



 >>Y&JJL

668VW557UV002U	
 	//1T	
 	#,,(BCr)   c                    \         P                  ! R 4       \        V R7      w  rp\	        4       pVP                  RV4       VP                  R4      p. pVP                  R4      P                  VP                  V P                  4       VP                  4        VP                  4       pV P                  VP                  ^4       V P                  VP                  ^4       V P                  VP                   ^4       V P                  VP"                  ^ 4       \        V R7      w  rpVP                  RV4       VP                  R4      pVP                  R4      P                  VP                  V P                  4       VP                  4        VP                  4       pV P                  VP"                  ^4       R#   \         d     ELi ; i)r  r  r   getPubN)r  r  r  r   GetPublisherr  r  r  r[  r?  r  rU   r   r  activateCalledisActivatedyayIGotPublished_wasCleanWhenLoaded)r$   r   rk  rS   r   r  accumrK  s   &       r&   test_publishableBrokerTests.test_publishablev  sh   	II-. .48
dn	%%ooe$x --ellD<N<NO

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

iik00!4/  		s   G   GGc                (    VP                   V n        R # r5   )r   r  )r$   vals   &&r&   gotCopyBrokerTests.gotCopy  s    66r)   c                   \        V R 7      w  rp^cp\        4       pVP                  RV4       VP                  R4      pVP	                  RV4      P                  V P                  V P                  4       VP                  4        VP                  4        VP                  4        V P                  V P                  VRV P                   24       R# )r  r   
getFactoryz!ID not correct on factory object N)r   r   r  r  r  r[  rn  r  rS   r  r  )r$   r   rk  rS   IDrK  r   s   &      r&   test_factoryCopyBrokerTests.test_factoryCopy  s    -48
dl	%%OOE"	\2&33DLL$BUBUV						/0@0@/AB	
r)   )r  r!  r  )r+   r,   r-   r.   r  r  r  r  r  r  r  r  r"  r/  r3  r9  r>  rK  r`  rj  rn  rs  r/   r0   r1   s   @r&   r  r    sj     KD"?K0(#P 
88(=$08@DD58"
 
r)   r  c                      V s VsR # r5   )callbackArgscallbackKeyword)argsr  s   *,r&   finishedCallbackry    s    LOr)   c                   ,   a  ] tR tRt o R tR tRtV tR# )	Pagerizeri  c                0    WVuV n         V n        V n        R # r5   )r   rx  r  )r$   r   rx  r  s   &&*,r&   rN   Pagerizer.__init__  s    ,4B)ty$'r)   c                    \         P                  ! V\        ^dV P                  .V P                  O5/ V P
                  B  R;V n        V n        R# )d   N)r   StringPager	bigStringr   rx  r  r$   	collectors   &&r&   remote_getPagesPagerizer.remote_getPages  sE    y#t}}	
7;yy	
DHGG	
 #"	DGr)   )rx  r   r  N)r+   r,   r-   r.   rN   r  r/   r0   r1   s   @r&   r{  r{    s     ?# #r)   r{  c                   0   a  ] tR tRt o RtR tR tRtV tR# )FilePagerizeri  Nc                <    Wn         W#VuV n        V n        V n        R # r5   )filenamer   rx  r  )r$   r  r   rx  r  s   &&&*,r&   rN   FilePagerizer.__init__  s     ,4B)ty$'r)   c                    \         P                  ! V\        V P                  R 4      V P                  .V P
                  O5/ V P                  B V n        R;V n        V n        R# )rbN)r   	FilePageropenr  r   rx  r  pagerr  s   &&r&   r  FilePagerizer.remote_getPages  sP    ^^tDMM40$--
BF))
OSww

 #"	DGr)   )rx  r   r  r  r  )	r+   r,   r-   r.   r  rN   r  r/   r0   r1   s   @r&   r  r    s     E?# #r)   r  c                   H   a  ] tR tRt o RtR tR tR tR tR t	R t
R	tV tR
# )PagingTestsi  z(
Test pb objects sending data by pages.
c                    V P                  4       V n        \        V P                  R4      ;_uu_ 4       pVP                  \        4       RRR4       R#   + '       g   i     R# ; i)z/
Create a file used to test L{util.FilePager}.
wbN)mktempr  r  writer  )r$   fs   & r&   r  PagingTests.setUp  s?     $--&&!GGI '&&&s   AA%	c           	        \        V R7      w  rpVP                  R\        \        R^
R7      4       VP	                  R4      p. p\
        P                  ! VR4      P                  VP                  4       V'       g   VP                  4        K  V P                  RP                  V^ ,          4      \        R4       V P                  \        RR4       V P                  \        R	^
/R4       R
# )zO
Test L{util.StringPager}, passing a callback to fire when all pages
are sent.
r  r   hellor   getPagesr)   'Pages received not equal to pages sent!Completed callback not invokedr   N)r  )r   r  r{  ry  r  r   getAllPagesr  r?  rS   r  joinr  rv  rw  r$   r   rk  rS   r   r+  s   &     r&   test_pagingWithCallback#PagingTests.test_pagingWithCallback  s    
 .48
d	%+;WB!OPOOE"J'33AHH=IIKHHQqTNI'P	
 	z3STgr],L	
r)   c                n   \        V R7      w  rpVP                  R\        R4      4       VP                  R4      p. p\        P
                  ! VR4      P                  VP                  4       V'       g   VP                  4        K  V P                  RP                  V^ ,          4      \        R4       R# )z.
Test L{util.StringPager} without a callback.
r  r   Nr  r)   r  )r   r  r{  r  r   r  r  r?  rS   r  r  r  r  s   &     r&   test_pagingWithoutCallback&PagingTests.test_pagingWithoutCallback  s     .48
d	%41OOE"J'33AHH=IIKHHQqTNI'P	
r)   c                   V P                  4       p\        VR4      P                  4        \        V R7      w  r#p\	        VR4      pVP                  RV4       VP                  R4      p. p\        P                  ! VR4      P                  VP                  4       ^
pV'       g#   V^ 8  d   VP                  4        V^,          pK*  V'       g   V P                  R4       V P                  RP                  V^ ,          4      RR4       R# )	z0
Test L{util.FilePager}, sending an empty file.
wr  Nr  r  zgetAllPages timed outr)   r  )r  r  closer   r  r  r  r   r  r  r?  rS   r  r  r  )	r$   filenameEmptyr   rk  rS   	pagerizerr   r+  ttls	   &        r&   test_emptyFilePaging PagingTests.test_emptyFilePaging  s     ]C &&(-48
d!-6		%+OOE"J'33AHH=aIIK1HCII-.!A$.WXr)   c                B   \        V R7      w  rp\        V P                  \        R^	R7      pVP	                  RV4       VP                  R4      p. p\        P                  ! VR4      P                  VP                  4       V'       g   VP                  4        K  V P                  RP                  V^ ,          4      \        R4       V P                  \        RR4       V P                  \        R	^	/R4       V P                  VP                   P"                  . 4       R
# )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  frodor  r  r  r)   r  r  r   N)r  )r   r  r  ry  r  r  r   r  r  r?  rS   r  r  r  rv  rw  r  chunksr$   r   rk  rS   r  r   r+  s   &      r&   test_filePagingWithCallback'PagingTests.test_filePagingWithCallback  s    
 .48
d!$--1A7RST		%+OOE"J'33AHH=IIKHHQqTNI'P	
 	z3STgq\+K	
 	//4r)   c                   \        V R7      w  rp\        V P                  R4      pVP                  RV4       VP	                  R4      p. p\
        P                  ! VR4      P                  VP                  4       V'       g   VP                  4        K  V P                  RP                  V^ ,          4      \        R4       V P                  VP                  P                  . 4       R# )z,
Test L{util.FilePager} without a callback.
r  Nr  r  r)   r  )r   r  r  r  r  r   r  r  r?  rS   r  r  r  r  r  r  s   &      r&   test_filePagingWithoutCallback*PagingTests.test_filePagingWithoutCallback%  s     .48
d!$--6		%+OOE"J'33AHH=IIKHHQqTNI'P	
 	//4r)   )r  N)r+   r,   r-   r.   r9   r  r  r  r  r  r  r/   r0   r1   s   @r&   r  r    s.     
(
Y(5,5 5r)   r  c                   &   a  ] tR tRt o R tRtV tR# )DumbPublishablei7  c                
    R ^/# )rg  r*   r6   s   &r&   getStateToPublish!DumbPublishable.getStateToPublish8  s    "A&&r)   r*   N)r+   r,   r-   r.   r  r/   r0   r1   s   @r&   r  r  7  s     ' 'r)   r  c                   &   a  ] tR tRt o R tRtV tR# )DumbPubi<  c                    ^V n         R# r   re  r6   s   &r&   	activatedDumbPub.activated=  s
    r)   r  N)r+   r,   r-   r.   r  r/   r0   r1   s   @r&   r  r  <  s        r)   r  c                   ,   a  ] tR tRt o R tR tRtV tR# )rd  iA  c                &    \        R 4      V n        R# )TESTINGN)r  pubr6   s   &r&   rN   GetPublisher.__init__B  s    "9-r)   c                    V P                   # r5   r  r6   s   &r&   remote_getPubGetPublisher.remote_getPubE  s    xxr)   r  N)r+   r,   r-   r.   rN   r  r/   r0   r1   s   @r&   rd  rd  A  s     . r)   rd  c                   B   a  ] tR tRt o RtR tR tR tR tR t	Rt
V tR	# )
DisconnectionTestsiL  z
Test disconnection callbacks.
c                    \        R V 24      h)zI shouldn't have been called: r   )r$   rx  s   &*r&   r  DisconnectionTests.errorQ  s    ;D6BCCr)   c                    ^V n         R# )z
Called on broker disconnect.
N)gotCallbackr6   s   &r&   gotDisconnected"DisconnectionTests.gotDisconnectedT  s     r)   c                J    V P                  WP                  4       ^V n        R# )z'
Called on RemoteReference disconnect.
N)r  remoteObjectobjectCallbackr$   os   &&r&   objectDisconnected%DisconnectionTests.objectDisconnectedZ  s      	--.r)   c                Z   \        V R 7      w  rpVP                  4        VP                  R\        4       4       VP	                  R4      p. pVP                  R\        4       4      P                  VP                  4       VP                  4        V P                  \        V4      ^4       R# )r  r  
setBadCopyN)r   rS   r  
BadCopySetr  r  BadCopyablerQ  r?  rU   r  r*  )r$   r   rk  rS   gr+  s   &     r&   test_badSerialization(DisconnectionTests.test_badSerializationa  sz    -48
d			#z|,OOC 	\;=1<<QXXF

Q#r)   c                   \        V R 7      w  rpVP                  4        VP                  R\        4       4       VP	                  R4      pVP                  4        VP                  4        VP                  4        VP                  V P                  4       V P                  V P                  VP                  4       VP                  V P                  4       V P                  V P                  VP                  4       VP                  V P                  4       V P                  VP                  VP                  4       V P                  V P                  VP                  4       VP                  V P                  4       V P                  VP                  VP                  4       V P                  V P                  VP                  4       VP                  V P                  4       VP                  V P                  4       W@n        VP!                  \"        P$                  ! \&        P(                  4      4       V P+                  V P,                  4       V P+                  V P.                  4       R# )r  r  N)r   rS   r  r   r  notifyOnDisconnectr  rC  disconnectsdontNotifyOnDisconnectrI  _disconnecteddisconnectCallbacksr  r  r  rh   r   ri   r   rj   r)  r  r  )r$   r   rk  rS   rs   &    r&   test_disconnection%DisconnectionTests.test_disconnectionk  s   -48
d			#|~. OOC 						 	
TZZ(djj!--0	  ,Q]]3	TZZ(aooq}}5djj!"7"78	  ,!--8Q%:%:; 	
T112	T445 	
)=)=>?(()++,r)   )r  r  r  N)r+   r,   r-   r.   r9   r  r  r  r  r  r/   r0   r1   s   @r&   r  r  L  s)     D $!- !-r)   r  c                       ] tR tRtRtR# )FreakOuti  r*   Nr   r*   r)   r&   r  r    r   r)   r  c                   &   a  ] tR tRt o R tRtV tR# )r  i  c                    \        4       hr5   )r  )r$   ps   &&r&   getStateToCopyForBadCopyable.getStateToCopyFor  s
    jr)   r*   N)r+   r,   r-   r.   r  r/   r0   r1   s   @r&   r  r    s      r)   r  c                   &   a  ] tR tRt o R tRtV tR# )r  i  c                    R # r5   r*   )r$   bcs   &&r&   remote_setBadCopyBadCopySet.remote_setBadCopy  s    r)   r*   N)r+   r,   r-   r.   r  r/   r0   r1   s   @r&   r  r    s      r)   r  c                   :   a  ] tR tRt o ^ tR tRR ltR tRtV t	R# )LocalRemoteTesti  c                    V^,           # r   r*   )r$   r   s   &&r&   	sync_add1LocalRemoteTest.sync_add1  s    1ur)   c                    W,           # r5   r*   )r$   r   r   s   &&&r&   	async_addLocalRemoteTest.async_add  s	    ur)   c                    \        4       hr5   r  r6   s   &r&   
async_failLocalRemoteTest.async_fail  s
    nr)   r*   N)rP  r   )
r+   r,   r-   r.   reportAllTracebacksr  r  r  r/   r0   r1   s   @r&   r  r    s      r)   r  c                   J   a  ] tR tRt o RtR;ttR tR tR t	R t
R tR	tV tR
# )MyPerspectivei  z
@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                    Wn         R # r5   rA   r$   rA   s   &&r&   rN   MyPerspective.__init__  s     r)   c                    V P                   # )zD
Return the avatar identifier which was used to access this avatar.
r  r6   s   &r&   perspective_getAvatarId%MyPerspective.perspective_getAvatarId  s     }}r)   c                    \        4       # r5   )MyViewr6   s   &r&   perspective_getViewPoint&MyPerspective.perspective_getViewPoint  s	    xr)   c                    W,           # )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_addMyPerspective.perspective_add  s     ur)   c                    R V n         R# TN	loggedOutr6   s   &r&   logoutMyPerspective.logout  	    r)   )rA   r  N)r+   r,   r-   r.   r9   loggedInr  rN   r  r  r  r  r/   r0   r1   s   @r&   r  r    s4      ! Hy! r)   r  c                   2   a  ] tR tRt o Rt]tRtR tRt	V t
R# )	TestRealmi  a  
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                R   V\         P                  8X  g   Q hVR8X  g   Q hV\        P                  J d   \         P                  \	        4       R 3# V P                  V4      V n        RV P                  n        \         P                  V P                  V P                  P                  3# )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                      R # r5   r*   r*   r)   r&   r>   )TestRealm.requestAvatar.<locals>.<lambda>  s    dr)   T)	r   r@   r   	ANONYMOUSr|  perspectiveFactorylastPerspectiver  r  )r$   rA   rB   	interfaces   &&&&r&   rE   TestRealm.requestAvatar  s     BOO+++y   x)))??FHl::#'#:#:8#DD ,0D  )OOT%9%94;O;O;V;VWWr)   )r$  )r+   r,   r-   r.   r9   r  r#  r$  rE   r/   r0   r1   s   @r&   r  r    s#     
 'OX Xr)   r  c                   &   a  ] tR tRt o R tRtV tR# )r  i  c                "    \        V\        4      # r5   )r!   r  r#   s   &&r&   
view_checkMyView.view_check  s    $..r)   r*   N)r+   r,   r-   r.   r)  r/   r0   r1   s   @r&   r  r    s     / /r)   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )
LeakyRealmi  zQ
A realm which hangs onto a reference to the mind object in its logout
function.
c                    Wn         R# )zx
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&   rN   LeakyRealm.__init__  s	     $r)   c                z   aa V P                  S4       V P                  V4      o\        P                  SVV3R  l3# )c                  (   < S SP                  4       3# r5   )r  )rB   persps   r&   r>   *LeakyRealm.requestAvatar.<locals>.<lambda>  s    u||~0Fr)   )r/  r#  r   r@   )r$   rA   rB   r%  r4  s   &&f&@r&   rE   LeakyRealm.requestAvatar  s1    ''1(FGGr)   r.  N)	r+   r,   r-   r.   r9   rN   rE   r/   r0   r1   s   @r&   r,  r,    s     
$H Hr)   r,  c                   *   a  ] tR tRt o RtR tRtV tR# )NewCredLeakTestsi	  z'
Tests to try to trigger memory leaks.
c                  a aaa	 RS n         V 3R lp\        S \        V4      R7      w  po	o. oVP                  R4      pVP	                  RR4      pR pVP                  V4       VVV	3R lpVP                  V4       SP                  4        S P                  S^.4       \        P                  ! 4        S P                  S P                  4       4       R# )	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                 >   < \         P                  ! V 4      Sn        R # r5   )weakrefr  mindRef)rB   r$   s   &r&   
setMindRef4NewCredLeakTests.test_logoutLeak.<locals>.setMindRef  s    ";;t,DLr)   )r{   r   r  loginr   c                 n    V w  r\        4       pVP                  R \        P                  ! VR4      V4      # )respondr   )r   r  r   rA  )r   	challenge
challengerrB   s   &   r&   
cbResponse4NewCredLeakTests.test_logoutLeak.<locals>.cbResponse$  s6    $%!I>D((2::i:D r)   c                    < SP                  4        SP                  ^4       SP                  \        P                  ! \        R4      4      4       R# )r   boomN)rX   r?  rh   r   ri   r   )_connectionBrokenrS   r   s   &r&   rh   8NewCredLeakTests.test_logoutLeak.<locals>.connectionLost-  s6    IIK##A&''V8L(MNr)   )r<  r   r,  r  r  r  rU   r  rG  rH  rV  )
r$   r=  r~   r  r\  rD  rh   rI  rS   r   s
   f      @@@r&   test_logoutLeak NewCredLeakTests.test_logoutLeak  s     	- ,DZ
3,
(lD
 ))&1OOGX.	 	
j!	O
 	
n% 	

)A3/
 	

$,,.)r)   )r<  N)r+   r,   r-   r.   r9   rK  r/   r0   r1   s   @r&   r8  r8  	  s     .* .*r)   r8  c                      a  ] tR tRt o RtR tRR lt]P                  ! ]	P                  4      3R ltR tR tR	 tR
 tR tR tR tR tR tR tR tR tR tR tRtV tR# )NewCredTestsi?  z5
Tests related to the L{twisted.cred} support in PB.
c                    \        4       V n        \        P                  ! V P                  4      V n        \	        V P                  4      V n        \        P                  ! 4       V n        R# )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   r  r|   r   r   rr   r6   s   &r&   r  NewCredTests.setUpD  sC     [
mmDJJ/:4;;G//1r)   Nc                R   \        W P                  V P                  4      w  V n        V n        V n        \        4       V n        \        \        P                  ! RRR4      V P                  4      V n        V P                  P                  4       P                  V P                  4       R# )an  
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}
TCPru   i  N)r   rr   r|   rJ   rK   rS   r   connectorStater   r   IPv4Addressro   r   r  establishClientAndServer)r$   _ignoreds   &&r&   rU  %NewCredTests.establishClientAndServerO  s    , /E$$d&8&8/
+T[$) >?3{D94;N;N
 	++-99$:W:WXr)   c                    V P                  V P                  P                  P                  4       V P                  P	                  V4       V P
                  P                  V P                  V4       R# )aL  
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)  rJ   r^   r(  rh   rr   rq   ro   )r$   rp   s   &&r&   completeClientLostConnection)NewCredTests.completeClientLostConnectiono  sN     	--445 	""6*//Gr)   c                   a  S P                  4        S P                  P                  4       pV 3R lpV 3R lpVP                  V4       VP                  V4       V# )z
Assert that L{PBClientFactory.getRootObject}'s Deferred fires with
a L{RemoteReference}, and that disconnecting it runs its
disconnection callbacks.
c                 H   < SP                  V \        P                  4       V # r5   )r  r   RemoteReference)rootObjr$   s   &r&   gotRootObject6NewCredTests.test_getRootObject.<locals>.gotRootObject  s    !!'2+=+=>Nr)   c                    < \        4       pV P                  VP                  4       SP                  P	                  4        SP                  4        V# r5   )r   r  r   rr   
disconnectrY  )r^  disconnectedDeferredr$   s   & r&   rb  3NewCredTests.test_getRootObject.<locals>.disconnect  sD    #+: &&';'D'DE))+--/''r)   rU  rr   r  r  )r$   rootObjDeferredr_  rb  s   f   r&   test_getRootObjectNewCredTests.test_getRootObject  sS     	%%',,::<		( 	##M2##J/r)   c                   a  S P                  4        S P                  P                  4       pV 3R lpVP                  V4      # )z{
Test that when a connection is lost, calling a method on a
RemoteReference obtained from it raises L{DeadReferenceError}.
c                    <a  \        4       pS P                  VP                  4       V V3R  lpVP                  V4       SP                  P                  4        SP                  4        V# )c                 ^   < SP                  \        P                  SP                  R 4       R# )methodN)assertRaisesr   DeadReferenceErrorr  )ignr^  r$   s   &r&   lostConnectionSNewCredTests.test_deadReferenceError.<locals>.gotRootObject.<locals>.lostConnection  s!    !!""7"79K9KXVr)   )r   r  r   r  rr   rb  rY  )r^  rc  rp  r$   s   f  r&   r_  ;NewCredTests.test_deadReferenceError.<locals>.gotRootObject  sZ    #+: &&';'D'DEW !,,^<))+--/''r)   re  )r$   rf  r_  s   f  r&   test_deadReferenceError$NewCredTests.test_deadReferenceError  s=    
 	%%',,::<	( **=99r)   c                   a   ! R R\         P                  4      pV! 4       S n        S P                  4        S P                  P	                  4       pV 3R lpVP                  V4      # )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                   *   a  ] tR tRt o RtR tRtV tR# )=NewCredTests.test_clientConnectionLost.<locals>.ReconnectOncei  Fc                    V P                   '       * pR V n         \        P                  P                  WW#4      pV'       d   VP	                  4        V# )T)reconnectedAlreadyr   r   rq   r   )r$   ro   rp   reconnectingr  s   &&&  r&   rq   RNewCredTests.test_clientConnectionLost.<locals>.ReconnectOnce.clientConnectionLost  sI    #'#:#::*.'++@@V  %%'r)   )ry  N)r+   r,   r-   r.   ry  rq   r/   r0   r1   s   @r&   ReconnectOncerw    s     !& r)   r|  c                   < SP                  V \        P                  4       \        4       pV P	                  VP
                  4       SP                  P                  4        SP                  4        V3R  lpVP                  V4      # )c                 f   < SP                   P                  4       pV3R  lpVP                  V4      # )c                    < SP                  V \        P                  4       \        4       pV P	                  VP
                  4       SP                  P                  4        SP                  4        V# r5   )	r  r   r]  r   r  r   rr   rb  rY  )anotherRootObjr\  r$   s   & r&   gotAnotherRootObjectqNewCredTests.test_clientConnectionLost.<locals>.gotRootObject.<locals>.disconnected.<locals>.gotAnotherRootObject  sU    )).":L:LM 
A"55ajjA&&113557Hr)   )rr   r  r  )ro  r\  r  r$   s   &  r&   rg   SNewCredTests.test_clientConnectionLost.<locals>.gotRootObject.<locals>.disconnected  s.    &&446 }}%9::r)   )
r  r   r]  r   r  r   rr   rb  rY  r  )r^  r\  rg   r$   s   &  r&   r_  =NewCredTests.test_clientConnectionLost.<locals>.gotRootObject  sf    !!'2+=+=>
A&&qzz2))+--/; ==..r)   )r   r   rr   rU  r  r  )r$   r|  rf  r_  s   f   r&   test_clientConnectionLost&NewCredTests.test_clientConnectionLost  sY    	B.. 	 +_%%',,::<	/0 **=99r)   c                   V P                  4        V P                  P                  R4      pVP                  \        P
                  ! \        4       4      4       VP                  \        P                  ! \        P                  4      4       R# )z|
Test that if a Broker loses its connection without receiving any bytes,
it doesn't raise any exceptions or log any errors.
N)ru   i90  )rU  r|   rv   rx   r   ry   rw   rh   r   ri   r   rj   )r$   serverProtos   & r&   test_immediateClose NewCredTests.test_immediateClose  s_    
 	%%'((667KL""8#7#7
#CD""7??43G3G#HIr)   c                   \         P                  ! 4       pVP                  \        P                  ! RR4      4      pVP                  R\        P                  ! \        R4      4      4       V P                  V\        4      # )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   ri   r   assertFailure)r$   rr   loginDeferreds   &  r&   test_loginConnectionRefused(NewCredTests.test_loginConnectionRefused  sp     **,%++((8
 	,,OO&'JK	
 !!-1GHHr)   c                F  a a S P                   P                  \        P                  ! RR7      4       \        P
                  ! RR4      pRp\        4       oS P                  P                  W4      pVV 3R lpV 3R lpVP                  V4       VP                  V4       V 3R lpVP                  V4       S P                  4        S P                  P                  4        \        P                  ! 4        S P                  P                  4        SP                  R4       V# )	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                    < SP                  SP                  P                  P                  4       SP	                  V \
        P                  4       S# r5   )r)  r   r$  r  r  r   r]  )r  loginCompletedr$   s   &r&   cbLogin.NewCredTests.test_loginLogout.<locals>.cbLogin  s;    OODJJ66??@!!+r/A/AB!!r)   c                 \   < SP                   P                  4        SP                  4        R # r5   )rr   rb  rY  ignoredr$   s   &r&   cbDisconnect3NewCredTests.test_loginLogout.<locals>.cbDisconnect  s!    ))+--/r)   c                 f   < SP                  SP                  P                  P                  4       R # r5   )r)  r   r$  r  r  s   &r&   cbLogout/NewCredTests.test_loginLogout.<locals>.cbLogout&  s    OODJJ66@@Ar)   N)r	   registerCheckerr   r   r   r  r   rr   r?  r  rU  rS   rU   rG  rH  r   )r$   credsrB   r\  r  r  r  r  s   f      @r&   test_loginLogoutNewCredTests.test_loginLogout  s    
 	##<<'J	
 ,,Wg> !$$U1	"
	0 	
g	l#	B 	
h%%'		 	

		%r)   c                H  a a \        4       o ! V3R lR\        P                  4      pVS P                  n        S P
                  P                  \        P                  ! RR7      4       S P                  P                  \        P                  ! RR4      R4      pV3R lpVP                  V4       V 3R lpVP                  V4       S P                  4        S P                  P!                  4        \"        P$                  ! 4        S P                  P!                  4        V# )	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                   8   <a  ] tR tRt o RtR tV3R ltRtV tR# )=NewCredTests.test_logoutAfterDecref.<locals>.EventPerspectivei>  z9
An avatar which fires a Deferred when it is logged out.
c                    R # r5   r*   r  s   &&r&   rN   FNewCredTests.test_logoutAfterDecref.<locals>.EventPerspective.__init__C  s    r)   c                *   < SP                  R 4       R # r5   )r   )r$   r  s   &r&   r  DNewCredTests.test_logoutAfterDecref.<locals>.EventPerspective.logoutF  s    ""4(r)   r*   N)	r+   r,   r-   r.   r9   rN   r  r/   r0   )r2   r  s   @r&   EventPerspectiver  >  s     ) )r)   r  r  r  r  r  c                    < S# r5   r*   )avatarr  s   &r&   
cbLoggedIn7NewCredTests.test_logoutAfterDecref.<locals>.cbLoggedInS  s     r)   c                 h   < SP                  SP                  P                  P                  / 4       R # r5   )r  r|   r  _localCleanupr  s   &r&   cbLoggedOut8NewCredTests.test_logoutAfterDecref.<locals>.cbLoggedOutZ  s(     T//@@NNPRSr)   )r   r   Avatarr   r#  r	   r  r   r   rr   r?  r   r  r  rU  rS   rU   rG  rH  )r$   r  r\  r  r  r  s   f    @r&   test_logoutAfterDecref#NewCredTests.test_logoutAfterDecref6  s     J			)ryy 		) )9

%##<<H	
 $$((8)
	
 	
j!	T
 	
k"%%' 			 	

		r)   c                  a  S P                   P                  \        P                  ! RRR7      4       S P                  P                  \        P                  ! RR4      R4      pS P                  P                  \        P                  ! RR4      R4      p\        W.4      pR pVP                  V4       V 3R lpVP                  V4       S P                  4        S P                  P                  4        V# )	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                 `    V w  r\        VP                  R 4      VP                  R 4      .4      # )getAvatarId)r   r  )r  firstseconds   &  r&   r  5NewCredTests.test_concurrentLogin.<locals>.cbLoggedIn}  s4    $OU !!-0&2C2CM2RS r)   c                 X   < V w  rSP                  VR 4       SP                  VR4       R# )r  r  N)r  )r   r  r  r$   s   &  r&   cbAvatarIds6NewCredTests.test_concurrentLogin.<locals>.cbAvatarIds  s*    MEUF+VV,r)   )r	   r  r   r   rr   r?  r   r  r   r  rU  rS   rU   )r$   
firstLoginsecondLoginr\  r  r  s   f     r&   test_concurrentLogin!NewCredTests.test_concurrentLoginl  s    
 	##<<WU	
 ''--((8)

 ((..((99
 :34	 	
j!	-
 	
k"%%'		r)   c                  a  S P                   P                  \        P                  ! RR7      4       S P                  P                  \        P                  ! RR4      4      pS P                  P                  \        P                  ! RR4      4      pS P                  V\        4       S P                  V\        4       \        W.4      pV 3R lpVP                  V4       S P                  4        S P                  P                  4        V# )zb
Test that a login attempt with an invalid user or invalid password
fails in the appropriate way.
r  r  s
   nosuchuserr  s	   wrongpassc                 h   < SP                  \        4      pSP                  \        V4      ^4       R# r  )flushLoggedErrorsr
   r  r*  ignoreerrorsr$   s   & r&   cleanup;NewCredTests.test_badUsernamePasswordLogin.<locals>.cleanup  s(    ++,=>FS[!,r)   )r	   r  r   r   rr   r?  r   r  r  r
   r   r  rU  rS   rU   )r$   r  r  r\  r  s   f    r&   test_badUsernamePasswordLogin*NewCredTests.test_badUsernamePasswordLogin  s    
 	##<<'J	
 ''--((@

 ((..((,?
 	:'89;(9::34	- 	
g%%'		r)   c                t   V P                   P                  \        P                  ! 4       4       V P                  P                  \        P                  ! 4       R4      pR pVP                  V4       VP                  V P                  ^{4       V P                  4        V P                  P                  4        V# )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                 &    V P                  R ^{4      # r  r  r  s   &r&   r  4NewCredTests.test_anonymousLogin.<locals>.cbLoggedIn      ))&#66r)   )r	   r  r   AllowAnonymousAccessrr   r?  r   	Anonymousr  r  rU  rS   rU   )r$   r\  r  s   &  r&   test_anonymousLogin NewCredTests.test_anonymousLogin  s     	##H$A$A$CD$$[%:%:%<iH	7 	
j!	d&&,%%'		r)   c                t  a  S P                   P                  \        P                  ! RR7      4       S P                  P                  \        P                  ! 4       R4      pS P                  V\        4       V 3R lpVP                  V4       S P                  4        S P                  P                  4        V# )zO
Verify that without an anonymous checker set up, anonymous login is
rejected.
passr  r  c                 h   < SP                  \        4      pSP                  \        V4      ^4       R# r   )r  r   r  r*  r  s   & r&   r  =NewCredTests.test_anonymousLoginNotPermitted.<locals>.cleanup  s(    ++,@AFS[!,r)   )r	   r  r   r   rr   r?  r   r  r  r   r  rU  rS   rU   )r$   r\  r  s   f  r&   test_anonymousLoginNotPermitted,NewCredTests.test_anonymousLoginNotPermitted  s    
 	##<<&I	
 $$[%:%:%<iH123	- 	
g%%'		r)   c                   V P                   P                  \        P                  ! 4       4       V P                   P                  \        P                  ! RR7      4       V P
                  P                  \        P                  ! 4       R4      pR pVP                  V4       VP                  V P                  ^{4       V P                  4        V P                  P                  4        V# )zl
Like L{test_anonymousLogin} but against a portal with a checker for
both IAnonymous and IUsernamePassword.
r  r  r  c                 &    V P                  R ^{4      # r  r  r  s   &r&   r  ENewCredTests.test_anonymousLoginWithMultipleCheckers.<locals>.cbLogin  r  r)   )r	   r  r   r  r   rr   r?  r   r  r  r  rU  rS   rU   r$   r\  r  s   &  r&   'test_anonymousLoginWithMultipleCheckers4NewCredTests.test_anonymousLoginWithMultipleCheckers  s    
 	##H$A$A$CD##<<'J	
 $$[%:%:%<iH	7 	
g	d&&,%%'		r)   c                   V P                   P                  \        P                  ! 4       4       V P                   P                  \        P                  ! RR7      4       V P
                  P                  \        P                  ! RR4      R4      pR pVP                  V4       VP                  V P                  ^{4       V P                  4        V P                  P                  4        V# )zh
Like L{test_anonymousLoginWithMultipleCheckers} but check that
username/password authentication works.
r  r  r  r  c                 (    V P                  R ^d^4      # )addr  r  s   &r&   r  INewCredTests.test_authenticatedLoginWithMultipleCheckers.<locals>.cbLogin  s    ))%b99r)   )r	   r  r   r  r   rr   r?  r   r  r  r  rU  rS   rU   r  s   &  r&   +test_authenticatedLoginWithMultipleCheckers8NewCredTests.test_authenticatedLoginWithMultipleCheckers  s    
 	##H$A$A$CD##<<'J	
 $$((':I
	: 	
g	d&&,%%'		r)   c                   V P                   P                  \        P                  ! RR7      4       V P                  P                  \        P                  ! RR4      R4      pR pVP                  V4       R pVP                  V4       VP                  V P                  4       V P                  4        V P                  P                  4        V# )zJ
Verify that a viewpoint can be retrieved after authenticating with
cred.
r  r  r  r  c                 $    V P                  R 4      # )getViewPointr  r  s   &r&   r  'NewCredTests.test_view.<locals>.cbLogin  s    )).99r)   c                 $    V P                  R 4      # r"  r  )	viewpoints   &r&   cbView&NewCredTests.test_view.<locals>.cbView  s    ''00r)   )r	   r  r   r   rr   r?  r   r  r  r)  rU  rS   rU   )r$   r\  r  r  s   &   r&   	test_viewNewCredTests.test_view
  s    
 	##<<'J	
 $$((':I
	: 	
g	1 	
f	doo&%%'		r)   )	rJ   rr   ro   rS  r	   rS   r   rK   r|   r5   )r+   r,   r-   r.   r9   r  rU  r   ri   r   rj   rY  rg  rs  r  r  r  r  r  r  r  r  r  r  r  r  r/   r0   r1   s   @r&   rN  rN  ?  s     	2YB __T%9%9:H(6:01:fJI$/b4l#J>(,.2 r)   rN  c                   2   a  ] tR tRt o R tR tR tRtV tR# )NonSubclassingPerspectivei(  c                    R # r5   r*   r  s   &&r&   rN   "NonSubclassingPerspective.__init__*  r  r)   c                l    VP                  W04      pVP                  W@4      pVP                  W#V34      # r5   )unserialize	serialize)r$   rk   messagerx  kwargss   &&&&&r&   perspectiveMessageReceived4NonSubclassingPerspective.perspectiveMessageReceived.  s8    !!$-##F1 788r)   c                    R V n         R# r  r  r6   s   &r&   r   NonSubclassingPerspective.logout4  r  r)   r  N)	r+   r,   r-   r.   rN   r  r  r/   r0   r1   s   @r&   r  r  (  s     9 r)   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )NSPTestsi8  zs
Tests for authentication against a realm where the L{IPerspective}
implementation is not a subclass of L{Avatar}.
c                   \        4       V n        \        V P                  n        \        P
                  ! V P                  4      V n        \        P                  ! 4       V n        V P                  P                  R R4       V P                  P                  V P                  4       \        \        P                  ! V P                  4      4      V n        \        P                   ! ^ V P                  RR7      V n        V P%                  V P"                  P&                  4       V P"                  P)                  4       P"                  V n        R# )r  r  ru   )r%  N)r  r   r  r#  r	   r   r   r   r   addUserr  r   r   r   r  r   r  r  rz   r  r  portnor6   s   &r&   r  NSPTests.setUp>  s    [
(A

%mmDJJ/GGIWg.##DLL1&r'9'9$++'FG%%aM			//0ii'')..r)   c                \  a a \         P                  ! 4       oSP                  \        P                  ! RR4      R4      p\
        P                  ! RS P                  S4       VP                  R 4       VP                  S P                  RR
RR/34       VV 3R	 lpVP                  V4       V# )zw
An L{IPerspective} implementation which does not subclass
L{Avatar} can expose remote methods for the client to call.
r  r  r  ru   c                 *    V P                  R RRR7      # )ANYTHINGherer  )r  r  )r  s   &r&   r>   #NSPTests.test_NSP.<locals>.<lambda>R  s    ZU Kr)   r  r  r  c                    < SP                  4        SP                  P                   F  pVP                  P	                  4        K  	  R # r5   )rb  r  	protocolsr^   r  )r  r  r  r$   s   & r&   r  "NSPTests.test_NSP.<locals>.cleanupU  s3     \\++**, ,r)   )r  )
r   r   r?  r   r  r   r  r  r  r  )r$   r\  r  r  s   f  @r&   test_NSPNSPTests.test_NSPJ  s    
 $$&MM+66wH)T;W=	KL	d&&Y(OP	-
 	
gr)   )r   r  r  r	   r  r   N)	r+   r,   r-   r.   r9   r  r  r/   r0   r1   s   @r&   r  r  8  s     

/ r)   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )
IForwardedi^  z9
Interface used for testing L{util.LocalAsyncForwarder}.
c                     R# )z
Simple synchronous method.
Nr*   r*   r)   r&   	forwardMeIForwarded.forwardMec      r)   c                     R# )z
Simple asynchronous method.
Nr*   r*   r)   r&   forwardDeferredIForwarded.forwardDeferredh  r  r)   r*   N)	r+   r,   r-   r.   r9   r  r  r/   r0   r1   s   @r&   r  r  ^  s     
 r)   r  c                   >   a  ] tR tRt o RtRtRtR tR tR t	Rt
V tR# )		Forwardedin  z
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                    RV n         R# )z&
Set a local flag to test afterwards.
TN)	forwardedr6   s   &r&   r  Forwarded.forwardMe|  s     r)   c                    RV n         R# )z^
Set a local flag to test afterwards. This should not be called as it's
not in the interface.
TN)unforwardedr6   s   &r&   dontForwardMeForwarded.dontForwardMe  s    
  r)   c                    \        R4      # )z 
Asynchronously return C{True}.
T)r   r6   s   &r&   r  Forwarded.forwardDeferred  s     t}r)   )r#  r&  N)r+   r,   r-   r.   r9   r#  r&  r  r'  r  r/   r0   r1   s   @r&   r!  r!  n  s*      IK  r)   r!  c                   B   a  ] tR tRt o RtR tR tR tR tR t	Rt
V tR	# )
SpreadUtilTestsi  z#
Tests for L{twisted.spread.util}.
c                ^    \        4       pV P                  VP                  R^4      ^4       R# )zS
Call a synchronous method of a L{util.LocalAsRemote} object and check
the result.
add1N)r  r  r  r  s   & r&   	test_syncSpreadUtilTests.test_sync  s'    
 fa0!4r)   c                    \        4       p\        4       pVP                  R^^R7      pV P                  V\        4       VP	                  V P
                  ^4       V# )zU
Call an asynchronous method of a L{util.LocalAsRemote} object and check
the result.
r  )r   )r  r  r  r   r  r  )r$   r  r\  s   &  r&   
test_asyncSpreadUtilTests.test_async  sQ    
 LLQL'a*	d&&*r)   c                v   a  \        4       pVP                  R4      pV 3R lpVP                  V 3R lV4       V# )z7
Test an asynchronous failure on a remote method call.
r  c                 r   < SP                  V \        P                  4       V P                  \        4       R # r5   )r  r   ri   trapr   )r  r$   s   &r&   eb*SpreadUtilTests.test_asyncFail.<locals>.eb  s#    !!!W__5FF< r)   c                 &   < SP                  R 4      # )zsupposed to failr  )r  r$   s   &r&   r>   0SpreadUtilTests.test_asyncFail.<locals>.<lambda>  s    499-?#@r)   )r  r  r[  )r$   r  r\  r7  s   f   r&   test_asyncFailSpreadUtilTests.test_asyncFail  s6     LL 	! 	
@"Er)   c                l    \        4       pVP                  R4      pV P                  V! ^4      ^4       R# )z=
Test the C{remoteMethod} facility of L{util.LocalAsRemote}.
r.  N)r  r  r  )r$   r  ms   &  r&   test_remoteMethod!SpreadUtilTests.test_remoteMethod  s.     NN6"1q!r)   c                   \        4       p\        P                  ! V\        4      pVP	                  R4       V P                  VP                  4       VP	                  R4       V P                  VP                  4       VP	                  R4      p. pVP                  VP                  4       V P                  V^ ,          ^4       R# )zM
Test a call to L{util.LocalAsyncForwarder} using L{Forwarded} local
object.
r  r'  r  N)r!  r   LocalAsyncForwarderr  r  r)  r#  r  r&  r  r?  r  )r$   r  lfrrr+  s   &    r&   test_localAsyncForwarder(SpreadUtilTests.test_localAsyncForwarder  s    
 K%%a4
k"$
o&']],-
qxx 1q!r)   r*   N)r+   r,   r-   r.   r9   r/  r2  r;  r?  rE  r/   r0   r1   s   @r&   r,  r,    s(     5
"" "r)   r,  c                   <   a  ] tR tRt o RtR tR tR tR tRt	V t
R# )	PBWithSecurityOptionsTestsi  z
Test security customization.
c                    \         P                  ! 4       pVP                  R4      pV P                  VP                  \
        P                  4       R# )zT
By default, client broker should use C{jelly.globalSecurity} as
security settings.
N)r   r   rv   r  securityr   globalSecurityr$   r  rk   s   &  r&   !test_clientDefaultSecurityOptions<PBWithSecurityOptionsTests.test_clientDefaultSecurityOptions  s:    
 $$&&&t,foou';';<r)   c                    \         P                  ! \        4       4      pVP                  R4      pV P	                  VP
                  \        P                  4       R# )zT
By default, server broker should use C{jelly.globalSecurity} as
security settings.
N)r   r   r|  rv   r  rJ  r   rK  rL  s   &  r&   !test_serverDefaultSecurityOptions<PBWithSecurityOptionsTests.test_serverDefaultSecurityOptions  s>    
 $$VX.&&t,foou';';<r)   c                    \         P                  ! 4       p\        P                  ! VR7      pVP	                  R4      pV P                  VP                  V4       R# )z[
Check that the security settings are passed from the client factory to
the broker object.
rJ  N)r   SecurityOptionsr   r   rv   r  rJ  r$   rJ  r  rk   s   &   r&    test_clientSecurityCustomization;PBWithSecurityOptionsTests.test_clientSecurityCustomization  sD    
 ((*$$h7&&t,foox0r)   c                    \         P                  ! 4       p\        P                  ! \	        4       VR7      pVP                  R4      pV P                  VP                  V4       R# )z[
Check that the security settings are passed from the server factory to
the broker object.
rS  N)r   rT  r   r   r|  rv   r  rJ  rU  s   &   r&    test_serverSecurityCustomization;PBWithSecurityOptionsTests.test_serverSecurityCustomization  sH    
 ((*$$VXA&&t,foox0r)   r*   N)r+   r,   r-   r.   r9   rM  rP  rV  rY  r/   r0   r1   s   @r&   rH  rH    s#     ==11 1r)   rH  r5   s  helloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworld)r9   rG  r  rE  rR   r;  collectionsr   ior   rw   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"   IRealmr;   rH   r   r   r   r   r  r   r   Copyabler   
RemoteCopyr   setUnjellyableForClassr   r   setUnjellyableFactoryForClassr   	Cacheabler   r   r   RemoteCacher  r  r-  r9  rN  r`  rh  rn  rx  Rootr|  r  SynchronousTestCaser  r   r  TestCaser  r  r  rv  rw  ry  r{  r  r  Publishabler  RemotePublishedr  rd  r  r   r  r  r  LocalAsRemoter  r@   r  r  r  r,  r8  rN  r  r  r  r!  r,  rH  r*   r)   r&   <module>rx     s   
 	 
    "  1 6 6 F = = C C 9 3 6 ' + 3 3 "+BKK +ryy  V]]G G G8 8v0,f4 4B   4F2## 2## 
 	bmm 	   *o 6
, 
,      !24E F(!! (",, R-- !2<< !*% %   68J Kr~~    +'7 8""" 5!! 5R%% ,,r ,2;; 
   , 5'BKK '   - 7bnn 
   +-> ?RWW RWW OH00 OdB$6$6 @4(++ 4nR
(## R
j 	#   ##B$$ #i5(## i5X'g)) '
 g%%  
2##    /7 3@-** @-F	y 	"++ 
!! 

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