
    i                        d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ er	  ed	d
           G d de                      ZdS )    )annotations)TYPE_CHECKING)versionchanged)Version)parse_storage_uri)ConfigurationError)RedisStorage)RedisClientz4.3zuAdded support for using the redis client from :pypi:`valkey` if :paramref:`uri` has the ``valkey+sentinel://`` schema)versionreasonc                       e Zd ZdZddgZ	  ed           ed           ed           ed          dZdddej        d	fd fdZ	e
dd            Zd d!dZ xZS )"RedisSentinelStoragez
    Rate limit storage with redis sentinel as backend

    Depends on :pypi:`redis` package (or :pypi:`valkey` if :paramref:`uri` starts with
    ``valkey+sentinel://``)
    zredis+sentinelzvalkey+sentinelz3.0z6.0)rediszredis.sentinelvalkeyzvalkey.sentinelNTFuristrservice_name
str | Noneuse_replicasboolsentinel_kwargs$dict[str, float | str | bool] | None
key_prefixwrap_exceptionsoptionsfloat | str | boolreturnNonec                ^    t          t          |           j        |fd|i| t          |          }g }	|r|                                ni }
i }|                    d|j                  x}r||d<   |                    d|j                  x}r||d<   |	                    |j	                   || _
        |j        r|j                            dd          n|| _        | j        t          d          |                    d          rdnd	| _        | j        | j         d
         j        } |j        |	fdi ||
ii ||| _        | j                            | j                  | _        | j                            | j                  | _        || _        |                     |           dS )a  
        :param uri: url of the form
         ``redis+sentinel://host:port,host:port/service_name``

         If the uri scheme is ``valkey+sentinel`` the implementation used will be from
         :pypi:`valkey`.
        :param service_name: sentinel service name
         (if not provided in :attr:`uri`)
        :param use_replicas: Whether to use replicas for read only operations
        :param sentinel_kwargs: kwargs to pass as
         :attr:`sentinel_kwargs` to :class:`redis.sentinel.Sentinel`
        :param key_prefix: the prefix for each key created in redis
        :param wrap_exceptions: Whether to wrap storage exceptions in
         :exc:`limits.errors.StorageError` before raising it.
        :param options: all remaining keyword arguments are passed
         directly to the constructor of :class:`redis.sentinel.Sentinel`
        :raise ConfigurationError: when the redis library is not available
         or if the redis master host cannot be pinged.
        r   usernamepassword/ Nz'service_name' not providedr   r   z	.sentinelr   )superr	   __init__r   copygetr    r!   extend	locationsr   pathreplacer   r   
startswithtarget_serverdependenciesmoduleSentinelsentinel
master_forstorage	slave_forstorage_slaver   initialize_storage)selfr   r   r   r   r   r   r   storage_uri_optionssentinel_configurationsentinel_optionsparsed_authr    r!   sentinel_dep	__class__s                  m/var/www/html/crypto-mining-system/backend/venv/lib/python3.11/site-packages/limits/storage/redis_sentinel.pyr%   zRedisSentinelStorage.__init__*   s   < 	+lD!!*	
 	
!0	
4;	
 	
 	
 044!#5DL?//111"57{{:/B/KLLL8 	/&.K
#{{:/B/KLLL8 	/&.K
#%%&9&CDDD$ #'$,,S"555 	 $$%BCCC),)A)ANXXw(D,>)I)I)IJQ--"
 
?{?.>?
 )((
 

 %)M$<$<T=N$O$O*.-*A*A$BS*T*T($$$$$    -type[Exception] | tuple[type[Exception], ...]c                t    | j         dk    r| j        d         j        j        n| j        d         j        j        S )Nr   r   )r-   r.   r/   
RedisErrorValkeyError)r7   s    r>   base_exceptionsz$RedisSentinelStorage.base_exceptionsn   s>     !W,, g&-88"8,3?	
r?   readonlyr
   c                0    |r| j         r| j        n| j        S )N)r   r5   r3   )r7   rE   s     r>   get_connectionz#RedisSentinelStorage.get_connectionx   s    &.W43DWt!!4<Wr?   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r@   )F)rE   r   r   r
   )__name__
__module____qualname____doc__STORAGE_SCHEMEr   DEPENDENCIESr	   PREFIXr%   propertyrD   rG   __classcell__)r=   s   @r>   r   r      s          '(9:NQ !'%..'%.."75>>	 L $(!@D&- %B% B% B% B% B% B% B%H 
 
 
 X
X X X X X X X X Xr?   r   N)
__future__r   typingr   deprecated.sphinxr   packaging.versionr   limits._storage_schemer   limits.errorsr   limits.storage.redisr	   limits.typingr
   r    r?   r>   <module>rZ      s   " " " " " "             , , , , , , % % % % % % 4 4 4 4 4 4 , , , , , , - - - - - - % % % % % % 	 	D  aX aX aX aX aX< aX aX aX aX aXr?   