0
 ñ    ‹      µ”QoÓ0…ß÷+.~à-¹mZ4èœ ÑT¢¢k«®!Äƒ;‰·ÔŽl—2~=NS´€Z`¼$qrrîùîMLŸ¥‹ñúãro×73X¾3›Ž�ˆcÄt�¶†a¯�8™ ¥sõq¿ß‡ûA¨M�ë–n[Ñ:#3rÇIrA›{ÉÐR0îÏ@�t•H¦Š‹¯ s@½sVr1ÄÚè]i¼0°¢ÊÑhípgÚ’�JsqgqSíÄFN±uòÞx4§Íššýâïm�ÙæP¦¹4	u%|a•,TLœ®IBå¶ k²˜ Ì´j˜º™`•‹É§éxñÙë|íæí„2ð!ò˜¼Çó«Eœ’dÎ¶‚";­¹ñšk’Ì˜u°Õ\æRð³âÛV|+¿�7L[M*lfdí¤V�Rôˆ]ÔLW¶fžõ…'(MWÕJøŸºÁ²Ÿš±¼^Mæëtºj[Â‹ÇtOžI–~¥¤ÒˆÌiópdi�Ÿ«�­¯~,á˜ÔÈ¢t$à¤ò	x¹®¸0]Àsh‡°þÐÍ÷K ¨‚Þ« z	ýá(ºø�Éwê^é½êF÷s?½ö3d…ï¬V$é®~=Ïs	ýh4ì�…‰Âþ»ó0ù-âñ/¥xØ(¶ûÎw—]åšÚ    C   ˆl–Ðz¾”ªe¶¥	@ŠãNÜlJbÑ¿�þYi§Vl¢rFÙ–A” þÅ„,¼ÏÄ_ŠI|¥�+Wé3ž¯ÄÃ 4G    import asyncio
import random
import weakref
from typing import AsyncIterator, Iterable, Mapping, Sequence, Tuple, Type

from redis.asyncio.client import Redis
from redis.asyncio.connection import (
    Connection,
    ConnectionPool,
    EncodableT,
    SSLConnection,
)
from redis.commands import AsyncSentinelCommands
from redis.exceptions import ConnectionError, ReadOnlyError, ResponseError, TimeoutError
from redis.utils import str_if_bytes


class MasterNotFoundError(ConnectionError):
    pass


class SlaveNotFoundError(ConnectionError):
    pass


class SentinelManagedConnection(Connection):
    def __init__(self, **kwargs):
        self.connection_pool = kwargs.pop("connection_pool")
        super().__init__(**kwargs)

    def __repr__(self):
        pool = self.connection_pool
        s = f"{self.__class__.__name__}<service={pool.service_name}"
        if self.host:
            host_info = f",host={self.host},port={self.port}"
            s += host_info
        return s + ">"

    async def connect_to(self, address):
        self.host, self.port = address
        await super().connect()
        if self.connection_pool.check_connection:
            await self.send_command("PING")
            if str_if_bytes(await self.read_response()) != "PONG":
                raise ConnectionError("PING failed")

    async def connect(self):
        if self._reader:
            return  # already connected
        if self.connection_pool.is_master:
            await self.connect_to(await self.connection_pool.get_master_address())
        else:
            async for slave in self.connection_pool.rotate_slaves():
                try:
                    return await self.connect_to(slave)
                except ConnectionError:
                    continue
            raise SlaveNotFoundError  # Never be here

    async def read_response(self, disable_decoding: bool = False):
        try:
            return await super().read_response(disable_decoding=disable_decoding)
        except ReadOnlyError:
            if self.connection_pool.is_master:
                # When talking to a master, a ReadOnlyError when likely
                # indicates that the previous master that we're still connected
                # to has been demoted to a slave and there's a new master.
                # calling disconnect will force the connection to re-query
                # sentinel during the next connect() attempt.
                await self.disconnect()
                raise ConnectionError("The previous master is now a slave")
            raise


class SentinelManagedSSLConnection(SentinelManagedConnection, SSLConnection):
    pass


class SentinelConnectionPool(ConnectionPool):
    """
    Sentinel backed connection pool.

    If ``check_connection`` flag is set to True, SentinelManagedConnection
    sends a PING command right after establishing the connection.
    """

    def __init__(self, service_name, sentinel_manager, **kwargs):
        kwargs["connection_class"] = kwargs.get(
            "connection_class",
            SentinelManagedSSLConnection
            if kwargs.pop("ssl", False)
            else SentinelManagedConnection,
        )
        self.is_master = kwargs.pop("is_master", True)
        self.check_connection = kwargs.pop("check_connection", False)
        super().__init__(**kwargs)
        self.connection_kwargs["connection_pool"] = weakref.proxy(self)
        self.service_name = service_name
        self.sentinel_manager = sentinel_manager
 