
    k7i8                     r   S r SSKJrJr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr  SSKJrJr  SSKJr  SS	KJr  SS
KJr  SSKJrJrJr  SSKJrJr  SSKJrJrJrJ r J!r!J"r"   " S S\"\5      r# " S S\#\!\5      r$ " S S\#\5      r% " S S\#\ \5      r& " S S\#\\5      r' " S S\#\\5      r( " S S\#\\5      r)g)zB
Base abstract class for managed key-value store implementations.
    )ABCabstractmethod)Lock)defaultdict)Sequence)TracebackType)AnySupportsFloat)DEFAULT_COLLECTION_NAME)StoreSetupError)ManagedEntry)nowprepare_ttlprepare_ttls)Selfoverride)AsyncCullProtocolAsyncDestroyCollectionProtocolAsyncDestroyStoreProtocol!AsyncEnumerateCollectionsProtocolAsyncEnumerateKeysProtocolAsyncKeyValueProtocolc                   J  ^  \ rS rSr% Sr\\S'   \\S'   \\	\4   \S'   \\	\4   \S'   \	\S'   SS	.S\	S-  S
S4U 4S jjjr
S*S jrS\	S
S4S jrS*S jrS\	S
S4S jr\S\	S\	S
\S-  4S j5       rS\	S\\	   S
\\S-     4S jr\SS.S\	S\	S-  S
\\	\4   S-  4S jj5       r\SS.S\\	   S\	S-  S
\\\	\4   S-     4S jj5       r\SS.S\	S\	S-  S
\\\	\4   S-  \S-  4   4S jj5       r\SS.S\\	   S\	S-  S
\\\\	\4   S-  \S-  4      4S jj5       r\S\	S\	S\S
S4S j5       rS\	S\\	   S\\   S
S4S jr\SSS.S\	S\\	\4   S\	S-  S \ S-  S
S4
S! jj5       r!S\\	   S"\\\	\4      S \\ S-     \ -  S-  S
\\\	   \\\	\4      \\S-     4   4S# jr"\SSS.S\\	   S"\\\	\4      S\	S-  S \\ S-     S-  S
S4
S$ jj5       r#\S\	S\	S
\4S% j5       r$S\\	   S\	S
\%4S& jr&\SS.S\	S\	S-  S
\4S' jj5       r'\SS.S\\	   S\	S-  S
\%4S( jj5       r(S)r)U =r*$ )+	BaseStore   as  An opinionated Abstract base class for managed key-value stores using ManagedEntry objects.

This class implements all of the methods required for compliance with the KVStore protocol but
requires subclasses to implement the _get_managed_entry, _put_managed_entry, and _delete_managed_entry methods.

Subclasses can also override the _get_managed_entries, _put_managed_entries, and _delete_managed_entries methods if desired.

Subclasses can implement the _setup, which will be called once before the first use of the store, and _setup_collection, which will
be called once per collection before the first use of a collection.
_setup_complete_setup_lock_setup_collection_locks_setup_collection_completedefault_collectionN)r    returnc                   > SU l         [        5       U l        [        [        5      U l        [        [
        5      U l        U=(       d    [        U l        [        TU ])  5         g)zInitialize the managed key-value store.

Args:
    default_collection: The default collection to use if no collection is provided.
        Defaults to "default_collection".
FN)r   r   r   r   r   boolr   r   r    super__init__)selfr    	__class__s     S/home/james-whalen/.local/lib/python3.13/site-packages/key_value/aio/stores/base.pyr%   BaseStore.__init__0   sJ      %6'24'8$*5d*;'"4"O8O    c                    #    g7f)z4Initialize the store (called once before first use).N r&   s    r(   _setupBaseStore._setupA           
collectionc                   #    g7f)zKInitialize the collection (called once before first use of the collection).Nr,   r&   r2   s     r(   _setup_collectionBaseStore._setup_collectionD   r0   r1   c                   #    U R                   (       dW  U R                   IS h  vN   U R                   (       d    U R                  5       I S h  vN   SU l         S S S 5      IS h  vN   g g  NG N! [         a)  n[	        SU 3SU R
                  R                  0S9UeS nAff = f N@! , IS h  vN  (       d  f       g = f7f)Nz!Failed to setup key value store: storemessage
extra_infoT)r   r   r.   	Exceptionr   r'   __name__)r&   es     r(   setupBaseStore.setupG   s     ##'''++!"kkm++
 ,0D( ('' $' ,$ !-&Gs$KY`bfbpbpbybyXz !!	 ('''sy   "CA,CB(A0A.A0B(C%B&&C.A00
B#:$BB##B(&C(B?.B1/B?;Cc                  #    U R                  5       I S h  vN   U R                  U   (       dd  U R                  U    IS h  vN   U R                  U   (       d'   U R                  US9I S h  vN   SU R                  U'   S S S 5      IS h  vN   g g  N} NS N)! [         a  n[        SU 3SU0S9UeS nAff = f N.! , IS h  vN  (       d  f       g = f7f)Nr2   zFailed to setup collection: r2   r9   T)r?   r   r   r5   r<   r   )r&   r2   r>   s      r(   setup_collectionBaseStore.setup_collectionS   s     jjl..z:33J??66zBH"44
4KKK CGD33J? @?? ; 	 @ L$ H-8TUVTW6Xfrt~e  A  GH  HH	 @???s   CB+CBCB>B.B/B3B>CB<CCB
B9$B44B99B><C>CCCCkeyc                   #    g7f)z<Retrieve a cache entry by key from the specified collection.Nr,   )r&   r2   rE   s      r(   _get_managed_entryBaseStore._get_managed_entry_   r0   r1   keysc                f   #    U Vs/ s H  o0R                  XS9I Sh  vN PM     sn$  Ns  snf 7f)zGRetrieve multiple managed entries by key from the specified collection.r2   rE   N)rG   )r&   r2   rI   rE   s       r(   _get_managed_entriesBaseStore._get_managed_entriesc   s9      Z^^Y]RU---MMMY]^^M^s   1,*
,1,1rB   c                   #    U=(       d    U R                   nU R                  US9I Sh  vN   U R                  X!S9I Sh  vN nU(       d  gUR                  (       a  gUR                  $  NA N,7f)a:  Retrieve a value by key from the specified collection.

Args:
    collection: The collection to retrieve the value from. If no collection is provided, it will use the default collection.
    key: The key to retrieve the value from.

Returns:
    The value associated with the key, or None if not found or expired.
rB   NrK   )r    rC   rG   
is_expiredvaluer&   rE   r2   managed_entrys       r(   getBaseStore.geth   sk        :4#:#:
##z#:::373J3JV`3J3j-j##""" 	;-js!   (A0A,A0A.+A0.A0c                  #    U=(       d    U R                   nU R                  US9I S h  vN   U R                  XS9I S h  vN nU Vs/ s H(  oD(       a  UR                  (       d  UR                  OS PM*     sn$  NQ N<s  snf 7f)NrB   rI   r2   )r    rC   rL   rO   rP   r&   rI   r2   entriesentrys        r(   get_manyBaseStore.get_many   sw     :4#:#:
##z#:::11t1SSU\]U\EuU-=-=4GU\]] 	;S]s3   (BA<BA>B
/B 9B>B Bc                   #    U=(       d    U R                   nU R                  US9I S h  vN   U R                  X!S9I S h  vN nU(       a  UR                  (       a  gUR                  UR
                  4$  NL N77f)NrB   rK   NN)r    rC   rG   rO   rP   ttlrQ   s       r(   r^   BaseStore.ttl   sp     :4#:#:
##z#:::373J3JV`3J3j-j 8 8##]%6%677 	;-js!   (A;A7A;A96A;9A;c                &  #    U=(       d    U R                   nU R                  US9I Sh  vN   U R                  XS9I Sh  vN nU Vs/ s H4  oD(       a)  UR                  (       d  UR                  UR
                  4OSPM6     sn$  N] NHs  snf 7f)zRetrieve multiple values and TTLs by key from the specified collection.

Returns a list of tuples of the form (value, ttl_seconds). Missing or expired
entries are represented as (None, None).
rB   NrV   r]   )r    rC   rL   rO   rP   r^   rW   s        r(   ttl_manyBaseStore.ttl_many   s       :4#:#:
##z#:::11t1SSjqrjqafE%:J:Jeii(P\\jqrr 	;Srs3   (BBBB
B
;BB
BBrR   c                   #    g7f)z9Store a managed entry by key in the specified collection.Nr,   )r&   r2   rE   rR   s       r(   _put_managed_entryBaseStore._put_managed_entry   
      	r1   managed_entriesc                h   #    [        X#SS9 H  u  pEU R                  UUUS9I Sh  vN   M      g N	7f)zBStore multiple managed entries by key in the specified collection.T)strictr2   rE   rR   N)ziprd   )r&   r2   rI   rg   rE   rR   s         r(   _put_managed_entriesBaseStore._put_managed_entries   sG      #&dD"IC))%+ *    #Js   $20
2)r2   r^   rP   r^   c                   #    U=(       d    U R                   nU R                  US9I Sh  vN   [        U[        US9[	        5       S9nU R                  UUUS9I Sh  vN   g N8 N7f)zEStore a key-value pair in the specified collection with optional TTL.rB   N)trP   r^   
created_atrj   )r    rC   r   r   r   rd   )r&   rE   rP   r2   r^   rR   s         r(   putBaseStore.put   sv       :4#:#:
##z#:::&2KRUDVcfch&i%%!' & 
 	
 	
	 	;	
s!   (A'A#2A'A%A'%A'valuesc                    [        U5      [        U5      :w  a  Sn[        U5      SeU(       a;  [        U[        5      (       a&  [        U5      [        U5      :w  a  Sn[        U5      Se[	        U[        U5      S9nXU4$ )zPrepare multiple managed entries for a put_many operation.

Inheriting classes can use this method if they need to modify a put_many operation.zGput_many called but a different number of keys and values were providedNzKput_many called but a different number of keys and ttl values were provided)ro   count)len
ValueError
isinstancer   r   )r&   rI   rt   r^   msgttl_for_entriess         r(   _prepare_put_manyBaseStore._prepare_put_many   so     t9F#[CS/t+:c8,,SSY1F_CS/t+.:SD	.Ro..r*   c          
      2  #    U=(       d    U R                   nU R                  US9I Sh  vN   U R                  XUS9u  pn[        U5       VVs/ s H  u  pg[	        XuU   [        5       S9PM     nnnU R                  X1US9I Sh  vN   g Nbs  snnf  N7f)z;Store multiple key-value pairs in the specified collection.rB   N)rI   rt   r^   rp   )r2   rI   rg   )r    rC   r|   	enumerater   r   rl   )	r&   rI   rt   r2   r^   r{   irP   rg   s	            r(   put_manyBaseStore.put_many   s       :4#:#:
##z#:::(,(>(>D]`(>(a%o ajjp`q/
`qT\TULu!*<O`q 	 /
 '':Zi'jjj 	;/
 	ks-   (BB%B!B1BBBBc                   #    g7f)z<Delete a managed entry by key from the specified collection.Nr,   r&   rE   r2   s      r(   _delete_managed_entryBaseStore._delete_managed_entry   rf   r1   c                n   #    SnU H&  nU R                  XBS9I Sh  vN (       d  M!  US-  nM(     U$  N7f)EDelete multiple managed entries by key from the specified collection.r   rE   r2   N   )r   )r&   rI   r2   deleted_countrE   s        r(   _delete_managed_entries!BaseStore._delete_managed_entries   sE      C//C/OOO"   Ps   5355c                   #    U=(       d    U R                   nU R                  US9I S h  vN   U R                  XS9I S h  vN $  N N7f)NrB   r   )r    rC   r   r   s      r(   deleteBaseStore.delete  sK     :4#:#:
##z#::://C/OOO 	;O!   (A
AA
AA
A
c                   #    U=(       d    U R                   nU R                  US9I Sh  vN   U R                  XS9I Sh  vN $  N N7f)r   rB   NrV   )r    rC   r   )r&   rI   r2   s      r(   delete_manyBaseStore.delete_many  sM       :4#:#:
##z#:::11t1SSS 	;Sr   )r   r   r   r   r    r!   N)+r=   
__module____qualname____firstlineno____doc__r#   __annotations__r   r   strr%   r.   r5   r?   rC   r   r   rG   listrL   r   dictr	   rS   rZ   tuplefloatr^   ra   rd   r   rl   r
   rr   r|   r   r   intr   r   r   __static_attributes____classcell__)r'   s   @r(   r   r      s   	 (d33 +CI 66;? cDj D  "CZS ZT Z
0
GC 
GD 
G Kc K KW[H[ K K_ _49 _QUVbeiViQj _
 
 "&	## $J	#
 
c3h$	# #8 JN ^49 ^S4Z ^SWX\]`be]eXfimXmSn ^ ^ >B 	8S 	8t 	8uTRUWZRZ^^bMbdilpdpMpGq 	8 	8 
 "&	s3is $J	s
 
eDcNT)54<78	9s s" c  T` ei   49 _ght_u z~  UYw{ 
S 
c3h 
d
 
`mpt`t 
  AE 
 
/Cy/*24S>*B/IQR_bfRfIgjwIwz~I~/	tCy(4S>2D4FF	G/&  "&59k3ik c3h(k
 $Jk md*+d2k 
k k* # 3 4  	T#Y 	C 	TW 	 AE P PC$J P$ P P MQ Td3i Td
 TVY T Tr*   r   c            
           \ rS rSrSr\SSS.S\S-  S\S-  S\\   4S jjj5       r	\
SS.S\S\S-  S\\   4S	 jj5       rS
rg)BaseEnumerateKeysStorei  zsAn abstract base class for enumerate key-value stores.

Subclasses must implement the _get_collection_keys method.
Nlimitr2   r   r!   c                   #    U=(       d    U R                   nU R                  US9I Sh  vN   U R                  XS9I Sh  vN $  N N7f)*List all keys in the specified collection.rB   N)r2   r   )r    rC   _get_collection_keysr&   r2   r   s      r(   rI   BaseEnumerateKeysStore.keys  sM       :4#:#:
##z#:::..*.RRR 	;Rr   c                   #    g7f)r   Nr,   r   s      r(   r   +BaseEnumerateKeysStore._get_collection_keys   r0   r1   r,   N)r=   r   r   r   r   r   r   r   r   rI   r   r   r   r,   r*   r(   r   r     s    
 St SS4Z S#* SX\]`Xa S S QU 9 9C$J 9Z^_bZc 9 9r*   r   c                   v    \ rS rSrSrS\4S jrS\\   S-  S\S-  S\	S-  SS4S	 jr
SS
 jr\SS j5       rSrg)BaseContextManagerStorei%  z2An abstract base class for context manager stores.r!   c                 B   #    U R                  5       I S h  vN   U $  N7fr   )r?   r-   s    r(   
__aenter__"BaseContextManagerStore.__aenter__(  s     jjl 	s   exc_typeN	exc_value	tracebackc                 @   #    U R                  5       I S h  vN   g  N7fr   _close)r&   r   r   r   s       r(   	__aexit__!BaseContextManagerStore.__aexit__,  s      kkm   c                 @   #    U R                  5       I S h  vN   g  N7fr   r   r-   s    r(   closeBaseContextManagerStore.close1  s     kkmr   c                    #    g7f)zClose the store.Nr,   r-   s    r(   r   BaseContextManagerStore._close4  rf   r1   r,   r   )r=   r   r   r   r   r   r   typeBaseExceptionr   r   r   r   r   r   r,   r*   r(   r   r   %  sd    <$ ]+d2?Lt?S`mpt`t	
  r*   r   c                   x    \ rS rSrSr\SS.S\S-  S\\   4S jj5       r	\
SS.S\S-  S\\   4S jj5       rS	rg)
BaseEnumerateCollectionsStorei:  zvAn abstract base class for enumerate collections stores.

Subclasses must implement the _get_collection_names method.
Nr   r   r!   c                p   #    U R                  5       I Sh  vN   U R                  US9I Sh  vN $  N N7f)DList all available collection names (may include empty collections).Nr   )r?   _get_collection_namesr&   r   s     r(   collections)BaseEnumerateCollectionsStore.collections@  s5      jjl//e/<<< 	<   626466c                   #    g7f)r   Nr,   r   s     r(   r   3BaseEnumerateCollectionsStore._get_collection_namesG  r0   r1   r,   )r=   r   r   r   r   r   r   r   r   r   r   r   r   r,   r*   r(   r   r   :  se    
 7; =#* =S	 = = AE SC$J S$s) S Sr*   r   c                   H    \ rS rSrSr\S\4S j5       r\S\4S j5       r	Sr
g)BaseDestroyStoreiL  zdAn abstract base class for destroyable stores.

Subclasses must implement the _delete_store method.
r!   c                 r   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN $  N N7f)zDestroy the store.N)r?   _delete_storer-   s    r(   destroyBaseDestroyStore.destroyR  s0      jjl''))) 	)   737577c                    #    g7f)zDelete the store.Nr,   r-   s    r(   r   BaseDestroyStore._delete_storeY  rf   r1   r,   N)r=   r   r   r   r   r   r#   r   r   r   r   r,   r*   r(   r   r   L  s=    
 *t * * T  r*   r   c                   P    \ rS rSrSr\S\S\4S j5       r\	S\S\4S j5       r
Srg)	BaseDestroyCollectionStorei_  znAn abstract base class for destroyable collections.

Subclasses must implement the _delete_collection method.
r2   r!   c                 p   #    U R                  5       I Sh  vN   U R                  US9I Sh  vN $  N N7f)zDestroy the collection.NrB   )r?   _delete_collectionr4   s     r(   destroy_collection-BaseDestroyCollectionStore.destroy_collectione  s5      jjl,,
,CCC 	Cr   c                   #    g7f)zDelete the collection.Nr,   r4   s     r(   r   -BaseDestroyCollectionStore._delete_collectionl  rf   r1   r,   N)r=   r   r   r   r   r   r   r#   r   r   r   r   r,   r*   r(   r   r   _  sO    
 D3 D4 D D c d  r*   r   c                   @    \ rS rSrSr\SS j5       r\SS j5       rSr	g)BaseCullStoreir  zYAn abstract base class for cullable stores.

Subclasses must implement the _cull method.
Nc                 r   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN $  N N7fzCull the store.N)r?   _cullr-   s    r(   cullBaseCullStore.cullx  s-      jjlZZ\!! 	!r   c                    #    g7fr   r,   r-   s    r(   r   BaseCullStore._cull  rf   r1   r,   r   )
r=   r   r   r   r   r   r   r   r   r   r,   r*   r(   r   r   r  s/    
 " "  r*   r   N)*r   abcr   r   asyncio.locksr   r   r   collections.abcr   typesr   typingr	   r
   key_value.shared.constantsr   key_value.shared.errorsr   $key_value.shared.utils.managed_entryr   #key_value.shared.utils.time_to_liver   r   r   typing_extensionsr   r   !key_value.aio.protocols.key_valuer   r   r   r   r   r   r   r   r   r   r   r   r   r,   r*   r(   <module>r      s    $  # $  % > 3 = N N , rT%s rTj9Y(BC 9(i *SI/PRU S$y";S &,JC &I0# r*   