
    ZeIi                        d dl mZ d dl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 )    )annotationsN)TYPE_CHECKING)versionchanged)Version)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          j                            |          }g }	|r|                                ni }
i }|j        r
|j        |d<   |j        r
|j        |d<   |j	        
                    d          dz   }|j	        |d                             d          D ]>}|                    d          \  }}|	                    |t          |          f           ?|| _        |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@   N,:/ z'service_name' not providedr   r   z	.sentinelr   )superr   __init__urllibparseurlparsecopyr   r    netlocfindsplitappendintr   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   parsedsentinel_configurationsentinel_optionsparsed_authseplochostportsentinel_dep	__class__s                    b/var/www/html/MCyber-Diagnostic/venv/lib/python3.11/site-packages/limits/storage/redis_sentinel.pyr(   zRedisSentinelStorage.__init__*   s@   < 	+lD!!*	
 	
!0	
4;	
 	
 	
 &&s++!#5DL?//111"57? 	6&,oK
#? 	6&,oK
#m  %%)=&,,S11 	= 	=C3JD$"))4T*;<<<<$,2KIFKR(((\ 	 $$%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   )r5   r6   r7   
RedisErrorValkeyError)r?   s    rJ   base_exceptionsz$RedisSentinelStorage.base_exceptionsp   s>     !W,, g&-88"8,3?	
rK   readonlyr	   c                0    |r| j         r| j        n| j        S )N)r   r=   r;   )r?   rQ   s     rJ   get_connectionz#RedisSentinelStorage.get_connectionz   s    &.W43DWt!!4<WrK   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   rL   )F)rQ   r   r   r	   )__name__
__module____qualname____doc__STORAGE_SCHEMEr   DEPENDENCIESr   PREFIXr(   propertyrP   rS   __classcell__)rI   s   @rJ   r   r      s          '(9:NQ !'%..'%.."75>>	 L $(!@D&- %D% D% D% D% D% D% D%L 
 
 
 X
X X X X X X X X XrK   r   )
__future__r   urllib.parser)   typingr   deprecated.sphinxr   packaging.versionr   limits.errorsr   limits.storage.redisr   limits.typingr	   r    rK   rJ   <module>rf      s   " " " " " "                 , , , , , , % % % % % % , , , , , , - - - - - - % % % % % % 	 	D  cX cX cX cX cX< cX cX cX cX cXrK   