o
    i                     @   sT   d dl mZ d dlmZmZ d dlmZ d dlmZ d dl	m
Z
 G dd de
ZdS )	    )Sequence)AnySupportsFloat)override)AsyncKeyValue)BaseWrapperc                       s  e Zd ZdZefdfdededeee df dedd	f
 fd
dZ	e
d	ddeded	B deeef d	B fddZe
d	ddee ded	B deeeef d	B  fddZe
d	ddeded	B deeeef d	B ed	B f fddZe
d	ddee ded	B deeeeef d	B ed	B f  fddZe
d	d	ddedeeef ded	B ded	B dd	f
ddZe
d	d	ddee deeeef  ded	B deed	B  d	B dd	f
ddZe
d	ddeded	B defd d!Ze
d	ddee ded	B defd"d#Z  ZS )$FallbackWrapperaB  Wrapper that falls back to a secondary store when the primary store fails.

    This wrapper attempts operations on the primary store first. If the operation fails
    with one of the specified exceptions, it automatically falls back to the secondary store.
    This provides high availability and graceful degradation when the primary store is unavailable.

    Note: This wrapper only provides read fallback by default. Writes always go to the primary store.
    For write fallback, consider using write_to_fallback=True, but be aware of potential
    consistency issues.
    Fprimary_key_valuefallback_key_valuefallback_on.write_to_fallbackreturnNc                    s&   || _ || _|| _|| _t   dS )a  Initialize the fallback wrapper.

        Args:
            primary_key_value: The primary store to use.
            fallback_key_value: The fallback store to use when primary fails.
            fallback_on: Tuple of exception types that trigger fallback. Defaults to (Exception,).
            write_to_fallback: If True, write operations also fall back to secondary store.
                               If False (default), write operations only go to primary.
        N)r	   r
   r   r   super__init__)selfr	   r
   r   r   	__class__ m/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/key_value/aio/wrappers/fallback/wrapper.pyr      s
   zFallbackWrapper.__init__)
collectionkeyr   c                   F   z| j j||dI d H W S  | jy"   | jj||dI d H  Y S w N)r   r   )r	   getr   r
   r   r   r   r   r   r   r   -      zFallbackWrapper.getkeysc                   r   N)r   r   )r	   get_manyr   r
   r   r   r   r   r   r   r   4   r   zFallbackWrapper.get_manyc                   r   r   )r	   ttlr   r
   r   r   r   r   r    ;   r   zFallbackWrapper.ttlc                   r   r   )r	   ttl_manyr   r
   r   r   r   r   r!   B   r   zFallbackWrapper.ttl_many)r   r    valuer    c             	      n   | j r*z| jj||||dI d H W S  | jy)   | jj||||dI d H  Y S w | jj||||dI d H S )N)r   r"   r   r    )r   r	   putr   r
   )r   r   r"   r   r    r   r   r   r$   I   s   zFallbackWrapper.putvaluesc             	      r#   )N)r   r%   r   r    )r   r	   put_manyr   r
   )r   r   r%   r   r    r   r   r   r&   S   s   	zFallbackWrapper.put_manyc                   b   | j r&z| jj||dI d H W S  | jy%   | jj||dI d H  Y S w | jj||dI d H S r   )r   r	   deleter   r
   r   r   r   r   r(   d      zFallbackWrapper.deletec                   r'   r   )r   r	   delete_manyr   r
   r   r   r   r   r*   n   r)   zFallbackWrapper.delete_many)__name__
__module____qualname____doc__	Exceptionr   tupletypeboolr   r   strdictr   r   listr   floatr    r!   r   r$   r   r&   r(   intr*   __classcell__r   r   r   r   r   
   sV    .6:B8	"	.r   N)collections.abcr   typingr   r   typing_extensionsr   !key_value.aio.protocols.key_valuer   key_value.aio.wrappers.baser   r   r   r   r   r   <module>   s    