# Path: aredis/compat.py

# 
# Path: aredis/exceptions.py
# class PubSubError(RedisError):
#     pass
# 
# class ConnectionError(RedisError):
#     pass
# 
# class TimeoutError(RedisError):
#     pass
# 
# Path: aredis/utils.py
# def list_or_args(keys, args):
#     # returns a single list combining keys and args
#     try:
#         iter(keys)
#         # a string or bytes instance can be iterated, but indicates
#         # keys wasn't passed as a list
#         if isinstance(keys, (str, bytes)):
#             keys = [keys]
#     except TypeError:
#         keys = [keys]
#     if args:
#         keys.extend(args)
#     return keys
# 
# def iteritems(x):
#     return iter(x.items())
# 
# def iterkeys(x):
#     return iter(x.keys())
# 
# def nativestr(x):
#     return x if isinstance(x, str) else x.decode('utf-8', 'replace')


import asyncio
import threading
from aredis.compat import CancelledError
from aredis.exceptions import PubSubError, ConnectionError, TimeoutError
from aredis.utils import (list_or_args,
                          iteritems,
                          iterkeys,
                          nativestr)
        if args:
            args = list_or_args(args[0], args[1:])
        return await self.execute_command('UNSUBSCRIBE', *args)

    async def listen(self):
        """
        Listens for messages on channels this client has been subscribed to
        """
        if self.subscribed:
            return self.handle_message(await self.parse_response(block=True))

    async def get_message(self, ignore_subscribe_messages=False, timeout=0):
        """
        Gets the next message if one is available, otherwise None.

        If timeout is specified, the system will wait for `timeout` seconds
        before returning. Timeout should be specified as a floating point
        number.
        """
        response = await self.parse_response(block=False, timeout=timeout)
        if response:
            return self.handle_message(response, ignore_subscribe_messages)
        return None

    def handle_message(self, response, ignore_subscribe_messages=False):
        """
        Parses a pub/sub message. If the channel or pattern was subscribed to
        with a message handler, the handler is invoked instead of a parsed
        message being returned.
        """

# Path: aredis/compat.py

# 
# Path: aredis/exceptions.py
# class PubSubError(RedisError):
#     pass
# 
# class ConnectionError(RedisError):
#     pass
# 
# class TimeoutError(RedisError):
#     pass
# 
# Path: aredis/utils.py
# def list_or_args(keys, args):
#     # returns a single list combining keys and args
#     try:
#         iter(keys)
#         # a string or bytes instance can be iterated, but indicates
#         # keys wasn't passed as a list
#         if isinstance(keys, (str, bytes)):
#             keys = [keys]
#     except TypeError:
#         keys = [keys]
#     if args:
#         keys.extend(args)
#     return keys
# 
# def iteritems(x):
#     return iter(x.items())
# 
# def iterkeys(x):
#     return iter(x.keys())
# 
# def nativestr(x):
#     return x if isinstance(x, str) else x.decode('utf-8', 'replace')


# Path: aredis/pubsub.py
import asyncio
import threading
from aredis.compat import CancelledError
from aredis.exceptions import PubSubError, ConnectionError, TimeoutError
from aredis.utils import (list_or_args,
                          iteritems,
                          iterkeys,
                          nativestr)

        if args:
            args = list_or_args(args[0], args[1:])
        return await self.execute_command('UNSUBSCRIBE', *args)

    async def listen(self):
        """
        Listens for messages on channels this client has been subscribed to
        """
        if self.subscribed:
            return self.handle_message(await self.parse_response(block=True))

    async def get_message(self, ignore_subscribe_messages=False, timeout=0):
        """
        Gets the next message if one is available, otherwise None.

        If timeout is specified, the system will wait for `timeout` seconds
        before returning. Timeout should be specified as a floating point
        number.
        """
        response = await self.parse_response(block=False, timeout=timeout)
        if response:
            return self.handle_message(response, ignore_subscribe_messages)
        return None

    def handle_message(self, response, ignore_subscribe_messages=False):
        """
        Parses a pub/sub message. If the channel or pattern was subscribed to
        with a message handler, the handler is invoked instead of a parsed
        message being returned.
        """

        message_type = nativestr(response[0])