generated from daniil-berg/boilerplate-py
Fix control server response writes
This commit is contained in:
parent
ee0b8c0002
commit
051d0cb911
@ -22,7 +22,7 @@ copyright = '2022 Daniil Fajnberg'
|
|||||||
author = 'Daniil Fajnberg'
|
author = 'Daniil Fajnberg'
|
||||||
|
|
||||||
# The full version, including alpha/beta/rc tags
|
# The full version, including alpha/beta/rc tags
|
||||||
release = '1.1.3'
|
release = '1.1.4'
|
||||||
|
|
||||||
|
|
||||||
# -- General configuration ---------------------------------------------------
|
# -- General configuration ---------------------------------------------------
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = asyncio-taskpool
|
name = asyncio-taskpool
|
||||||
version = 1.1.3
|
version = 1.1.4
|
||||||
author = Daniil Fajnberg
|
author = Daniil Fajnberg
|
||||||
author_email = mail@daniil.fajnberg.de
|
author_email = mail@daniil.fajnberg.de
|
||||||
description = Dynamically manage pools of asyncio tasks
|
description = Dynamically manage pools of asyncio tasks
|
||||||
|
@ -103,7 +103,7 @@ class ControlSession:
|
|||||||
elif param.kind == param.VAR_POSITIONAL:
|
elif param.kind == param.VAR_POSITIONAL:
|
||||||
var_pos = kwargs.pop(param.name)
|
var_pos = kwargs.pop(param.name)
|
||||||
output = await return_or_exception(method, *normal_pos, *var_pos, **kwargs)
|
output = await return_or_exception(method, *normal_pos, *var_pos, **kwargs)
|
||||||
self._writer.write(CMD_OK if output is None else str(output).encode())
|
self._response_buffer.write(CMD_OK.decode() if output is None else str(output))
|
||||||
|
|
||||||
async def _exec_property_and_respond(self, prop: property, **kwargs) -> None:
|
async def _exec_property_and_respond(self, prop: property, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
@ -122,10 +122,10 @@ class ControlSession:
|
|||||||
if kwargs:
|
if kwargs:
|
||||||
log.debug("%s sets %s.%s", self._client_class_name, self._pool.__class__.__name__, prop.fset.__name__)
|
log.debug("%s sets %s.%s", self._client_class_name, self._pool.__class__.__name__, prop.fset.__name__)
|
||||||
await return_or_exception(prop.fset, self._pool, **kwargs)
|
await return_or_exception(prop.fset, self._pool, **kwargs)
|
||||||
self._writer.write(CMD_OK)
|
self._response_buffer.write(CMD_OK.decode())
|
||||||
else:
|
else:
|
||||||
log.debug("%s gets %s.%s", self._client_class_name, self._pool.__class__.__name__, prop.fget.__name__)
|
log.debug("%s gets %s.%s", self._client_class_name, self._pool.__class__.__name__, prop.fget.__name__)
|
||||||
self._writer.write(str(await return_or_exception(prop.fget, self._pool)).encode())
|
self._response_buffer.write(str(await return_or_exception(prop.fget, self._pool)))
|
||||||
|
|
||||||
async def client_handshake(self) -> None:
|
async def client_handshake(self) -> None:
|
||||||
"""
|
"""
|
||||||
@ -147,8 +147,7 @@ class ControlSession:
|
|||||||
self._parser.add_subparsers(title="Commands",
|
self._parser.add_subparsers(title="Commands",
|
||||||
metavar="(A command followed by '-h' or '--help' will show command-specific help.)")
|
metavar="(A command followed by '-h' or '--help' will show command-specific help.)")
|
||||||
self._parser.add_class_commands(self._pool.__class__)
|
self._parser.add_class_commands(self._pool.__class__)
|
||||||
self._writer.write(str(self._pool).encode())
|
self._writer.write(str(self._pool).encode() + b'\n')
|
||||||
self._writer.write(b'\n')
|
|
||||||
await self._writer.drain()
|
await self._writer.drain()
|
||||||
|
|
||||||
async def _parse_command(self, msg: str) -> None:
|
async def _parse_command(self, msg: str) -> None:
|
||||||
@ -194,9 +193,8 @@ class ControlSession:
|
|||||||
log.debug("%s disconnected", self._client_class_name)
|
log.debug("%s disconnected", self._client_class_name)
|
||||||
break
|
break
|
||||||
await self._parse_command(msg)
|
await self._parse_command(msg)
|
||||||
response = self._response_buffer.getvalue()
|
response = self._response_buffer.getvalue() + "\n"
|
||||||
self._response_buffer.seek(0)
|
self._response_buffer.seek(0)
|
||||||
self._response_buffer.truncate()
|
self._response_buffer.truncate()
|
||||||
self._writer.write(response.encode())
|
self._writer.write(response.encode())
|
||||||
self._writer.write(b'\n')
|
|
||||||
await self._writer.drain()
|
await self._writer.drain()
|
||||||
|
Loading…
Reference in New Issue
Block a user