Example #1
0
    async def connect(self, host, port=6600, loop=None):
        self.__loop = loop

        if "/" in host:
            r, w = await asyncio.open_unix_connection(host, loop=loop)
        else:
            r, w = await asyncio.open_connection(host, port, loop=loop)
        self.__rfile, self.__wfile = r, w

        self.__commandqueue = asyncio.Queue(loop=loop)
        self.__idle_results = asyncio.Queue(
            loop=loop)  #: a queue of CommandResult("idle") futures
        self.__idle_consumers = [
        ]  #: list of (subsystem-list, callbacks) tuples

        try:
            helloline = await asyncio.wait_for(self.__readline(), timeout=5)
        except asyncio.TimeoutError:
            self.disconnect()
            raise ConnectionError(
                "No response from server while reading MPD hello")
        # FIXME should be reusable w/o reaching in
        SyncMPDClient._hello(self, helloline)

        self.__run_task = asyncio.Task(self.__run())
        self.__idle_task = asyncio.Task(self.__distribute_idle_results())
Example #2
0
    async def connect(self, host, port=6600, loop=None):
        if "/" in host:
            r, w = await asyncio.open_unix_connection(host, loop=loop)
        else:
            r, w = await asyncio.open_connection(host, port, loop=loop)
        self.__rfile, self.__wfile = r, w

        self.__command_queue = asyncio.Queue(maxsize=self.COMMAND_QUEUE_LENGTH)
        self.__idle_consumers = []  #: list of (subsystem-list, callbacks) tuples

        try:
            helloline = await asyncio.wait_for(self.__readline(), timeout=5)
        except asyncio.TimeoutError:
            self.disconnect()
            raise ConnectionError("No response from server while reading MPD hello")
        # FIXME should be reusable w/o reaching in
        SyncMPDClient._hello(self, helloline)

        self.__run_task = asyncio.Task(self.__run())
Example #3
0
    async def connect(self, host, port=6600, loop=None):
        self.__loop = loop

        if '/' in host:
            r, w = await asyncio.open_unix_connection(host, loop=loop)
        else:
            r, w = await asyncio.open_connection(host, port, loop=loop)
        self.__rfile, self.__wfile = r, w

        self.__commandqueue = asyncio.Queue(loop=loop)
        self.__idle_results = asyncio.Queue(loop=loop) #: a queue of CommandResult("idle") futures
        self.__idle_consumers = [] #: list of (subsystem-list, callbacks) tuples

        try:
            helloline = await asyncio.wait_for(self.__readline(), timeout=5)
        except asyncio.TimeoutError:
            self.disconnect()
            raise ConnectionError("No response from server while reading MPD hello")
        # FIXME should be reusable w/o reaching in
        SyncMPDClient._hello(self, helloline)

        self.__run_task = asyncio.Task(self.__run())
        self.__idle_task = asyncio.Task(self.__distribute_idle_results())
Example #4
0
def create_mpd_client(*args, **kwargs):
    client = MPDClient(*args, **kwargs)

    _customize(client)

    return client