a
    a *j  ã                   @  st   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mZmZmZ er`G dd	„ d	eƒZdS )
é    )ÚannotationsN)ÚTYPE_CHECKING)ÚVersion)ÚConfigurationError)ÚRedisStorage)ÚOptionalÚRedisClientÚTypeÚUnionc                	      sp   e Zd ZdZdgZedƒedƒdœZddd	d
dd
dddœ‡ fdd„Zeddœdd„ƒZ	dd
ddœdd„Z
‡  ZS )ÚRedisSentinelStorageza
    Rate limit storage with redis sentinel as backend

    Depends on :pypi:`redis` package
    zredis+sentinelz3.0)Úredisúredis.sentinelNTFÚstrzOptional[str]Úboolz,Optional[dict[str, Union[float, str, bool]]]zUnion[float, str, bool]ÚNone)ÚuriÚservice_nameÚuse_replicasÚsentinel_kwargsÚwrap_exceptionsÚoptionsÚreturnc                   s>  t t| ƒj|fd|i|¤Ž tj |¡}g }|r8| ¡ ni }	i }
|jrP|j|
d< |jr`|j|
d< |j	 
d¡d }|j	|d…  d¡D ]$}| d¡\}}| |t|ƒf¡ q„|jr¾|j d	d
¡n|| _| jdu rÖtdƒ‚| 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``
        :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 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   )Úsuperr   Ú__init__ÚurllibÚparseÚurlparseÚcopyr   r   ÚnetlocÚfindÚsplitÚappendÚintÚpathÚreplacer   r   ÚdependenciesÚmoduleZSentinelÚsentinelZ
master_forÚstorageZ	slave_forÚstorage_slaver   Zinitialize_storage)Úselfr   r   r   r   r   r   ÚparsedZsentinel_configurationZsentinel_optionsZparsed_authÚsepÚlocÚhostÚportZsentinel_dep©Ú	__class__© úY/var/www/html/assistant/venv/lib/python3.9/site-packages/limits/storage/redis_sentinel.pyr!      sF    
ÿÿÿ

ÿ
ÿ
þ
ýzRedisSentinelStorage.__init__z3Union[Type[Exception], tuple[Type[Exception], ...]])r   c                 C  s   | j d jjS )Nr   )r-   r.   Z
RedisError)r2   r:   r:   r;   Úbase_exceptions[   s    z$RedisSentinelStorage.base_exceptionsr   )Úreadonlyr   c                 C  s   |r| j r| jS | jS )N)r   r1   r0   )r2   r=   r:   r:   r;   Úget_connectiona   s    z#RedisSentinelStorage.get_connection)NTNF)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ZSTORAGE_SCHEMEr   ZDEPENDENCIESr!   Úpropertyr<   r>   Ú__classcell__r:   r:   r8   r;   r      s       ú ?r   )Ú
__future__r   Úurllib.parser"   Útypingr   Zpackaging.versionr   Zlimits.errorsr   Zlimits.storage.redisr   Zlimits.typingr   r   r	   r
   r   r:   r:   r:   r;   Ú<module>   s   