# Path: aredis/exceptions.py
# class ConnectionError(RedisError):
#     pass
# 
# class TimeoutError(RedisError):
#     pass
# 
# class RedisError(Exception):
#     pass
# 
# class ExecAbortError(ResponseError):
#     pass
# 
# class BusyLoadingError(ConnectionError):
#     pass
# 
# class NoScriptError(ResponseError):
#     pass
# 
# class ReadOnlyError(ResponseError):
#     pass
# 
# class ResponseError(RedisError):
#     pass
# 
# class InvalidResponse(RedisError):
#     pass
# 
# class AskError(ResponseError):
#     """
#     src node: MIGRATING to dst node
#         get > ASK error
#         ask dst node > ASKING command
#     dst node: IMPORTING from src node
#         asking command only affects next command
#         any op will be allowed after asking command
#     """
# 
#     def __init__(self, resp):
#         """should only redirect to master node"""
#         self.args = (resp,)
#         self.message = resp
#         slot_id, new_node = resp.split(' ')
#         host, port = new_node.rsplit(':', 1)
#         self.slot_id = int(slot_id)
#         self.node_addr = self.host, self.port = host, int(port)
# 
# class MovedError(AskError):
#     pass
# 
# class TryAgainError(ResponseError):
# 
#     def __init__(self, *args, **kwargs):
#         pass
# 
# class ClusterDownError(ClusterError, ResponseError):
# 
#     def __init__(self, resp):
#         self.args = (resp,)
#         self.message = resp
# 
# class ClusterCrossSlotError(ResponseError):
#     message = "Keys in request don't hash to the same slot"
# 
# Path: aredis/utils.py
# def b(x):
#     return x.encode('latin-1') if not isinstance(x, bytes) else x
# 
# def nativestr(x):
#     return x if isinstance(x, str) else x.decode('utf-8', 'replace')
# 
# LOOP_DEPRECATED = sys.version_info >= (3, 8)


import asyncio
import inspect
import os
import socket
import ssl
import sys
import time
import warnings
import aredis.compat
    import hiredis
from io import BytesIO
from aredis.exceptions import (ConnectionError, TimeoutError,
                               RedisError, ExecAbortError,
                               BusyLoadingError, NoScriptError,
                               ReadOnlyError, ResponseError,
                               InvalidResponse, AskError,
                               MovedError, TryAgainError,
                               ClusterDownError, ClusterCrossSlotError)
from aredis.utils import b, nativestr, LOOP_DEPRECATED
            await self.connect()
        return self._parser.can_read()

    async def connect(self):
        try:
            await self._connect()
        except aredis.compat.CancelledError:
            raise
        except Exception as exc:
            raise ConnectionError()
        # run any user callbacks. right now the only internal callback
        # is for pubsub channel/pattern resubscription
        for callback in self._connect_callbacks:
            task = callback(self)
            # typing.Awaitable is not available in Python3.5
            # so use inspect.isawaitable instead
            # according to issue https://github.com/NoneGG/aredis/issues/77
            if inspect.isawaitable(task):
                await task

    async def _connect(self):
        raise NotImplementedError

    async def on_connect(self):
        self._parser.on_connect(self)

        # if a password is specified, authenticate
        if self.password:
            await self.send_command('AUTH', self.password)
            if nativestr(await self.read_response()) != 'OK':

# Path: aredis/exceptions.py
# class ConnectionError(RedisError):
#     pass
# 
# class TimeoutError(RedisError):
#     pass
# 
# class RedisError(Exception):
#     pass
# 
# class ExecAbortError(ResponseError):
#     pass
# 
# class BusyLoadingError(ConnectionError):
#     pass
# 
# class NoScriptError(ResponseError):
#     pass
# 
# class ReadOnlyError(ResponseError):
#     pass
# 
# class ResponseError(RedisError):
#     pass
# 
# class InvalidResponse(RedisError):
#     pass
# 
# class AskError(ResponseError):
#     """
#     src node: MIGRATING to dst node
#         get > ASK error
#         ask dst node > ASKING command
#     dst node: IMPORTING from src node
#         asking command only affects next command
#         any op will be allowed after asking command
#     """
# 
#     def __init__(self, resp):
#         """should only redirect to master node"""
#         self.args = (resp,)
#         self.message = resp
#         slot_id, new_node = resp.split(' ')
#         host, port = new_node.rsplit(':', 1)
#         self.slot_id = int(slot_id)
#         self.node_addr = self.host, self.port = host, int(port)
# 
# class MovedError(AskError):
#     pass
# 
# class TryAgainError(ResponseError):
# 
#     def __init__(self, *args, **kwargs):
#         pass
# 
# class ClusterDownError(ClusterError, ResponseError):
# 
#     def __init__(self, resp):
#         self.args = (resp,)
#         self.message = resp
# 
# class ClusterCrossSlotError(ResponseError):
#     message = "Keys in request don't hash to the same slot"
# 
# Path: aredis/utils.py
# def b(x):
#     return x.encode('latin-1') if not isinstance(x, bytes) else x
# 
# def nativestr(x):
#     return x if isinstance(x, str) else x.decode('utf-8', 'replace')
# 
# LOOP_DEPRECATED = sys.version_info >= (3, 8)


# Path: aredis/connection.py
import asyncio
import inspect
import os
import socket
import ssl
import sys
import time
import warnings
import aredis.compat
    import hiredis
from io import BytesIO
from aredis.exceptions import (ConnectionError, TimeoutError,
                               RedisError, ExecAbortError,
                               BusyLoadingError, NoScriptError,
                               ReadOnlyError, ResponseError,
                               InvalidResponse, AskError,
                               MovedError, TryAgainError,
                               ClusterDownError, ClusterCrossSlotError)
from aredis.utils import b, nativestr, LOOP_DEPRECATED

            await self.connect()
        return self._parser.can_read()

    async def connect(self):
        try:
            await self._connect()
        except aredis.compat.CancelledError:
            raise
        except Exception as exc:
            raise ConnectionError()
        # run any user callbacks. right now the only internal callback
        # is for pubsub channel/pattern resubscription
        for callback in self._connect_callbacks:
            task = callback(self)
            # typing.Awaitable is not available in Python3.5
            # so use inspect.isawaitable instead
            # according to issue https://github.com/NoneGG/aredis/issues/77
            if inspect.isawaitable(task):
                await task

    async def _connect(self):
        raise NotImplementedError

    async def on_connect(self):
        self._parser.on_connect(self)

        # if a password is specified, authenticate
        if self.password:
            await self.send_command('AUTH', self.password)
            if nativestr(await self.read_response()) != 'OK':

                raise ConnectionError('Invalid Password')