
    LȂi7                         S r SSKrSSKrSSKJr  SSKJr  SSKJr  SSK	J
r
   " S S\5      r " S	 S
\5      r " S S\5      r\" 5       rSrS rS r " S S5      r\
" S5      rS rg)zBase Cache class.    N)sync_to_async)ImproperlyConfigured)import_string)_lazy_re_compilec                       \ rS rSrSrg)InvalidCacheBackendError    N__name__
__module____qualname____firstlineno____static_attributes__r
       PD:\sksbv-state-backend\venv\Lib\site-packages\django/core/cache/backends/base.pyr   r          r   r   c                       \ rS rSrSrg)CacheKeyWarning   r
   Nr   r
   r   r   r   r      r   r   r   c                       \ rS rSrSrg)InvalidCacheKey   r
   Nr   r
   r   r   r   r      r   r   r      c                     U< SU< SU < 3$ )z
Default function to generate keys.

Construct the key used by all other methods. By default, prepend
the `key_prefix`. KEY_FUNCTION can be used to specify an alternate
function with custom key making behavior.
:r
   )key
key_prefixversions      r   default_key_funcr    !   s     $Wc22r   c                 N    U b  [        U 5      (       a  U $ [        U 5      $ [        $ )zQ
Function to decide which key function to use.

Default to ``default_key_func``.
)callabler   r    )key_funcs    r   get_key_funcr$   ,   s+     HO **r   c                      \ rS rSr\" 5       rS r\4S jrS*S jr	S r
S*S jr\S4S jr\S4S	 jrS+S
 jrS+S jr\S4S jr\S4S jr\S4S jr\S4S jrS*S jrS*S jrS*S jrS*S jr\S4S jr\S4S jrS*S jrS*S jrS,S jrS,S jrS,S jrS,S jrS r \S4S jr!\S4S jr"S*S jr#S*S  jr$S! r%S" r&S,S# jr'S,S$ jr(S,S% jr)S,S& jr*S' r+S( r,S)r-g)-	BaseCache:   c                    UR                  SUR                  SS5      5      nUb   [        U5      nX l        UR                  S0 5      nUR                  SUR                  SS5      5      n [        U5      U l        UR                  SUR                  SS	5      5      n [        U5      U l        UR                  S
S5      U l        UR                  SS5      U l        [        UR                  S5      5      U l
        g ! [        [        4 a    Sn Nf = f! [        [        4 a
    SU l         Nf = f! [        [        4 a
    S	U l         Nf = f)NtimeoutTIMEOUTi,  OPTIONSmax_entriesMAX_ENTRIEScull_frequencyCULL_FREQUENCY   
KEY_PREFIX VERSION   KEY_FUNCTION)getint
ValueError	TypeErrordefault_timeout_max_entries_cull_frequencyr   r   r$   r#   )selfparamsr)   optionsr,   r.   s         r   __init__BaseCache.__init__=   s8   **Y

9c(BCg,  '**Y+jjM30OP	$ #K 0D  $4gkkBRTU6VW	%#&~#6D  !**\26zz)Q/$VZZ%?@' 	*  I& 	$ #D	$ I& 	%#$D 	%s5   C> -D  D3 >DDD0/D03EEc                 z    U[         :X  a  U R                  nOUS:X  a  SnUc  S$ [        R                  " 5       U-   $ )zR
Return the timeout value usable by this backend based upon the provided
timeout.
r   N)DEFAULT_TIMEOUTr:   time)r=   r)   s     r   get_backend_timeoutBaseCache.get_backend_timeoutW   s=    
 o%**G\GtADIIK',AAr   Nc                 X    Uc  U R                   nU R                  XR                  U5      $ )a@  
Construct the key used by all other methods. By default, use the
key_func to generate a key (which, by default, prepends the
`key_prefix' and 'version'). A different key function can be provided
at the time of cache construction; alternatively, you can subclass the
cache backend to provide custom key making behavior.
)r   r#   r   r=   r   r   s      r   make_keyBaseCache.make_keyc   s'     ?llG}}S//7;;r   c                 ^    [        U5       H  n[        R                  " U[        5        M      g)z
Warn about keys that would not be portable to the memcached
backend. This encourages (but does not force) writing backend-portable
cache code.
N)memcache_key_warningswarningswarnr   )r=   r   warnings      r   validate_keyBaseCache.validate_keyp   s!     -S1GMM'?3 2r   c                 F    U R                  XS9nU R                  U5        U$ )z!Helper to make and validate keys.r   )rJ   rQ   rI   s      r   make_and_validate_keyBaseCache.make_and_validate_keyy   s%    mmCm1#
r   c                     [        S5      e)z
Set a value in the cache if the key does not already exist. If
timeout is given, use that timeout for the key; otherwise use the
default cache timeout.

Return True if the value was stored, False otherwise.
z4subclasses of BaseCache must provide an add() methodNotImplementedErrorr=   r   valuer)   r   s        r   addBaseCache.add   s     "B
 	
r   c                 T   #    [        U R                  SS9" XX45      I S h  vN $  N7fNT)thread_sensitive)r   r\   rZ   s        r   aaddBaseCache.aadd   ,     "488dC
 
 	
 
   (&(c                     [        S5      e)zm
Fetch a given key from the cache. If the key does not exist, return
default, which itself defaults to None.
z3subclasses of BaseCache must provide a get() methodrX   r=   r   defaultr   s       r   r6   BaseCache.get       
 ""WXXr   c                 T   #    [        U R                  SS9" XU5      I S h  vN $  N7fr_   )r   r6   rf   s       r   agetBaseCache.aget   s,     "488dC'
 
 	
 
rd   c                     [        S5      e)zw
Set a value in the cache. If timeout is given, use that timeout for the
key; otherwise use the default cache timeout.
z3subclasses of BaseCache must provide a set() methodrX   rZ   s        r   setBaseCache.set   ri   r   c                 T   #    [        U R                  SS9" XX45      I S h  vN $  N7fr_   )r   rn   rZ   s        r   asetBaseCache.aset   rc   rd   c                     [        S5      e)zk
Update the key's expiry time using timeout. Return True if successful
or False if the key does not exist.
z5subclasses of BaseCache must provide a touch() methodrX   r=   r   r)   r   s       r   touchBaseCache.touch   s    
 "C
 	
r   c                 T   #    [        U R                  SS9" XU5      I S h  vN $  N7fr_   )r   ru   rt   s       r   atouchBaseCache.atouch   s,     "4::E'
 
 	
 
rd   c                     [        S5      e)zP
Delete a key from the cache and return whether it succeeded, failing
silently.
z6subclasses of BaseCache must provide a delete() methodrX   rI   s      r   deleteBaseCache.delete   s    
 "D
 	
r   c                 R   #    [        U R                  SS9" X5      I S h  vN $  N7fr_   )r   r{   rI   s      r   adeleteBaseCache.adelete   s!     "4;;FsTTTTs   '%'c                 x    0 nU H1  nU R                  X@R                  US9nXPR                  Ld  M-  XSU'   M3     U$ )a  
Fetch a bunch of keys from the cache. For certain backends (memcached,
pgsql) this can be *much* faster when fetching multiple values.

Return a dict mapping each key in keys to its value. If the given
key is missing, it will be missing from the response dict.
rT   r6   _missing_keyr=   keysr   dkvals         r   get_manyBaseCache.get_many   sE     A((1//(AC+++!  r   c                    #    0 nU H9  nU R                  X@R                  US9I Sh  vN nXPR                  Ld  M5  XSU'   M;     U$  N7f)zSee get_many().rT   Nrk   r   r   s         r   	aget_manyBaseCache.aget_many   sO     A		!%6%6	HHC+++!   Is   %AAAAc                     U R                  XR                  US9nXPR                  L a7  [        U5      (       a  U" 5       nU R                  XX4S9  U R                  XUS9$ U$ )a%  
Fetch a given key from the cache. If the key does not exist,
add the key and set it to the default value. The default value can
also be any callable. If timeout is given, use that timeout for the
key; otherwise use the default cache timeout.

Return the value of the key stored or retrieved.
rT   r)   r   )r6   r   r"   r\   r=   r   rg   r)   r   r   s         r   
get_or_setBaseCache.get_or_set   sd     hhs--wh?###  !)HHS7HD 88C'8::
r   c                   #    U R                  XR                  US9I Sh  vN nXPR                  L aG  [        U5      (       a  U" 5       nU R                  XX4S9I Sh  vN   U R                  XUS9I Sh  vN $ U$  N[ N  N
7f)zSee get_or_set().rT   Nr   )rk   r   r"   ra   r   s         r   aget_or_setBaseCache.aget_or_set   s     IIc#4#4gIFF###  !)))C')KKK 3AAA
 G L Bs3   BA<<BA>B5B 6B>B Bc                 N    U R                  XR                  US9U R                  L$ )=
Return True if the key is in the cache and has not expired.
rT   r   rI   s      r   has_keyBaseCache.has_key   s*    
 HHS++WH=TEVEVV	
r   c                 j   #    U R                  XR                  US9I S h  vN U R                  L$  N7fNrT   r   rI   s      r   ahas_keyBaseCache.ahas_key  s4     ))C!2!2G)DD$$%	
Ds   313c                     U R                  XR                  US9nX@R                  L a  [        SU-  5      eXB-   nU R                  XUS9  U$ )z[
Add delta to value in the cache. If the key does not exist, raise a
ValueError exception.
rT   Key '%s' not found)r6   r   r8   rn   r=   r   deltar   r[   	new_values         r   incrBaseCache.incr  sV    
 //A%%%1C788M	1r   c                    #    U R                  XR                  US9I Sh  vN nX@R                  L a  [        SU-  5      eXB-   nU R                  XUS9I Sh  vN   U$  N> N7f)zSee incr().rT   Nr   )rk   r   r8   rq   r   s         r   aincrBaseCache.aincr  sk     ii%6%6iHH%%%1C788M	iii888 I 	9s!   A#A7A#A!A#!A#c                 $    U R                  X* US9$ )zb
Subtract delta from value in the cache. If the key does not exist,
raise a ValueError exception.
rT   )r   r=   r   r   r   s       r   decrBaseCache.decr  s    
 yyfgy66r   c                 @   #    U R                  X* US9I S h  vN $  N7fr   )r   r   s       r   adecrBaseCache.adecr#  s      ZZVWZ====s   c                 $    U R                  U5      $ )r   )r   )r=   r   s     r   __contains__BaseCache.__contains__&  s     ||C  r   c                 X    UR                  5        H  u  pEU R                  XEX#S9  M     / $ )a  
Set a bunch of values in the cache at once from a dict of key/value
pairs. For certain backends (memcached), this is much more efficient
than calling set() multiple times.

If timeout is given, use that timeout for the key; otherwise use the
default cache timeout.

On backends that support it, return a list of keys that failed
insertion, or an empty list if all keys were inserted successfully.
r   )itemsrn   r=   datar)   r   r   r[   s         r   set_manyBaseCache.set_many/  s+     **,JCHHSHB '	r   c                 t   #    UR                  5        H  u  pEU R                  XEX#S9I S h  vN   M     / $  N
7f)Nr   )r   rq   r   s         r   	aset_manyBaseCache.aset_many?  s8     **,JC))C)III '	 Js   )868c                 4    U H  nU R                  X2S9  M     g)z
Delete a bunch of values in the cache at once. For certain backends
(memcached), this is much more efficient than calling delete() multiple
times.
rT   N)r{   r=   r   r   r   s       r   delete_manyBaseCache.delete_manyD  s     CKKK- r   c                 P   #    U H  nU R                  X2S9I S h  vN   M     g  N	7fr   )r~   r   s       r   adelete_manyBaseCache.adelete_manyM  s&     C,,s,444 4s   &$
&c                     [        S5      e)z+Remove *all* values from the cache at once.z5subclasses of BaseCache must provide a clear() methodrX   r=   s    r   clearBaseCache.clearQ  s    !C
 	
r   c                 P   #    [        U R                  SS9" 5       I S h  vN $  N7fr_   )r   r   r   s    r   aclearBaseCache.aclearW  s     "4::EGGGGs   &$&c                     Uc  U R                   nU R                  XR                  US9nX@R                  L a  [        SU-  5      eU R	                  XX2-   S9  U R                  XS9  X2-   $ )zN
Add delta to the cache version for the supplied key. Return the new
version.
rT   r   )r   r6   r   r8   rn   r{   r=   r   r   r   r[   s        r   incr_versionBaseCache.incr_versionZ  so    
 ?llG//A%%%1C788W_5C)r   c                   #    Uc  U R                   nU R                  XR                  US9I Sh  vN nX@R                  L a  [        SU-  5      eU R	                  XX2-   S9I Sh  vN   U R                  XS9I Sh  vN   X2-   $  NU N! N7f)zSee incr_version().NrT   r   )r   rk   r   r8   rq   r~   r   s        r   aincr_versionBaseCache.aincr_versionj  s     ?llGii%6%6iHH%%%1C788iiGOi<<<ll3l000 I 	=0s3   -BB5B%B&B<B	=	BB	Bc                 (    U R                  X* U5      $ )zU
Subtract delta from the cache version for the supplied key. Return the
new version.
)r   r   s       r   decr_versionBaseCache.decr_versionw  s    
   fg66r   c                 D   #    U R                  X* U5      I S h  vN $  N7fN)r   r   s       r   adecr_versionBaseCache.adecr_version~  s      ''VW====s     c                     g)zClose the cache connectionNr
   r=   kwargss     r   closeBaseCache.close  s    r   c                    #    g 7fr   r
   r   s     r   acloseBaseCache.aclose  s     s   )r<   r;   r:   r#   r   r   r   )NN)r4   N).r   r   r   r   objectr   r@   rD   rF   rJ   rQ   rU   r\   ra   r6   rk   rn   rq   ru   rx   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&   r&   :   s   8LA4 +: 
B<4 '6t 

 .=d 

Y

 '6t Y .=d 

 "1$ 
 )8 


U 0? & 7Ft 



7>! &5d   -<T 
.5
H 7>r   r&   z[\x00-\x20\x7f]c              #      #    [        U 5      [        :  a  SU < S[        < S3v   [        R                  U 5      (       a	  SU < 3v   g g 7f)Nz4Cache key will cause errors if used with memcached: z (longer than )zMCache key contains characters that will cause errors if used with memcached: )lenMEMCACHE_MAX_KEY_LENGTHmemcached_error_chars_research)r   s    r   rM   rM     sQ     
3x)) #&'>@	
  &&s++"	
 ,s   A	A)__doc__rE   rN   asgiref.syncr   django.core.exceptionsr   django.utils.module_loadingr   django.utils.regex_helperr   r   RuntimeWarningr   r8   r   r   rD   r   r    r$   r&   r   rM   r
   r   r   <module>r      sz       & 7 5 6	3 		n 		j 	 (  3L L^
 ,,>? 

r   