
    h                     z    S SK r S SKrS SKJr  S SKJr  \ R                  " S5      R                  r " S S\5      r	g)    N)time)	BaseCachez[^\x00-\x21\xff]{1,250}$c            
          \ rS rSrSr   SS\R                  S\S\R                  \	   4S jjr
S\	S	\	4S
 jrS\R                  \   S	\4S jrS\	S	\R                  4S jrS\	S	\R                  \	\R                  4   4S jrS S\	S\R                  S\R                  \   S	\4S jjr S S\	S\R                  S\R                  \   S	\R                  \   4S jjrS\	S	\R&                  \R                     4S jr S S\R                  \	\R                  4   S\R                  \   S	\R&                  \R                     4S jjrS\	S	\4S jrS\	S	\R&                  \R                     4S jrS\	S	\4S jrS	\4S jrS!S\	S\S	\R                  \   4S jjrS!S\	S\S	\R                  \   4S jjrS\R                  S	\R                  4S jrSrg)"MemcachedCache   a  A cache that uses memcached as backend.

The first argument can either be an object that resembles the API of a
:class:`memcache.Client` or a tuple/list of server addresses. In the
event that a tuple/list is passed, Werkzeug tries to import the best
available memcache library.

This cache looks into the following packages/modules to find bindings for
memcached:

    - ``pylibmc``
    - ``google.appengine.api.memcached``
    - ``memcached``
    - ``libmc``

Implementation notes:  This cache backend works around some limitations in
memcached to simplify the interface.  For example unicode keys are encoded
to utf-8 on the fly.  Methods such as :meth:`~BaseCache.get_dict` return
the keys in the same format as passed.  Furthermore all get methods
silently ignore key errors to not cause problems when untrusted user data
is passed to the get methods which is often the case in web applications.

:param servers: a list or tuple of server addresses or alternatively
                a :class:`memcache.Client` or a compatible client.
:param default_timeout: the default timeout that is used if no timeout is
                        specified on :meth:`~BaseCache.set`. A timeout of
                        0 indicates that the cache never expires.
:param key_prefix: a prefix that is added before all keys.  This makes it
                   possible to use the same memcached server for different
                   applications.  Keep in mind that
                   :meth:`~BaseCache.clear` will also clear keys with a
                   different prefix.
Nserversdefault_timeout
key_prefixc                     [         R                  " X5        Ub  [        U[        [        45      (       a5  Uc  S/nU R                  U5      U l        U R                  c  [        S5      eOXl        X0l        g )Nz127.0.0.1:11211zno memcache module found)	r   __init__
isinstancelisttupleimport_preferred_memcache_lib_clientRuntimeErrorr
   )selfr   r	   r
   s       gC:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\cachelib/memcached.pyr   MemcachedCache.__init__.   sm     	41?j4-@@,-==gFDL||#"#=>> $
 #L$    keyreturnc                 F    U R                   (       a  U R                   U-   nU$ N)r
   r   r   s     r   _normalize_keyMemcachedCache._normalize_keyB   s    ??//C'C
r   timeoutc                 j    [         R                  " X5      nUS:  a  [        [        5       5      U-   nU$ Nr   )r   _normalize_timeoutintr   )r   r   s     r   r!   !MemcachedCache._normalize_timeoutG   s.    ..t=Q;$&kG+Gr   c                 |    U R                  U5      n[        U5      (       a  U R                  R                  U5      $ g r   )r   _test_memcached_keyr   getr   s     r   r&   MemcachedCache.getM   s9    !!#& s##<<##C(( $r   keysc                 t   0 nU H*  nU R                  U5      n[        U5      (       d  M&  X2U'   M,     [        U5      nU R                  R	                  U5      =pgU R
                  (       a!  0 nUR                  5        H  u  p8XX#   '   M     [        U5      [        U5      :  a  U H  nX7;  d  M
  S Xs'   M     U$ r   )r   r%   r   r   	get_multir
   itemslen)	r   r(   key_mappingr   encoded_key_keysdrvvalues	            r   get_dictMemcachedCache.get_dictU   s    C--c2K"3''+.K(  [!''..??Bggi
',;#$ (r7SY="BG  	r   r2   c                     U R                  U5      nU R                  U5      n[        U R                  R	                  XU5      5      $ r   )r   r!   boolr   addr   r   r2   r   s       r   r7   MemcachedCache.addg   s>    !!#&))'2DLL$$S9::r   c                     U R                  U5      nU R                  U5      n[        U R                  R	                  XU5      5      $ r   )r   r!   r6   r   setr8   s       r   r;   MemcachedCache.setl   s@     !!#&))'2DLL$$S9::r   c                 T    U R                   " U6 nU Vs/ s H  o2U   PM	     sn$ s  snf r   )r3   )r   r(   r0   r   s       r   get_manyMemcachedCache.get_manys   s*    MM4 "&'$3#$'''s   %mappingc                 R   0 nUR                  5        H  u  pEU R                  U5      nXSU'   M     U R                  U5      nU R                  R	                  X25      n[        UR                  5       UR                  5       5      nU VV	s/ s H  u  pX;  d  M  UPM     sn	n$ s  sn	nf r   )r+   r   r!   r   	set_multizipr(   )
r   r@   r   new_mappingr   r2   failed_keys	k_normkeyknkeys
             r   set_manyMemcachedCache.set_manyw   s     !--/JC%%c*C$ * ))'2ll,,
 (8(8(:;	!*Fgad.EFFFs   
B#B#c                     U R                  U5      n[        U5      (       a$  [        U R                  R	                  U5      5      $ g)NF)r   r%   r6   r   deleter   s     r   rL   MemcachedCache.delete   s:    !!#&s##++C011r   c                    / nU H7  nU R                  U5      n[        U5      (       d  M&  UR                  U5        M9     U R                  R	                  U5        U Vs/ s H  o@R                  U5      (       a  M  UPM     sn$ s  snf r   )r   r%   appendr   delete_multihas)r   r(   new_keysr   rG   s        r   delete_manyMemcachedCache.delete_many   sl    C%%c*C"3''$  	!!(+#78a88A;8777s   B<Bc                     U R                  U5      n[        U5      (       a%  [        U R                  R	                  US5      5      $ g)N F)r   r%   r6   r   rO   r   s     r   rQ   MemcachedCache.has   s<    !!#&s##++C455r   c                 H    [        U R                  R                  5       5      $ r   )r6   r   	flush_all)r   s    r   clearMemcachedCache.clear   s    DLL**,--r   deltac                     U R                  U5      nU R                  R                  U5      =(       d    SU-   nU R                  X5      (       a  U$ S $ r    r   r   r&   r;   r   r   r\   r2   s       r   incMemcachedCache.inc   I    !!#&!!#&+!u4,,u6$6r   c                     U R                  U5      nU R                  R                  U5      =(       d    SU-
  nU R                  X5      (       a  U$ S $ r    r^   r_   s       r   decMemcachedCache.dec   rb   r   c                 4    SSK nUR                  U5      $ ! [         a     Of = f SSKJn  UR                  5       $ ! [         a     Of = f SSKnUR                  U5      $ ! [         a     Of = f SSKnUR                  U5      $ ! [         a     gf = f)zAReturns an initialized memcache client.  Used by the constructor.r   N)memcache)pylibmcClientImportErrorgoogle.appengine.apirg   libmc)r   r   rh   rg   rl   s        r   r   ,MemcachedCache.import_preferred_memcache_lib   s    	+ >>'**  		
	%5 ??$$  		
	, ??7++  		
	) <<((  		s?    
$$> 
A
AA$ $
A10A15B
 

BB)r   r
   )Ni,  Nr   )   )__name__
__module____qualname____firstlineno____doc___tAnyr"   Optionalstrr   r   r!   r&   Dictr3   r6   r7   r;   Listr>   rI   rL   rS   rQ   rZ   r`   rd   r   __static_attributes__ r   r   r   r      s;    H "'+	%% % KK$	%(# # 
"++c*: s )s )rvv )c bggc266k&: $;s ;266 ;BKK4D ;PT ; DH;;!vv;02C0@;	T	;(c (bggbffo (
 JNGwwsBFF{+G68kk#6FG	G# $ 8 8 8s t .t .7s 73 7r{{3/? 7
7s 73 7r{{3/? 7
)RVV ) )r   r   )
retypingrt   r   cachelib.baser   compilematchr%   r   r{   r   r   <module>r      s7    	   # jj!<=CC y)Y y)r   