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):
|
||||
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
|
||||
|
||||
async def read(self):
|
||||
content = await self._socket_reader.readuntil(b"\n> ")
|
||||
return content.decode().rstrip().rstrip(">").rstrip()
|
||||
async def auth(self):
|
||||
response = await self.write(f"login {self.username} {self.password}")
|
||||
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())
|
||||
return self.read(wrap=wrap) if read else None
|
||||
|
||||
async def disconnect(self):
|
||||
if self._socket_writer:
|
||||
|
|
Loading…
Reference in a new issue