Wrap responses
This commit is contained in:
parent
3a98541524
commit
4aabaa9d9c
1 changed files with 11 additions and 5 deletions
|
@ -41,15 +41,21 @@ class ReportMonsterClient:
|
||||||
|
|
||||||
async def connect(self):
|
async def connect(self):
|
||||||
self._socket_reader, self._socket_writer = await asyncio.open_connection(self.host, self.port)
|
self._socket_reader, self._socket_writer = await asyncio.open_connection(self.host, self.port)
|
||||||
identification = await self.read()
|
identification = await self.read(wrap=False)
|
||||||
return identification
|
return identification
|
||||||
|
|
||||||
async def read(self):
|
async def auth(self):
|
||||||
content = await self._socket_reader.readuntil(b"\n> ")
|
response = await self.write(f"login {self.username} {self.password}")
|
||||||
return content.decode().rstrip().rstrip(">").rstrip()
|
return response
|
||||||
|
|
||||||
async def write(self, message):
|
async def read(self, wrap=True):
|
||||||
|
content = await self._socket_reader.readuntil(b"\n> ")
|
||||||
|
stripped = content.decode().rstrip().rstrip(">").rstrip()
|
||||||
|
return ReportMonsterResponse(stripped) if wrap else stripped
|
||||||
|
|
||||||
|
async def write(self, message, read=True, wrap=True):
|
||||||
await self._socket_writer.write(message.encode())
|
await self._socket_writer.write(message.encode())
|
||||||
|
return self.read(wrap=wrap) if read else None
|
||||||
|
|
||||||
async def disconnect(self):
|
async def disconnect(self):
|
||||||
if self._socket_writer:
|
if self._socket_writer:
|
||||||
|
|
Loading…
Reference in a new issue