o
    <‘ðiQ  ã                   @   s®   d dl mZmZ d dlmZ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 G dd	„ d	eƒZG d
d„ deƒZG dd„ deƒZe	eeef  ZG dd„ deeƒZdS )é    )ÚABCÚabstractmethod)ÚOptionalÚUnionN)ÚRedisCluster)ÚWeightedList)ÚCircuitBreaker)ÚNumberc                   @   sp   e Zd Zeedefdd„ƒƒZejedefdd„ƒƒZeedee	 fdd„ƒƒZ
e
jedee	 fd	d„ƒƒZ
d
S )ÚAbstractDatabaseÚreturnc                 C   ó   dS )z]The weight of this database in compare to others. Used to determine the database failover to.N© ©Úselfr   r   úU/root/parts/websockify/install/lib/python3.10/site-packages/redis/multidb/database.pyÚweight   ó   zAbstractDatabase.weightr   c                 C   r   )z5Set the weight of this database in compare to others.Nr   ©r   r   r   r   r   r      r   c                 C   r   )z6Health check URL associated with the current database.Nr   r   r   r   r   Úhealth_check_url   r   z!AbstractDatabase.health_check_urlr   c                 C   r   )z>Set the health check URL associated with the current database.Nr   ©r   r   r   r   r   r      r   N)Ú__name__Ú
__module__Ú__qualname__Úpropertyr   Úfloatr   Úsetterr   Ústrr   r   r   r   r   r
      s    r
   c                   @   sz   e Zd Z	ddedee fdd„Zedefdd„ƒZej	defd	d„ƒZedee fd
d„ƒZ
e
j	dee fdd„ƒZ
dS )ÚBaseDatabaseNr   r   c                 C   s   || _ || _d S ©N)Ú_weightÚ_health_check_url)r   r   r   r   r   r   Ú__init__&   s   
zBaseDatabase.__init__r   c                 C   ó   | j S r   ©r   r   r   r   r   r   .   ó   zBaseDatabase.weightc                 C   ó
   || _ d S r   r#   r   r   r   r   r   2   ó   
c                 C   r"   r   ©r    r   r   r   r   r   6   r$   zBaseDatabase.health_check_urlc                 C   r%   r   r'   r   r   r   r   r   :   r&   r   )r   r   r   r   r   r   r!   r   r   r   r   r   r   r   r   r   %   s    ýþ
ýr   c                   @   s€   e Zd ZdZeedeeje	f fdd„ƒƒZ
e
jedeeje	f fdd„ƒƒZ
eedefdd„ƒƒZejed	efd
d„ƒƒZdS )ÚSyncDatabasez5Database with an underlying synchronous redis client.r   c                 C   r   )zThe underlying redis client.Nr   r   r   r   r   ÚclientB   r   zSyncDatabase.clientr)   c                 C   r   )z Set the underlying redis client.Nr   ©r   r)   r   r   r   r)   H   r   c                 C   r   )z)Circuit breaker for the current database.Nr   r   r   r   r   ÚcircuitN   r   zSyncDatabase.circuitr+   c                 C   r   )z1Set the circuit breaker for the current database.Nr   ©r   r+   r   r   r   r+   T   r   N)r   r   r   Ú__doc__r   r   r   ÚredisÚRedisr   r)   r   r   r+   r   r   r   r   r(   ?   s    r(   c                
       s¨   e Zd Z	ddeejef dedede	e
 f‡ fdd„Zedeejef fd	d
„ƒZejdeejef fdd
„ƒZedefdd„ƒZejdefdd„ƒZdd„ Z‡  ZS )ÚDatabaseNr)   r+   r   r   c                    s&   || _ || _| | j_tƒ  ||¡ dS )at  
        Initialize a new Database instance.

        Args:
            client: Underlying Redis client instance for database operations
            circuit: Circuit breaker for handling database failures
            weight: Weight value used for database failover prioritization
            health_check_url: Health check URL associated with the current database
        N)Ú_clientÚ_cbÚdatabaseÚsuperr!   )r   r)   r+   r   r   ©Ú	__class__r   r   r!   _   s   zDatabase.__init__r   c                 C   r"   r   ©r1   r   r   r   r   r)   t   r$   zDatabase.clientc                 C   r%   r   r7   r*   r   r   r   r)   x   r&   c                 C   r"   r   ©r2   r   r   r   r   r+   |   r$   zDatabase.circuitc                 C   r%   r   r8   r,   r   r   r   r+   €   r&   c                 C   s   d| j › d| j› d�S )NzDatabase(client=z	, weight=ú))r)   r   r   r   r   r   Ú__repr__„   s   zDatabase.__repr__r   )r   r   r   r   r.   r/   r   r   r   r   r   r!   r   r)   r   r+   r:   Ú__classcell__r   r   r5   r   r0   ^   s(    ûþýüûr0   )Úabcr   r   Útypingr   r   r.   r   Úredis.data_structurer   Úredis.multidb.circuitr   Úredis.typingr	   r
   r   r(   ÚtupleÚ	Databasesr0   r   r   r   r   Ú<module>   s    