+
    Dfj9                        R t ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
HtHt ^ RIHt ^ RIHt  ! R R	]4      t ! R
 R]4      t ! R R]P(                  4      t ! R R]P(                  4      t ! R R]
P.                  ]P(                  ]P0                  4      t ! R R]P(                  ]P0                  4      t]P6                  ! ]]4       ]P6                  ! ]]4       ]P8                  P;                  ]4        ! R R]P<                  4      t ! R R]P@                  4      t! ! R R]PD                  4      t# ! R R]#4      t$ ! R R]$4      t% ! R R4      t& ! R  R!]PD                  4      t'R"# )#z!
Tests for error handling in PB.
)StringIO)defer)log)qual)flavorsjellypb)connectedServerAndClient)unittestc                       ] tR t^tRtRtR# )AsynchronousExceptionz|
Helper used to test remote methods which return Deferreds which fail with
exceptions which are not L{pb.Error} subclasses.
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r       D/usr/lib/python3/dist-packages/twisted/spread/test/test_pbfailure.pyr   r          r   r   c                       ] tR t^tRtRtR# )SynchronousExceptionza
Helper used to test remote methods which raise exceptions which are not
L{pb.Error} subclasses.
r   Nr   r   r   r   r   r      r   r   r   c                       ] tR t^"tRtRtR# )AsynchronousErrorzx
Helper used to test remote methods which return Deferreds which fail with
exceptions which are L{pb.Error} subclasses.
r   Nr   r   r   r   r   r   "   r   r   r   c                       ] tR t^)tRtRtR# )SynchronousErrorz]
Helper used to test remote methods which raise exceptions which are
L{pb.Error} subclasses.
r   Nr   r   r   r   r   r   )   r   r   r   c                       ] tR t^0tRtR# )
JellyErrorr   Nr   r   r   r   r   r   r   r   r   r   0       r   r   c                       ] tR t^4tRtR# )SecurityErrorr   Nr    r   r   r   r#   r#   4   r!   r   r#   c                   j   a  ] tR t^>t o R tR tR tR tR tR t	R t
R tR	 tRR ltRR ltRtV tR
# )
SimpleRootc                @    \         P                  ! \        R4      4      # )z4
Fail asynchronously with a non-pb.Error exception.
zremote asynchronous exception)r   failr   selfs   &r   remote_asynchronousException'SimpleRoot.remote_asynchronousException?   s     zz/0OPQQr   c                    \        R4      h)z3
Fail synchronously with a non-pb.Error exception.
zremote synchronous exception)r   r(   s   &r   remote_synchronousException&SimpleRoot.remote_synchronousExceptionE   s     ##ABBr   c                @    \         P                  ! \        R4      4      # )z0
Fail asynchronously with a pb.Error exception.
zremote asynchronous error)r   r'   r   r(   s   &r   remote_asynchronousError#SimpleRoot.remote_asynchronousErrorK   s     zz+,GHIIr   c                    \        R4      h)z/
Fail synchronously with a pb.Error exception.
zremote synchronous error)r   r(   s   &r   remote_synchronousError"SimpleRoot.remote_synchronousErrorQ   s     9::r   c                D     ! R R\         P                  4      pV! R4      h)z.
Fail with error that is not known to client.
c                       ] tR t^\tRtR# )4SimpleRoot.remote_unknownError.<locals>.UnknownErrorr   Nr    r   r   r   UnknownErrorr7   \   s    r   r8   zI'm not known to client!)r   Error)r)   r8   s   & r   remote_unknownErrorSimpleRoot.remote_unknownErrorW   s     
	288 	 566r   c                &    V P                  4        R # N)
raiseJellyr(   s   &r   remote_jellySimpleRoot.remote_jellya   s    r   c                &    V P                  4        R # r=   )raiseSecurityr(   s   &r   remote_securitySimpleRoot.remote_securityd   s    r   c                    \         P                  ! 4       pVP                  V P                  4       VP	                  R 4       V# r=   )r   DeferredaddCallbackr>   callbackr)   ds   & r   remote_deferredJellySimpleRoot.remote_deferredJellyg   s/    NN	doo&	

4r   c                    \         P                  ! 4       pVP                  V P                  4       VP	                  R 4       V# r=   )r   rF   rG   rB   rH   rI   s   & r   remote_deferredSecurity"SimpleRoot.remote_deferredSecuritym   s1    NN	d(()	

4r   Nc                    \        R 4      h)zI'm jellyable!)r   r)   resultss   &&r   r>   SimpleRoot.raiseJellys   s    )**r   c                    \        R 4      h)zI'm secure!)r#   rQ   s   &&r   rB   SimpleRoot.raiseSecurityv   s    M**r   r   r=   )r   r   r   r   r*   r-   r0   r3   r:   r?   rC   rK   rN   r>   rB   r   __classdictcell____classdict__s   @r   r%   r%   >   sD     RCJ;7++ +r   r%   c                   .   a  ] tR t^zt o RtRtR tRtV tR# )SaveProtocolServerFactoryzX
A L{pb.PBServerFactory} that saves the latest connected client in
C{protocolInstance}.
Nc                    Wn         R# )z#
Keep track of the given protocol.
NprotocolInstance)r)   protocols   &&r   clientConnectionMade.SaveProtocolServerFactory.clientConnectionMade   s
     !)r   r\   )	r   r   r   r   r   r]   r_   r   rV   rW   s   @r   rZ   rZ   z   s     
 ) )r   rZ   c                   *   a  ] tR t^t o ^ tR tRtV tR# )PBConnTestCasec                   a  \        \        4       4      S n        S P                  S P                  n        \        P
                  ! 4       S n        \        V 3R  lV 3R l4      w  S n        S n	        S n
        R# )c                  :   < S P                   P                  R 4      # r=   )serverFactorybuildProtocolr(   s   r   <lambda>&PBConnTestCase.setUp.<locals>.<lambda>       D&&44T:r   c                  :   < S P                   P                  R 4      # r=   )clientFactoryrf   r(   s   r   rg   rh      ri   r   N)rZ   r%   re   unsafeTracebacksr   PBClientFactoryrk   r	   connectedServerconnectedClientpumpr(   s   fr   setUpPBConnTestCase.setUp   s]    6z|D.2.C.C+//1
 %::
		
  Ir   )rk   ro   rn   rp   re   N)r   r   r   r   rl   rq   r   rV   rW   s   @r   rb   rb      s     
 
r   rb   c                      a  ] tR t^t o ]P
                  P                  tR tR t	R t
R tR tR tR tRR	 ltR
 tR tR tR tR tR tR tR tR tRtV tR# )PBFailureTestsc                   a aaaa VVV 3R  loS P                   P                  4       pVV3R lpVP                  V4       S P                  P	                  4        R# )c                   < V P                  S4       SP                  V P                  R 4       S'       d-   SP                  S4      pSP	                  \        V4      ^4       V P                  V P                  V P                  3# )Traceback unavailable
)trapcompare	tracebackflushLoggedErrorsassertEquallentypevalue)errerrsexceptionTypeflushr)   s   & r   eb)PBFailureTests._exceptionTest.<locals>.eb   sb    HH]#LL(AB--m<  TA.HHcii77r   c                 L   < V P                  S4      pVP                  S4       V# r=   )
callRemote
addErrback)rootrJ   r   methods   & r   gotRootObject4PBFailureTests._exceptionTest.<locals>.gotRootObject   s"    'ALLHr   Nrk   getRootObjectrG   rp   r   )r)   r   r   r   rJ   r   r   s   ffff  @r   _exceptionTestPBFailureTests._exceptionTest   s?    	8 ,,.	
 	
m$		r   c                0    V P                  R\        R4      # )z
Test that a Deferred returned by a remote method which already has a
Failure correctly has that error passed back to the calling side.
asynchronousExceptionT)r   r   r(   s   &r   test_asynchronousException)PBFailureTests.test_asynchronousException   s    
 ""#:<QSWXXr   c                0    V P                  R\        R4      # )z_
Like L{test_asynchronousException}, but for a method which raises an
exception synchronously.
synchronousExceptionT)r   r   r(   s   &r   test_synchronousException(PBFailureTests.test_synchronousException   s    
 ""#9;OQUVVr   c                0    V P                  R\        R4      # )zu
Like L{test_asynchronousException}, but for a method which returns a
Deferred failing with an L{pb.Error} subclass.
asynchronousErrorF)r   r   r(   s   &r   test_asynchronousError%PBFailureTests.test_asynchronousError   s    
 ""#68I5QQr   c                0    V P                  R\        R4      # )ze
Like L{test_asynchronousError}, but for a method which synchronously
raises a L{pb.Error} subclass.
synchronousErrorF)r   r   r(   s   &r   test_synchronousError$PBFailureTests.test_synchronousError   s    
 ""#57GOOr   c                (    V P                  W4       V# r=   )r|   )r)   resultexpectedResults   &&&r   _successPBFailureTests._success   s    0r   c                B    VP                  V P                  W23R 7       V# ))callbackArgs)addCallbacksr   )r)   
remoteCallr   r   s   &&&&r   _addFailingCallbacks#PBFailureTests._addFailingCallbacks   s"    r@QRr   Nc                   a aaaa S P                   P                  4       pVVVVV 3R lpVP                  V4       S P                  P	                  4        R# )z
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.
c                    < SP                  V P                  S4      SS4      pSe   VV3R lpVP                  V4       V# )Nc                 \   < SP                  \        SP                  S4      4      ^4       V # )   )r|   r}   r{   )r   excr)   s   &r   
gotFailure@PBFailureTests._testImpl.<locals>.gotRootObj.<locals>.gotFailure   s(    $$S)?)?)D%EqIJr   )r   r   addBoth)objfailureDeferredr   r   r   expectedr   r)   s   &  r   
gotRootObj,PBFailureTests._testImpl.<locals>.gotRootObj   sE    "77v&"O   ''
3""r   Nr   )r)   r   r   r   r   rootDeferredr   s   fffff  r   	_testImplPBFailureTests._testImpl   sA     ))779	# 	# 	  ,		r   c                6   a  V 3R lpS P                  R^+V4      # )z
Test that an exception which is a subclass of L{pb.Error} has more
information passed across the network to the calling side.
c                    < V P                  \        4       SP                  V P                  \        4       SP                  V P                  V P                  4       ^+# )+   rx   r   assertNotIsInstancer~   strassertIsInstancer   r'   r)   s   &r   failureJelly6PBFailureTests.test_jellyFailure.<locals>.failureJelly   s>    IIj!$$TYY4!!$**dii8r   r   r   )r)   r   s   f r   test_jellyFailure PBFailureTests.test_jellyFailure   s    	 ~~gr<88r   c                6   a  V 3R lpS P                  RRV4      # )zw
Test that a Deferred which fails with a L{pb.Error} is treated in
the same way as a synchronously raised L{pb.Error}.
c                    < V P                  \        4       SP                  V P                  \        4       SP                  V P                  V P                  4       R # )  r   r   s   &r   failureDeferredJellyFPBFailureTests.test_deferredJellyFailure.<locals>.failureDeferredJelly   s>    IIj!$$TYY4!!$**dii8r   deferredJellyr   r   )r)   r   s   f r   test_deferredJellyFailure(PBFailureTests.test_deferredJellyFailure   s    	 ~~os4HIIr   c                6   a  V 3R lpS P                  RRV4      # )z
A 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.
c                 @   < SP                  V P                  R 4       R# )s3   twisted.spread.test.test_pbfailure.SynchronousError  r|   r~   r   s   &r   failureUnjellyableBPBFailureTests.test_unjellyableFailure.<locals>.failureUnjellyable  s     		Q r   r   r   r   )r)   r   s   f r   test_unjellyableFailure&PBFailureTests.test_unjellyableFailure  s    	 ~~0#7IJJr   c                6   a  V 3R lpS P                  RRV4      # )zw
Test that an exception which is a subclass of L{pb.Error} but not
known on the client side has its type set properly.
c                 @   < SP                  V P                  R 4       R# )s/   twisted.spread.test.test_pbfailure.UnknownError  r   r   s   &r   failureUnknown:PBFailureTests.test_unknownFailure.<locals>.failureUnknown  s     		M r   unknownErrorr   r   )r)   r   s   f r   test_unknownFailure"PBFailureTests.test_unknownFailure  s    	 ~~ndNCCr   c                6   a  V 3R lpS P                  RRV4      # )z
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.
c                    < V P                  \        4       SP                  V P                  \        4       SP                  V P                  V P                  4       R # )  rx   r#   r   r~   r   r   r   r   s   &r   failureSecurity<PBFailureTests.test_securityFailure.<locals>.failureSecurity,  s>    IIm$$$TYY4!!$**dii8r   securityr   r   )r)   r   s   f r   test_securityFailure#PBFailureTests.test_securityFailure%  s    	 ~~j$@@r   c                6   a  V 3R lpS P                  RRV4      # )z
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.
c                    < V P                  \        4       SP                  V P                  \        4       SP                  V P                  V P                  4       R # )  r   r   s   &r   failureDeferredSecurityEPBFailureTests.test_deferredSecurity.<locals>.failureDeferredSecurity;  s>    IIm$$$TYY4!!$**dii8r   deferredSecurityr   r   )r)   r   s   f r   test_deferredSecurity$PBFailureTests.test_deferredSecurity4  s    	 ~~0%9PQQr   c                @   a  V 3R lpS P                  RRV\        4      # )zx
Test that attempting to call a method which is not defined correctly
results in an AttributeError on the calling side.
c                 ~   < V P                  \        P                  4       SP                  V P                  R 4       R# )rw     )rx   r   NoSuchMethodry   rz   r   s   &r   failureNoSuch>PBFailureTests.test_noSuchMethodFailure.<locals>.failureNoSuchI  s)    IIboo&LL)BCr   nosuchr   )r   AttributeError)r)   r   s   f r   test_noSuchMethodFailure'PBFailureTests.test_noSuchMethodFailureC  s    	
 ~~h}nMMr   c                   a  S P                   P                  4       pR pVP                  V4       V 3R lpVP                  V4       S P                  P                  4        R# )z
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.
c                 $    V P                  R 4      # )r   )r   )rootObjs   &r   	connected;PBFailureTests.test_copiedFailureLogging.<locals>.connectedZ  s    %%&<==r   c                    < \         P                  ! V 4       SP                  \        4      pSP	                  \        V4      ^4       R# )   N)r   r   r{   r   r|   r}   )failurer   r)   s   & r   	exception;PBFailureTests.test_copiedFailureLogging.<locals>.exception_  s4    GGG))*>?DSY*r   N)rk   r   rG   r   rp   r   )r)   rJ   r   r  s   f   r   test_copiedFailureLogging(PBFailureTests.test_copiedFailureLoggingP  sM     ,,.	> 	
i 	+
 	
Y		r   c                \  a a \         P                  ! \        R4      4      p\        P                  ! \        P                  ! V\        4       R7      4      p. oVV 3R lpV! 4       pVP                  R4       S P                  \        VP                  V4       S P                  \        S4      ^4       S^ ,          pS P                  VP                  \        \        4      P                  R4      4       S P                  VP                  R4       S P                  VP                   R4       R# )z
L{pb.CopiedFailure.throwExceptionIntoGenerator} will throw a
L{RemoteError} into the given paused generator at the point where it
last yielded.
fooinvokerc               3      <"    R x  SP                  R4       R #   \        P                   d   p SP                  T 4        R p ? R # R p ? ii ; i5i)NzRemoteError not raised)r'   r   RemoteErrorappend)r   r  r)   s    r   generatorFuncFPBFailureTests.test_throwExceptionIntoGenerator.<locals>.generatorFuncq  sE     4
 		23 >> &  %%&s*   A AAAAAANasciirw   )r	  )r   CopyableFailurer   r   unjellyDummyInvokersendassertRaisesStopIterationthrowExceptionIntoGeneratorr|   r}   
remoteTyper   encodeargsremoteTraceback)r)   originalcopyr  genr   r  s   f     @r    test_throwExceptionIntoGenerator/PBFailureTests.test_throwExceptionIntoGeneratorg  s     %%nU&;<}}U[[<>JK		4 o-)I)I3OY+ln)=)D)DW)MN8,,,.GHr   r   r=   )r   r   r   r   r
   TestCaser|   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   rV   rW   s   @r   rt   rt      s|     ++G&YWRP09JKDARN.I Ir   rt   c                   F    ] tR tRt]P
                  P                  t^tRt	R# )PBFailureUnsafeTestsi  r   N)
r   r   r   r   r
   r"  failIfEqualsry   rl   r   r   r   r   r$  r$    s    ,,Gr   r$  c                       ] tR tRtRtRtRtR# )r  i  zN
A behaviorless object to be used as the invoker parameter to
L{jelly.jelly}.
Nr   )r   r   r   r   r   serializingPerspectiver   r   r   r   r  r    s    
 "r   r  c                   6   a  ] tR tRt o RtR tR tR tRtV t	R# )FailureJellyingTestsi  z2
Tests for the interaction of jelly and failures.
c                   \         P                  ! \        4       4      pV P                  VP	                  \        4      \        4       V P                  VP	                  \
        4      \
        4       \        P                  ! \        P                  ! V\        4       R7      4      pV P                  VP	                  \        4      \        4       V P                  VP	                  \
        4      \
        4       R# )z
An unjellied L{CopyableFailure} has a check method which behaves the
same way as the original L{CopyableFailure}'s check method.
r
  N	r   r  ZeroDivisionErrorassertIscheckArithmeticErrorr   r  r  )r)   r  copieds   &  r   test_unjelliedFailureCheck/FailureJellyingTests.test_unjelliedFailureCheck  s    
 %%&7&9:hnn%679JKhnn_5Gu{{8\^LMfll#457HIfll?3_Er   c                   \         P                  ! \        4       4      pV P                  VP	                  \        4      \        4       V P                  VP	                  \
        4      \
        4       \        P                  ! \        P                  ! V\        4       R7      4      p\         P                  ! V4      p\        P                  ! \        P                  ! V\        4       R7      4      pV P                  VP	                  \        4      \        4       V P                  VP	                  \
        4      \
        4       R# )a(  
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.
r
  Nr+  )r)   r  
copiedOnce
derivativecopiedTwices   &    r   test_twiceUnjelliedFailureCheck4FailureJellyingTests.test_twiceUnjelliedFailureCheck  s     %%&7&9:hnn%679JKhnn_5G]]5;;x#PQ
''
3
mmEKK
LN$STk''(9:<MNk''8/Jr   c                `   \         P                  ! \        R4      4      p\        P                  ! \        P                  ! V\        4       R7      4      p\        4       pVP                  V4       \        \        4      pRP                  V4      pV P                  WSP                  4       4       R# )z
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.
zsome reasonr
  z.Traceback from remote host -- {}: some reason
N)r   r  	Exceptionr   r  r  r   printTracebackr   formatr|   getvalue)r)   r  r0  outputr  expectedOutputs   &     r    test_printTracebackIncludesValue5FailureJellyingTests.test_printTracebackIncludesValue  s|     %%i&>?u{{8\^LMf%O	MTT
 	):;r   r   N)
r   r   r   r   r   r1  r7  r@  r   rV   rW   s   @r   r)  r)    s      
FK"< <r   r)  N)(r   ior   twisted.internetr   twisted.pythonr   twisted.python.reflectr   twisted.spreadr   r   r   twisted.test.iosimr	   twisted.trialr
   r:  r   r   r9   r   r   	Jellyable
RemoteCopyr   r#   setUnjellyableForClassglobalSecurityallowInstancesOfRootr%   PBServerFactoryrZ   r"  rb   rt   r$  r  r)  r   r   r   <module>rP     s4    "  ' - - 7 "
I 9  rxx 	""BHHbmm 		BHHbmm 	   *j 1   - 7    " "= 19+ 9+x) 2 2 )
X&& 
"fI^ fIR> 
" "1<8,, 1<r   