]Rc@sdZddlmZddlmZddlmZmZmZddlm Z m Z ddl m Z de fdYZd e fd YZd ejfd YZd ejfdYZdejejejfdYZdejejfdYZejeeejeeejjedejfdYZdejfdYZdejfdYZdefdYZ de fdYZ!de"fdYZ#dejfd YZ$d!S("s! Tests for error handling in PB. i(tStringIO(tunittest(tpbtflavorstjelly(treactortdefer(tlogtAsynchronousExceptioncBseZdZRS(s Helper used to test remote methods which return Deferreds which fail with exceptions which are not L{pb.Error} subclasses. (t__name__t __module__t__doc__(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyRstSynchronousExceptioncBseZdZRS(sm Helper used to test remote methods which raise exceptions which are not L{pb.Error} subclasses. (R R R (((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyR stAsynchronousErrorcBseZdZRS(s Helper used to test remote methods which return Deferreds which fail with exceptions which are L{pb.Error} subclasses. (R R R (((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyR stSynchronousErrorcBseZdZRS(si Helper used to test remote methods which raise exceptions which are L{pb.Error} subclasses. (R R R (((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyR'st JellyErrorcBseZRS((R R (((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyR/st SecurityErrorcBseZRS((R R (((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyR3st SimpleRootcBsqeZdZdZdZdZdZdZdZdZ dZ d d Z d d Z RS( cCstjtdS(sD Fail asynchronously with a non-pb.Error exception. sremote asynchronous exception(RtfailR(tself((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytremote_asynchronousException?scCstddS(sC Fail synchronously with a non-pb.Error exception. sremote synchronous exceptionN(R (R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytremote_synchronousExceptionEscCstjtdS(s@ Fail asynchronously with a pb.Error exception. sremote asynchronous error(RRR (R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytremote_asynchronousErrorKscCstddS(s? Fail synchronously with a pb.Error exception. sremote synchronous errorN(R(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytremote_synchronousErrorQscCs)dtjfdY}|ddS(s> Fail with error that is not known to client. t UnknownErrorcBseZRS((R R (((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyR[ssI'm not known to client!N(RtError(RR((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytremote_unknownErrorWscCs|jdS(N(t raiseJelly(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyt remote_jelly_scCs|jdS(N(t raiseSecurity(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytremote_securitybscCs-tj}|j|j|jd|S(N(RtDeferredt addCallbackRtcallbacktNone(Rtd((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytremote_deferredJellyes  cCs-tj}|j|j|jd|S(N(RRR RR!R"(RR#((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytremote_deferredSecurityks  cCstddS(NsI'm jellyable!(R(Rtresults((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyRqscCstddS(Ns I'm secure!(R(RR&((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyRtsN(R R RRRRRRRR$R%R"RR(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyR>s          tSaveProtocolServerFactorycBseZdZdZdZRS(sd A L{pb.PBServerFactory} that saves the latest connected client in C{protocolInstance}. cCs ||_dS(s3 Keep track of the given protocol. N(tprotocolInstance(Rtprotocol((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytclientConnectionMadesN(R R R R"R(R*(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyR'ystPBConnTestCasecBsDeZdZdZdZdZdZdZdZRS(icCs|j|jdS(N(t _setUpServert _setUpClient(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytsetUps cCsCtt|_|j|j_tjd|jdd|_dS(Nit interfaces 127.0.0.1(R'Rt serverFactorytunsafeTracebacksRt listenTCPt serverPort(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyR,scCs@|jjj}tj|_tjd||j|_dS(Ns 127.0.0.1( R3tgetHosttportRtPBClientFactoryt clientFactoryRt connectTCPtclientConnector(RtportNo((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyR-scCsG|jjdk r(|jjjjntj|j|jgS(N( R0R(R"t transporttloseConnectionRt gatherResultst_tearDownServert_tearDownClient(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyttearDowns  cCstj|jjS(N(Rt maybeDeferredR3t stopListening(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyR>scCs|jjtjdS(N(R9t disconnectRtsucceedR"(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyR?s ( R R R1R.R,R-R@R>R?(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyR+s     t PBFailureTestcBseZejjZdZdZdZdZ dZ dZ dZ ddZdZd Zd Zd Zd Zd ZdZdZdZRS(csGfdjj}fd}|j||S(Ncsd|jj|jdrNj}jt|dn|j|j|jfS(NsTraceback unavailable i(ttraptcomparet tracebacktflushLoggedErrorst assertEqualtlenttypetvalue(terrterrs(t exceptionTypetflushR(s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytebs  cs |j}|j|S(N(t callRemotet addErrback(trootR#(RRtmethod(s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyt gotRootObjects (R7t getRootObjectR (RRVRPRQR#RW((RRRPRQRVRs?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyt_exceptionTests  cCs|jdttS(s Test that a Deferred returned by a remote method which already has a Failure correctly has that error passed back to the calling side. tasynchronousException(RYRtTrue(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyttest_asynchronousExceptionscCs|jdttS(sw Like L{test_asynchronousException}, but for a method which raises an exception synchronously. tsynchronousException(RYR R[(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyttest_synchronousExceptionscCs|jdttS(s Like L{test_asynchronousException}, but for a method which returns a Deferred failing with an L{pb.Error} subclass. tasynchronousError(RYR tFalse(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyttest_asynchronousErrorscCs|jdttS(s} Like L{test_asynchronousError}, but for a method which synchronously raises a L{pb.Error} subclass. tsynchronousError(RYRR`(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyttest_synchronousErrorscCs|j|||S(N(RJ(RtresulttexpectedResult((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyt_successscCs |j|j|d|f|S(Nt callbackArgs(t addCallbacksRf(Rt remoteCallReRR((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyt_addFailingCallbackss cs;jj}fd}|j||S(s Call the given remote method and attach the given errback to the resulting Deferred. If C{exc} is not None, also assert that one exception of that type was logged. csPj|j}dk rLfd}|j|n|S(Ncs#jtjd|S(Ni(RJRKRI(RN(texcR(s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyt gotFailures(RjRSR"taddBoth(tobjtfailureDeferredRl(RRRktexpectedRVR(s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyt gotRootObjs  (R7RXR (RRVRpRRRkt rootDeferredRq((RRRkRpRVRs?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyt _testImpls cs"fd}jdd|S(s Test that an exception which is a subclass of L{pb.Error} has more information passed across the network to the calling side. csF|jtjt|jtjt|j|jdS(Ni+(RFRtfailIft isinstanceRLtstrt failUnlessRM(R(R(s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyt failureJellys Ri+(Rs(RRx((Rs?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyttest_jellyFailurescs"fd}jdd|S(s Test that a Deferred which fails with a L{pb.Error} is treated in the same way as a synchronously raised L{pb.Error}. csF|jtjt|jtjt|j|jdS(Ni(RFRRtRuRLRvRwRM(R(R(s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytfailureDeferredJellys t deferredJellyi(Rs(RRz((Rs?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyttest_deferredJellyFailure scs"fd}jdd|S(s An non-jellyable L{pb.Error} subclass raised by a remote method is turned into a Failure with a type set to the FQPN of the exception type. csj|jddS(Ns,twisted.test.test_pbfailure.SynchronousErrori(RJRL(R(R(s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytfailureUnjellyable s Rbi(Rs(RR}((Rs?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyttest_unjellyableFailurescs"fd}jdd|S(s Test that an exception which is a subclass of L{pb.Error} but not known on the client side has its type set properly. csj|jddS(Ns(twisted.test.test_pbfailure.UnknownErrori(RJRL(R(R(s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytfailureUnknown,s t unknownErrori(Rs(RR((Rs?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyttest_unknownFailure'scs"fd}jdd|S(s Test that even if an exception is not explicitly jellyable (by being a L{pb.Jellyable} subclass), as long as it is an L{pb.Error} subclass it receives the same special treatment. csF|jtjt|jtjt|j|jdS(Ni(RFRRtRuRLRvRwRM(R(R(s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytfailureSecurity9s tsecurityi(Rs(RR((Rs?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyttest_securityFailure3scs"fd}jdd|S(s Test that a Deferred which fails with a L{pb.Error} which is not also a L{pb.Jellyable} is treated in the same way as a synchronously raised exception of the same type. csF|jtjt|jtjt|j|jdS(Ni(RFRRtRuRLRvRwRM(R(R(s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytfailureDeferredSecurityGs tdeferredSecurityi(Rs(RR((Rs?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyttest_deferredSecurityAscs%fd}jdd|tS(s Test that attempting to call a method which is not defined correctly results in an AttributeError on the calling side. cs'|jtjj|jddS(NsTraceback unavailable i(RFRt NoSuchMethodRGRH(R(R(s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyt failureNoSuchTstnosuchi(RstAttributeError(RR((Rs?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyttest_noSuchMethodFailureOscsEjj}d}|j|fd}|j||S(s Test that a copied failure received from a PB call can be logged locally. Note: this test needs some serious help: all it really tests is that log.err(copiedFailure) doesn't raise an exception. cSs |jdS(NR](RS(trootObj((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyt connectedescs6tj|jt}jt|ddS(Ni(RRNRIR RJRK(tfailureRO(R(s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyt exceptionis (R7RXR RT(RR#RR((Rs?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyttest_copiedFailureLogging[s    cstjtd}tjtj|dt}gfd}|}|jdjt |j |j t dd}j |j dj |jd j |jddS( s L{pb.CopiedFailure.throwExceptionIntoGenerator} will throw a L{RemoteError} into the given paused generator at the point where it last yielded. tfootinvokerc3s@y dVWn#tjk r.}j|nXjddS(NsRemoteError not raised(R"Rt RemoteErrortappendR(Rk(RR(s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyt generatorFunc{s  iisexceptions.AttributeErrorsTraceback unavailable N(R(RtCopyableFailureRRtunjellyt DummyInvokertsendR"t assertRaisest StopIterationtthrowExceptionIntoGeneratorRJRKt remoteTypetargstremoteTraceback(RtoriginaltcopyRtgenRk((RRs?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyt test_throwExceptionIntoGeneratorrs!   N(R R RtTestCaseRJRGRYR\R^RaRcRfRjR"RsRyR|R~RRRRRR(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyREs$        tPBFailureTestUnsafecBseZejjZdZRS(i(R R RRt failIfEqualsRGR1(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyRs RcBseZdZdZRS(sZ A behaviorless object to be used as the invoker parameter to L{jelly.jelly}. N(R R R R"tserializingPerspective(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyRstFailureJellyingTestscBs)eZdZdZdZdZRS(s: Tests for the interaction of jelly and failures. cCstjt}|j|jtt|j|jtttjtj|dt}|j|jtt|j|jttdS(s An unjellied L{CopyableFailure} has a check method which behaves the same way as the original L{CopyableFailure}'s check method. RN( RRtZeroDivisionErrortassertIdenticaltchecktArithmeticErrorRRR(RRtcopied((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyttest_unjelliedFailureChecks!cCstjt}|j|jtt|j|jtttjtj|dt}tj|}tjtj|dt}|j|jtt|j|jttdS(sX The object which results from jellying a L{CopyableFailure}, unjellying the result, creating a new L{CopyableFailure} from the result of that, jellying it, and finally unjellying the result of that has a check method which behaves the same way as the original L{CopyableFailure}'s check method. RN( RRRRRRRRR(RRt copiedOncet derivativet copiedTwice((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyttest_twiceUnjelliedFailureCheckscCsftjtd}tjtj|dt}t}|j||jd|j dS(s When L{CopiedFailure.printTraceback} is used to print a copied failure which was unjellied from a L{CopyableFailure} with C{unsafeTracebacks} set to C{False}, the string representation of the exception value is included in the output. s some reasonRsVTraceback from remote host -- Traceback unavailable exceptions.Exception: some reason N( RRt ExceptionRRRRtprintTracebackRJtgetvalue(RRRtoutput((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyt test_printTracebackIncludesValues!  (R R R RRR(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyRs  N(%R Rt twisted.trialRttwisted.spreadRRRttwisted.internetRRttwisted.pythonRRRR RR Rt Jellyablet RemoteCopyRRtsetUnjellyableForClasstglobalSecuritytallowInstancesOftRootRtPBServerFactoryR'RR+RERtobjectRR(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyts*%;!