§
    ÈtºfÂb  ã                   óÀ   — d Z ddlmZ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mZmZ ddlmZ  G d„ d	¦  «        Z G d
„ dee¦  «        Z G d„ dee¦  «        ZdS )z$
Test the memcache client protocol.
é    )ÚDeferredÚDeferredListÚTimeoutErrorÚgatherResults)ÚConnectionDone)ÚClock)Ú StringTransportWithDisconnection)ÚClientErrorÚMemCacheProtocolÚNoSuchCommandÚServerError)ÚTestCasec                   óŠ   — e 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„ Zd„ Zd„ ZdS )ÚCommandMixinzO
    Setup and tests for basic invocation of L{MemCacheProtocol} commands.
    c                 ó   — t          ¦   «         ‚)zp
        Helper test method to test the resulting C{Deferred} of a
        L{MemCacheProtocol} command.
        )ÚNotImplementedError©ÚselfÚdÚsendÚrecvÚresults        úY/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/test/test_memcache.pyÚ_testzCommandMixin._test   s   € õ
 "Ñ#Ô#Ð#ó    c                 ób   — |                       | j                             d¦  «        ddd¦  «        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©r   s    r   Útest_getzCommandMixin.test_get"   s4   € ð �zŠzØŒJ�NŠN˜6Ñ"Ô"ØØ.Øñ	
ô 
ð 	
r   c                 ób   — |                       | j                             d¦  «        ddd¦  «        S )zu
        Test getting a non-available key: it succeeds but return L{None} as
        value and C{0} as flag.
        r   r   ó   END
©r   Nr"   r%   s    r   Útest_emptyGetzCommandMixin.test_emptyGet/   s*   € ð
 �zŠz˜$œ*Ÿ.š.¨Ñ0Ô0°.À*ÈiÑXÔXÐXr   c                 ól   — |                       | j                             ddg¦  «        dddddœ¦  «        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
s1   VALUE foo 0 3
bar
VALUE cow 0 7
chicken
END
)r   s   chickenr    ©r,   r   ©r   r#   ÚgetMultipler%   s    r   Útest_getMultiplezCommandMixin.test_getMultiple6   sC   € ð
 �zŠzØŒJ×"Ò" F¨FÐ#3Ñ4Ô4ØØJØ$¨kÐ:Ð:ñ	
ô 
ð 	
r   c                 ól   — |                       | j                             ddg¦  «        dddddœ¦  «        S )z‰
        When L{MemCacheProtocol.getMultiple} is called with non-available keys,
        the corresponding tuples are (0, None).
        r   r,   r-   s   VALUE cow 1 3
bar
END
)é   r!   r)   r.   r/   r%   s    r   Útest_getMultipleWithEmptyz&CommandMixin.test_getMultipleWithEmptyB   sC   € ð
 �zŠzØŒJ×"Ò" F¨FÐ#3Ñ4Ô4ØØ.Ø ¨)Ð4Ð4ñ	
ô 
ð 	
r   c                 ód   — |                       | j                             dd¦  «        ddd¦  «        S )z†
        L{MemCacheProtocol.set} returns a L{Deferred} which is called back with
        C{True} when the operation succeeds.
        r   r!   s   set foo 0 0 3
bar
ó   STORED
T)r   r#   Úsetr%   s    r   Útest_setzCommandMixin.test_setN   ó6   € ð
 �zŠzØŒJ�NŠN˜6 6Ñ*Ô*Ø'ØØñ	
ô 
ð 	
r   c                 ód   — |                       | j                             dd¦  «        ddd¦  «        S )z†
        L{MemCacheProtocol.add} returns a L{Deferred} which is called back with
        C{True} when the operation succeeds.
        r   r!   ó   add foo 0 0 3
bar
r6   T©r   r#   Úaddr%   s    r   Útest_addzCommandMixin.test_addZ   r9   r   c                 ód   — |                       | j                             dd¦  «        ddd¦  «        S )zŠ
        L{MemCacheProtocol.replace} returns a L{Deferred} which is called back
        with C{True} when the operation succeeds.
        r   r!   ó   replace foo 0 0 3
bar
r6   T©r   r#   Úreplacer%   s    r   Útest_replacezCommandMixin.test_replacef   s8   € ð
 �zŠzØŒJ×Ò˜v vÑ.Ô.Ø+ØØñ	
ô 
ð 	
r   c                 ód   — |                       | j                             dd¦  «        ddd¦  «        S )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}.
        r   r!   r;   ó   NOT STORED
Fr<   r%   s    r   Útest_errorAddzCommandMixin.test_errorAddr   s6   € ð �zŠzØŒJ�NŠN˜6 6Ñ*Ô*Ø'ØØñ	
ô 
ð 	
r   c                 ód   — |                       | j                             dd¦  «        ddd¦  «        S )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}.
        r   r!   r@   rE   FrA   r%   s    r   Útest_errorReplacezCommandMixin.test_errorReplace   s8   € ð �zŠzØŒJ×Ò˜v vÑ.Ô.Ø+ØØñ	
ô 
ð 	
r   c                 ób   — |                       | j                             d¦  «        ddd¦  «        S )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©r   r#   Údeleter%   s    r   Útest_deletezCommandMixin.test_deleteŒ   s4   € ð
 �zŠzØŒJ×Ò˜fÑ%Ô%Ð'8¸.È$ñ
ô 
ð 	
r   c                 ób   — |                       | j                             d¦  «        ddd¦  «        S )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}.
        r!   rJ   s   NOT FOUND
FrK   r%   s    r   Útest_errorDeletezCommandMixin.test_errorDelete•   s5   € ð �zŠzØŒJ×Ò˜fÑ%Ô%Ð'8Ð:JÈEñ
ô 
ð 	
r   c                 ób   — |                       | j                             d¦  «        ddd¦  «        S )zµ
        Test incrementing a variable: L{MemCacheProtocol.increment} returns a
        L{Deferred} which is called back with the incremented value of the
        given key.
        r   s   incr foo 1
ó   4
é   ©r   r#   Ú	incrementr%   s    r   Útest_incrementzCommandMixin.test_incrementŸ   ó.   € ð �zŠz˜$œ*×.Ò.¨vÑ6Ô6Ð8IÈ8ÐUVÑWÔWÐWr   c                 ób   — |                       | j                             d¦  «        ddd¦  «        S )zµ
        Test decrementing a variable: L{MemCacheProtocol.decrement} returns a
        L{Deferred} which is called back with the decremented value of the
        given key.
        r   s   decr foo 1
ó   5
é   ©r   r#   Ú	decrementr%   s    r   Útest_decrementzCommandMixin.test_decrement§   rV   r   c                 ód   — |                       | j                             dd¦  «        ddd¦  «        S )z‘
        L{MemCacheProtocol.increment} takes an optional argument C{value} which
        replaces the default value of 1 when specified.
        r   é   s   incr foo 8
rQ   rR   rS   r%   s    r   Útest_incrementValzCommandMixin.test_incrementVal¯   ó6   € ð
 �zŠzØŒJ× Ò  ¨Ñ+Ô+Ð->ÀÈ!ñ
ô 
ð 	
r   c                 ód   — |                       | j                             dd¦  «        ddd¦  «        S )z‘
        L{MemCacheProtocol.decrement} takes an optional argument C{value} which
        replaces the default value of 1 when specified.
        r   é   s   decr foo 3
rX   rY   rZ   r%   s    r   Útest_decrementValzCommandMixin.test_decrementVal¸   r`   r   c                 óf   — |                       | j                             ¦   «         dddddœ¦  «        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.
        s   stats
ó"   STAT foo bar
STAT egg spam
END
r!   ó   spam©r   ó   egg©r   r#   Ústatsr%   s    r   Ú
test_statszCommandMixin.test_statsÁ   s<   € ð �zŠzØŒJ×ÒÑÔØØ7Ø WÐ-Ð-ñ	
ô 
ð 	
r   c                 óh   — |                       | j                             d¦  «        dddddœ¦  «        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).
        s   blahs   stats blah
re   r!   rf   rg   ri   r%   s    r   Útest_statsWithArgumentz#CommandMixin.test_statsWithArgumentÎ   s>   € ð �zŠzØŒJ×Ò˜WÑ%Ô%ØØ7Ø WÐ-Ð-ñ	
ô 
ð 	
r   c                 ó`   — |                       | j                             ¦   «         ddd¦  «        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
s   1.1)r   r#   Úversionr%   s    r   Útest_versionzCommandMixin.test_versionÜ   s2   € ð �zŠzØŒJ×ÒÑ Ô  .Ð2DÀfñ
ô 
ð 	
r   c                 ó`   — |                       | j                             ¦   «         ddd¦  «        S )z’
        L{MemCacheProtocol.flushAll} returns a L{Deferred} which is called back
        with C{True} if the server acknowledges success.
        s   flush_all
s   OK
T)r   r#   ÚflushAllr%   s    r   Útest_flushAllzCommandMixin.test_flushAllæ   s+   € ð
 �zŠz˜$œ*×-Ò-Ñ/Ô/Ð1AÀ9ÈdÑSÔSÐSr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r&   r*   r1   r4   r8   r>   rC   rF   rH   rM   rO   rU   r\   r_   rc   rk   rm   rp   rs   © r   r   r   r      sX  € € € € € ðð ð$ð $ð $ð
ð 
ð 
ðYð Yð Yð

ð 

ð 

ð

ð 

ð 

ð

ð 

ð 

ð

ð 

ð 

ð

ð 

ð 

ð
ð 
ð 
ð
ð 
ð 
ð
ð 
ð 
ð
ð 
ð 
ðXð Xð XðXð Xð Xð
ð 
ð 
ð
ð 
ð 
ð
ð 
ð 
ð
ð 
ð 
ð
ð 
ð 
ðTð Tð Tð Tð Tr   r   c                   óÆ   — e 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„ 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 S )!ÚMemCacheTestsz9
    Test client protocol class L{MemCacheProtocol}.
    c                 ó  — t          ¦   «         | _        t          ¦   «         | _        | j        j        | j        _        t          ¦   «         | _        | j        | j        _        | j                             | j        ¦  «         dS )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%   s    r   ÚsetUpzMemCacheTests.setUpó   sb   € õ
 &Ñ'Ô'ˆŒ
Ý‘W”WˆŒ
Ø#œzÔ3ˆŒ
ÔÝ9Ñ;Ô;ˆŒØ"&¤*ˆŒÔØŒ
×!Ò! $¤.Ñ1Ô1Ð1Ð1Ð1r   c                 óÎ   ‡ ‡— ˆˆ fd„}‰                       ‰ 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}
        c                 ó4   •— ‰                      | ‰¦  «         d S ©N)ÚassertEqual)Úresr   r   s    €€r   ÚcbzMemCacheTests._test.<locals>.cb  s   ø€ Ø×Ò˜S &Ñ)Ô)Ð)Ð)Ð)r   )r…   r~   ÚvalueÚaddCallbackr#   ÚdataReceived)r   r   r   r   r   r‡   s   `   ` r   r   zMemCacheTests._testÿ   su   øø€ ð$	*ð 	*ð 	*ð 	*ð 	*ð 	*ð 	×Ò˜œ×-Ò-Ñ/Ô/°Ñ6Ô6Ð6Ø	�Š�bÑÔÐØŒ
×Ò Ñ%Ô%Ð%Øˆr   c                 ó†   — | j                              d¦  «         |                      t          | j         j        d¦  «         dS )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}.
        r   s   VALUE bar 0 7
spamegg
END
N)r#   r$   ÚassertRaisesÚRuntimeErrorrŠ   r%   s    r   Útest_invalidGetResponsez%MemCacheTests.test_invalidGetResponse  sH   € ð
 	Œ
�Š�vÑÔÐØ×ÒÝØŒJÔ#Ø2ñ	
ô 	
ð 	
ð 	
ð 	
r   c                 óŠ   — | j                              ddg¦  «         |                      t          | j         j        d¦  «         dS )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}.
        r   r!   s   VALUE egg 0 7
spamegg
END
N)r#   r0   rŒ   r�   rŠ   r%   s    r   Útest_invalidMultipleGetResponsez-MemCacheTests.test_invalidMultipleGetResponse%  sO   € ð 	Œ
×Ò ¨Ð/Ñ0Ô0Ð0Ø×ÒÝØŒJÔ#Ø2ñ	
ô 	
ð 	
ð 	
ð 	
r   c                 óˆ   — | j                              dd¦  «         |                      t          | j         j        d¦  «         dS )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}.
        s   keys   valuer(   N)r#   r7   rŒ   r�   rŠ   r%   s    r   Útest_invalidEndResponsez%MemCacheTests.test_invalidEndResponse2  s=   € ð 	Œ
�Š�v˜xÑ(Ô(Ð(Ø×Ò�,¨¬
Ô(?ÀÑLÔLÐLÐLÐLr   c                 óì  ‡ — ‰ j                              d¦  «        }‰ j                              d¦  «        }t          ¦   «         }|j        ‰ j         _        ‰ j                             ‰ j         j        ¦  «         ‰                      |t          ¦  «         ‰                      |t          ¦  «         ˆ fd„}| 
                    |¦  «         ‰                      |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.
        r   r!   c                 óN   •— ‰                      t          | ¦  «        d¦  «         d S )NzConnection timeout)r…   Ústr)Úerrorr   s    €r   ÚcheckMessagez0MemCacheTests.test_timeOut.<locals>.checkMessageJ  s&   ø€ Ø×Ò�S ™ZœZÐ)=Ñ>Ô>Ð>Ð>Ð>r   )r#   r$   r   ÚcallbackÚconnectionLostr|   ÚadvanceÚpersistentTimeOutÚassertFailurer   r‰   r   r   )r   Úd1Úd2Úd3r—   s   `    r   Útest_timeOutzMemCacheTests.test_timeOut;  sÞ   ø€ ð ŒZ�^Š^˜FÑ#Ô#ˆØŒZ�^Š^˜FÑ#Ô#ˆÝ‰ZŒZˆØ$&¤KˆŒ
Ô!àŒ
×Ò˜4œ:Ô7Ñ8Ô8Ð8Ø×Ò˜2�|Ñ,Ô,Ð,Ø×Ò˜2�|Ñ,Ô,Ð,ð	?ð 	?ð 	?ð 	?ð 	?ð 	�Š�|Ñ$Ô$Ð$Ø×Ò˜2�~Ñ.Ô.Ð.Ý˜b " b˜\Ñ*Ô*Ð*r   c                 óò   ‡ — ‰ j                              d¦  «        }‰ j                             ‰ j         j        dz
  ¦  «         ‰ j                              d¦  «         ˆ fd„}|                     |¦  «         |S )zY
        When a request gets a response, no pending timeout call remains around.
        r   r3   r   c                 óŽ   •— ‰                      | d¦  «         ‰                      t          ‰j        j        ¦  «        d¦  «         d S )Nr    r   )r…   Úlenr|   Úcalls)r   r   s    €r   Úcheckz0MemCacheTests.test_timeoutRemoved.<locals>.checkZ  sB   ø€ Ø×Ò˜V [Ñ1Ô1Ð1Ø×Ò�S ¤Ô!1Ñ2Ô2°AÑ6Ô6Ð6Ð6Ð6r   )r#   r$   r|   rš   r›   rŠ   r‰   )r   r   r¥   s   `  r   Útest_timeoutRemovedz!MemCacheTests.test_timeoutRemovedQ  s�   ø€ ð ŒJ�NŠN˜6Ñ"Ô"ˆàŒ
×Ò˜4œ:Ô7¸!Ñ;Ñ<Ô<Ð<ØŒ
×ÒÐ BÑCÔCÐCð	7ð 	7ð 	7ð 	7ð 	7ð 	
�Š�eÑÔÐØˆr   c                 ó~  — | j                              d¦  «        }t          ¦   «         }|j        | j         _        | j                              d¦  «         | j                             | j         j        ¦  «         |  	                    |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.
        r   s   VALUE foo 0 10
12345)r#   r$   r   r˜   r™   rŠ   r|   rš   r›   rœ   r   r   r   ©r   r�   rž   s      r   Útest_timeOutRawzMemCacheTests.test_timeOutRawa  sœ   € ð ŒZ�^Š^˜FÑ#Ô#ˆÝ‰ZŒZˆØ$&¤KˆŒ
Ô!àŒ
×ÒÐ :Ñ;Ô;Ð;ØŒ
×Ò˜4œ:Ô7Ñ8Ô8Ð8Ø×Ò˜2�|Ñ,Ô,Ð,Ø×Ò˜2�~Ñ.Ô.Ð.Ý˜b "˜XÑ&Ô&Ð&r   c                 ó|  — | j                              ¦   «         }t          ¦   «         }|j        | j         _        | j                              d¦  «         | j                             | j         j        ¦  «         |  	                    |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.
        s   STAT foo bar
)r#   rj   r   r˜   r™   rŠ   r|   rš   r›   rœ   r   r   r   r¨   s      r   Útest_timeOutStatzMemCacheTests.test_timeOutStatq  sœ   € ð
 ŒZ×ÒÑÔˆÝ‰ZŒZˆØ$&¤KˆŒ
Ô!àŒ
×ÒÐ 3Ñ4Ô4Ð4ØŒ
×Ò˜4œ:Ô7Ñ8Ô8Ð8Ø×Ò˜2�|Ñ,Ô,Ð,Ø×Ò˜2�~Ñ.Ô.Ð.Ý˜b "˜XÑ&Ô&Ð&r   c                 ó¬  ‡ ‡‡— ‰ j                              d¦  «        }‰ j                              d¦  «        Št          ¦   «         }|j        ‰ j         _        ‰ j                             ‰ j         j        dz
  ¦  «         ‰ j                              d¦  «         ˆˆˆ fd„}ˆ fd„Š| 	                    |¦  «         ‰  
                    |t          ¦  «         |S )zŒ
        When two requests are sent, a timeout call remains around for the
        second request, and its timeout time is correct.
        r   r!   r3   r   c                 óR  •— ‰                      | d¦  «         ‰                      t          ‰j        j        ¦  «        d¦  «         t	          ‰j        j        ¦  «        D ]}‰j                             d¦  «         Œ‰                     ‰t          ¦  «         
                    ‰¦  «        S )Nr    r3   )r…   r£   r|   r¤   Úranger#   r›   rš   rœ   r   r‰   )r   ÚiÚ	checkTimerž   r   s     €€€r   r¥   z3MemCacheTests.test_timeoutPipelining.<locals>.check�  s•   ø€ Ø×Ò˜V [Ñ1Ô1Ð1Ø×Ò�S ¤Ô!1Ñ2Ô2°AÑ6Ô6Ð6Ý˜4œ:Ô7Ñ8Ô8ð &ð &�Ø”
×"Ò" 1Ñ%Ô%Ð%Ð%Ø×%Ò% b­,Ñ7Ô7×CÒCÀIÑNÔNÐNr   c                 ó‚   •— ‰                      ‰j                             ¦   «         d‰j        j        z  dz
  ¦  «         d S )Né   r3   )r…   r|   Úsecondsr#   r›   )Úignoredr   s    €r   r°   z7MemCacheTests.test_timeoutPipelining.<locals>.checkTime”  s?   ø€ ð ×Ò˜TœZ×/Ò/Ñ1Ô1°1°t´zÔ7SÑ3SÐVWÑ3WÑXÔXÐXÐXÐXr   )r#   r$   r   r˜   r™   r|   rš   r›   rŠ   r‰   rœ   r   )r   r�   rŸ   r¥   r°   rž   s   `   @@r   Útest_timeoutPipeliningz$MemCacheTests.test_timeoutPipelining€  sð   øøø€ ð
 ŒZ�^Š^˜FÑ#Ô#ˆØŒZ�^Š^˜FÑ#Ô#ˆÝ‰ZŒZˆØ$&¤KˆŒ
Ô!àŒ
×Ò˜4œ:Ô7¸!Ñ;Ñ<Ô<Ð<ØŒ
×ÒÐ BÑCÔCÐCð	Oð 	Oð 	Oð 	Oð 	Oð 	Oð 	Oð	Yð 	Yð 	Yð 	Yð 	Yð
 	�Š�uÑÔÐØ×Ò˜2�~Ñ.Ô.Ð.Øˆ	r   c                 óð  — | j                              d¦  «        }t          ¦   «         }|j        | j         _        | j                             | j         j        dz
  ¦  «         | 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.
        r   r3   r!   )r#   r$   r   r˜   r™   r|   rš   r›   rœ   r   r   r   )r   r�   rŸ   rž   s       r   Útest_timeoutNotResetz"MemCacheTests.test_timeoutNotReset�  sË   € ð
 ŒZ�^Š^˜FÑ#Ô#ˆÝ‰ZŒZˆØ$&¤KˆŒ
Ô!àŒ
×Ò˜4œ:Ô7¸!Ñ;Ñ<Ô<Ð<ØŒZ�^Š^˜FÑ#Ô#ˆØŒ
×Ò˜1ÑÔÐØ×Ò˜2�|Ñ,Ô,Ð,Ø×Ò˜2�|Ñ,Ô,Ð,Ø×Ò˜2�~Ñ.Ô.Ð.Ý˜b " b˜\Ñ*Ô*Ð*r   c                 ó@  — | j                              d¦  «        }| j                             | j         j        ¦  «         |                      |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}.
        r   r!   )	r#   r$   r|   rš   r›   rœ   r   r�   r   r¨   s      r   Útest_timeoutCleanDeferredsz(MemCacheTests.test_timeoutCleanDeferreds®  sƒ   € ð ŒZ�^Š^˜FÑ#Ô#ˆØŒ
×Ò˜4œ:Ô7Ñ8Ô8Ð8Ø×Ò˜2�|Ñ,Ô,Ð,ØŒZ�^Š^˜FÑ#Ô#ˆØ×Ò˜2�|Ñ,Ô,Ð,Ý˜b "˜XÑ&Ô&Ð&r   c                 óø   ‡ — ‰ j                              d¦  «        }‰ j                              d¦  «        }‰ j                             ¦   «          t	          ||gd¬¦  «        }ˆ fd„}|                     |¦  «        S )zl
        When disconnection occurs while commands are still outstanding, the
        commands fail.
        r   r!   T)ÚconsumeErrorsc                 óv   •— | D ]4\  }}‰                      |¦  «         |                     t          ¦  «         Œ5d S r„   )ÚassertFalseÚtrapr   )ÚresultsÚsuccessr   r   s      €r   ÚcheckFailuresz8MemCacheTests.test_connectionLost.<locals>.checkFailuresÆ  sI   ø€ Ø#*ð ,ð ,‘�˜Ø× Ò  Ñ)Ô)Ð)Ø—’�NÑ+Ô+Ð+Ð+ð,ð ,r   )r#   r$   r~   ÚloseConnectionr   r‰   )r   r�   rž   ÚdonerÁ   s   `    r   Útest_connectionLostz!MemCacheTests.test_connectionLost¼  s„   ø€ ð
 ŒZ�^Š^˜FÑ#Ô#ˆØŒZ�^Š^˜FÑ#Ô#ˆØŒ×%Ò%Ñ'Ô'Ð'Ý˜R ˜H°DÐ9Ñ9Ô9ˆð	,ð 	,ð 	,ð 	,ð 	,ð
 ×Ò Ñ.Ô.Ð.r   c                 óš  — |                       | j                             dd¦  «        t          ¦  «        }|                       | j                             d¦  «        t          ¦  «        }|                       | j                             d¦  «        t          ¦  «        }|                       | j                             dd¦  «        t          ¦  «        }|                       | j                             dd¦  «        t          ¦  «        }|                       | j                             ddg¦  «        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ô  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar!   r   )
rœ   r#   r7   r
   rT   r$   ÚappendÚprependr0   r   )r   r�   rž   rŸ   Úd4Úd5Úd6s          r   Útest_tooLongKeyzMemCacheTests.test_tooLongKeyÍ  s  € ð
 ×Ò ¤
§¢¨z¸6Ñ BÔ BÅKÑPÔPˆØ×Ò ¤
× 4Ò 4°ZÑ @Ô @Å+ÑNÔNˆØ×Ò ¤
§¢¨zÑ :Ô :½KÑHÔHˆØ×Ò ¤
× 1Ò 1°*¸fÑ EÔ EÅ{ÑSÔSˆØ×Ò ¤
× 2Ò 2°:¸vÑ FÔ FÍÑTÔTˆØ×ÒØŒJ×"Ò" F¨JÐ#7Ñ8Ô8½+ñ
ô 
ˆõ ˜b " b¨"¨b°"Ð5Ñ6Ô6Ð6r   c                 ó  — | j                              dddddd¦  «        }|                      | 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}.
        rh   r   r!   r   r   s   egg foo 0 0 3
bar
s   ERROR
)r#   Ú_setr…   r~   rˆ   rœ   r   rŠ   ©r   r   s     r   Útest_invalidCommandz!MemCacheTests.test_invalidCommandÜ  sw   € ð ŒJ�OŠO˜F F¨F°A°q¸#Ñ>Ô>ˆØ×Ò˜œ×-Ò-Ñ/Ô/Ð1LÑMÔMÐMØ×Ò˜1�mÑ,Ô,Ð,ØŒ
×Ò Ñ-Ô-Ð-Øˆr   c                 ó:  ‡ — d}‰ j                              d|¦  «        }‰                      ‰ j                             ¦   «         d¦  «         ‰                      |t          ¦  «         ˆ fd„}|                     |¦  «         ‰ 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                 óh   •— ‰                      t          | ¦  «        t          d¦  «        ¦  «         d S )Ns   We don't like egg and spam©r…   r•   Úrepr©Úerrr   s    €r   r¥   z-MemCacheTests.test_clientError.<locals>.checkó  s.   ø€ Ø×Ò�S ™XœX¥tÐ,IÑ'JÔ'JÑKÔKÐKÐKÐKr   s)   CLIENT_ERROR We don't like egg and spam
)	r#   r7   r…   r~   rˆ   rœ   r
   r‰   rŠ   ©r   Úar   r¥   s   `   r   Útest_clientErrorzMemCacheTests.test_clientErrorè  s¨   ø€ ð ˆØŒJ�NŠN˜6 1Ñ%Ô%ˆØ×Ò˜œ×-Ò-Ñ/Ô/Ð1QÑRÔRÐRØ×Ò˜1�kÑ*Ô*Ð*ð	Lð 	Lð 	Lð 	Lð 	Lð 	
�Š�eÑÔÐØŒ
×ÒÐ NÑOÔOÐOØˆr   c                 ó:  ‡ — d}‰ j                              d|¦  «        }‰                      ‰ j                             ¦   «         d¦  «         ‰                      |t          ¦  «         ˆ fd„}|                     |¦  «         ‰ j                              d¦  «         |S )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Ñ   r   rÒ   c                 óh   •— ‰                      t          | ¦  «        t          d¦  «        ¦  «         d S )Ns   zomgrÔ   rÖ   s    €r   r¥   z-MemCacheTests.test_serverError.<locals>.check  s+   ø€ Ø×Ò�S ™XœX¥t¨G¡}¤}Ñ5Ô5Ð5Ð5Ð5r   s   SERVER_ERROR zomg
)	r#   r7   r…   r~   rˆ   rœ   r   r‰   rŠ   rØ   s   `   r   Útest_serverErrorzMemCacheTests.test_serverErrorú  s£   ø€ ð ˆØŒJ�NŠN˜6 1Ñ%Ô%ˆØ×Ò˜œ×-Ò-Ñ/Ô/Ð1QÑRÔRÐRØ×Ò˜1�kÑ*Ô*Ð*ð	6ð 	6ð 	6ð 	6ð 	6ð 	
�Š�eÑÔÐØŒ
×ÒÐ 8Ñ9Ô9Ð9Øˆr   c           	      ó  — |                       | j                             dd¦  «        t          ¦  «        }|                       | j                             d¦  «        t          ¦  «        }|                       | j                             d¦  «        t          ¦  «        }|                       | j                             d¦  «        t          ¦  «        }|                       | j                             dd¦  «        t          ¦  «        }|                       | j                             dd¦  «        t          ¦  «        }|                       | j         	                    ddg¦  «        t          ¦  «        }t          |||||||g¦  «        S )zQ
        Using a non-string key as argument to commands raises an error.
        Úfoor!   Úeggr3   Úbarrh   )rœ   r#   r7   r
   rT   r$   rL   rÆ   rÇ   r0   r   )r   r�   rž   rŸ   rÈ   rÉ   rÊ   Úd7s           r   Útest_unicodeKeyzMemCacheTests.test_unicodeKey  s*  € ð ×Ò ¤
§¢¨u°fÑ =Ô =½{ÑKÔKˆØ×Ò ¤
× 4Ò 4°UÑ ;Ô ;½[ÑIÔIˆØ×Ò ¤
§¢¨qÑ 1Ô 1µ;Ñ?Ô?ˆØ×Ò ¤
× 1Ò 1°%Ñ 8Ô 8½+ÑFÔFˆØ×Ò ¤
× 1Ò 1°%¸Ñ @Ô @Å+ÑNÔNˆØ×Ò ¤
× 2Ò 2°5¸&Ñ AÔ AÅ;ÑOÔOˆØ×Ò ¤
× 6Ò 6¸À°{Ñ CÔ CÅ[ÑQÔQˆÝ˜b " b¨"¨b°"°bÐ9Ñ:Ô:Ð:r   c                 ój   — |                       | j                             dd¦  «        t          ¦  «        S )z;
        Using a non-string value raises an error.
        r   rá   )rœ   r#   r7   r
   r%   s    r   Útest_unicodeValuezMemCacheTests.test_unicodeValue  s*   € ð ×!Ò! $¤*§.¢.°¸Ñ"?Ô"?ÅÑMÔMÐMr   c                 óô  — | j                              d¦  «        }|                     | j        d¦  «         | j                              dd¦  «        }|                     | j        d¦  «         | j                              d¦  «        }|                     | j        d¦  «         |                      | 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.
        r   r    r!   s   spamspamspamTrh   )r   rf   s0   get 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$   r‰   r…   r7   r~   rˆ   rŠ   r   )r   r�   rž   rŸ   s       r   Útest_pipeliningzMemCacheTests.test_pipelining  sç   € ð ŒZ�^Š^˜FÑ#Ô#ˆØ
�Š�tÔ'¨Ñ5Ô5Ð5ØŒZ�^Š^˜F OÑ4Ô4ˆØ
�Š�tÔ'¨Ñ.Ô.Ð.ØŒZ�^Š^˜FÑ#Ô#ˆØ
�Š�tÔ'¨Ñ6Ô6Ð6Ø×ÒØŒN× Ò Ñ"Ô"ØGñ	
ô 	
ð 	
ð 	Œ
×Òð0ñ	
ô 	
ð 	
õ
 ˜b " b˜\Ñ*Ô*Ð*r   c                 óš  — | j                              d¦  «        }|                     | j        d¦  «         |                      | 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   )r   s
   0123456789r   s   VALUE foo 0 10
0123456s   789s   
ENDs   
)r#   r$   r‰   r…   r~   rˆ   rŠ   rÎ   s     r   Útest_getInChunkszMemCacheTests.test_getInChunks6  s±   € ð
 ŒJ�NŠN˜6Ñ"Ô"ˆØ	�Š�dÔ&Ð(:Ñ;Ô;Ð;Ø×Ò˜œ×-Ò-Ñ/Ô/°Ñ@Ô@Ð@ØŒ
×ÒÐ <Ñ=Ô=Ð=ØŒ
×Ò Ñ'Ô'Ð'ØŒ
×Ò 
Ñ+Ô+Ð+ØŒ
×Ò Ñ(Ô(Ð(Øˆr   c                 ód   — |                       | j                             dd¦  «        ddd¦  «        S )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.
        r   r!   s   append foo 0 0 3
bar
r6   T)r   r#   rÆ   r%   s    r   Útest_appendzMemCacheTests.test_appendD  s8   € ð �zŠzØŒJ×Ò˜f fÑ-Ô-Ø*ØØñ	
ô 
ð 	
r   c                 ód   — |                       | j                             dd¦  «        ddd¦  «        S )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.
        r   r!   s   prepend foo 0 0 3
bar
r6   T)r   r#   rÇ   r%   s    r   Útest_prependzMemCacheTests.test_prependQ  s8   € ð �zŠzØŒJ×Ò˜v vÑ.Ô.Ø+ØØñ	
ô 
ð 	
r   c                 ód   — |                       | j                             dd¦  «        ddd¦  «        S )z©
        L{MemCacheProtocol.get} handles an additional cas result when
        C{withIdentifier} is C{True} and forward it in the resulting
        L{Deferred}.
        r   Tó
   gets foo
s   VALUE foo 0 3 1234
bar
END
)r   ó   1234r!   r"   r%   s    r   Ú	test_getszMemCacheTests.test_gets^  s6   € ð �zŠzØŒJ�NŠN˜6 4Ñ(Ô(ØØ3Ø ñ	
ô 
ð 	
r   c                 ód   — |                       | j                             dd¦  «        ddd¦  «        S )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.
        r   Trï   r(   ©r   r   Nr"   r%   s    r   Útest_emptyGetszMemCacheTests.test_emptyGetsk  s3   € ð
 �zŠzØŒJ�NŠN˜6 4Ñ(Ô(¨/¸:À~ñ
ô 
ð 	
r   c                 ón   — |                       | j                             ddgd¦  «        dddddœ¦  «        S )	z‘
        L{MemCacheProtocol.getMultiple} handles an additional cas field in the
        returned tuples if C{withIdentifier} is C{True}.
        r   r!   Tó   gets foo bar
ó8   VALUE foo 0 3 1234
egg
VALUE bar 0 4 2345
spam
END
©r   s   2345rf   ©r   rð   rh   ©r!   r   r/   r%   s    r   Útest_getsMultiplezMemCacheTests.test_getsMultiplet  sF   € ð
 �zŠzØŒJ×"Ò" F¨FÐ#3°TÑ:Ô:ØØUØ*Ð4HÐIÐIñ	
ô 
ð 	
r   c                 óˆ   — |                       | j                             t          ddg¦  «        d¦  «        dddddœ¦  «        S )	zO
        L{MemCacheProtocol.getMultiple} accepts any iterable of keys.
        r   r!   Trö   r÷   rø   rù   rú   )r   r#   r0   Úiterr%   s    r   Útest_getsMultipleIterableKeysz+MemCacheTests.test_getsMultipleIterableKeys€  sN   € ð �zŠzØŒJ×"Ò"¥4¨°Ð(8Ñ#9Ô#9¸4Ñ@Ô@ØØUØ*Ð4HÐIÐIñ	
ô 
ð 	
r   c                 ón   — |                       | j                             ddgd¦  «        dddddœ¦  «        S )	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.
        r   r!   Trö   s   VALUE foo 0 3 1234
egg
END
ró   rù   rú   r/   r%   s    r   Útest_getsMultipleWithEmptyz(MemCacheTests.test_getsMultipleWithEmpty‹  sF   € ð �zŠzØŒJ×"Ò" F¨FÐ#3°TÑ:Ô:ØØ3Ø#Ð-AÐBÐBñ	
ô 
ð 	
r   c                 óh   — |                       | j                             ddd¬¦  «        ddd¦  «        S )z�
        L{MemCacheProtocol.checkAndSet} passes an additional cas identifier
        that the server handles to check if the data has to be updated.
        r   r!   rð   ©Úcasó   cas foo 0 0 3 1234
bar
r6   T©r   r#   ÚcheckAndSetr%   s    r   Útest_checkAndSetzMemCacheTests.test_checkAndSet™  s=   € ð
 �zŠzØŒJ×"Ò" 6¨6°wÐ"Ñ?Ô?Ø,ØØñ	
ô 
ð 	
r   c                 óh   — |                       | j                             ddd¬¦  «        ddd¦  «        S )z„
        When L{MemCacheProtocol.checkAndSet} response is C{EXISTS}, the
        resulting L{Deferred} fires with C{False}.
        r   r!   rð   r  r  s   EXISTS
Fr  r%   s    r   Útest_casUnknowKeyzMemCacheTests.test_casUnknowKey¥  s=   € ð
 �zŠzØŒJ×"Ò" 6¨6°wÐ"Ñ?Ô?Ø,ØØñ	
ô 
ð 	
r   N)"rt   ru   rv   rw   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ô   rû   rþ   r   r  r	  rx   r   r   rz   rz   î   sæ  € € € € € ðð ð
2ð 
2ð 
2ðð ð ð4

ð 

ð 

ð
ð 
ð 
ðMð Mð Mð+ð +ð +ð,ð ð ð 'ð 'ð 'ð 'ð 'ð 'ðð ð ð:+ð +ð +ð"'ð 'ð 'ð/ð /ð /ð"7ð 7ð 7ð
ð 
ð 
ðð ð ð$ð ð ð$;ð ;ð ;ðNð Nð Nð+ð +ð +ð.ð ð ð
ð 
ð 
ð
ð 
ð 
ð
ð 
ð 
ð
ð 
ð 
ð

ð 

ð 

ð	
ð 	
ð 	
ð
ð 
ð 
ð

ð 

ð 

ð

ð 

ð 

ð 

ð 

r   rz   c                   ó   — e Zd ZdZd„ Zd„ ZdS )ÚCommandFailureTestszZ
    Tests for correct failure of commands on a disconnected
    L{MemCacheProtocol}.
    c                 ó6  — t          ¦   «         | _        t          ¦   «         | _        | j        j        | j        _        t          ¦   «         | _        | j        | j        _        | j                             | j        ¦  «         | j         	                    ¦   «          dS )zU
        Create a disconnected memcache client, using a deterministic clock.
        N)
r   r#   r   r|   r}   r	   r~   r   r€   rÂ   r%   s    r   r�   zCommandFailureTests.setUp¸  sv   € õ &Ñ'Ô'ˆŒ
Ý‘W”WˆŒ
Ø#œzÔ3ˆŒ
ÔÝ9Ñ;Ô;ˆŒØ"&¤*ˆŒÔØŒ
×!Ò! $¤.Ñ1Ô1Ð1ØŒ×%Ò%Ñ'Ô'Ð'Ð'Ð'r   c                 ó8   — |                       |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œ   r�   r   s        r   r   zCommandFailureTests._testÄ  s   € ð ×!Ò! !¥\Ñ2Ô2Ð2r   N)rt   ru   rv   rw   r�   r   rx   r   r   r  r  ²  s<   € € € € € ðð ð

(ð 
(ð 
(ð3ð 3ð 3ð 3ð 3r   r  N)rw   Útwisted.internet.deferr   r   r   r   Útwisted.internet.errorr   Útwisted.internet.taskr   Útwisted.internet.testingr	   Útwisted.protocols.memcacher
   r   r   r   Útwisted.trial.unittestr   r   rz   r  rx   r   r   ú<module>r     s`  ððð ð
 WÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VØ 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø EÐ EÐ EÐ EÐ EÐ Eðð ð ð ð ð ð ð ð ð ð ð ð ,Ð +Ð +Ð +Ð +Ð +ðUTð UTð UTð UTð UTñ UTô UTð UTðpA
ð A
ð A
ð A
ð A
�L (ñ A
ô A
ð A
ðH3ð 3ð 3ð 3ð 3˜,¨ñ 3ô 3ð 3ð 3ð 3r   