Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/test/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyc


*Nc@sdZddlZddlmZddlmZddlmZmZmZddl	m
Z
mZddlm
Z
defd	YZd
efdYZdejfd
YZdejfdYZdejejejfdYZdejejfdYZejeeejeeejjedejfdYZdejfdYZdejfdYZ de fdYZ!de!fdYZ"de#fdYZ$d ejfd!YZ%dS("s!
Tests for error handling in PB.
iN(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.pyR1st
SecurityErrorcBseZRS((R	R
(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyR5st
SimpleRootcBsqeZdZdZdZdZdZdZdZdZ	dZ
dd	Zdd
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_asynchronousExceptionAscCstddS(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_synchronousExceptionGscCstjtdS(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_asynchronousErrorMscCstddS(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_synchronousErrorSscCs)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_unknownErrorYscCs|jdS(N(t
raiseJelly(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytremote_jellyascCs|jdS(N(t
raiseSecurity(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytremote_securitydscCs-tj}|j|j|jd|S(N(RtDeferredtaddCallbackRtcallbacktNone(Rtd((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytremote_deferredJellygs
cCs-tj}|j|j|jd|S(N(RRR RR!R"(RR#((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pytremote_deferredSecurityms
cCstddS(NsI'm jellyable!(R(Rtresults((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyRsscCstddS(NsI'm secure!(R(RR&((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyRvsN(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
RR"R(R*(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyR'{stPBConnTestCasecBsDeZdZdZdZdZdZdZdZRS(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
dZdZddZdZd	Zd
ZdZdZd
ZdZdZdZejd dkrde_nRS(csGfdjj}fd}|j||S(Ncsd|jj|jdrNj}jt|dn|j|j|jfS(NsTraceback unavailable
i(ttraptcomparet	tracebacktflushLoggedErrorstassertEqualtlenttypetvalue(terrterrs(Rt
exceptionTypetflush(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((RRPRRRQRVs?/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(Rtexc(s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyt
gotFailures(RjRSR"taddBoth(tobjtfailureDeferredRl(RkRRRtexpectedRV(s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyt
gotRootObjs
(R7RXR (RRVRpRRRktrootDeferredRq((RkRRVRpRRs?/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_deferredJellyFailurescs"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.pytfailureSecurity;s
tsecurityi(Rs(RR((Rs?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyttest_securityFailure5scs"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.pytfailureDeferredSecurityIs
tdeferredSecurityi(Rs(RR((Rs?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyttest_deferredSecurityCscs%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
failureNoSuchVstnosuchi(RstAttributeError(RR((Rs?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyttest_noSuchMethodFailureQscsEjj}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	connectedgscs6tj|jt}jt|ddS(Ni(RRNRIRRJRK(tfailureRO(R(s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyt	exceptionks
(R7RXR RT(RR#RR((Rs?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyttest_copiedFailureLogging]s	

cstjtd}tjtj|dt}gfd}|}|jdjt	|j
|jt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"RtRemoteErrortappendR(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_throwExceptionIntoGeneratorts!	

iis<throwExceptionIntoGenerator is not supported in Python < 2.5N(ii(R	R
RtTestCaseRJRGRYR\R^RaRcRfRjR"RsRyR|R~RRRRRRtsystversion_infotskip(((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
RR"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
derivativetcopiedTwice((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.
        ssome 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
RRRR(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyRs		(&RRRt
twisted.trialRttwisted.spreadRRRttwisted.internetRRttwisted.pythonRRRRRR
Rt	Jellyablet
RemoteCopyRRtsetUnjellyableForClasstglobalSecuritytallowInstancesOftRootRtPBServerFactoryR'RR+RERtobjectRR(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_pbfailure.pyt<module>s,%;!