
    Ki                     ~    d dl mZmZmZ d dlmZmZ d dlmZ d dl	m
Z
 d dlmZ eedz  ge
dz  f   Z G d de      Zy)	    )CallableMappingSequence)AnySupportsFloat)override)AsyncKeyValue)BaseWrapperNc                   j    e Zd ZU dZeed<   eed<   dededdf fdZd	edz  defd
Z	e
ddded	edz  deeef   dz  fd       Ze
dddee   d	edz  deeeef   dz     fd       Ze
ddded	edz  deeeef   dz  edz  f   fd       Ze
dddee   d	edz  deeeeef   dz  edz  f      fd       Ze
ddddedeeef   d	edz  dedz  ddf
d       Ze
ddddee   deeeef      d	edz  dedz  ddf
d       Ze
ddded	edz  defd       Ze
dddee   d	edz  defd       Z xZS )RoutingWrappera  Routes operations to different stores based on a routing function.

    The routing function receives the collection name and returns the appropriate store.
    This allows dynamic routing of requests to different backing stores based on
    collection name or other custom logic.

    Example:
        def route_by_collection(collection: str | None) -> AsyncKeyValue | None:
            if collection == "sessions":
                return redis_store
            elif collection == "users":
                return dynamo_store
            return None

        router = RoutingWrapper(
            routing_function=route_by_collection,
            default_store=memory_store
        )
    _routing_function_default_storerouting_functiondefault_storereturnNc                 >    || _         || _        t        |           y)a4  Initialize the routing wrapper.

        Args:
            routing_function: Function that takes a collection name and returns the store to use.
                             Should return None if no specific store is found.
            default_store: Fallback store if routing_function returns None.
        N)r   r   super__init__)selfr   r   	__class__s      r/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/key_value/aio/wrappers/routing/wrapper.pyr   zRoutingWrapper.__init__$   s      "2+    
collectionc                 D    | j                  |      }|| j                  S |S )zGet the appropriate store for the given collection.

        Args:
            collection: The collection name to route.

        Returns:
            The AsyncKeyValue store to use for this collection.
        )r   r   )r   r   stores      r   
_get_storezRoutingWrapper._get_store5   s*     '+&<&<Z&H=&&&r   )r   keyc                f   K   | j                  |      }|j                  ||       d {   S 7 wN)r   r   )r   getr   r   r   r   s       r   r    zRoutingWrapper.getC   -     #z:YY3:Y>>>>   (1/1keysc                f   K   | j                  |      }|j                  ||       d {   S 7 wN)r$   r   )r   get_manyr   r$   r   r   s       r   r'   zRoutingWrapper.get_manyH   -     #z:^^*^EEEEr#   c                f   K   | j                  |      }|j                  ||       d {   S 7 wr   )r   ttlr!   s       r   r+   zRoutingWrapper.ttlM   r"   r#   c                f   K   | j                  |      }|j                  ||       d {   S 7 wr&   )r   ttl_manyr(   s       r   r-   zRoutingWrapper.ttl_manyR   r)   r#   )r   r+   valuer+   c                j   K   | j                  |      }|j                  ||||       d {   S 7 w)N)r   r.   r   r+   )r   put)r   r   r.   r   r+   r   s         r   r0   zRoutingWrapper.putW   s2     #z:YY3e
PSYTTTT   *313valuesc                j   K   | j                  |      }|j                  ||||       d {   S 7 w)N)r$   r2   r   r+   )r   put_many)r   r$   r2   r   r+   r   s         r   r4   zRoutingWrapper.put_many\   s4       $z:^^fY\^]]]]r1   c                f   K   | j                  |      }|j                  ||       d {   S 7 wr   )r   deleter!   s       r   r6   zRoutingWrapper.deleteh   s-     #z:\\cj\AAAAr#   c                f   K   | j                  |      }|j                  ||       d {   S 7 wr&   )r   delete_manyr(   s       r   r8   zRoutingWrapper.delete_manym   s0     #z:&&DZ&HHHHr#   )__name__
__module____qualname____doc__RoutingFunction__annotations__r	   r   strr   r   dictr   r    r   listr'   tuplefloatr+   r-   r   r   r0   r4   boolr6   intr8   __classcell__)r   s   @r   r   r      s   ( '&!!) % 
	"S4Z M  >B ?S ?t ?tCQTH~X\G\ ? ? NR F8C= Ft FW[\`adfiai\jmq\qWr F F >B ?S ?t ?uTRUWZRZ^^bMbdilpdpMpGq ? ? NR F8C= Ft FW[\abfgjlogobpswbwy~  BF  zF  cF  ]G  XH F F X\z~ US Uc): U3QU: Ucpswcw U  DH U U  "&$(	^sm	^ c*+	^
 $J	^ T!	^ 
	^ 	^ AE B BC$J B$ B B QU Ihsm IC$J IZ] I Ir   r   )collections.abcr   r   r   typingr   r   typing_extensionsr   !key_value.aio.protocols.key_valuer	   key_value.aio.wrappers.baser
   r?   r=   r    r   r   <module>rM      sA    7 7 % & ; 3C$J<)==>dI[ dIr   