
    J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y)    )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.sentinelNTFc                p   t        t        | 
  |fd|i| t        |      }g }	|r|j	                         ni }
i }|j                  d|j                        x}r||d<   |j                  d|j                        x}r||d<   |	j                  |j                         || _
        |j                  r|j                  j                  dd      n|| _        | j                  t        d      |j                  d      rdnd	| _        | j"                  | j                    d
   j$                  } |j&                  |	fdi ||
ii ||| _        | j(                  j+                  | j                        | _        | j(                  j/                  | j                        | _        || _        | j5                  |       y)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.
        wrap_exceptionsusernamepassword/ Nz'service_name' not providedr   r   z	.sentinelsentinel_kwargs)superr	   __init__r   copygetr   r   extend	locations
key_prefixpathreplaceservice_namer   
startswithtarget_serverdependenciesmoduleSentinelsentinel
master_forstorage	slave_forstorage_slaveuse_replicasinitialize_storage)selfurir!   r,   r   r   r   optionsstorage_uri_optionssentinel_configurationsentinel_optionsparsed_authr   r   sentinel_dep	__class__s                  a/var/www/html/asim.com/backend/venv/lib/python3.12/site-packages/limits/storage/redis_sentinel.pyr   zRedisSentinelStorage.__init__*   s   < 	lD*	
!0	
4;	
 04!#5D?//1"57{{:/B/K/KLL8L&.K
#{{:/B/K/KLL8L&.K
#%%&9&C&CD$ #''  $$,,S"5 	 $$%BCC),)AXw((D,>,>+?y)IJQQ---"
?{?.>?
 )((

 %)MM$<$<T=N=N$O*.--*A*A$BSBS*T($    c                    | j                   dk(  r#| j                  d   j                  j                  S | j                  d   j                  j                  S )Nr   r   )r#   r$   r%   
RedisErrorValkeyError)r.   s    r7   base_exceptionsz$RedisSentinelStorage.base_exceptionsn   sT     !!W, g&--88	
 ""8,33??	
r8   c                N    |r| j                   r| j                  S | j                  S )N)r,   r+   r)   )r.   readonlys     r7   get_connectionz#RedisSentinelStorage.get_connectionx   s!    &.43D3Dt!!W4<<Wr8   )r/   strr!   z
str | Noner,   boolr   z$dict[str, float | str | bool] | Noner   r@   r   rA   r0   zfloat | str | boolreturnNone)rB   z-type[Exception] | tuple[type[Exception], ...])F)r>   rA   rB   r
   )__name__
__module____qualname____doc__STORAGE_SCHEMEr   DEPENDENCIESr	   PREFIXr   propertyr<   r?   __classcell__)r6   s   @r7   r   r      s     '(9:NQ !%.%."5>	L $(!@D&-- %B%B% !B% 	B%
 >B% B% B% &B% 
B%H 
	6
 
X Xr8   r   N)
__future__r   typingr   deprecated.sphinxr   packaging.versionr   limits._storage_schemer   limits.errorsr   limits.storage.redisr	   limits.typingr
   r    r8   r7   <module>rV      sR    "   , % 4 , - % 	DaX< aXaXr8   