1 ''' Asynchronous python bindings for the lircd socket interface. '''
43 from lirc.client import AbstractConnection
as AbstractConnection
46 class AsyncConnection(object):
47 ''' Asynchronous read interface on top of an AbstractConnection.
50 - connection: Typically a lirc.RawConnection or lirc.LircdConnection.
51 - loop: AbstractEventLoop, typically obtained using
52 asyncio.get_event_loop().
55 def __init__(self, connection: AbstractConnection,
56 loop: asyncio.AbstractEventLoop):
59 ''' Read data from the connection fd and put into queue. '''
62 asyncio.ensure_future(self.
_queue.put(line))
64 self.
_conn = connection
67 self.
_loop.add_reader(self.
_conn.fileno(), read_from_fd)
70 ''' Clean up loop and the base connection. '''
74 ''' Asynchronous get next line from the connection. '''
75 return await self.
_queue.get()
78 ''' Return async iterator. '''
82 ''' Implement async iterator.next(). '''
83 return await self.
_queue.get()
86 ''' Implement "async with". '''
89 async
def __aexit__(self, exc_type, exc, traceback):
90 ''' Implement exit from "async with". '''