
    \db                         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mZmZmZ ddl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)ClientErrorMemCacheProtocolNoSuchCommandServerError) StringTransportWithDisconnection)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        :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     zzJNN6"".	
 
 	
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*    
 zz$*..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    
 zzJ""FF#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    
 zzJ""FF#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    
 zzJNN66**'	
 
 	
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    
 zzJvv..+	
 
 	
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     zzJNN66**'	
 
 	
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     zzJvv..+	
 
 	
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    
 zz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     zzJf%%'8:JE
 
 	
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   .     zz$*..v668I8UV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    
 zz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<     zz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>     zz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     zzJ  .2Df
 
 	
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+    
 zz$*--//1A9d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    
 &''
WW
#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=     	
vx(((,
(?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ZZ)=>>>>>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##ZZ$&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2A66666r   )r#   r$   r|   r   r   r   r   )r   r   r   s   `  r   test_timeoutRemovedz!MemCacheTests.test_timeoutRemovedQ  s     JNN6""
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##ZZ$&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ZZ$&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2A6664:788 & &
""1%%%%%%b,77CCI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?     TZ//111tz7S3SVW3W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##ZZ$&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##ZZ$&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HD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   
 
z6 B BKPP
 4 4Z @ @+NN
z : :KHH
 1 1*f E E{SS
 2 2:v F FTTJ""FJ#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     JOOFFFAq#>>--//1LMMM1m,,,
---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XXt,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     JNN61%%--//1QRRR1k***	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XXtG}}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     JNN61%%--//1QRRR1k***	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*    
uf = ={KK
 4 4U ; ;[II
q 1 1;??
 1 1% 8 8+FF
 1 1% @ @+NN
 2 25& 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^^FO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    
 JNN6""	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     zzJff--*	
 
 	
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     zzJvv..+	
 
 	
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     zzJNN64((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    
 zzJNN64((/:~
 
 	
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    
 zzJ""FF#3T::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     zzJ""4(8#9#94@@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     zzJ""FF#3T::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=    
 zzJ""66w"??,	
 
 	
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=    
 zzJ""66w"??,	
 
 	
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     &''
WW
#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.protocols.memcacher	   r
   r   r   twisted.test.proto_helpersr   twisted.trial.unittestr   r   rz   r  rx   r   r   <module>r     sa   
 W V V V V V V V V V V V 1 1 1 1 1 1 ' ' ' ' ' '            H G G G G G + + + + + +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   