§
    Ètºfc\  ã                   óö   — d Z ddlmZ ddlmZmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZmZ dZ G d	„ d
e¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ d¦  «        Z G d„ dee
¦  «        Zg d¢ZdS )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                   ó   — e Zd ZdZdS )ÚNoSuchCommandzA
    Exception raised when a non existent command is called.
    N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úY/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/protocols/memcache.pyr   r   (   ó   € € € € € ðð ð ð r   r   c                   ó   — e Zd ZdZdS )ÚClientErrorz1
    Error caused by an invalid client call.
    Nr   r   r   r   r   r   .   r   r   r   c                   ó   — e Zd ZdZdS )ÚServerErrorz*
    Problem happening on the server.
    Nr   r   r   r   r   r   4   r   r   r   c                   ó$   — e Zd ZdZd„ Zd„ Zd„ ZdS )Ú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}
    c                 ó�   — || _         t          ¦   «         | _        |                     ¦   «         D ]\  }}t	          | ||¦  «         ŒdS )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Úvs        r   Ú__init__zCommand.__init__G   sP   € ð ˆŒÝ!™œˆŒØ—L’L‘N”Nð 	 ð 	 ‰DˆAˆqÝ�D˜!˜QÑÔÐÐð	 ð 	 r   c                 ó:   — | j                              |¦  «         dS )zB
        Shortcut method to fire the underlying deferred.
        N)r   Úcallback)r"   Úvalues     r   ÚsuccesszCommand.successV   s    € ð 	Œ×Ò Ñ&Ô&Ð&Ð&Ð&r   c                 ó:   — | j                              |¦  «         dS )z5
        Make the underlying deferred fails.
        N)r   Úerrback)r"   Úerrors     r   r   zCommand.fail\   s    € ð 	Œ×Ò˜uÑ%Ô%Ð%Ð%Ð%r   N)r   r   r   r   r&   r*   r   r   r   r   r   r   :   sK   € € € € € ð
ð 
ð ð  ð  ð'ð 'ð 'ð&ð &ð &ð &ð &r   r   c                   ó  — e Zd ZdZdZdZd-d„Zd„ Zd„ Zd„ Z	d	„ Z
d
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd.d„Zd.d„Zd„ Zd/d„Zd/d„Zd/d „Zd/d!„Z d"„ Z!d#„ Z"d$„ Z#d0d%„Z$d0d&„Z%d'„ Z&d1d)„Z'd*„ Z(d+„ Z)d,„ Z*d(S )2Ú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é<   c                 ór   — t          ¦   «         | _        d| _        d| _        d| _        |x| _        | _        dS )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)r"   r8   s     r   r&   zMemCacheProtocol.__init__€   s9   € õ ™œˆŒØ ˆÔØˆŒØ!ˆÔØ07Ð7ˆÔ ¤  r   c                 ó‚   — | j         r7| j                              ¦   «         }|                     |¦  «         | j         °5dS dS )zW
        Cancel all the outstanding commands, making them fail with C{reason}.
        N)r3   Úpopleftr   )r"   ÚreasonÚcmds      r   Ú_cancelCommandsz MemCacheProtocol._cancelCommandsŽ   sS   € ð Œmð 	Ø”-×'Ò'Ñ)Ô)ˆCØ�HŠH�VÑÔÐð Œmð 	ð 	ð 	ð 	ð 	r   c                 ó|   — |                       t          d¦  «        ¦  «         | j                             ¦   «          dS )z:
        Close the connection in case of timeout.
        zConnection timeoutN)r=   r   Ú	transportÚloseConnection©r"   s    r   ÚtimeoutConnectionz"MemCacheProtocol.timeoutConnection–   s;   € ð 	×Ò�\Ð*>Ñ?Ô?Ñ@Ô@Ð@ØŒ×%Ò%Ñ'Ô'Ð'Ð'Ð'r   c                 óh   — d| _         |                      |¦  «         t          j        | |¦  «         dS )z9
        Cause any outstanding commands to fail.
        TN)Ú_disconnectedr=   r   ÚconnectionLost)r"   r;   s     r   rE   zMemCacheProtocol.connectionLost�   s9   € ð "ˆÔØ×Ò˜VÑ$Ô$Ð$ÝÔ# D¨&Ñ1Ô1Ð1Ð1Ð1r   c                 ór   — | j         s|                      | j        ¦  «         t          j        | |¦  «         dS )zA
        Override sendLine to add a timeout to response.
        N)r3   Ú
setTimeoutr7   r   ÚsendLine)r"   Úlines     r   rH   zMemCacheProtocol.sendLine¥   s<   € ð Œ}ð 	4Ø�OŠO˜DÔ2Ñ3Ô3Ð3ÝÔ˜d DÑ)Ô)Ð)Ð)Ð)r   c                 ó  — |                       ¦   «          | j                             |¦  «         | xj        t	          |¦  «        z  c_        | j        | j        dz   k    r¬d                     | j        ¦  «        }|d| j        …         }|| j        dz   d…         }|}d| _        d| _        d| _        | j        d         }|j        r(|j	        |j
                 \  }}|||f|j	        |j
        <   n||_        |                      |¦  «         dS dS )z)
        Collect data for a get.
        é   r   Nr   )ÚresetTimeoutr5   Úappendr6   Úlenr4   Újoinr3   ÚmultipleÚvaluesÚ
currentKeyr)   ÚsetLineMode)r"   ÚdataÚbufÚremÚvalr<   ÚflagsÚcass           r   ÚrawDataReceivedz MemCacheProtocol.rawDataReceived­   s  € ð 	×ÒÑÔÐØŒ×Ò˜tÑ$Ô$Ð$ØÐÔ�c $™iœiÑ'ÐÔØÔ Ô!2°QÑ!6Ò6Ð6Ø—8’8˜DœOÑ,Ô,ˆDØÐ*˜Ô*Ð*Ô+ˆCØ�tÔ(¨1Ñ,Ð.Ð.Ô/ˆCØˆCØ $ˆDÔØ"ˆDŒOØ!%ˆDÔØ”- Ô"ˆCØŒ|ð  Ø œZ¨¬Ô7‘
��sØ.3°S¸#Ð->�”
˜3œ>Ñ*Ð*à�”	Ø×Ò˜SÑ!Ô!Ð!Ð!Ð!ð 7Ð6r   c                 ó^   — | j                              ¦   «                              d¦  «         dS )z?
        Manage a success response to a set operation.
        TN©r3   r:   r*   rA   s    r   Ú
cmd_STOREDzMemCacheProtocol.cmd_STOREDÄ   ó,   € ð 	Œ×ÒÑÔ×'Ò'¨Ñ-Ô-Ð-Ð-Ð-r   c                 ó^   — | j                              ¦   «                              d¦  «         dS )zŠ
        Manage a specific 'not stored' response to a set operation: this is not
        an error, but some condition wasn't met.
        FNr\   rA   s    r   Úcmd_NOT_STOREDzMemCacheProtocol.cmd_NOT_STOREDÊ   s,   € ð
 	Œ×ÒÑÔ×'Ò'¨Ñ.Ô.Ð.Ð.Ð.r   c                 óv  — | j                              ¦   «         }|j        dk    rd|j        r:d„ |j                             ¦   «         D ¦   «         }|                     |¦  «         dS |                     |j        |j        f¦  «         dS |j        dk    rL|j        r|                     |j        ¦  «         dS |                     |j        |j	        |j        f¦  «         dS |j        dk    r|                     |j        ¦  «         dS t          d                     t          |j        ¦  «        ¦  «        ¦  «        ‚)zB
        This the end token to a get or a stat operation.
        ó   getc                 ó,   — i | ]\  }}||d d d…         “ŒS )NrK   r   )Ú.0ÚkeyrW   s      r   ú
<dictcomp>z,MemCacheProtocol.cmd_END.<locals>.<dictcomp>Ø   s(   € ÐKÐKÐK©H¨C°˜#˜s 3 3 Q 3œxÐKÐKÐKr   ó   getsó   statsz%Unexpected END response to {} commandN)r3   r:   r   rP   rQ   r    r*   rX   r)   rY   ÚRuntimeErrorÚformatr
   )r"   r<   rQ   s      r   Úcmd_ENDzMemCacheProtocol.cmd_ENDÑ   s7  € ð Œm×#Ò#Ñ%Ô%ˆØŒ;˜&Ò Ð ØŒ|ð 4ØKÐK¸¼
×8HÒ8HÑ8JÔ8JÐKÑKÔK�Ø—’˜FÑ#Ô#Ð#Ð#Ð#à—’˜SœY¨¬	Ð2Ñ3Ô3Ð3Ð3Ð3ØŒ[˜GÒ#Ð#ØŒ|ð =Ø—’˜CœJÑ'Ô'Ð'Ð'Ð'à—’˜SœY¨¬°´Ð;Ñ<Ô<Ð<Ð<Ð<ØŒ[˜HÒ$Ð$Ø�KŠK˜œ
Ñ#Ô#Ð#Ð#Ð#åØ7×>Ò>Ý  ¤Ñ-Ô-ñô ñô ð r   c                 ó^   — | j                              ¦   «                              d¦  «         dS )z=
        Manage error response for incr/decr/delete.
        FNr\   rA   s    r   Úcmd_NOT_FOUNDzMemCacheProtocol.cmd_NOT_FOUNDê   ó,   € ð 	Œ×ÒÑÔ×'Ò'¨Ñ.Ô.Ð.Ð.Ð.r   c                 óô  — | j         d         }|j        dk    r|                     ¦   «         \  }}}d}n|                     ¦   «         \  }}}}t          |¦  «        | _        g | _        d| _        |j        r9||j        vrt          d¦  «        ‚||_
        t          |¦  «        |g|j        |<   n5|j        |k    rt          d¦  «        ‚t          |¦  «        |_        ||_        |                      ¦   «          dS )z:
        Prepare the reading a value after a get.
        r   rb   r   zUnexpected commands answer.N)r3   r   ÚsplitÚintr4   r5   r6   rP   Úkeysri   rR   rQ   re   rX   rY   Ú
setRawMode)r"   rI   r<   re   rX   ÚlengthrY   s          r   Ú	cmd_VALUEzMemCacheProtocol.cmd_VALUEð   sô   € ð Œm˜AÔˆØŒ;˜&Ò Ð Ø!%§¢¡¤ÑˆC�˜ØˆCˆCà&*§j¢j¡l¤lÑ#ˆC�˜ Ý ™KœKˆÔØˆŒØˆÔØŒ<ð 		Ø˜#œ(Ð"Ð"Ý"Ð#@ÑAÔAÐAØ ˆCŒNÝ" 5™zœz¨3Ð/ˆCŒJ�s‰OˆOàŒw˜#Š~ˆ~Ý"Ð#@ÑAÔAÐAÝ˜E™
œ
ˆCŒIØˆCŒGØ�ŠÑÔÐÐÐr   c                 óf   — | j         d         }|                     dd¦  «        \  }}||j        |<   dS )z-
        Reception of one stat line.
        r   ó    é   N)r3   rp   rQ   )r"   rI   r<   re   rW   s        r   Úcmd_STATzMemCacheProtocol.cmd_STAT	  s6   € ð Œm˜AÔˆØ—:’:˜d AÑ&Ô&‰ˆˆSØˆŒ
�3‰ˆˆr   c                 ó^   — | j                              ¦   «                              |¦  «         dS )z%
        Read version token.
        Nr\   )r"   ÚversionDatas     r   Úcmd_VERSIONzMemCacheProtocol.cmd_VERSION  s,   € ð 	Œ×ÒÑÔ×'Ò'¨Ñ4Ô4Ð4Ð4Ð4r   c                 ó¢   — t          j        d¦  «         | j                             ¦   «         }|                     t          ¦   «         ¦  «         dS )z7
        A non-existent command has been sent.
        zNon-existent command sent.N)r	   Úerrr3   r:   r   r   )r"   r<   s     r   Ú	cmd_ERRORzMemCacheProtocol.cmd_ERROR  sD   € õ 	ŒÐ,Ñ-Ô-Ð-ØŒm×#Ò#Ñ%Ô%ˆØ�Š•‘”Ñ!Ô!Ð!Ð!Ð!r   c                 óÈ   — t          |¦  «        }t          j        d|z   ¦  «         | j                             ¦   «         }|                     t          |¦  «        ¦  «         dS )z0
        An invalid input as been sent.
        zInvalid input: N)Úreprr	   r~   r3   r:   r   r   ©r"   ÚerrTextr<   s      r   Úcmd_CLIENT_ERRORz!MemCacheProtocol.cmd_CLIENT_ERROR  sX   € õ �w‘-”-ˆÝŒÐ! GÑ+Ñ,Ô,Ð,ØŒm×#Ò#Ñ%Ô%ˆØ�Š•˜WÑ%Ô%Ñ&Ô&Ð&Ð&Ð&r   c                 óÈ   — t          |¦  «        }t          j        d|z   ¦  «         | j                             ¦   «         }|                     t          |¦  «        ¦  «         dS )z4
        An error has happened server-side.
        zServer error: N)r�   r	   r~   r3   r:   r   r   r‚   s      r   Úcmd_SERVER_ERRORz!MemCacheProtocol.cmd_SERVER_ERROR(  sX   € õ �w‘-”-ˆÝŒÐ  7Ñ*Ñ+Ô+Ð+ØŒm×#Ò#Ñ%Ô%ˆØ�Š•˜WÑ%Ô%Ñ&Ô&Ð&Ð&Ð&r   c                 ó^   — | j                              ¦   «                              d¦  «         dS )z>
        A delete command has completed successfully.
        TNr\   rA   s    r   Úcmd_DELETEDzMemCacheProtocol.cmd_DELETED1  r^   r   c                 ó^   — | j                              ¦   «                              d¦  «         dS )z6
        The last command has been completed.
        TNr\   rA   s    r   Úcmd_OKzMemCacheProtocol.cmd_OK7  r^   r   c                 ó^   — | j                              ¦   «                              d¦  «         dS )z5
        A C{checkAndSet} update has failed.
        FNr\   rA   s    r   Ú
cmd_EXISTSzMemCacheProtocol.cmd_EXISTS=  rn   r   c                 ód  — |                       ¦   «          |                     dd¦  «        d         }t          | dt          |¦  «        z   d¦  «        }|�=|                     dd¦  «        dd…         }|r ||d         ¦  «         nŒ |¦   «          n�|                     dd¦  «        }t          | dt          |¦  «        z   d¦  «        }|� |¦   «          n=| j                             ¦   «         }t          |¦  «        }|                     |¦  «         | j        s|  	                    d¦  «         dS dS )z8
        Receive line commands from the server.
        rw   rx   r   Úcmd_Nó   _)
rL   rp   Úgetattrr
   Úreplacer3   r:   rq   r*   rG   )r"   rI   Útokenr<   ÚargsrW   s         r   ÚlineReceivedzMemCacheProtocol.lineReceivedC  s8  € ð 	×ÒÑÔÐØ—
’
˜4 Ñ#Ô# AÔ&ˆå�d˜F¥\°%Ñ%8Ô%8Ñ8¸$Ñ?Ô?ˆØˆ?Ø—:’:˜d AÑ&Ô& q r rÔ*ˆDØð Ø��D˜”G‘”��à�‘”��ð —<’<  dÑ+Ô+ˆDÝ˜$ ­°dÑ);Ô);Ñ ;¸TÑBÔBˆCØˆØ�‘”��ð ”m×+Ò+Ñ-Ô-�Ý˜$‘i”i�Ø—’˜CÑ Ô Ð ØŒ}ð 	"à�OŠO˜DÑ!Ô!Ð!Ð!Ð!ð	"ð 	"r   rx   c                 ó0   — |                       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}
        s   incr©Ú	_incrdecr©r"   re   rW   s      r   Ú	incrementzMemCacheProtocol.increment`  s   € ð �~Š~˜g s¨CÑ0Ô0Ð0r   c                 ó0   — |                       d||¦  «        S )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}
        s   decrr–   r˜   s      r   Ú	decrementzMemCacheProtocol.decrementq  s   € ð  �~Š~˜g s¨CÑ0Ô0Ð0r   c                 ó  — | j         rt          t          d¦  «        ¦  «        S t          |t          ¦  «        s-t          t          dt          |¦  «        › d�¦  «        ¦  «        S t          |¦  «        | j        k    rt          t          d¦  «        ¦  «        S d 	                    ||dt          |¦  «        fz  g¦  «        }|                      |¦  «         t          ||¬¦  «        }| j                             |¦  «         |j        S )z1
        Internal wrapper for incr/decr.
        únot connectedúInvalid type for key: ú, expecting bytesúKey too longrw   s   %d©re   )rD   r   ri   Ú
isinstanceÚbytesr   ÚtyperN   ÚMAX_KEY_LENGTHrO   rq   rH   r   r3   rM   r   )r"   r<   re   rW   ÚfullcmdÚcmdObjs         r   r—   zMemCacheProtocol._incrdecrƒ  sú   € ð Ôð 	7Ý� _Ñ5Ô5Ñ6Ô6Ð6Ý˜#�uÑ%Ô%ð 	ÝÝÐQµT¸#±Y´YÐQÐQÐQÑRÔRñô ð õ ˆs‰8Œ8�dÔ)Ò)Ð)Ý� NÑ3Ô3Ñ4Ô4Ð4Ø—)’)˜S # uµ°C±´¨{Ñ':Ð;Ñ<Ô<ˆØ�Š�gÑÔÐÝ˜ #Ð&Ñ&Ô&ˆØŒ×Ò˜VÑ$Ô$Ð$ØÔÐr   r   c                 ó6   — |                       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}
        s   replacer   ©Ú_set©r"   re   rW   rX   Ú
expireTimes        r   r‘   zMemCacheProtocol.replace•  s    € ð* �yŠy˜ S¨#¨u°jÀ#ÑFÔFÐFr   c                 ó6   — |                       d||||d¦  «        S )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}
        s   addr   r©   r«   s        r   ÚaddzMemCacheProtocol.add¬  ó    € ð* �yŠy˜  c¨5°*¸cÑBÔBÐBr   c                 ó6   — |                       d||||d¦  «        S )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}
        s   setr   r©   r«   s        r   ÚsetzMemCacheProtocol.setÃ  r¯   r   c                 ó6   — |                       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}
        s   casr©   )r"   re   rW   rY   rX   r¬   s         r   ÚcheckAndSetzMemCacheProtocol.checkAndSetÚ  s    € ð4 �yŠy˜  c¨5°*¸cÑBÔBÐBr   c           
      óü  — | j         rt          t          d¦  «        ¦  «        S t          |t          ¦  «        s-t          t          dt          |¦  «        › d�¦  «        ¦  «        S t          |¦  «        | j        k    rt          t          d¦  «        ¦  «        S t          |t          ¦  «        s-t          t          dt          |¦  «        › d�¦  «        ¦  «        S |rd|z   }t          |¦  «        }d 	                    ||t          d|||fz  ¦  «        g¦  «        |z   }|                      |¦  «         |                      |¦  «         t          ||||¬¦  «        }	| j                             |	¦  «         |	j        S )	z6
        Internal wrapper for setting values.
        r�   rž   rŸ   r    zInvalid type for value: rw   z%d %d %d)re   rX   rt   )rD   r   ri   r¢   r£   r   r¤   rN   r¥   rO   r   rH   r   r3   rM   r   )
r"   r<   re   rW   rX   r¬   rY   rt   r¦   r§   s
             r   rª   zMemCacheProtocol._setö  sŠ  € ð Ôð 	7Ý� _Ñ5Ô5Ñ6Ô6Ð6Ý˜#�uÑ%Ô%ð 	ÝÝÐQµT¸#±Y´YÐQÐQÐQÑRÔRñô ð õ ˆs‰8Œ8�dÔ)Ò)Ð)Ý� NÑ3Ô3Ñ4Ô4Ð4Ý˜#�uÑ%Ô%ð 	ÝÝÐSµt¸C±y´yÐSÐSÐSÑTÔTñô ð ð ð 	Ø˜‘*ˆCÝ�S‘”ˆà�IŠIØ�c�=¨°u¸jÈ&Ð6QÑ)QÑRÔRÐSñô ð ñð 	ð 	�Š�gÑÔÐØ�Š�cÑÔÐÝ˜ #¨U¸6ÐBÑBÔBˆØŒ×Ò˜VÑ$Ô$Ð$ØÔÐr   c                 ó6   — |                       d||ddd¦  «        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}
        s   appendr   r   r©   r˜   s      r   rM   zMemCacheProtocol.append  s    € ð  �yŠy˜ C¨¨a°°CÑ8Ô8Ð8r   c                 ó6   — |                       d||ddd¦  «        S )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}
        s   prependr   r   r©   r˜   s      r   ÚprependzMemCacheProtocol.prepend'  s    € ð  �yŠy˜ S¨#¨q°!°SÑ9Ô9Ð9r   c                 ó2   — |                       |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)r"   re   ÚwithIdentifiers      r   ÚgetzMemCacheProtocol.get9  s   € ð, �yŠy˜#˜ °Ñ6Ô6Ð6r   c                 ó0   — |                       ||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¹   )r"   rr   r»   s      r   ÚgetMultiplezMemCacheProtocol.getMultipleQ  s   € ð0 �yŠy˜˜~¨tÑ4Ô4Ð4r   c           	      óŠ  — t          |¦  «        }| j        rt          t          d¦  «        ¦  «        S |D ]|}t	          |t
          ¦  «        s/t          t          dt          |¦  «        › d�¦  «        ¦  «        c S t          |¦  «        | j	        k    rt          t          d¦  «        ¦  «        c S Œ}|rd}nd}d 
                    |g|z   ¦  «        }|                      |¦  «         |r d„ |D ¦   «         }t          |||d	¬
¦  «        }nt          ||d         dddd¬¦  «        }| j                             |¦  «         |j        S )z>
        Helper method for C{get} and C{getMultiple}.
        r�   rž   rŸ   r    rg   rb   rw   c                 ó   — i | ]}|d “ŒS ))r   r   Nr   )rd   re   s     r   rf   z)MemCacheProtocol._get.<locals>.<dictcomp>€  s   € Ð:Ð:Ð:¨c�c˜>Ð:Ð:Ð:r   T)rr   rQ   rP   r   Nr   F)re   r)   rX   rY   rP   )ÚlistrD   r   ri   r¢   r£   r   r¤   rN   r¥   rO   rH   r   r3   rM   r   )	r"   rr   r»   rP   re   r<   r¦   rQ   r§   s	            r   rº   zMemCacheProtocol._getk  sw  € õ �D‰zŒzˆØÔð 	7Ý� _Ñ5Ô5Ñ6Ô6Ð6Øð 	9ð 	9ˆCÝ˜c¥5Ñ)Ô)ð ÝÝÐ U½¸c¹¼Ð UÐ UÐ UÑVÔVñô ð ð ð õ �3‰xŒx˜$Ô-Ò-Ð-Ý�K¨Ñ7Ô7Ñ8Ô8Ð8Ð8Ð8ð .àð 	ØˆCˆCàˆCØ—)’)˜S˜E D™LÑ)Ô)ˆØ�Š�gÑÔÐØð 	Ø:Ð:°TÐ:Ñ:Ô:ˆFÝ˜S t°FÀTÐJÑJÔJˆFˆFåØ˜˜aœ¨°A¸3Èðñ ô ˆFð 	Œ×Ò˜VÑ$Ô$Ð$ØÔÐr   Nc                 óê   — |rd|z   }nd}| j         rt          t          d¦  «        ¦  «        S |                      |¦  «         t	          di ¬¦  «        }| j                             |¦  «         |j        S )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}
        s   stats rh   r�   )rQ   ©rD   r   ri   rH   r   r3   rM   r   )r"   Úargr<   r§   s       r   ÚstatszMemCacheProtocol.stats‰  s€   € ð ð 	Ø˜c‘/ˆCˆCàˆCØÔð 	7Ý� _Ñ5Ô5Ñ6Ô6Ð6Ø�Š�cÑÔÐÝ˜¨"Ð-Ñ-Ô-ˆØŒ×Ò˜VÑ$Ô$Ð$ØÔÐr   c                 óÒ   — | j         rt          t          d¦  «        ¦  «        S |                      d¦  «         t	          d¦  «        }| j                             |¦  «         |j        S )zª
        Get the version of the server.

        @return: a deferred that will fire with the string value of the
            version.
        @rtype: L{Deferred}
        r�   s   versionrÃ   ©r"   r§   s     r   ÚversionzMemCacheProtocol.version¢  sc   € ð Ôð 	7Ý� _Ñ5Ô5Ñ6Ô6Ð6Ø�Š�jÑ!Ô!Ð!Ý˜Ñ$Ô$ˆØŒ×Ò˜VÑ$Ô$Ð$ØÔÐr   c                 ó`  — | j         rt          t          d¦  «        ¦  «        S t          |t          ¦  «        s-t          t          dt          |¦  «        › d�¦  «        ¦  «        S |                      d|z   ¦  «         t          d|¬¦  «        }| j	         
                    |¦  «         |j        S )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Ÿ   s   delete s   deleter¡   )rD   r   ri   r¢   r£   r   r¤   rH   r   r3   rM   r   )r"   re   r§   s      r   ÚdeletezMemCacheProtocol.delete±  s°   € ð Ôð 	7Ý� _Ñ5Ô5Ñ6Ô6Ð6Ý˜#�uÑ%Ô%ð 	ÝÝÐQµT¸#±Y´YÐQÐQÐQÑRÔRñô ð ð 	�Š�j 3Ñ&Ñ'Ô'Ð'Ý˜¨Ð,Ñ,Ô,ˆØŒ×Ò˜VÑ$Ô$Ð$ØÔÐr   c                 óÒ   — | j         rt          t          d¦  «        ¦  «        S |                      d¦  «         t	          d¦  «        }| j                             |¦  «         |j        S )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Ç   s     r   ÚflushAllzMemCacheProtocol.flushAllÇ  sc   € ð Ôð 	7Ý� _Ñ5Ô5Ñ6Ô6Ð6Ø�Š�lÑ#Ô#Ð#Ý˜Ñ&Ô&ˆØŒ×Ò˜VÑ$Ô$Ð$ØÔÐr   )r1   )rx   )r   r   )F)N)+r   r   r   r   r¥   rD   r&   r=   rB   rE   rH   rZ   r]   r`   rk   rm   ru   ry   r|   r   r„   r†   rˆ   rŠ   rŒ   r”   r™   r›   r—   r‘   r®   r±   r³   rª   rM   r·   r¼   r¾   rº   rÅ   rÈ   rÊ   rÌ   r   r   r   r/   r/   c   s—  € € € € € ðð ð2 €NØ€Mð8ð 8ð 8ð 8ðð ð ð(ð (ð (ð2ð 2ð 2ð*ð *ð *ð"ð "ð "ð..ð .ð .ð/ð /ð /ðð ð ð2/ð /ð /ðð ð ð2ð ð ð5ð 5ð 5ð"ð "ð "ð'ð 'ð 'ð'ð 'ð 'ð.ð .ð .ð.ð .ð .ð/ð /ð /ð"ð "ð "ð:1ð 1ð 1ð 1ð"1ð 1ð 1ð 1ð$ ð  ð  ð$Gð Gð Gð Gð.Cð Cð Cð Cð.Cð Cð Cð Cð.Cð Cð Cð Cð8 ð  ð  ð>9ð 9ð 9ð$:ð :ð :ð$7ð 7ð 7ð 7ð05ð 5ð 5ð 5ð4 ð  ð  ð< ð  ð  ð  ð2 ð  ð  ð ð  ð  ð, ð  ð  ð  ð  r   r/   )r/   ÚDEFAULT_PORTr   r   r   N)r   Úcollectionsr   Útwisted.internet.deferr   r   r   Útwisted.protocols.basicr   Útwisted.protocols.policiesr   Útwisted.pythonr	   Útwisted.python.compatr
   r   rÍ   Ú	Exceptionr   r   r   r   r/   Ú__all__r   r   r   ú<module>rÖ      s…  ðð
ð ð0 Ð Ð Ð Ð Ð à ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø Ð Ð Ð Ð Ð Ø =Ð =Ð =Ð =Ð =Ð =Ð =Ð =à€ðð ð ð ð �Iñ ô ð ðð ð ð ð �)ñ ô ð ðð ð ð ð �)ñ ô ð ð&&ð &&ð &&ð &&ð &&ñ &&ô &&ð &&ðRq	 ð q	 ð q	 ð q	 ð q	 �| \ñ q	 ô q	 ð q	 ðhð ð €€€r   