From c9a8d9ecd1b01962a085a0c3e5c626f2deada1ea Mon Sep 17 00:00:00 2001 From: Daniil Fajnberg Date: Sun, 13 Feb 2022 19:45:53 +0100 Subject: [PATCH] better placeholders --- src/asyncio_taskpool/exceptions.py | 8 ++++++++ src/asyncio_taskpool/session.py | 13 ++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/asyncio_taskpool/exceptions.py b/src/asyncio_taskpool/exceptions.py index e6e31cc..dbc28df 100644 --- a/src/asyncio_taskpool/exceptions.py +++ b/src/asyncio_taskpool/exceptions.py @@ -55,5 +55,13 @@ class ServerException(Exception): pass +class UnknownTaskPoolClass(ServerException): + pass + + +class NotATaskPool(ServerException): + pass + + class HelpRequested(ServerException): pass diff --git a/src/asyncio_taskpool/session.py b/src/asyncio_taskpool/session.py index b4c069a..70298e8 100644 --- a/src/asyncio_taskpool/session.py +++ b/src/asyncio_taskpool/session.py @@ -5,9 +5,9 @@ from asyncio.streams import StreamReader, StreamWriter from typing import Callable, Optional, Union, TYPE_CHECKING from .constants import CMD, SESSION_PARSER_WRITER, SESSION_MSG_BYTES, CLIENT_INFO -from .exceptions import HelpRequested +from .exceptions import HelpRequested, NotATaskPool, UnknownTaskPoolClass from .helpers import get_first_doc_line, return_or_exception, tasks_str -from .pool import TaskPool, SimpleTaskPool +from .pool import BaseTaskPool, TaskPool, SimpleTaskPool from .session_parser import CommandParser, NUM if TYPE_CHECKING: @@ -67,6 +67,9 @@ class ControlSession: CMD.FUNC_NAME, short_help=get_first_doc_line(self._pool.__class__.func_name.fget) ) + def _add_advanced_commands(self) -> None: + raise NotImplementedError + def _init_parser(self, client_terminal_width: int) -> None: parser_kwargs = { 'prog': '', @@ -76,9 +79,13 @@ class ControlSession: self._parser = CommandParser(**parser_kwargs) self._add_base_commands() if isinstance(self._pool, TaskPool): - pass # TODO + self._add_advanced_commands() elif isinstance(self._pool, SimpleTaskPool): self._add_simple_commands() + elif isinstance(self._pool, BaseTaskPool): + raise UnknownTaskPoolClass(f"No interface defined for {self._pool.__class__.__name__}") + else: + raise NotATaskPool(f"Not a task pool instance: {self._pool}") async def client_handshake(self) -> None: client_info = json.loads((await self._reader.read(SESSION_MSG_BYTES)).decode().strip())