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 :  /lib/python3/dist-packages/twisted/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


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

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

�b�b�@s�dZddlmZmZmZmZddlmZddlm	Z	ddl
mZmZm
Z
mZddlmZddlmZGdd	�d	�ZGd
d�dee�ZGdd
�d
ee�ZdS)z$
Test the memcache client protocol.
�)�Deferred�DeferredList�TimeoutError�
gatherResults)�ConnectionDone)�Clock)�ClientError�MemCacheProtocol�
NoSuchCommand�ServerError)� StringTransportWithDisconnection)�TestCasec@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*S)+�CommandMixinzO
    Setup and tests for basic invocation of L{MemCacheProtocol} commands.
    cCst��)zp
        Helper test method to test the resulting C{Deferred} of a
        L{MemCacheProtocol} command.
        )�NotImplementedError��self�d�send�recv�result�r�</usr/lib/python3/dist-packages/twisted/test/test_memcache.py�_testszCommandMixin._testcC�|�|j�d�ddd�S)z�
        L{MemCacheProtocol.get} returns a L{Deferred} which is called back with
        the value and the flag associated with the given key if the server
        returns a successful result.
        �foo�	get foo
�VALUE foo 0 3
bar
END
�r�bar�r�proto�get�rrrr�test_get"s
�zCommandMixin.test_getcCr)zu
        Test getting a non-available key: it succeeds but return L{None} as
        value and C{0} as flag.
        rr�END
�rNrr"rrr�
test_emptyGet/szCommandMixin.test_emptyGetcC�"|�|j�ddg�ddddd��S)z�
        L{MemCacheProtocol.getMultiple} returns a L{Deferred} which is called
        back with a dictionary of flag, value for each given key.
        r�cow�
get foo cow
s1VALUE foo 0 3
bar
VALUE cow 0 7
chicken
END
)rschickenr�r(r�rr �getMultipler"rrr�test_getMultiple6��zCommandMixin.test_getMultiplecCr')z�
        When L{MemCacheProtocol.getMultiple} is called with non-available keys,
        the corresponding tuples are (0, None).
        rr(r)sVALUE cow 1 3
bar
END
)�rr%r*r+r"rrr�test_getMultipleWithEmptyBr.z&CommandMixin.test_getMultipleWithEmptycC�|�|j�dd�ddd�S)z�
        L{MemCacheProtocol.set} returns a L{Deferred} which is called back with
        C{True} when the operation succeeds.
        rrsset foo 0 0 3
bar
�STORED
T)rr �setr"rrr�test_setN��zCommandMixin.test_setcCr1)z�
        L{MemCacheProtocol.add} returns a L{Deferred} which is called back with
        C{True} when the operation succeeds.
        rr�add foo 0 0 3
bar
r2T�rr �addr"rrr�test_addZr5zCommandMixin.test_addcCr1)z�
        L{MemCacheProtocol.replace} returns a L{Deferred} which is called back
        with C{True} when the operation succeeds.
        rr�replace foo 0 0 3
bar
r2T�rr �replacer"rrr�test_replacefr5zCommandMixin.test_replacecCr1)z�
        Test an erroneous add: if a L{MemCacheProtocol.add} is called but the
        key already exists on the server, it returns a B{NOT STORED} answer,
        which calls back the resulting L{Deferred} with C{False}.
        rrr6�NOT STORED
Fr7r"rrr�
test_errorAddr��zCommandMixin.test_errorAddcCr1)z�
        Test an erroneous replace: if a L{MemCacheProtocol.replace} is called
        but the key doesn't exist on the server, it returns a B{NOT STORED}
        answer, which calls back the resulting L{Deferred} with C{False}.
        rrr:r>Fr;r"rrr�test_errorReplacer@zCommandMixin.test_errorReplacecCr)z�
        L{MemCacheProtocol.delete} returns a L{Deferred} which is called back
        with C{True} when the server notifies a success.
        r�delete bar
s	DELETED
T�rr �deleter"rrr�test_delete�s�zCommandMixin.test_deletecCr)z�
        Test an error during a delete: if key doesn't exist on the server, it
        returns a B{NOT FOUND} answer which calls back the resulting
        L{Deferred} with C{False}.
        rrBsNOT FOUND
FrCr"rrr�test_errorDelete�s�zCommandMixin.test_errorDeletecCr)z�
        Test incrementing a variable: L{MemCacheProtocol.increment} returns a
        L{Deferred} which is called back with the incremented value of the
        given key.
        rsincr foo 1
�4
��rr �	incrementr"rrr�test_increment��zCommandMixin.test_incrementcCr)z�
        Test decrementing a variable: L{MemCacheProtocol.decrement} returns a
        L{Deferred} which is called back with the decremented value of the
        given key.
        rsdecr foo 1
�5
��rr �	decrementr"rrr�test_decrement�rLzCommandMixin.test_decrementcCr1)z�
        L{MemCacheProtocol.increment} takes an optional argument C{value} which
        replaces the default value of 1 when specified.
        r�sincr foo 8
rGrHrIr"rrr�test_incrementVal���zCommandMixin.test_incrementValcCr1)z�
        L{MemCacheProtocol.decrement} takes an optional argument C{value} which
        replaces the default value of 1 when specified.
        r�sdecr foo 3
rMrNrOr"rrr�test_decrementVal�rTzCommandMixin.test_decrementValcCs|�|j��ddddd��S)z�
        Test retrieving server statistics via the L{MemCacheProtocol.stats}
        command: it parses the data sent by the server and calls back the
        resulting L{Deferred} with a dictionary of the received statistics.
        sstats
�"STAT foo bar
STAT egg spam
END
r�spam�r�egg�rr �statsr"rrr�
test_stats�s�zCommandMixin.test_statscCs|�|j�d�ddddd��S)a9
        L{MemCacheProtocol.stats} takes an optional C{bytes} argument which,
        if specified, is sent along with the I{STAT} command.  The I{STAT}
        responses from the server are parsed as key/value pairs and returned
        as a C{dict} (as in the case where the argument is not specified).
        sblahsstats blah
rWrrXrYr[r"rrr�test_statsWithArgument�s
�z#CommandMixin.test_statsWithArgumentcC�|�|j��ddd�S)z�
        Test version retrieval via the L{MemCacheProtocol.version} command: it
        returns a L{Deferred} which is called back with the version sent by the
        server.
        s	version
s
VERSION 1.1
s1.1)rr �versionr"rrr�test_version�s�zCommandMixin.test_versioncCr_)z�
        L{MemCacheProtocol.flushAll} returns a L{Deferred} which is called back
        with C{True} if the server acknowledges success.
        sflush_all
sOK
T)rr �flushAllr"rrr�
test_flushAll�szCommandMixin.test_flushAllN)�__name__�
__module__�__qualname__�__doc__rr#r&r-r0r4r9r=r?rArErFrKrQrSrVr]r^rarcrrrrrs,


	
		

rc@seZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>S)?�
MemCacheTestsz9
    Test client protocol class L{MemCacheProtocol}.
    cCs@t�|_t�|_|jj|j_t�|_|j|j_|j�|j�dS)z{
        Create a memcache client, connect it to a string protocol, and make it
        use a deterministic clock.
        N)	r	r r�clock�	callLaterr�	transport�protocol�makeConnectionr"rrr�setUp�s
zMemCacheTests.setUpcs:��fdd�}���j��|�|�|��j�|�|S)a�
        Implementation of C{_test} which checks that the command sends C{send}
        data, and that upon reception of C{recv} the result is C{result}.

        @param d: the resulting deferred from the memcache command.
        @type d: C{Deferred}

        @param send: the expected data to be sent.
        @type send: C{bytes}

        @param recv: the data to simulate as reception.
        @type recv: C{bytes}

        @param result: the expected result.
        @type result: C{any}
        cs��|��dS�N)�assertEqual)�res�rrrr�cbszMemCacheTests._test.<locals>.cb)rprk�value�addCallbackr �dataReceived)rrrrrrsrrrrr�s

zMemCacheTests._testcCs"|j�d�|�t|jjd�dS)z�
        If the value returned doesn't match the expected key of the current
        C{get} command, an error is raised in L{MemCacheProtocol.dataReceived}.
        rsVALUE bar 0 7
spamegg
END
N)r r!�assertRaises�RuntimeErrorrvr"rrr�test_invalidGetResponses�z%MemCacheTests.test_invalidGetResponsecCs&|j�ddg�|�t|jjd�dS)z�
        If the value returned doesn't match one the expected keys of the
        current multiple C{get} command, an error is raised error in
        L{MemCacheProtocol.dataReceived}.
        rrsVALUE egg 0 7
spamegg
END
N)r r,rwrxrvr"rrr�test_invalidMultipleGetResponse%s�z-MemCacheTests.test_invalidMultipleGetResponsecCs$|j�dd�|�t|jjd�dS)z�
        If an END is received in response to an operation that isn't C{get},
        C{gets}, or C{stats}, an error is raised in
        L{MemCacheProtocol.dataReceived}.
        skeysvaluer$N)r r3rwrxrvr"rrr�test_invalidEndResponse2sz%MemCacheTests.test_invalidEndResponsecs��j�d�}�j�d�}t�}|j�j_�j��jj���|t	���|t	��fdd�}|�
|���|t�t|||g�S)z�
        Test the timeout on outgoing requests: when timeout is detected, all
        current commands fail with a L{TimeoutError}, and the connection is
        closed.
        rrcs��t|�d�dS)NzConnection timeout)rp�str)�errorr"rr�checkMessageJsz0MemCacheTests.test_timeOut.<locals>.checkMessage)
r r!r�callback�connectionLostri�advance�persistentTimeOut�
assertFailurerrurr)r�d1�d2�d3r~rr"r�test_timeOut;s

zMemCacheTests.test_timeOutcsF�j�d�}�j��jjd��j�d��fdd�}|�|�|S)zY
        When a request gets a response, no pending timeout call remains around.
        rr/rcs$��|d���t�jj�d�dS)Nrr)rp�lenri�calls)rr"rr�checkZsz0MemCacheTests.test_timeoutRemoved.<locals>.check)r r!rir�r�rvru)rrr�rr"r�test_timeoutRemovedQs
z!MemCacheTests.test_timeoutRemovedcCs\|j�d�}t�}|j|j_|j�d�|j�|jj�|�	|t
�|�	|t�t||g�S)z�
        Test the timeout when raw mode was started: the timeout is not reset
        until all the data has been received, so we can have a L{TimeoutError}
        when waiting for raw data.
        rsVALUE foo 0 10
12345)
r r!rrr�rvrir�r�r�rrr�rr�r�rrr�test_timeOutRawas
zMemCacheTests.test_timeOutRawcCsZ|j��}t�}|j|j_|j�d�|j�|jj�|�	|t
�|�	|t�t||g�S)z�
        Test the timeout when stat command has started: the timeout is not
        reset until the final B{END} is received.
        sSTAT foo bar
)
r r\rrr�rvrir�r�r�rrrr�rrr�test_timeOutStatqs

zMemCacheTests.test_timeOutStatcs~�j�d�}�j�d��t�}|j�j_�j��jjd��j�d����fdd�}�fdd��|�	|���
|t�|S)	z�
        When two requests are sent, a timeout call remains around for the
        second request, and its timeout time is correct.
        rrr/rcsP��|d���t�jj�d�t�jj�D]}�j�d�q���t	��
��S)Nrr/)rpr�rir��ranger r�r�r�rru)r�i��	checkTimer�rrrr��s
z3MemCacheTests.test_timeoutPipelining.<locals>.checkcs"���j��d�jjd�dS)N�r/)rpri�secondsr r�)�ignoredr"rrr��s"z7MemCacheTests.test_timeoutPipelining.<locals>.checkTime)r r!rrr�rir�r�rvrur�r)rr�r�r�rr�r�test_timeoutPipelining�s

z$MemCacheTests.test_timeoutPipeliningcCsz|j�d�}t�}|j|j_|j�|jjd�|j�d�}|j�d�|�|t	�|�|t	�|�|t
�t|||g�S)z�
        Check that timeout is not resetted for every command, but keep the
        timeout from the first command without response.
        rr/r)r r!rrr�rir�r�r�rrr)rr�r�r�rrr�test_timeoutNotReset�s
z"MemCacheTests.test_timeoutNotResetcCsL|j�d�}|j�|jj�|�|t�|j�d�}|�|t�t||g�S)a
        C{timeoutConnection} cleans the list of commands that it fires with
        C{TimeoutError}: C{connectionLost} doesn't try to fire them again, but
        sets the disconnected state so that future commands fail with a
        C{RuntimeError}.
        rr)	r r!rir�r�r�rrxrr�rrr�test_timeoutCleanDeferreds�sz(MemCacheTests.test_timeoutCleanDeferredscsH�j�d�}�j�d�}�j��t||gdd�}�fdd�}|�|�S)zl
        When disconnection occurs while commands are still outstanding, the
        commands fail.
        rrT)�
consumeErrorscs&|D]\}}��|�|�t�qdSro)�assertFalse�trapr)�results�successrr"rr�
checkFailures�s
�z8MemCacheTests.test_connectionLost.<locals>.checkFailures)r r!rk�loseConnectionrru)rr�r��doner�rr"r�test_connectionLost�s

z!MemCacheTests.test_connectionLostcCs�|�|j�dd�t�}|�|j�d�t�}|�|j�d�t�}|�|j�dd�t�}|�|j�dd�t�}|�|j�ddg�t�}t	||||||g�S)z�
        An error is raised when trying to use a too long key: the called
        command returns a L{Deferred} which fails with a L{ClientError}.
        s�aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarr)
r�r r3rrJr!�append�prependr,r)rr�r�r��d4�d5�d6rrr�test_tooLongKey�s�zMemCacheTests.test_tooLongKeycCsD|j�dddddd�}|�|j��d�|�|t�|j�d�|S)z�
        When an unknown command is sent directly (not through public API), the
        server answers with an B{ERROR} token, and the command fails with
        L{NoSuchCommand}.
        rZrrr�segg foo 0 0 3
bar
sERROR
)r �_setrprkrtr�r
rv�rrrrr�test_invalidCommand�s
z!MemCacheTests.test_invalidCommandc�Vd}�j�d|�}���j��d���|t��fdd�}|�|��j�d�|S)z�
        Test the L{ClientError} error: when the server sends a B{CLIENT_ERROR}
        token, the originating command fails with L{ClientError}, and the error
        contains the text sent by the server.
        �eggspammr�set foo 0 0 8
eggspamm
c���t|�td��dS)NsWe don't like egg and spam�rpr|�repr��errr"rrr���z-MemCacheTests.test_clientError.<locals>.checks)CLIENT_ERROR We don't like egg and spam
)	r r3rprkrtr�rrurv�r�arr�rr"r�test_clientError��
zMemCacheTests.test_clientErrorcr�)z�
        Test the L{ServerError} error: when the server sends a B{SERVER_ERROR}
        token, the originating command fails with L{ServerError}, and the error
        contains the text sent by the server.
        r�rr�cr�)Nszomgr�r�r"rrr�r�z-MemCacheTests.test_serverError.<locals>.checksSERVER_ERROR zomg
)	r r3rprkrtr�rrurvr�rr"r�test_serverError�r�zMemCacheTests.test_serverErrorcCs�|�|j�dd�t�}|�|j�d�t�}|�|j�d�t�}|�|j�d�t�}|�|j�dd�t�}|�|j�dd�t�}|�|j�	ddg�t�}t
|||||||g�S)zQ
        Using a non-string key as argument to commands raises an error.
        �foor�eggr/�barrZ)r�r r3rrJr!rDr�r�r,r)rr�r�r�r�r�r��d7rrr�test_unicodeKeyszMemCacheTests.test_unicodeKeycCs|�|j�dd�t�S)z;
        Using a non-string value raises an error.
        rr�)r�r r3rr"rrr�test_unicodeValueszMemCacheTests.test_unicodeValuecCs||j�d�}|�|jd�|j�dd�}|�|jd�|j�d�}|�|jd�|�|j��d�|j�d	�t|||g�S)
z�
        Multiple requests can be sent subsequently to the server, and the
        protocol orders the responses correctly and dispatch to the
        corresponding client command.
        rrrsspamspamspamTrZ)rrXs0get foo
set bar 0 0 12
spamspamspam
get egg
s;VALUE foo 0 3
bar
END
STORED
VALUE egg 0 4
spam
END
)	r r!rurpr3rkrtrvr)rr�r�r�rrr�test_pipelinings��zMemCacheTests.test_pipeliningcCs`|j�d�}|�|jd�|�|j��d�|j�d�|j�d�|j�d�|j�d�|S)z�
        If the value retrieved by a C{get} arrive in chunks, the protocol
        is able to reconstruct it and to produce the good value.
        r)rs
0123456789rsVALUE foo 0 10
0123456s789s
ENDs
)r r!rurprkrtrvr�rrr�test_getInChunks6szMemCacheTests.test_getInChunkscCr1)z�
        L{MemCacheProtocol.append} behaves like a L{MemCacheProtocol.set}
        method: it returns a L{Deferred} which is called back with C{True} when
        the operation succeeds.
        rrsappend foo 0 0 3
bar
r2T)rr r�r"rrr�test_appendDr@zMemCacheTests.test_appendcCr1)z�
        L{MemCacheProtocol.prepend} behaves like a L{MemCacheProtocol.set}
        method: it returns a L{Deferred} which is called back with C{True} when
        the operation succeeds.
        rrsprepend foo 0 0 3
bar
r2T)rr r�r"rrr�test_prependQr@zMemCacheTests.test_prependcCr1)z�
        L{MemCacheProtocol.get} handles an additional cas result when
        C{withIdentifier} is C{True} and forward it in the resulting
        L{Deferred}.
        rT�
gets foo
sVALUE foo 0 3 1234
bar
END
)r�1234rrr"rrr�	test_gets^r@zMemCacheTests.test_getscCr1)z�
        Test getting a non-available key with gets: it succeeds but return
        L{None} as value, C{0} as flag and an empty cas value.
        rTr�r$�rr�Nrr"rrr�test_emptyGetskrTzMemCacheTests.test_emptyGetscC�$|�|j�ddgd�ddddd��S)	z�
        L{MemCacheProtocol.getMultiple} handles an additional cas field in the
        returned tuples if C{withIdentifier} is C{True}.
        rrT�gets foo bar
�8VALUE foo 0 3 1234
egg
VALUE bar 0 4 2345
spam
END
�rs2345rX�rr�rZ�rrr+r"rrr�test_getsMultiplets�zMemCacheTests.test_getsMultiplecCs(|�|j�tddg�d�ddddd��S)	zO
        L{MemCacheProtocol.getMultiple} accepts any iterable of keys.
        rrTr�r�r�r�r�)rr r,�iterr"rrr�test_getsMultipleIterableKeys�s�z+MemCacheTests.test_getsMultipleIterableKeyscCr�)	a
        When getting a non-available key with L{MemCacheProtocol.getMultiple}
        when C{withIdentifier} is C{True}, the other keys are retrieved
        correctly, and the non-available key gets a tuple of C{0} as flag,
        L{None} as value, and an empty cas value.
        rrTr�sVALUE foo 0 3 1234
egg
END
r�r�r�r+r"rrr�test_getsMultipleWithEmpty�s�z(MemCacheTests.test_getsMultipleWithEmptycC�|�|jjdddd�ddd�S)z�
        L{MemCacheProtocol.checkAndSet} passes an additional cas identifier
        that the server handles to check if the data has to be updated.
        rrr���cas�cas foo 0 0 3 1234
bar
r2T�rr �checkAndSetr"rrr�test_checkAndSet���zMemCacheTests.test_checkAndSetcCr�)z�
        When L{MemCacheProtocol.checkAndSet} response is C{EXISTS}, the
        resulting L{Deferred} fires with C{False}.
        rrr�r�r�sEXISTS
Fr�r"rrr�test_casUnknowKey�r�zMemCacheTests.test_casUnknowKeyN)"rdrerfrgrnrryrzr{r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrh�s@
	



	rhc@s eZdZdZdd�Zdd�ZdS)�CommandFailureTestszZ
    Tests for correct failure of commands on a disconnected
    L{MemCacheProtocol}.
    cCsJt�|_t�|_|jj|j_t�|_|j|j_|j�|j�|j�	�dS)zU
        Create a disconnected memcache client, using a deterministic clock.
        N)
r	r rrirjrrkrlrmr�r"rrrrn�s
zCommandFailureTests.setUpcCs|�|t�S)z�
        Implementation of C{_test} which checks that the command fails with
        C{RuntimeError} because the transport is disconnected. All the
        parameters except C{d} are ignored.
        )r�rxrrrrr�szCommandFailureTests._testN)rdrerfrgrnrrrrrr��sr�N)rg�twisted.internet.deferrrrr�twisted.internet.errorr�twisted.internet.taskr�twisted.protocols.memcacherr	r
r�twisted.test.proto_helpersr�twisted.trial.unittestr
rrhr�rrrr�<module>sYG

Anon7 - 2022
AnonSec Team