Ϫf6" dZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl mZmZddlmZmZmZddlmZmZdd lmZmZmZmZdd lmZmZmZdd l m!Z!dd l"m#Z#dd l$m%Z%ddl&m'Z'm(Z(ddl)m*Z*ddl+m,Z,m-Z-m.Z.m/Z/ddl0m1Z1Gdde-jdZ3Gdde-jhZ5eejlGddZ7GddZ8dZ9GddZ:Gdde#Z;ddZ<Gd d!e-jzZ>Gd"d#e-jzZ?Gd$d%e-jZAGd&d'e-jZCe-jeAeCGd(d)e-jZEd*ZFe-jeEeFGd+d,e-jzZHGd-d.e-jZJGd/d0e-jzZKGd1d2e-jZLGd3d4e-jZNe-jeLeNGd5d6e-jZOe-jeJeOGd7d8e-jzZPGd9d:e-jzZQGd;de-jzZSGd?d@e-je-jZTe-jeTeTGdAdBe-je-jZUe-jeUeUGdCdDe-je-jZVe-jeVeVGdEdFe-jZXGdGdHe-jZYGdIdJe1jZ[GdKdLe-jZ]GdMdNe1jZ_GdOdPe1jZ`dQZadabdacdRZdGdSdTe-jzZeGdUdVe-jzZfGdWdXe1jZgGdYdZe.jZiGd[d\e.jZkGd]d^e-jzZle-jeiekGd_d`e1jZmGdadbenZoGdcdde-jZpGdedfe-jzZqGdgdhe/jZsee-jGdidje-jhZuGdkdlZvGdmdne-jdZwGdodpevZxGdqdre1jZyGdsdte1jZzee-jGdudvZ{Gdwdxe1jZ|GdydzeZ}ee}Gd{d|Z~Gd}d~e1jZGdde1jZy)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 credentialsportal)UnauthorizedLoginUnhandledCredentials)addressmainprotocolreactor)Deferred gatherResultssucceed)ConnectionRefusedError)_FakeConnector)WrappingFactory)failurelog) iterbytes)jellypbpublishutil)unittestceZdZdZy)Dummyc&t|tryy)Nz hello world!zgoodbye, cruel world!) isinstanceDummyPerspectiveselfusers =/usr/lib/python3/dist-packages/twisted/spread/test/test_pb.pyview_doNothingzDummy.view_doNothing(s d, -!*N)__name__ __module__ __qualname__r(r)r'r r 's+r)r ceZdZdZdZy)r#zE An L{IPerspective} avatar which will be used in some tests. ctSN)r r%s r'perspective_getDummyViewPointz.DummyPerspective.perspective_getDummyViewPoint4s wr)N)r*r+r,__doc__r2r-r)r'r#r#/s r)r#ceZdZdZy) DummyRealmcX|D]%}|tjus|t|dfcSy)Ncyr0r-r-r)r'z*DummyRealm.requestAvatar..=r))r IPerspectiver#)r%avatarIdmind interfacesifaces r' requestAvatarzDummyRealm.requestAvatar:s2 GE'.x8,FF Gr)N)r*r+r,r?r-r)r'r5r58sGr)r5c(eZdZdZdZdZdZdZy)IOPumpz Utility to pump data between clients and servers for protocol testing. Perhaps this is a utility worthy of being in protocol.py? c<||_||_||_||_yr0)clientserverclientIOserverIO)r%rCrDrErFs r'__init__zIOPump.__init__Gs      r)cd|_tjdz}|jsH|jr7tj|kDry|js|jr5yyyy)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)_stoptimepump)r%timeouts r'flushz IOPump.flushMsQ ))+/**yy{W$****r)cd|_y)zd Stop a running L{flush} operation, even if data remains to be transferred. TN)rJr1s r'stopz IOPump.stopZs  r)c|jjd|jjd|jj}|jj}|jjd|jjd|jj |jj |j j j|jj jt|D]}|jj|t|D]}|j j||s|ryy)zX Move data back and forth. Returns whether any data was moved. r) rEseekrFreadtruncaterC transport_checkProducerrDr dataReceived)r%cDatasDatabytes r'rLz IOPump.pumpas 1 1 ""$ ""$ 1 1     ,,. ,,.e$ +D KK $ $T * +e$ +D KK $ $T * + Er)N)r*r+r,r3rGrNrPrLr-r)r'rArA@s ! r)rAcd}j|}|j|}t}t}|jtj||jtj|t ||||}d} fd} |j | ||j | ||j | |j|||fS)al Create a server and a client and connect the two with an L{IOPump}. @param test: the test case where the client and server will be used. @type test: L{twisted.trial.unittest.TestCase} @param clientFactory: The factory that creates the client object. @type clientFactory: L{twisted.spread.pb.PBClientFactory} @param serverFactory: The factory that creates the server object. @type serverFactory: L{twisted.spread.pb.PBServerFactory} @return: a 3-tuple of (client, server, pump) @rtype: (L{twisted.spread.pb.Broker}, L{twisted.spread.pb.Broker}, L{IOPump}) ) 127.0.0.1c|js3|jtjtj yyr0) disconnectedconnectionLostrFailurerCONNECTION_DONE)brokers r'maybeDisconnectz/connectServerAndClient..maybeDisconnects-""  ! !'//$2F2F"G H#r)cnjdtjtjy)N) connectorreason)clientConnectionLostrrarrb) clientFactorysr'disconnectClientFactoryz7connectServerAndClient..disconnectClientFactorys, **7??43G3G#H + r)) buildProtocolStringIOmakeConnectionr FileWrapperrA addCleanuprL) testri serverFactoryaddr clientBroker serverBrokerclientTransportserverTransportrLrdrjs ` r'connectServerAndClientrw{s& D ..t4L ..t4LjOjO 4 4_ EF 4 4_ EF , o ODI  OOO\2OOO\2OO+,IIK t ++r)c"eZdZdZdZdZdZy)_ReconnectingFakeConnectorStatez Manages connection notifications for a L{_ReconnectingFakeConnector} instance. @ivar notifications: pending L{Deferreds} that will fire when the L{_ReconnectingFakeConnector}'s connect method is called c"t|_yr0)r notificationsr1s r'rGz(_ReconnectingFakeConnectorState.__init__s "Wr)cPt}|jj||S)z Connection notification. @return: A L{Deferred} that fires when this instance's L{twisted.internet.interfaces.IConnector.connect} method is called. @rtype: L{Deferred} )rr{ appendleft)r%notifiers r'notifyOnConnectz/_ReconnectingFakeConnectorState.notifyOnConnects$: %%h/r)c|jr7|jjj||jr6yy)z1 Fire all pending notifications. N)r{popcallbackr1s r' notifyAllz)_ReconnectingFakeConnectorState.notifyAlls5     " " $ - -d 3  r)N)r*r+r,r3rGrrr-r)r'ryrys% 4r)ryc,eZdZdZfdZfdZxZS)_ReconnectingFakeConnectorzc A fake L{IConnector} that can fire L{Deferred}s when its C{connect} method is called. c2t||||_y)a @param address: An L{IAddress} provider that represents this connector's destination. @type address: An L{IAddress} provider. @param state: The state instance @type state: L{_ReconnectingFakeConnectorState} N)superrG_state)r%r state __class__s r'rGz#_ReconnectingFakeConnector.__init__s ! r)cVt||jjy)zM A C{connect} implementation that calls C{reconnectCallback} N)rconnectrr)r%rs r'rz"_ReconnectingFakeConnector.connects  r))r*r+r,r3rGr __classcell__)rs@r'rrs   r)rc|xs t}tjd}tjt j ||g}tj}t|||S)z Connect a client and server L{Broker} together with an L{IOPump} @param realm: realm to use, defaulting to a L{DummyRealm} @returns: a 3-tuple (client, server, pump). guest)guest) r5r'InMemoryUsernamePasswordDatabaseDontUserPBServerFactoryr PortalPBClientFactoryrw)rprealmcheckerrqris r'connectedServerAndClientrsZ  !Z\E>>XNG&&v}}UWI'FGM&&(M !$ } EEr)ceZdZdZdZy) SimpleRemotec||_|dzSNrR)argr%rs r' remote_thunkzSimpleRemote.remote_thunkQwr)ctr0) Exceptionrs r' remote_knuthzSimpleRemote.remote_knuths kr)N)r*r+r,rrr-r)r'rrs r)rceZdZdZy) NestedRemotectSr0)rr1s r'remote_getSimplezNestedRemote.remote_getSimples ~r)N)r*r+r,rr-r)r'rrsr)rceZdZdZy) SimpleCopyc4d|_ddi|_dg|_yNrRHelloWorldrpxyzr1s r'rGzSimpleCopy.__init__7#r)Nr*r+r,rGr-r)r'rrr)rc eZdZy)SimpleLocalCopyNr*r+r,r-r)r'rr r)rc0eZdZUdZiZeedfed<dZy)SimpleFactoryCopyz] @cvar allIDs: hold every created instances of this class. @type allIDs: C{dict} allIDsc8||_|tj|<yr0)idrr)r%rs r'rGzSimpleFactoryCopy.__init__s'+  $r)N) r*r+r,r3rrint__annotations__rGr-r)r'rrs# .0FD)) */,r)rc|jdd}|tdt||tjvrtdtjtj|}|s td|S)zl Factory of L{SimpleFactoryCopy}, getting a created instance given the C{id} found in C{state}. rNz&factory copy state has no 'id' member zfactory class has no ID: z&factory method found no object with id)get RuntimeErrorreprrr)rstateIdinsts r'createFactoryCopyr!s~ iid#GCDK=QRR'...67H7O7O6PQRR  # #G ,D CDD Kr)ceZdZdZdZy) NestedCopyctSr0)rr1s r'remote_getCopyzNestedCopy.remote_getCopy5s |r)ct|Sr0)r)r%values r'remote_getFactoryzNestedCopy.remote_getFactory8s  ''r)N)r*r+r,rrr-r)r'rr4s (r)rceZdZdZy) SimpleCachec4d|_ddi|_dg|_yrrr1s r' __init___zSimpleCache.__init___=rr)N)r*r+r,rr-r)r'rr<rr)rceZdZdZdZy)NestedComplicatedCachec"t|_yr0)VeryVeryComplicatedCacheablecr1s r'rGzNestedComplicatedCache.__init__Ds -/r)c|jSr0)rr1s r'remote_getCachez&NestedComplicatedCache.remote_getCacheGs vv r)N)r*r+r,rGrr-r)r'rrCs 0r)rc$eZdZdZdZdZdZy)rc.d|_d|_d|_y)NrRrrfoor1s r'rGz%VeryVeryComplicatedCacheable.__init__Lsr)cJd|_|jjddy)Nr)robserver callRemoter1s r'setFoo4z$VeryVeryComplicatedCacheable.setFoo4Qs   *r)cX||_|j|j|jdS)Nr)rrrrr% perspectivers r'getStateToCacheAndObserveForz9VeryVeryComplicatedCacheable.getStateToCacheAndObserveForUs"  VV$&&::r)c~tjd|jd||jk(rd|_yy)Nzstopped observingend)rmsgrrrs r'stoppedObservingz-VeryVeryComplicatedCacheable.stoppedObservingYs5 #$E" t}} $ DM %r)N)r*r+r,rGrrrr-r)r'rrKs +;!r)rceZdZdZdZy)RatherBaroqueCachec||_yr0r)r%newFoos r' observe_foozRatherBaroqueCache.observe_fooas r)c.tjdy)Nzthe end of things)rrr1s r' observe_endzRatherBaroqueCache.observe_endds #$r)N)r*r+r,rrr-r)r'rr`s %r)rc$eZdZdZdZdZdZy)SimpleLocalCachec:|jj|yr0)__dict__update)r%rs r'setCopyableStatez!SimpleLocalCache.setCopyableStatels U#r)c|jSr0)checkr1s r' checkMethodzSimpleLocalCache.checkMethodo zzr)c|Sr0r-r1s r' checkSelfzSimpleLocalCache.checkSelfrs r)cyrr-r1s r'rzSimpleLocalCache.checkusr)N)r*r+r,rrrrr-r)r'rrks$r)rceZdZdZdZdZy) NestedCachec"t|_yr0)rrr1s r'rGzNestedCache.__init__}s r)c2|j|jgSr0rr1s r'rzNestedCache.remote_getCachesr)c|j|uSr0rr%caches r'remote_putCachezNestedCache.remote_putCachesvvr)N)r*r+r,rGrrr-r)r'rr|s r)rc$eZdZdZdZdZdZy) Observablecg|_yr0) observersr1s r'rGzObservable.__init__s r)c:|jj|yr0)r appendr%obss r'remote_observezObservable.remote_observe c"r)c:|jj|yr0)r removers r'remote_unobservezObservable.remote_unobserverr)cL|jD]}|jd||y)Nnotify)r r)r%objrs r'rzObservable.notifys' 5H   $ 4 5r)N)r*r+r,rGrrrr-r)r'r r s##5r)r c$eZdZdZdZdZdZy)DeferredRemotecd|_y)Nrrunr1s r'rGzDeferredRemote.__init__s r)c||_|dzSrrrs r'runMezDeferredRemote.runMerr)cJd)Nzshouldn't have been run!r-rs r' dontRunMezDeferredRemote.dontRunMes ,,,qr)ctt}|j|j|j||_|S)zo Return a L{Deferred} to be fired on client side. When fired, C{self.runMe} is called. )r addCallbacksrr!d)r%r$s r'remote_doItLaterzDeferredRemote.remote_doItLaters- J tzz4>>2r)N)r*r+r,rGrr!r%r-r)r'rrs-r)rceZdZdZdZdZy)ObserverrNc^||_|jdz|_|jd|y)NrR unobserve)rnotifiedr)r%otherrs r' remote_notifyzObserver.remote_notifys) )  d+r))r*r+r,r*rr,r-r)r'r'r'sH C,r)r'ceZdZdZy) NewStyleCopyc||_yr0)s)r%r0s r'rGzNewStyleCopy.__init__s r)Nrr-r)r'r.r.sr)r.c$eZdZdZdZdZdZdZy) NewStyleCopy2rrRcptxjdz c_tj|}d|_|S)NrRr)r2 allocatedobject__new__r)r%rs r'r6zNewStyleCopy2.__new__s-1$~~d#  r)c6txjdz c_yr)r2 initializedr1s r'rGzNewStyleCopy2.__init__s!!Q&!r)N)r*r+r,r4r8rr6rGr-r)r'r2r2sIK E 'r)r2ceZdZdZy)NewStyleCacheCopyc|jSr0)rrs r'rz.NewStyleCacheCopy.getStateToCacheAndObserveFors }}r)N)r*r+r,rr-r)r'r:r:sr)r:ceZdZdZdZy)Echoerc|Sr0r-r%sts r' remote_echozEchoer.remote_echos r)c ||fSr0r-)r%r@kws r'remote_echoWithKeywordszEchoer.remote_echoWithKeywordss Bxr)N)r*r+r,rArDr-r)r'r=r=s r)r=ceZdZdZdZy)CachedReturnerc||_yr0rrs r'rGzCachedReturner.__init__s  r)c|jSr0rHr?s r'remote_giveMeCachez!CachedReturner.remote_giveMeCacherr)N)r*r+r,rGrJr-r)r'rFrFs r)rFc*eZdZdZdZdZdZdZy) NewStyleTestsctjt|_tj}t |||j\}|_|_|j|j|_ y)zY Create a pb server using L{Echoer} protocol and connect a client to it. )rprirqN) rrr=rqrrwrDrLsuccessResultOf getRootObjectref)r%rirCs r'setUpzNewStyleTests.setUpsf //9**, )?]$BTBT* & TY'' (C(C(EFr)cFdt_dt_dt_y)zp Close client and server connections, reset values of L{NewStyleCopy2} class variables. rrRN)r2r4r8rr1s r'tearDownzNewStyleTests.tearDowns #$ $% ! r)ctdjjd}jj fd}|j ||S)zY Create a new style object, send it over the wire, and check the result. rechocj|tj|jdj |uy)Nr)assertIsInstancer. assertEqualr0 assertFalseresorigr%s r'cbz'NewStyleTests.test_newStyle..cbs9  ! !#| 4   SUUG ,   SD[ )r)r.rPrrLrN addCallbackr%r$r]r\s` @r' test_newStylezNewStyleTests.test_newStylesKG$ HH   -  * br)c8tjtjdjtjdjj d}j jfd}|j||S)zN Send a new style object and check the number of allocations. rRrUcj|tj|jdjtjdjtj dj |y)NrrrR)rWr2rXrr4r8 assertIsNotrZs r'r]z$NewStyleTests.test_alloc..cbsc  ! !#} 5   SYY *   ]44a 8   ]66 :   S$ 'r)) r2rXr4r8rPrrLrNr_r`s` @r' test_alloczNewStyleTests.test_alloc st 00!4 22A6 HH   -  ( br)ctdjjddd}jj fd}|j ||S)zo Create a new style object with keywords, send it over the wire, and check the result. value1echoWithKeywordsonetwokeyword1keyword2c.j|tj|dtj|dtj |dj dj |dj |ddddy)NrrRrgrirjrk)rWtupler.dictrXr0rdrZs r'r]z3NewStyleTests.test_newStyleWithKeywords..cb.s  ! !#u -  ! !#a&, 7  ! !#a&$ /   SVXXx 0   SVT *   SV%U%K Lr)r^r`s` @r'test_newStyleWithKeywordsz'NewStyleTests.test_newStyleWithKeywords#sZ H% HH   uu    M br)N)r*r+r,rQrSrarerqr-r)r'rLrLs G  ,r)rLc eZdZdZdZdZdZy)ConnectionNotifyServerFactoryaj A server factory which stores the last connection and fires a L{Deferred} on connection made. This factory can handle only one client connection. @ivar protocolInstance: the last protocol instance. @type protocolInstance: C{pb.Broker} @ivar connectionMade: the deferred fired upon connection. @type connectionMade: C{Deferred} Ncbtjj||t|_y)z) Initialize the factory. N)rrrGrconnectionMade)r%roots r'rGz&ConnectionNotifyServerFactory.__init__Is$ ##D$/&jr)cb||_|jdc}|_||jdyy)zF Store the protocol and fire the connection deferred. N)protocolInstancerur)r%rr$s r'clientConnectionMadez2ConnectionNotifyServerFactory.clientConnectionMadePs7!)!%!4!4d4  = JJt  r))r*r+r,r3rxrGryr-r)r'rsrs:s )r)rsceZdZdZdZdZy)NewStyleCachedTestsct_dj_tjdt t j_tj}tjdjjj|fd}|jj|}jjj }t#||gS)zi Create a pb server using L{CachedReturner} protocol and connect a client to it. rr localhostc|_yr0)rP)rPr%s r'gotRootz*NewStyleCachedTests.setUp..gotRooths DHr))r:r\r0r listenTCPrsrFrDrr connectTCPgetHostportrOr_factoryrur)r%rird1d2s` r'rQzNewStyleCachedTests.setUp[s &'  '' ,^DII-FG  **, ; (;(;(=(B(BMR  ( ( * 6 6w ? [[ / /b"X&&r)c|jjjjj |j j jj |jjS)z6 Close client and server connections. )rDrrxrVloseConnectionrPrc stopListeningr1s r'rSzNewStyleCachedTests.tearDownosS ,,66EEG !!002{{((**r)cjjdj}fd}|j|d|j|d|S)z A new-style cacheable object can be retrieved and re-retrieved over a single connection. The value of an attribute of the cacheable can be accessed on the receiving side. giveMeCachecj|tjd|jj j ||r-|_jjdj Sy)Nrr) rWr:rXr0rdr\r[rPr)r[againr%s r'r]z2NewStyleCachedTests.test_newStyleCache..cbsh  ! !#'8 9   Wcee ,   TYY ,xx**=$))DD r)TF)rPrr\r_)r%r$r]s` r'test_newStyleCachez&NewStyleCachedTests.test_newStyleCachewsH HH   tyy 9 E b$ b% r)N)r*r+r,rQrSrr-r)r'r{r{Zs'(+r)r{cveZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZy) BrokerTestsNcN tjdy#t$rYywxYw)NNone-None-TESTING.pub)osunlinkOSErrorr1s r'rSzBrokerTests.tearDowns&  II- .   s  $$c,|jd|y)Nz&This should cause a return value, not fail)r%errors r' thunkErrorBadzBrokerTests.thunkErrorBads :5'BCr)c||_yr0) thunkResultr%results r'thunkResultGoodzBrokerTests.thunkResultGoods !r)cyr0r-)r%tbs r'thunkErrorGoodzBrokerTests.thunkErrorGood r)c,|jd|y)Nz This should cause an error, not rrs r'thunkResultBadzBrokerTests.thunkResultBads 4VH=>r)ct|\}}}Gddtj}Gddtj}|jd||j d}|}|}|j d|||j |j |j |j|j|d|j|jd|jdy) NrpceZdZdZy)%BrokerTests.test_reference..Xc||_yr0)caughtrs r' remote_catchz2BrokerTests.test_reference..X.remote_catchs ! r)N)r*r+r,rr-r)r'Xrs "r)rceZdZdZy)%BrokerTests.test_reference..Yc(|jd|y)Ncatchrr%abs r' remote_throwz2BrokerTests.test_reference..Y.remote_throws Wa(r)N)r*r+r,rr-r)r'Yrs )r)rrthrowzX should have caught Z) rr ReferenceablesetNameForLocal remoteForNamerrLassertIsrrX remoteMethod) r%rr0rLrrrrrs r'test_referencezBrokerTests.test_references-48 1d "   " )   ) #qs# OOC  C C Wa#    ahh#;< 0!..2IJr)ct|\}}}||f||ffD]\}}t}|jd||jd}d|_|j d|jdz j |j|j|j|j|j|j|jdy)NrrthunkrRzresult wasn't received.) rrrrexpectedThunkResultrr#rrrLrXr)r%rr0rLrrrbars r' test_resultzBrokerTests.test_results-48 1dFQFN DAq.C  eS )//%(C'(D $ NN7D$<$ ))++A.7r)c t|\}}}t}t}|jd||j d}|j d||j |jd|j |j |jd|j |j |j|jd|j|jddy)NrrobserverRrz didn't notifyznotified too much) rr r'rrrrLrassertIsNotNonerrX)r%rr0rLrrras r' test_observezBrokerTests.test_observes-48 1d L J #q! __S ! i#          QUUO4 #67r)cjt|\}}}t}|jd||jd}|j |j g}|j dj |j|j |j |j|jd|jjd|j|jdd|j |j |j|ddd y) Nrr$ doItLaterzDeferred method run too early.rIzDeferred method run too late.rzIncorrect result.) rrrrrLrr_rrYrr$rrX)r%rr0rLr$rresultss r' test_deferzBrokerTests.test_defers-48 1d   #q! OOC    [!--gnn=    @A  Q #BC   Q(;>Y & JJL    /r)c*t|\}}}t}t}|j}|j d||j d||j d}|j d}g} |j dj| jj| j|j dj| jj| jg} |j dj| j|j dj| j|j|j| djd|j| djd|j| djd|j|j|j| djd |jt!| d| dd} |j#| j%j&| d |j#| j)| d g} |j d | j| j|j|j+| d|j|j-d|j-d| j.} | dj.}|j1| |j2d ~ ~ |j~ ~ |jt4j6dk\rt9j:|j|j=| |j2d|j=| |j>d|j=||j2d|j=||j>d|jA|jBdy)NrrxxxgetCacherrRrrrzpotential refcounting issuez!other potential refcounting issueputCachezremote cache doesn't have itrzServer still had it after GCzClient still had it after GCz!Server still had complex after GCz!Client still had complex after GCzobserver was not removed)"rrrrrrrr_r addErrbackrNrXrrrrrassertIdenticalr__self__rrrrrremotelyCachedObjectsrrrrrlocallyCachedObjects assertIsNoner)r%rr0rLrobj2vcco2o3collcomplexcpcol2r baroqueLuids r' test_cachezBrokerTests.test_cache4s!-48 1dm%'ff %% %& __U # __U # j!--dkk:EEdkkR j!--dkk:EEdkkR j!--gnn= j!--gnn=  q) q) +   + TA& !WQZ  NN  % %r+H  R\\^R1TU j"%11$++>  Q  4booj6QRwwajoo  dA335ST      >>Y & JJL  q668VW q557UV  002U   //1T  #,,(BCr)c tjdt|\}}}t }|j d||j d}g}|jdj|j|j|j|j}|j|jd|j|jd|j|j d|j|j"dt|\}}}|j d||j d}|jdj|j|j|j|j}|j|j"dy#t$rYwxYw)NrrrgetPubrRr)rrrr GetPublisherrrrr#rrrNrrXactivateCalled isActivatedyayIGotPublished_wasCleanWhenLoaded)r%rr0rLrraccumrs r'test_publishablezBrokerTests.test_publishablevsl  II- ..48 1dn %%ooe$ x --ellD||_|||c|_|_|_yr0)filenamerrrC)r%r%rrrCs r'rGzFilePagerizer.__init__s  ,4dB) ty$'r)ctj|t|jd|jg|j i|j |_dx|_|_y)Nrb)r FilePageropenr%rrrCpagerrs r'r!zFilePagerizer.remote_getPagessP^^ tDMM40$-- BF)) OSww  #" DGr))r*r+r,r*rGr!r-r)r'r#r#s E?#r)r#c4eZdZdZdZdZdZdZdZdZ y) PagingTestsz0 Test pb objects sending data by pages. c|j|_t|jd5}|jtdddy#1swYyxYw)z? Create a file used to test L{util.FilePager}. wbN)mktempr%r)writer)r%fs r'rQzPagingTests.setUpsB  $-- & ! GGI    s A  Act|\}}}|jdttdd|j d}g}t j |dj|j|s|j|s|jdj|dtd |jtd d |jtd did y )zg Test L{util.StringPager}, passing a callback to fire when all pages are sent. rrhellorrgetPagesr)r'Pages received not equal to pages sent!)r3Completed callback not invokedrN)rrrrrr getAllPagesr_rrLrXjoinrrrr%rr0rLrrs r'test_pagingWithCallbackz#PagingTests.test_pagingWithCallbacks .48 1d %+;WB!OP OOE "  J'33AHH= IIK  HHQqTNI'P  z3ST  gr],L r)cZt|\}}}|jdtd|jd}g}t j |dj |j|s|j|s|jdj|dtdy)z> Test L{util.StringPager} without a callback. rrNr5r)rr6) rrrrrr8r_rrLrXr9rr:s r'test_pagingWithoutCallbackz&PagingTests.test_pagingWithoutCallbacks.48 1d %41 OOE "  J'33AHH= IIK  HHQqTNI'P r)c|j}t|djt|\}}}t |d}|j d||j d}g}tj|dj|jd}|s"|dkDr|j|dz}|s|dkDr|s|jd |jd j|dd d y) z@ Test L{util.FilePager}, sending an empty file. wrNrr5rrrRzgetAllPages timed outr)r6)r/r)closerr#rrrr8r_rrLrrXr9) r% filenameEmptyrr0rL pagerizerrrttls r'test_emptyFilePagingz PagingTests.test_emptyFilePagings  ]C &&(-48 1d!-6  %+ OOE "  J'33AHH=a IIK 1HCa II- . !A$.WXr)c.t|\}}}t|jtdd}|j d||j d}g}t j|dj|j|s|j|s|jdj|dtd |jtd d |jtd did |j|j j"gy )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. rfrodo r4rr5r)rr6)rFr7rN)rr#r%rrrrr8r_rrLrXr9rrrr*chunksr%rr0rLrBrrs r'test_filePagingWithCallbackz'PagingTests.test_filePagingWithCallbacks .48 1d!$--1A7RST  %+ OOE "  J'33AHH= IIK  HHQqTNI'P  z3ST  gq\+K  //4r)ct|\}}}t|jd}|jd||j d}g}t j |dj|j|s|j|s|jdj|dtd|j|jjgy)z< Test L{util.FilePager} without a callback. rNrr5r)rr6)rr#r%rrrr8r_rrLrXr9rr*rHrIs r'test_filePagingWithoutCallbackz*PagingTests.test_filePagingWithoutCallback%s.48 1d!$--6  %+ OOE "  J'33AHH= IIK  HHQqTNI'P  //4r)N) r*r+r,r3rQr;r=rDrJrLr-r)r'r,r,s& (  Y(5,5r)r,ceZdZdZy)DumbPublishablec ddiS)NrrRr-r1s r'getStateToPublishz!DumbPublishable.getStateToPublish8s "A&&r)N)r*r+r,rPr-r)r'rNrN7s'r)rNceZdZdZy)DumbPubcd|_yr)rr1s r' activatedzDumbPub.activated=s r)N)r*r+r,rTr-r)r'rRrR<s r)rRceZdZdZdZy)rc$td|_y)NTESTING)rNpubr1s r'rGzGetPublisher.__init__Bs"9-r)c|jSr0)rXr1s r' remote_getPubzGetPublisher.remote_getPubEs xxr)N)r*r+r,rGrZr-r)r'rrAs .r)rc.eZdZdZdZdZdZdZdZy)DisconnectionTestsz' Test disconnection callbacks. ctd|)NzI shouldn't have been called: r)r%rs r'rzDisconnectionTests.errorQs;D6BCCr)cd|_y)z. Called on broker disconnect. rRN) gotCallbackr1s r'gotDisconnectedz"DisconnectionTests.gotDisconnectedTs r)cJ|j||jd|_y)z7 Called on RemoteReference disconnect. rRN)rX remoteObjectobjectCallbackr%os r'objectDisconnectedz%DisconnectionTests.objectDisconnectedZs" D--.r)cZt|\}}}|j|jdt|j d}g}|j dt j|j|j|jt|dy)Nrrf setBadCopyrR) rrLr BadCopySetrr BadCopyablerrrNrXr)r%rr0rLgrs r'test_badSerializationz(DisconnectionTests.test_badSerializationas|-48 1d  #z|, OOC   \;=1<? (() ++,r)N) r*r+r,r3rrargrmrur-r)r'r\r\Ls!D  $!-r)r\c eZdZy)FreakOutNrr-r)r'rwrwrr)rwceZdZdZy)rkctr0)rw)r%ps r'getStateToCopyForzBadCopyable.getStateToCopyFors jr)N)r*r+r,r{r-r)r'rkrksr)rkceZdZdZy)rjcyr0r-)r%bcs r'remote_setBadCopyzBadCopySet.remote_setBadCopysr)N)r*r+r,rr-r)r'rjrjsr)rjc$eZdZdZdZddZdZy)LocalRemoteTestrc |dzSrr-)r%rs r' sync_add1zLocalRemoteTest.sync_add1 1u r)c ||zSr0r-)r%rrs r' async_addzLocalRemoteTest.async_addrr)ctr0r^r1s r' async_failzLocalRemoteTest.async_fails nr)N)rrR)r*r+r,reportAllTracebacksrrrr-r)r'rrsr)rc6eZdZdZdxZZdZdZdZdZ dZ y) MyPerspectivez @ivar loggedIn: set to C{True} when the avatar is logged in. @type loggedIn: C{bool} @ivar loggedOut: set to C{True} when the avatar is logged out. @type loggedOut: C{bool} Fc||_yr0r;r%r;s r'rGzMyPerspective.__init__s   r)c|jS)zT Return the avatar identifier which was used to access this avatar. rr1s r'perspective_getAvatarIdz%MyPerspective.perspective_getAvatarIds}}r)ctSr0)MyViewr1s r'perspective_getViewPointz&MyPerspective.perspective_getViewPoints xr)c ||zS)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-rs r'perspective_addzMyPerspective.perspective_adds 1u r)cd|_yNT loggedOutr1s r'logoutzMyPerspective.logout r)N) r*r+r,r3loggedInrrGrrrrr-r)r'rrs,! Hy! r)rceZdZdZeZdZdZy) TestRealma A realm which repeatedly gives out a single instance of L{MyPerspective} for non-anonymous logins and which gives out a new instance of L{Echoer} for each anonymous login. @ivar lastPerspective: The L{MyPerspective} most recently created and returned from C{requestAvatar}. @ivar perspectiveFactory: A one-argument callable which will be used to create avatars to be returned from C{requestAvatar}. NcF|tjk(sJ|dk(sJ|tjurtjt dfS|j ||_d|j _tj|j |j jfS)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!cyr0r-r-r)r'r8z)TestRealm.requestAvatar..r9r)T) rr:r ANONYMOUSr=perspectiveFactorylastPerspectiverr)r%r;r< interfaces r'r?zTestRealm.requestAvatars BOO+++y   x)) )??FHl: :#'#:#:8#DD ,0D )OOT%9%94;O;O;V;VW Wr))r*r+r,r3rrrr?r-r)r'rrs 'O Xr)rceZdZdZy)rc"t|tSr0)r"rr$s r' view_checkzMyView.view_checks$ ..r)N)r*r+r,rr-r)r'rrs/r)rceZdZdZdZdZy) LeakyRealmz] A realm which hangs onto a reference to the mind object in its logout function. c||_y)z Create a L{LeakyRealm}. @param mindEater: a callable that will be called with the C{mind} object when it is available N) _mindEater)r% mindEaters r'rGzLeakyRealm.__init__s $r)cx|j|j|tjfdfS)Nc(jfSr0)r)r<perspsr'r8z*LeakyRealm.requestAvatar..su||~0Fr))rrrr:)r%r;r<rrs ` @r'r?zLeakyRealm.requestAvatars1 ''1(FGGr)N)r*r+r,r3rGr?r-r)r'rrs $Hr)rceZdZdZdZy)NewCredLeakTestsz/ Tests to try to trigger memory leaks. c d_fd}tt|\} g|jd}|j dd}d}|j | fd}|j |j jd gtjjjy) 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:tj|_yr0)weakrefrPmindRef)r<r%s r' setMindRefz4NewCredLeakTests.test_logoutLeak..setMindRefs";;t,DLr))rprrvloginrcn|\}}t}|jdtj|d|S)Nrespondr)rrrr)r challenge challengerr<s r' cbResponsez4NewCredLeakTests.test_logoutLeak..cbResponse$s8$% !Iz>D((2::i:D r)cjjdjtjt dy)NrRboom)rPrr`rrar)_connectionBrokenrLrts r'r`z8NewCredLeakTests.test_logoutLeak..connectionLost-s6 IIK  # #A &  ' ' V8L(M Nr)rR) rrrrrr_rNrXrrr) r%rrsrvr$rr`rrLrts ` @@@r'test_logoutLeakz NewCredLeakTests.test_logoutLeaks  -,DZ 3, ( lD ))&1 OOGX .  j! O n%  )A3/  $,,.)r)N)r*r+r,r3rr-r)r'rr s .*r)rceZdZdZdZddZejejfdZ dZ dZ dZ d Zd Zd Zd Zd ZdZdZdZdZdZdZy) NewCredTestsz= Tests related to the L{twisted.cred} support in PB. ct|_tj|j|_t |j|_t j|_y)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) rrr rrsrqrrrir1s r'rQzNewCredTests.setUpDsC [ mmDJJ/ :4;;G//1r)NcPt||j|j\|_|_|_t |_ttjddd|j|_ |jjj|jy)a Connect a client obtained from C{clientFactory} and a server obtained from the current server factory via an L{IOPump}, then assign them to the appropriate instance variables @ivar clientFactory: the broker client factory @ivar clientFactory: L{pb.PBClientFactory} instance @ivar client: the client broker @type client: L{pb.Broker} @ivar server: the server broker @type server: L{pb.Broker} @ivar pump: the IOPump connecting the client and server @type pump: L{IOPump} @ivar connector: A connector whose connect method recreates the above instance variables @type connector: L{twisted.internet.base.IConnector} TCPr]iN)rwrirqrCrDrLryconnectorStaterr IPv4Addressrfrr_establishClientAndServer)r%_ignoreds r'rz%NewCredTests.establishClientAndServerOs,/E $$$d&8&8/ + T[$)>?3   {D 94;N;N  ++-99$:W:WXr)c|j|jjj|jj ||j j |j|y)a Asserts that the client broker's transport was closed and then mimics the event loop by calling the broker's connectionLost callback with C{reason}, followed by C{self.clientFactory}'s C{clientConnectionLost} @param reason: (optional) the reason to pass to the client broker's connectionLost callback @type reason: L{Failure} N)rrCrVrr`rirhrf)r%rgs r'completeClientLostConnectionz)NewCredTests.completeClientLostConnectionosN  --445 ""6* //Gr)cjjj}fd}fd}|j||j||S)z Assert that L{PBClientFactory.getRootObject}'s Deferred fires with a L{RemoteReference}, and that disconnecting it runs its disconnection callbacks. cHj|tj|Sr0)rWrRemoteReference)rootObjr%s r' gotRootObjectz6NewCredTests.test_getRootObject..gotRootObjects  ! !'2+=+= >Nr)ct}|j|jjj j |Sr0)rrorri disconnectr)rdisconnectedDeferredr%s r'rz3NewCredTests.test_getRootObject..disconnectsD#+:  & &';'D'D E    ) ) +  - - /' 'r)rrirOr_)r%rootObjDeferredrrs` r'test_getRootObjectzNewCredTests.test_getRootObjectsS %%',,::<  ( ##M2##J/r)cjjj}fd}|j|S)z Test that when a connection is lost, calling a method on a RemoteReference obtained from it raises L{DeadReferenceError}. ct}j|jfd}|j|jj j |S)Nc\jtjjdy)Nmethod) assertRaisesrDeadReferenceErrorr)ignrr%s r'lostConnectionzSNewCredTests.test_deadReferenceError..gotRootObject..lostConnections!!!""7"79K9KXVr))rrorr_rirr)rrrr%s` r'rz;NewCredTests.test_deadReferenceError..gotRootObjectsZ#+:  & &';'D'D E W ! , ,^ <    ) ) +  - - /' 'r)r)r%rrs` r'test_deadReferenceErrorz$NewCredTests.test_deadReferenceErrors= %%',,::< (**=99r)cGddtj}|_jjj }fd}|j |S)z Test that if the L{reconnecting} flag is passed with a True value then a remote call made from a disconnection notification callback gets a result successfully. ceZdZdZdZy)=NewCredTests.test_clientConnectionLost..ReconnectOnceFc|j }d|_tjj||||}|r|j |Sr)reconnectedAlreadyrrrhr)r%rfrg reconnectingrs r'rhzRNewCredTests.test_clientConnectionLost..ReconnectOnce.clientConnectionLostsM#'#:#:: *.'++@@)V\ %%' r)N)r*r+r,rrhr-r)r' ReconnectOncers !&  r)rcj|tjt}|j |j j jjfd}|j|S)Ncdjj}fd}|j|S)Ncj|tjt}|j |j j jj|Sr0) rWrrrrorrirr)anotherRootObjr$r%s r'gotAnotherRootObjectzqNewCredTests.test_clientConnectionLost..gotRootObject..disconnected..gotAnotherRootObjectsU)).":L:LM A"55ajjA&&113557Hr))rirOr_)rr$rr%s r'r_zSNewCredTests.test_clientConnectionLost..gotRootObject..disconnecteds.&&446}}%9::r)) rWrrrrorrirrr_)rr$r_r%s r'rz=NewCredTests.test_clientConnectionLost..gotRootObjectsf  ! !'2+=+= > A  & &qzz 2    ) ) +  - - / ;==. .r))rrrirrOr_)r%rrrs` r'test_clientConnectionLostz&NewCredTests.test_clientConnectionLostsY B.. +_ %%',,::< /0**=99r)c|j|jjd}|jt j t |jtjtjy)z Test that if a Broker loses its connection without receiving any bytes, it doesn't raise any exceptions or log any errors. )r]i90N) rrqrkrmrrnrlr`rrarrb)r% serverProtos r'test_immediateClosez NewCredTests.test_immediateCloses_ %%'((667KL ""8#7#7 #CD""7??43G3G#HIr)ctj}|jtjdd}|j dt jtd|j|tS)z L{PBClientFactory.login} returns a L{Deferred} which is errbacked with the L{ConnectionRefusedError} if the underlying connection is refused. foobarNz!Test simulated refused connection) rrrr UsernamePasswordclientConnectionFailedrrar assertFailure)r%ri loginDeferreds r'test_loginConnectionRefusedz(NewCredTests.test_loginConnectionRefusedsp **, %++  ( ( 8  ,,  OO&'JK  !!-1GHHr)c<jjtjdt j dd}d}t jj||}fd}fd}|j||j|fd}|j|jjjtjjjjd|S) z Test that login can be performed with IUsernamePassword credentials and that when the connection is dropped the avatar is logged out. passr&userrcjjjjj |t j Sr0)rrrrrWrr)rloginCompletedr%s r'cbLoginz.NewCredTests.test_loginLogout..cbLogins; OODJJ66?? @  ! !+r/A/A B! !r)cZjjjyr0)rirrignoredr%s r' cbDisconnectz3NewCredTests.test_loginLogout..cbDisconnects!    ) ) +  - - /r)cdjjjjyr0)rrrrrs r'cbLogoutz/NewCredTests.test_loginLogout..cbLogout&s OODJJ66@@ Ar)N)r registerCheckerrrr rrrirr_rrLrNrrr)r%credsr<r$rrrrs` @r'test_loginLogoutzNewCredTests.test_loginLogouts ##  < <' J ,,Wg>!    $ $UD 1 "  0 g l# B h %%'   %r)c<tGfddtj}|j_j j tjdjjtjddd}fd}|j|fd}|j|jjj!t#j$jj!|S) z If a L{RemoteReference} to an L{IPerspective} avatar is decrefed and there remain no other references to the avatar on the server, the avatar is garbage collected and the logout method called. c"eZdZdZdZfdZy)=NewCredTests.test_logoutAfterDecref..EventPerspectivezQ An avatar which fires a Deferred when it is logged out. cyr0r-rs r'rGzFNewCredTests.test_logoutAfterDecref..EventPerspective.__init__Csr)c(jdyr0)r)r%rs r'rzDNewCredTests.test_logoutAfterDecref..EventPerspective.logoutFs""4(r)N)r*r+r,r3rGrrsr'EventPerspectiver >s   )r)rrrrrcSr0r-)avatarrs r' cbLoggedInz7NewCredTests.test_logoutAfterDecref..cbLoggedInSs  r)cfjjjjiyr0)rXrqrx _localCleanuprs r' cbLoggedOutz8NewCredTests.test_logoutAfterDecref..cbLoggedOutZs(   T//@@NNPR Sr))rrAvatarrrr rrrrirr rr_rrLrNrr)r%rr$rrrs` @r'test_logoutAfterDecrefz#NewCredTests.test_logoutAfterDecref6s J  )ryy ))9 % ##  < < H     $ $  ( ( 8)   j! T k" %%'   r)cjjtjddjj t jddd}jj t jddd}t||g}d}|j|fd}|j|jjj|S) z Two different correct login attempts can be made on the same root object at the same time and produce two different resulting avatars. rsquux)rbazrrbazcb|\}}t|jd|jdgS)N getAvatarId)rr)rfirstseconds r'rz5NewCredTests.test_concurrentLogin..cbLoggedIn}s6$OUF !!-0&2C2CM2RS r)cX|\}}j|dj|dy)Nrr)rX)rrrr%s r' cbAvatarIdsz6NewCredTests.test_concurrentLogin..cbAvatarIdss,ME6   UF +   VV ,r)) r rrrrirr rrr_rrLrN)r% firstLogin secondLoginr$rr s` r'test_concurrentLoginz!NewCredTests.test_concurrentLoginls ##  < <W U ''--  ( ( 8) ((..  ( ( 99  :{3 4  j! - k" %%' r)cjjtjdjj t jdd}jj t jdd}j|tj|tt||g}fd}|j|jjj|S)zz Test that a login attempt with an invalid user or invalid password fails in the appropriate way. rrs nosuchuserrs wrongpasscfjt}jt|dy)Nr)flushLoggedErrorsr rXrignoreerrorsr%s r'cleanupz;NewCredTests.test_badUsernamePasswordLogin..cleanups(++,=>F   S[! ,r))r rrrrirr rrr rr_rrLrN)r%r!r"r$r*s` r'test_badUsernamePasswordLoginz*NewCredTests.test_badUsernamePasswordLogins ##  < <' J ''--  ( ( @ ((..  ( (, ?  :'89 ;(9: :{3 4 - g %%' r)cp|jjtj|jj t jd}d}|j||j|jd|j|jj|S)z Verify that a PB server using a portal configured with a checker which allows IAnonymous credentials can be logged into using IAnonymous credentials. rc&|jddSNrU{rrs r'rz4NewCredTests.test_anonymousLogin..cbLoggedIn))&#6 6r)r/) r rrAllowAnonymousAccessrirr Anonymousr_rXrrLrN)r%r$rs r'test_anonymousLoginz NewCredTests.test_anonymousLogins ##H$A$A$CD    $ $[%:%:%.cleanups(++,@AF   S[! ,r))r rrrrirr r3rr r_rrLrN)r%r$r*s` r'test_anonymousLoginNotPermittedz,NewCredTests.test_anonymousLoginNotPermitteds ##  < <& I     $ $[%:%:%.cbLoginr1r)r/)r rrr2rrirr r3r_rXrrLrNr%r$rs r''test_anonymousLoginWithMultipleCheckersz4NewCredTests.test_anonymousLoginWithMultipleCheckerss ##H$A$A$CD ##  < <' J     $ $[%:%:%.cbLogins))%b9 9r)r/)r rrr2rrirr rr_rXrrLrNr;s r'+test_authenticatedLoginWithMultipleCheckersz8NewCredTests.test_authenticatedLoginWithMultipleCheckerss ##H$A$A$CD ##  < <' J     $ $  ( (' :I  : g d&&, %%' r)c|jjtjd|jj t jddd}d}|j|d}|j||j|j|j|jj|S)zb Verify that a viewpoint can be retrieved after authenticating with cred. rrrrc$|jdS)N getViewPointrr0s r'rz'NewCredTests.test_view..cbLogins)).9 9r)c$|jdS)Nrr) viewpoints r'cbViewz&NewCredTests.test_view..cbViews''0 0r)) r rrrrirr rr_rrrLrN)r%r$rrGs r' test_viewzNewCredTests.test_view s ##  < <' J     $ $  ( (' :I  : g 1 f doo& %%' r)r0)r*r+r,r3rQrrrarrbrrrrrrr rr#r+r4r8r<rArHr-r)r'rr?s{ 2YB%W__T%9%9:H(6:01:fJI$/b4l#J>(,.2r)rceZdZdZdZdZy)NonSubclassingPerspectivecyr0r-rs r'rGz"NonSubclassingPerspective.__init__*rr)cr|j||}|j||}|j|||fSr0) unserialize serialize)r%rcmessagerkwargss r'perspectiveMessageReceivedz4NonSubclassingPerspective.perspectiveMessageReceived.s>!!$-##FD1$ 788r)cd|_yrrr1s r'rz NonSubclassingPerspective.logout4rr)N)r*r+r,rGrQrr-r)r'rJrJ(s 9 r)rJceZdZdZdZdZy)NSPTestsz Tests for authentication against a realm where the L{IPerspective} implementation is not a subclass of L{Avatar}. ct|_t|j_t j |j|_t j|_|jjdd|jj|jttj|j|_tj d|jd|_|j%|j"j&|j"j)j"|_y)Nrrrr])r)rrrJrr rrrraddUserrrrrrrrrrorrportnor1s r'rQzNSPTests.setUp>s[ (A %mmDJJ/ GGI  Wg. ##DLL1&r'9'9$++'FG %%aM   //0ii'').. r)cTtjjtjddd}t j dj|jd|jjdddd iffd }|j||S) z An L{IPerspective} implementation which does not subclass L{Avatar} can expose remote methods for the client to call. rrrr]c*|jdddS)NANYTHINGherer)rr)rzs r'r8z#NSPTests.test_NSP..Rs ZU Kr)rZ)r[rrcjjjD]}|jj yr0)rr protocolsrVr)rrzrr%s r'r*z"NSPTests.test_NSP..cleanupUs8    \\++ - **, -r)) rrrr rrrrWr_rX)r%r$r*rs` @r'test_NSPzNSPTests.test_NSPJs $$& MM+66wH) T; W= KL d&&Y(OP - gr)N)r*r+r,r3rQr^r-r)r'rTrT8s /r)rTceZdZdZdZdZy) IForwardedzA Interface used for testing L{util.LocalAsyncForwarder}. cy)z, Simple synchronous method. Nr-r-r)r' forwardMezIForwarded.forwardMecr9r)cy)z- Simple asynchronous method. Nr-r-r)r'forwardDeferredzIForwarded.forwardDeferredhr9r)N)r*r+r,r3rbrdr-r)r'r`r`^s  r)r`c*eZdZdZdZdZdZdZdZy) Forwardedz Test implementation of L{IForwarded}. @ivar forwarded: set if C{forwardMe} is called. @type forwarded: C{bool} @ivar unforwarded: set if C{dontForwardMe} is called. @type unforwarded: C{bool} Fcd|_y)z6 Set a local flag to test afterwards. TN) forwardedr1s r'rbzForwarded.forwardMe|s r)cd|_y)zv Set a local flag to test afterwards. This should not be called as it's not in the interface. TN) unforwardedr1s r' dontForwardMezForwarded.dontForwardMes  r)ctdS)z0 Asynchronously return C{True}. T)rr1s r'rdzForwarded.forwardDeferredst}r)N) r*r+r,r3rhrjrbrkrdr-r)r'rfrfns"IK  r)rfc.eZdZdZdZdZdZdZdZy)SpreadUtilTestsz+ Tests for L{twisted.spread.util}. c\t}|j|jdddy)zk Call a synchronous method of a L{util.LocalAsRemote} object and check the result. add1rrN)rrXrres r' test_synczSpreadUtilTests.test_syncs'   fa0!4r)ct}t}|jddd}|j|t|j |j d|S)zm Call an asynchronous method of a L{util.LocalAsRemote} object and check the result. r?rr)rr)rrrWrr_rX)r%rfr$s r' test_asynczSpreadUtilTests.test_asyncsQ     LLQL ' a* d&&*r)crt}|jd}fd}|jfd||S)zG Test an asynchronous failure on a remote method call. rcpj|tj|jtyr0)rWrratrapr)r1r%s r'ebz*SpreadUtilTests.test_asyncFail..ebs#  ! !!W__ 5 FF< r)c&jdS)Nzsupposed to failr)r[r%s r'r8z0SpreadUtilTests.test_asyncFail..s499-?#@r))rrr#)r%rfr$rws` r'test_asyncFailzSpreadUtilTests.test_asyncFails6   LL  ! @"Er)cjt}|jd}|j|ddy)zM Test the C{remoteMethod} facility of L{util.LocalAsRemote}. rprrN)rrrX)r%rfms r'test_remoteMethodz!SpreadUtilTests.test_remoteMethods.   NN6 " 1q!r)ct}tj|t}|j d|j |j |j d|j|j|j d}g}|j|j|j|ddy)ze Test a call to L{util.LocalAsyncForwarder} using L{Forwarded} local object. rbrkrdrrRN) rfrLocalAsyncForwarderr`rrrhrYrjr_rrX)r%r1lfrrrs r'test_localAsyncForwarderz(SpreadUtilTests.test_localAsyncForwarders K  % %a 4 k"  $ o& ' ]], -  qxx  1q!r)N) r*r+r,r3rqrsryr|rr-r)r'rnrns 5  ""r)rnc(eZdZdZdZdZdZdZy)PBWithSecurityOptionsTestsz& Test security customization. ctj}|jd}|j|jt j y)zl By default, client broker should use C{jelly.globalSecurity} as security settings. N)rrrkrsecurityrglobalSecurityr%rrcs r'!test_clientDefaultSecurityOptionsz $$VX.&&t, foou';';rs "166F==CC936'+33"+BKK+ryy V]]GGG88v0,f44B  4 F2##2##  bmm *o6 , ,  ! !24EF(!!(",,R--!2<<!*%%68JK r~~ +'78""" 5!! 5R%%,,r,2;;  , 5 'BKK '-7 bnn +->?RWWRWWOH00OdB$6$6@4(++4nR (##R j    #  # #B$$ #i5(##i5X'g))'  g%% 2##/73@-**@-F y "++ !! d((  R__ BII  FXXB/R[[/ HH*3*x((3*lf8$$fR R__   #x  #L     ZB="h''="@)1!2!2)1r)