HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/twisted/spread/test/__pycache__/test_pbfailure.cpython-38.pyc
U


W[I<�@sldZddlmZmZddlmZddlmZddlm	Z	ddl
mZmZm
Z
ddlmZGdd	�d	e�ZGd
d�de�ZGdd
�d
ej�ZGdd�dej�ZGdd�dejejej�ZGdd�dejej�Ze�ee�e�ee�ej�e�Gdd�dej�ZGdd�dej�Z Gdd�dej!�Z"Gdd�de"�Z#Gdd�de#�Z$Gdd�de%�Z&Gd d!�d!ej!�Z'd"S)#z!
Tests for error handling in PB.
�)�reactor�defer)�log)�NativeStringIO)�qual)�pb�flavors�jelly)�unittestc@seZdZdZdS)�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__�__doc__�rr�D/usr/lib/python3/dist-packages/twisted/spread/test/test_pbfailure.pyrsrc@seZdZdZdS)�SynchronousExceptionzm
    Helper used to test remote methods which raise exceptions which are not
    L{pb.Error} subclasses.
    Nrrrrrrsrc@seZdZdZdS)�AsynchronousErrorz�
    Helper used to test remote methods which return Deferreds which fail with
    exceptions which are L{pb.Error} subclasses.
    Nrrrrrrsrc@seZdZdZdS)�SynchronousErrorzi
    Helper used to test remote methods which raise exceptions which are
    L{pb.Error} subclasses.
    Nrrrrrr'src@seZdZdS)�
JellyErrorN�r
rrrrrrr/src@seZdZdS)�
SecurityErrorNrrrrrr4src@sheZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zddd�Zddd�Z
dS)�
SimpleRootcCst�td��S)zD
        Fail asynchronously with a non-pb.Error exception.
        zremote asynchronous exception)r�failr��selfrrr�remote_asynchronousException@sz'SimpleRoot.remote_asynchronousExceptioncCstd��dS)zC
        Fail synchronously with a non-pb.Error exception.
        zremote synchronous exceptionN)rrrrr�remote_synchronousExceptionGsz&SimpleRoot.remote_synchronousExceptioncCst�td��S)z@
        Fail asynchronously with a pb.Error exception.
        zremote asynchronous error)rrrrrrr�remote_asynchronousErrorNsz#SimpleRoot.remote_asynchronousErrorcCstd��dS)z?
        Fail synchronously with a pb.Error exception.
        zremote synchronous errorN)rrrrr�remote_synchronousErrorUsz"SimpleRoot.remote_synchronousErrorcCsGdd�dtj�}|d��dS)z>
        Fail with error that is not known to client.
        c@seZdZdS)z4SimpleRoot.remote_unknownError.<locals>.UnknownErrorNrrrrr�UnknownError`sr!zI'm not known to client!N)r�Error)rr!rrr�remote_unknownError\szSimpleRoot.remote_unknownErrorcCs|��dS�N)�
raiseJellyrrrr�remote_jellyeszSimpleRoot.remote_jellycCs|��dSr$)�
raiseSecurityrrrr�remote_securityiszSimpleRoot.remote_securitycCs"t��}|�|j�|�d�|Sr$)r�Deferred�addCallbackr%�callback�r�drrr�remote_deferredJellyms
zSimpleRoot.remote_deferredJellycCs"t��}|�|j�|�d�|Sr$)rr)r*r'r+r,rrr�remote_deferredSecurityts
z"SimpleRoot.remote_deferredSecurityNcCstd��dS)NzI'm jellyable!)r�rZresultsrrrr%{szSimpleRoot.raiseJellycCstd��dS)NzI'm secure!)rr0rrrr'szSimpleRoot.raiseSecurity)N)N)r
rrrrrr r#r&r(r.r/r%r'rrrrr?s	
rc@seZdZdZdZdd�ZdS)�SaveProtocolServerFactoryzd
    A L{pb.PBServerFactory} that saves the latest connected client in
    C{protocolInstance}.
    NcCs
||_dS)z3
        Keep track of the given protocol.
        N)�protocolInstance)rZprotocolrrr�clientConnectionMade�sz.SaveProtocolServerFactory.clientConnectionMade)r
rrrr2r3rrrrr1�sr1c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�PBConnTestCasercCs|��|��dSr$)�_setUpServer�_setUpClientrrrr�setUp�szPBConnTestCase.setUpcCs.tt��|_|j|j_tjd|jdd�|_dS)Nr�	127.0.0.1)Z	interface)r1r�
serverFactory�unsafeTracebacksrZ	listenTCP�
serverPortrrrrr5�s
zPBConnTestCase._setUpServercCs,|j��j}t��|_t�d||j�|_dS)Nr8)	r;ZgetHostZportrZPBClientFactory�
clientFactoryrZ
connectTCP�clientConnector)rZportNorrrr6�s
zPBConnTestCase._setUpClientcCs0|jjdk	r|jjj��t�|��|��g�Sr$)r9r2Z	transportZloseConnectionrZ
gatherResults�_tearDownServer�_tearDownClientrrrr�tearDown�s�zPBConnTestCase.tearDowncCst�|jj�Sr$)rZ
maybeDeferredr;Z
stopListeningrrrrr>�szPBConnTestCase._tearDownServercCs|j��t�d�Sr$)r=Z
disconnectrZsucceedrrrrr?�s
zPBConnTestCase._tearDownClientN)
r
rrr:r7r5r6r@r>r?rrrrr4�sr4c@s�eZdZejjZdd�Zdd�Zdd�Z	dd�Z
d	d
�Zdd�Zd
d�Z
d$dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�ZdS)%�PBFailureTestscs6���fdd���j��}��fdd�}|�|�|S)NcsF|�����|jd��r6����}��t|�d�|j|j|jfS)N�Traceback unavailable
�)�trap�compare�	traceback�flushLoggedErrors�assertEqual�len�type�value)�err�errs)�
exceptionType�flushrrr�eb�s

z)PBFailureTests._exceptionTest.<locals>.ebcs|���}|���|Sr$)�
callRemote�
addErrback)�rootr-)rP�methodrr�
gotRootObject�s

z4PBFailureTests._exceptionTest.<locals>.gotRootObject�r<�
getRootObjectr*)rrTrNrOr-rUr)rPrNrOrTrr�_exceptionTest�s


zPBFailureTests._exceptionTestcCs|�dtd�S)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.
        ZasynchronousExceptionT)rXrrrrr�test_asynchronousException�s
�z)PBFailureTests.test_asynchronousExceptioncCs|�dtd�S)zw
        Like L{test_asynchronousException}, but for a method which raises an
        exception synchronously.
        �synchronousExceptionT)rXrrrrr�test_synchronousException�s
�z(PBFailureTests.test_synchronousExceptioncCs|�dtd�S)z�
        Like L{test_asynchronousException}, but for a method which returns a
        Deferred failing with an L{pb.Error} subclass.
        ZasynchronousErrorF)rXrrrrr�test_asynchronousError�s
�z%PBFailureTests.test_asynchronousErrorcCs|�dtd�S)z}
        Like L{test_asynchronousError}, but for a method which synchronously
        raises a L{pb.Error} subclass.
        �synchronousErrorF)rXrrrrr�test_synchronousError�s
�z$PBFailureTests.test_synchronousErrorcCs|�||�|Sr$)rH)r�result�expectedResultrrr�_success�szPBFailureTests._successcCs|j|j||fd�|S)N)ZcallbackArgs)ZaddCallbacksra)rZ
remoteCallr`rPrrr�_addFailingCallbacks�s
�z#PBFailureTests._addFailingCallbacksNcs,�j��}�����fdd�}|�|�|S)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.
        cs8��|������}�dk	r4��fdd�}|�|�|S)Ncs��t�����d�|S)NrC)rHrIrG)rL)�excrrr�
gotFailuresz@PBFailureTests._testImpl.<locals>.gotRootObj.<locals>.gotFailure)rbrQZaddBoth)�objZfailureDeferredrd�rPrc�expectedrTrrr�
gotRootObjs

z,PBFailureTests._testImpl.<locals>.gotRootObjrV)rrTrgrPrcZrootDeferredrhrrfr�	_testImpl�s

zPBFailureTests._testImplcs�fdd�}��dd|�S)z�
        Test that an exception which is a subclass of L{pb.Error} has more
        information passed across the network to the calling side.
        cs,|�t���|jt���|j|j�dS)N�+�rDr�assertNotIsInstancerJ�str�assertIsInstancerK�rrrr�failureJellys
z6PBFailureTests.test_jellyFailure.<locals>.failureJellyr	rj�ri)rrprrr�test_jellyFailuresz PBFailureTests.test_jellyFailurecs�fdd�}��dd|�S)z�
        Test that a Deferred which fails with a L{pb.Error} is treated in
        the same way as a synchronously raised L{pb.Error}.
        cs,|�t���|jt���|j|j�dS)N�rkrorrr�failureDeferredJelly"s
zFPBFailureTests.test_deferredJellyFailure.<locals>.failureDeferredJellyZ
deferredJellyrsrq)rrtrrr�test_deferredJellyFailuresz(PBFailureTests.test_deferredJellyFailurecs�fdd�}��dd|�S)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.
        cs��|jd�dS)Ns3twisted.spread.test.test_pbfailure.SynchronousError��rHrJrorrr�failureUnjellyable0s
�zBPBFailureTests.test_unjellyableFailure.<locals>.failureUnjellyabler]rvrq)rrxrrr�test_unjellyableFailure*sz&PBFailureTests.test_unjellyableFailurecs�fdd�}��dd|�S)z�
        Test that an exception which is a subclass of L{pb.Error} but not
        known on the client side has its type set properly.
        cs��|jd�dS)Ns/twisted.spread.test.test_pbfailure.UnknownError��rwrorrr�failureUnknown=s
�z:PBFailureTests.test_unknownFailure.<locals>.failureUnknownZunknownErrorrzrq)rr{rrr�test_unknownFailure8sz"PBFailureTests.test_unknownFailurecs�fdd�}��dd|�S)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.
        cs,|�t���|jt���|j|j�dS)N���rDrrlrJrmrnrKrorrr�failureSecurityJs
z<PBFailureTests.test_securityFailure.<locals>.failureSecurityZsecurityr}rq)rrrrr�test_securityFailureDsz#PBFailureTests.test_securityFailurecs�fdd�}��dd|�S)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.
        cs,|�t���|jt���|j|j�dS)N�r~rorrr�failureDeferredSecurityXs
zEPBFailureTests.test_deferredSecurity.<locals>.failureDeferredSecurityZdeferredSecurityr�rq)rr�rrr�test_deferredSecurityRs�z$PBFailureTests.test_deferredSecuritycs�fdd�}��dd|t�S)z�
        Test that attempting to call a method which is not defined correctly
        results in an AttributeError on the calling side.
        cs|�tj���|jd�dS)NrB��)rDrZNoSuchMethodrErFrorrr�
failureNoSuchfsz>PBFailureTests.test_noSuchMethodFailure.<locals>.failureNoSuchZnosuchr�)ri�AttributeError)rr�rrr�test_noSuchMethodFailureasz'PBFailureTests.test_noSuchMethodFailurecs6�j��}dd�}|�|��fdd�}|�|�|S)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.
        cSs
|�d�S)NrZ)rQ)ZrootObjrrr�	connectedwsz;PBFailureTests.test_copiedFailureLogging.<locals>.connectedcs(t�|���t�}��t|�d�dS)N�)rrLrGrrHrI)ZfailurerMrrr�	exception{s

z;PBFailureTests.test_copiedFailureLogging.<locals>.exception)r<rWr*rR)rr-r�r�rrr�test_copiedFailureLoggingms


z(PBFailureTests.test_copiedFailureLoggingcs�t�td��}t�tj|t�d��}g���fdd�}|�}|�d���t|j	|���
t��d��d}��
|jt
t��d����
|jd	���
|jd
�dS)z�
        L{pb.CopiedFailure.throwExceptionIntoGenerator} will throw a
        L{RemoteError} into the given paused generator at the point where it
        last yielded.
        �foo�Zinvokerc
3sHz
dVWn.tjk
r8}z��|�W5d}~XYnX��d�dS)NzRemoteError not raised)rZRemoteError�appendr)rc�r�rrr�
generatorFunc�s

zFPBFailureTests.test_throwExceptionIntoGenerator.<locals>.generatorFuncNrCr�ascii)r�rB)r�CopyableFailurer�r	�unjelly�DummyInvoker�sendZassertRaises�
StopIterationZthrowExceptionIntoGeneratorrHrIZ
remoteTyper�encode�argsZremoteTraceback)r�original�copyr��genrcrr�r� test_throwExceptionIntoGenerator�s
z/PBFailureTests.test_throwExceptionIntoGenerator)N)r
rrr
�TestCaserHrErXrYr[r\r^rarbrirrruryr|r�r�r�r�r�rrrrrA�s$				


rAc@seZdZejjZdZdS)�PBFailureUnsafeTestsrCN)r
rrr
r�ZfailIfEqualsrEr:rrrrr��sr�c@seZdZdZdZdS)r�zZ
    A behaviorless object to be used as the invoker parameter to
    L{jelly.jelly}.
    N)r
rrrZserializingPerspectiverrrrr��sr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�FailureJellyingTestsz:
    Tests for the interaction of jelly and failures.
    cCsnt�t��}|�|�t�t�|�|�t�t�t�tj|t�d��}|�|�t�t�|�|�t�t�dS)z�
        An unjellied L{CopyableFailure} has a check method which behaves the
        same way as the original L{CopyableFailure}'s check method.
        r�N�	rr��ZeroDivisionErrorZassertIsZcheck�ArithmeticErrorr	r�r�)rr��copiedrrr�test_unjelliedFailureCheck�s��z/FailureJellyingTests.test_unjelliedFailureCheckcCs�t�t��}|�|�t�t�|�|�t�t�t�tj|t�d��}t�|�}t�tj|t�d��}|�|�t�t�|�|�t�t�dS)aX
        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�)rr�Z
copiedOnceZ
derivativeZcopiedTwicerrr�test_twiceUnjelliedFailureCheck�s*��
���z4FailureJellyingTests.test_twiceUnjelliedFailureCheckcCsZt�td��}t�tj|t�d��}t�}|�|�tt�}d�	|�}|�
||���dS)a
        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.
        zsome reasonr�z.Traceback from remote host -- {}: some reason
N)rr��	Exceptionr	r�r�rZprintTracebackr�formatrH�getvalue)rr�r��outputr�ZexpectedOutputrrr� test_printTracebackIncludesValue�s
�z5FailureJellyingTests.test_printTracebackIncludesValueN)r
rrrr�r�r�rrrrr��sr�N)(rZtwisted.internetrrZtwisted.pythonrZtwisted.python.compatrZtwisted.python.reflectrZtwisted.spreadrrr	Z
twisted.trialr
r�rrr"rrZ	JellyableZ
RemoteCopyrrZsetUnjellyableForClassZglobalSecurityZallowInstancesOfZRootrZPBServerFactoryr1r�r4rAr��objectr�r�rrrr�<module>s.E&g