diff options
Diffstat (limited to 'poezio/core/structs.py')
-rw-r--r-- | poezio/core/structs.py | 81 |
1 files changed, 30 insertions, 51 deletions
diff --git a/poezio/core/structs.py b/poezio/core/structs.py index 72c9628a..31d31339 100644 --- a/poezio/core/structs.py +++ b/poezio/core/structs.py @@ -1,45 +1,20 @@ """ Module defining structures useful to the core class and related methods """ +from __future__ import annotations +from dataclasses import dataclass +from typing import Any, Callable, List, TYPE_CHECKING, Optional + +if TYPE_CHECKING: + from poezio import windows __all__ = [ - 'ERROR_AND_STATUS_CODES', 'DEPRECATED_ERRORS', 'POSSIBLE_SHOW', 'Status', - 'Command', 'Completion' + 'Command', + 'Completion', + 'POSSIBLE_SHOW', + 'Status', ] -# http://xmpp.org/extensions/xep-0045.html#errorstatus -ERROR_AND_STATUS_CODES = { - '401': 'A password is required', - '403': 'Permission denied', - '404': 'The room doesn’t exist', - '405': 'Your are not allowed to create a new room', - '406': 'A reserved nick must be used', - '407': 'You are not in the member list', - '409': 'This nickname is already in use or has been reserved', - '503': 'The maximum number of users has been reached', -} - -# http://xmpp.org/extensions/xep-0086.html -DEPRECATED_ERRORS = { - '302': 'Redirect', - '400': 'Bad request', - '401': 'Not authorized', - '402': 'Payment required', - '403': 'Forbidden', - '404': 'Not found', - '405': 'Not allowed', - '406': 'Not acceptable', - '407': 'Registration required', - '408': 'Request timeout', - '409': 'Conflict', - '500': 'Internal server error', - '501': 'Feature not implemented', - '502': 'Remote server error', - '503': 'Service unavailable', - '504': 'Remote server timeout', - '510': 'Disconnected', -} - POSSIBLE_SHOW = { 'available': None, 'chat': 'chat', @@ -51,23 +26,11 @@ POSSIBLE_SHOW = { } +@dataclass class Status: __slots__ = ('show', 'message') - - def __init__(self, show, message): - self.show = show - self.message = message - - -class Command: - __slots__ = ('func', 'desc', 'comp', 'short_desc', 'usage') - - def __init__(self, func, desc, comp, short_desc, usage): - self.func = func - self.desc = desc - self.comp = comp - self.short_desc = short_desc - self.usage = usage + show: str + message: str class Completion: @@ -76,7 +39,13 @@ class Completion: """ __slots__ = ['func', 'args', 'kwargs', 'comp_list'] - def __init__(self, func, comp_list, *args, **kwargs): + def __init__( + self, + func: Callable[..., Any], + comp_list: List[str], + *args: Any, + **kwargs: Any + ) -> None: self.func = func self.comp_list = comp_list self.args = args @@ -84,3 +53,13 @@ class Completion: def run(self): return self.func(self.comp_list, *self.args, **self.kwargs) + + +@dataclass +class Command: + __slots__ = ('func', 'desc', 'comp', 'short_desc', 'usage') + func: Callable[..., Any] + desc: str + comp: Optional[Callable[['windows.Input'], Completion]] + short_desc: str + usage: str |