Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.52 (Ubuntu)
System : Linux webserver 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2 x86_64
User : www-data ( 33)
PHP Version : 8.1.2-1ubuntu2.21
Disable Function : NONE
Directory :  /lib/python3/dist-packages/twisted/protocols/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

�bc\�@s�dZddlmZddlmZmZmZddlmZddl	m
Z
ddlmZddl
mZmZdZGd	d
�d
e�ZGdd�de�ZGd
d�de�ZGdd�d�ZGdd�dee
�Zgd�ZdS)ap
Memcache client protocol. Memcached is a caching server, storing data in the
form of pairs key/value, and memcache is the protocol to talk with it.

To connect to a server, create a factory for L{MemCacheProtocol}::

    from twisted.internet import reactor, protocol
    from twisted.protocols.memcache import MemCacheProtocol, DEFAULT_PORT
    d = protocol.ClientCreator(reactor, MemCacheProtocol
        ).connectTCP("localhost", DEFAULT_PORT)
    def doSomething(proto):
        # Here you call the memcache operations
        return proto.set("mykey", "a lot of data")
    d.addCallback(doSomething)
    reactor.run()

All the operations of the memcache protocol are present, but
L{MemCacheProtocol.set} and L{MemCacheProtocol.get} are the more important.

See U{http://code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt} for
more information about the protocol.
�)�deque)�Deferred�TimeoutError�fail)�LineReceiver)�TimeoutMixin)�log)�nativeString�
networkStringi�+c@�eZdZdZdS)�
NoSuchCommandzA
    Exception raised when a non existent command is called.
    N��__name__�
__module__�__qualname__�__doc__�rr�</usr/lib/python3/dist-packages/twisted/protocols/memcache.pyr(�rc@r)�ClientErrorz1
    Error caused by an invalid client call.
    Nr
rrrrr.rrc@r)�ServerErrorz*
    Problem happening on the server.
    Nr
rrrrr4rrc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�Commanda8
    Wrap a client action into an object, that holds the values used in the
    protocol.

    @ivar _deferred: the L{Deferred} object that will be fired when the result
        arrives.
    @type _deferred: L{Deferred}

    @ivar command: name of the command sent to the server.
    @type command: L{bytes}
    cKs0||_t�|_|��D]
\}}t|||�qdS)z�
        Create a command.

        @param command: the name of the command.
        @type command: L{bytes}

        @param kwargs: this values will be stored as attributes of the object
            for future use
        N)�commandr�	_deferred�items�setattr)�selfr�kwargs�k�vrrr�__init__Gs

�zCommand.__init__cC�|j�|�dS)zB
        Shortcut method to fire the underlying deferred.
        N)r�callback)r�valuerrr�successV�zCommand.successcCr!)z5
        Make the underlying deferred fails.
        N)r�errback)r�errorrrrr\r%zCommand.failN)rrrrr r$rrrrrr:s
rc@sTeZdZdZdZdZdRdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�ZdSd.d/�ZdSd0d1�Zd2d3�ZdTd5d6�ZdTd7d8�ZdTd9d:�ZdTd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dUdCdD�Z$dUdEdF�Z%dGdH�Z&dVdJdK�Z'dLdM�Z(dNdO�Z)dPdQ�Z*dIS)W�MemCacheProtocola1
    MemCache protocol: connect to a memcached server to store/retrieve values.

    @ivar persistentTimeOut: the timeout period used to wait for a response.
    @type persistentTimeOut: L{int}

    @ivar _current: current list of requests waiting for an answer from the
        server.
    @type _current: L{deque} of L{Command}

    @ivar _lenExpected: amount of data expected in raw mode, when reading for
        a value.
    @type _lenExpected: L{int}

    @ivar _getBuffer: current buffer of data, used to store temporary data
        when reading in raw mode.
    @type _getBuffer: L{list}

    @ivar _bufferLength: the total amount of bytes in C{_getBuffer}.
    @type _bufferLength: L{int}

    @ivar _disconnected: indicate if the connectionLost has been called or not.
    @type _disconnected: L{bool}
    �F�<cCs*t�|_d|_d|_d|_||_|_dS)z�
        Create the protocol.

        @param timeOut: the timeout to wait before detecting that the
            connection is dead and close it. It's expressed in seconds.
        @type timeOut: L{int}
        N)r�_current�_lenExpected�
_getBuffer�
_bufferLength�persistentTimeOut�timeOut)rr0rrrr �s
zMemCacheProtocol.__init__cCs(|jr|j��}|�|�|jsdSdS)zW
        Cancel all the outstanding commands, making them fail with C{reason}.
        N)r+�popleftr)r�reason�cmdrrr�_cancelCommands�s

�z MemCacheProtocol._cancelCommandscCs|�td��|j��dS)z:
        Close the connection in case of timeout.
        zConnection timeoutN)r4r�	transport�loseConnection�rrrr�timeoutConnection�sz"MemCacheProtocol.timeoutConnectioncCs d|_|�|�t�||�dS)z9
        Cause any outstanding commands to fail.
        TN)�
_disconnectedr4r�connectionLost)rr2rrrr:�s
zMemCacheProtocol.connectionLostcCs"|js	|�|j�t�||�dS)zA
        Override sendLine to add a timeout to response.
        N)r+�
setTimeoutr/r�sendLine)r�linerrrr<�szMemCacheProtocol.sendLinecCs�|��|j�|�|jt|�7_|j|jdkr`d�|j�}|d|j�}||jdd�}|}d|_d|_d|_|jd}|jrV|j	|j
\}}|||f|j	|j
<n||_|�|�dSdS)z)
        Collect data for a get.
        ��Nr)
�resetTimeoutr-�appendr.�lenr,�joinr+�multiple�values�
currentKeyr#�setLineMode)r�data�buf�rem�valr3�flags�casrrr�rawDataReceived�s$
�z MemCacheProtocol.rawDataReceivedcC�|j���d�dS)z?
        Manage a success response to a set operation.
        TN�r+r1r$r7rrr�
cmd_STORED��zMemCacheProtocol.cmd_STOREDcCrO)z�
        Manage a specific 'not stored' response to a set operation: this is not
        an error, but some condition wasn't met.
        FNrPr7rrr�cmd_NOT_STORED�szMemCacheProtocol.cmd_NOT_STOREDcCs�|j��}|jdkr)|jrdd�|j��D�}|�|�dS|�|j|jf�dS|jdkrF|jr9|�|j�dS|�|j|j	|jf�dS|jdkrS|�|j�dSt
d�t|j����)zB
        This the end token to a get or a stat operation.
        �getcSs i|]\}}||ddd��qS)Nr>r)�.0�keyrKrrr�
<dictcomp>�s z,MemCacheProtocol.cmd_END.<locals>.<dictcomp>�gets�statsz%Unexpected END response to {} commandN)
r+r1rrDrErr$rLr#rM�RuntimeError�formatr	)rr3rErrr�cmd_END�s"



��zMemCacheProtocol.cmd_ENDcCrO)z=
        Manage error response for incr/decr/delete.
        FNrPr7rrr�
cmd_NOT_FOUND�rRzMemCacheProtocol.cmd_NOT_FOUNDcCs�|jd}|jdkr|��\}}}d}n|��\}}}}t|�|_g|_d|_|jr@||jvr3t	d��||_
t|�|g|j|<n|j|krIt	d��t|�|_
||_|��dS)z:
        Prepare the reading a value after a get.
        rrTr?zUnexpected commands answer.N)r+r�split�intr,r-r.rD�keysrZrFrErVrLrM�
setRawMode)rr=r3rVrL�lengthrMrrr�	cmd_VALUE�s$





zMemCacheProtocol.cmd_VALUEcCs(|jd}|�dd�\}}||j|<dS)z-
        Reception of one stat line.
        r� �N)r+r^rE)rr=r3rVrKrrr�cmd_STAT	s
zMemCacheProtocol.cmd_STATcCs|j���|�dS)z%
        Read version token.
        NrP)r�versionDatarrr�cmd_VERSIONrRzMemCacheProtocol.cmd_VERSIONcCs$t�d�|j��}|�t��dS)z7
        A non-existent command has been sent.
        zNon-existent command sent.N)r�errr+r1rr)rr3rrr�	cmd_ERRORs

zMemCacheProtocol.cmd_ERRORcC�2t|�}t�d|�|j��}|�t|��dS)z0
        An invalid input as been sent.
        zInvalid input: N)�reprrrir+r1rr�r�errTextr3rrr�cmd_CLIENT_ERROR�
z!MemCacheProtocol.cmd_CLIENT_ERRORcCrk)z4
        An error has happened server-side.
        zServer error: N)rlrrir+r1rrrmrrr�cmd_SERVER_ERROR(rpz!MemCacheProtocol.cmd_SERVER_ERRORcCrO)z>
        A delete command has completed successfully.
        TNrPr7rrr�cmd_DELETED1rRzMemCacheProtocol.cmd_DELETEDcCrO)z6
        The last command has been completed.
        TNrPr7rrr�cmd_OK7rRzMemCacheProtocol.cmd_OKcCrO)z5
        A C{checkAndSet} update has failed.
        FNrPr7rrr�
cmd_EXISTS=rRzMemCacheProtocol.cmd_EXISTScCs�|��|�dd�d}t|dt|�d�}|dur1|�dd�dd�}|r-||d�n*|�n&|�dd�}t|dt|�d�}|durI|�n|j��}t|�}|�|�|jsa|�	d�dSdS)z8
        Receive line commands from the server.
        rdrer�cmd_N�_)
r@r^�getattrr	�replacer+r1r_r$r;)rr=�tokenr3�argsrKrrr�lineReceivedCs$

�zMemCacheProtocol.lineReceivedrecC�|�d||�S)a�
        Increment the value of C{key} by given value (default to 1).
        C{key} must be consistent with an int. Return the new value.

        @param key: the key to modify.
        @type key: L{bytes}

        @param val: the value to increment.
        @type val: L{int}

        @return: a deferred with will be called back with the new value
            associated with the key (after the increment).
        @rtype: L{Deferred}
        sincr��	_incrdecr�rrVrKrrr�	increment`szMemCacheProtocol.incrementcCr|)a�
        Decrement the value of C{key} by given value (default to 1).
        C{key} must be consistent with an int. Return the new value, coerced to
        0 if negative.

        @param key: the key to modify.
        @type key: L{bytes}

        @param val: the value to decrement.
        @type val: L{int}

        @return: a deferred with will be called back with the new value
            associated with the key (after the decrement).
        @rtype: L{Deferred}
        sdecrr}rrrr�	decrementqszMemCacheProtocol.decrementcCs�|jr	ttd��St|t�sttdt|��d���St|�|jkr'ttd��Sd�	||dt
|�fg�}|�|�t||d�}|j
�|�|jS)z1
        Internal wrapper for incr/decr.
        �
not connected�Invalid type for key: �, expecting bytes�Key too longrds%d�rV)r9rrZ�
isinstance�bytesr�typerB�MAX_KEY_LENGTHrCr_r<rr+rAr)rr3rVrK�fullcmd�cmdObjrrrr~�s
�
zMemCacheProtocol._incrdecrrcC�|�d||||d�S)a�
        Replace the given C{key}. It must already exist in the server.

        @param key: the key to replace.
        @type key: L{bytes}

        @param val: the new value associated with the key.
        @type val: L{bytes}

        @param flags: the flags to store with the key.
        @type flags: L{int}

        @param expireTime: if different from 0, the relative time in seconds
            when the key will be deleted from the store.
        @type expireTime: L{int}

        @return: a deferred that will fire with C{True} if the operation has
            succeeded, and C{False} with the key didn't previously exist.
        @rtype: L{Deferred}
        sreplacer?��_set�rrVrKrL�
expireTimerrrrx��zMemCacheProtocol.replacecCr�)a�
        Add the given C{key}. It must not exist in the server.

        @param key: the key to add.
        @type key: L{bytes}

        @param val: the value associated with the key.
        @type val: L{bytes}

        @param flags: the flags to store with the key.
        @type flags: L{int}

        @param expireTime: if different from 0, the relative time in seconds
            when the key will be deleted from the store.
        @type expireTime: L{int}

        @return: a deferred that will fire with C{True} if the operation has
            succeeded, and C{False} with the key already exists.
        @rtype: L{Deferred}
        saddr?r�r�rrr�add�r�zMemCacheProtocol.addcCr�)a9
        Set the given C{key}.

        @param key: the key to set.
        @type key: L{bytes}

        @param val: the value associated with the key.
        @type val: L{bytes}

        @param flags: the flags to store with the key.
        @type flags: L{int}

        @param expireTime: if different from 0, the relative time in seconds
            when the key will be deleted from the store.
        @type expireTime: L{int}

        @return: a deferred that will fire with C{True} if the operation has
            succeeded.
        @rtype: L{Deferred}
        ssetr?r�r�rrr�set�r�zMemCacheProtocol.setcCs|�d|||||�S)am
        Change the content of C{key} only if the C{cas} value matches the
        current one associated with the key. Use this to store a value which
        hasn't been modified since last time you fetched it.

        @param key: The key to set.
        @type key: L{bytes}

        @param val: The value associated with the key.
        @type val: L{bytes}

        @param cas: Unique 64-bit value returned by previous call of C{get}.
        @type cas: L{bytes}

        @param flags: The flags to store with the key.
        @type flags: L{int}

        @param expireTime: If different from 0, the relative time in seconds
            when the key will be deleted from the store.
        @type expireTime: L{int}

        @return: A deferred that will fire with C{True} if the operation has
            succeeded, C{False} otherwise.
        @rtype: L{Deferred}
        scasr�)rrVrKrMrLr�rrr�checkAndSet�szMemCacheProtocol.checkAndSetc
	Cs�|jr	ttd��St|t�sttdt|��d���St|�|jkr'ttd��St|t�s8ttdt|��d���S|r>d|}t|�}d�	||t
d|||f�g�|}|�|�|�|�t||||d�}	|j
�|	�|	jS)	z6
        Internal wrapper for setting values.
        r�r�r�r�zInvalid type for value: rdz%d %d %d)rVrLrb)r9rrZr�r�rr�rBr�rCr
r<rr+rAr)
rr3rVrKrLr�rMrbr�r�rrrr��s4
�
����

zMemCacheProtocol._setcC�|�d||ddd�S)a�
        Append given data to the value of an existing key.

        @param key: The key to modify.
        @type key: L{bytes}

        @param val: The value to append to the current value associated with
            the key.
        @type val: L{bytes}

        @return: A deferred that will fire with C{True} if the operation has
            succeeded, C{False} otherwise.
        @rtype: L{Deferred}
        sappendrr?r�rrrrrA�zMemCacheProtocol.appendcCr�)a�
        Prepend given data to the value of an existing key.

        @param key: The key to modify.
        @type key: L{bytes}

        @param val: The value to prepend to the current value associated with
            the key.
        @type val: L{bytes}

        @return: A deferred that will fire with C{True} if the operation has
            succeeded, C{False} otherwise.
        @rtype: L{Deferred}
        sprependrr?r�rrrr�prepend'r�zMemCacheProtocol.prependcCs|�|g|d�S)a�
        Get the given C{key}. It doesn't support multiple keys. If
        C{withIdentifier} is set to C{True}, the command issued is a C{gets},
        that will return the current identifier associated with the value. This
        identifier has to be used when issuing C{checkAndSet} update later,
        using the corresponding method.

        @param key: The key to retrieve.
        @type key: L{bytes}

        @param withIdentifier: If set to C{True}, retrieve the current
            identifier along with the value and the flags.
        @type withIdentifier: L{bool}

        @return: A deferred that will fire with the tuple (flags, value) if
            C{withIdentifier} is C{False}, or (flags, cas identifier, value)
            if C{True}.  If the server indicates there is no value
            associated with C{key}, the returned value will be L{None} and
            the returned flags will be C{0}.
        @rtype: L{Deferred}
        F��_get)rrV�withIdentifierrrr�get9szMemCacheProtocol.getcCs|�||d�S)a
        Get the given list of C{keys}.  If C{withIdentifier} is set to C{True},
        the command issued is a C{gets}, that will return the identifiers
        associated with each values. This identifier has to be used when
        issuing C{checkAndSet} update later, using the corresponding method.

        @param keys: The keys to retrieve.
        @type keys: L{list} of L{bytes}

        @param withIdentifier: If set to C{True}, retrieve the identifiers
            along with the values and the flags.
        @type withIdentifier: L{bool}

        @return: A deferred that will fire with a dictionary with the elements
            of C{keys} as keys and the tuples (flags, value) as values if
            C{withIdentifier} is C{False}, or (flags, cas identifier, value) if
            C{True}.  If the server indicates there is no value associated with
            C{key}, the returned values will be L{None} and the returned flags
            will be C{0}.
        @rtype: L{Deferred}

        @since: 9.0
        Tr�)rr`r�rrr�getMultipleQszMemCacheProtocol.getMultiplec	Cs�t|�}|jr
ttd��S|D]$}t|t�s$ttdt|��d���St|�|j	kr3ttd��Sq|r9d}nd}d�
|g|�}|�|�|rZdd	�|D�}t|||d
d�}nt||dd
dddd�}|j
�|�|jS)z>
        Helper method for C{get} and C{getMultiple}.
        r�r�r�r�rXrTrdcSsi|]}|d�qS))rr?Nr)rUrVrrrrW�sz)MemCacheProtocol._get.<locals>.<dictcomp>T)r`rErDrNr?F)rVr#rLrMrD)�listr9rrZr�r�rr�rBr�rCr<rr+rAr)	rr`r�rDrVr3r�rEr�rrrr�ks0
��
�zMemCacheProtocol._getNcCsL|rd|}nd}|jrttd��S|�|�tdid�}|j�|�|jS)a�
        Get some stats from the server. It will be available as a dict.

        @param arg: An optional additional string which will be sent along
            with the I{stats} command.  The interpretation of this value by
            the server is left undefined by the memcache protocol
            specification.
        @type arg: L{None} or L{bytes}

        @return: a deferred that will fire with a L{dict} of the available
            statistics.
        @rtype: L{Deferred}
        sstats rYr�)rE�r9rrZr<rr+rAr)r�argr3r�rrr�stats�s

zMemCacheProtocol.statscC�6|jr	ttd��S|�d�td�}|j�|�|jS)z�
        Get the version of the server.

        @return: a deferred that will fire with the string value of the
            version.
        @rtype: L{Deferred}
        r�sversionr��rr�rrr�version��
zMemCacheProtocol.versioncCs`|jr	ttd��St|t�sttdt|��d���S|�d|�td|d�}|j	�
|�|jS)a
        Delete an existing C{key}.

        @param key: the key to delete.
        @type key: L{bytes}

        @return: a deferred that will be called back with C{True} if the key
            was successfully deleted, or C{False} if not.
        @rtype: L{Deferred}
        r�r�r�sdelete sdeleter�)r9rrZr�r�rr�r<rr+rAr)rrVr�rrr�delete�s
�zMemCacheProtocol.deletecCr�)z�
        Flush all cached values.

        @return: a deferred that will be called back with C{True} when the
            operation has succeeded.
        @rtype: L{Deferred}
        r�s	flush_allr�r�rrr�flushAll�r�zMemCacheProtocol.flushAll)r*)re)rr)F)N)+rrrrr�r9r r4r8r:r<rNrQrSr\r]rcrfrhrjrorqrrrsrtr{r�r�r~rxr�r�r�r�rAr�r�r�r�r�r�r�r�rrrrr(csR
		








r()r(�DEFAULT_PORTrrrN)r�collectionsr�twisted.internet.deferrrr�twisted.protocols.basicr�twisted.protocols.policiesr�twisted.pythonr�twisted.python.compatr	r
r��	Exceptionrrrrr(�__all__rrrr�<module>s$)x

Spamworldpro Mini