argenta 0.5.0b0__py3-none-any.whl → 1.0.0a0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- argenta/app/autocompleter/entity.py +32 -7
- argenta/app/defaults.py +4 -1
- argenta/app/dividing_line/models.py +55 -11
- argenta/app/exceptions.py +4 -11
- argenta/app/models.py +231 -108
- argenta/app/registered_routers/entity.py +21 -2
- argenta/command/exceptions.py +12 -0
- argenta/command/flag/defaults.py +4 -1
- argenta/command/flag/models.py +84 -6
- argenta/command/models.py +59 -7
- argenta/orchestrator/__init__.py +4 -0
- argenta/orchestrator/argparser/__init__.py +4 -0
- argenta/orchestrator/argparser/arguments/__init__.py +6 -0
- argenta/orchestrator/argparser/arguments/models.py +55 -0
- argenta/orchestrator/argparser/entity.py +49 -0
- argenta/orchestrator/entity.py +36 -0
- argenta/router/command_handler/entity.py +63 -5
- argenta/router/defaults.py +1 -2
- argenta/router/entity.py +99 -39
- argenta/router/exceptions.py +16 -1
- argenta-1.0.0a0.dist-info/METADATA +1438 -0
- argenta-1.0.0a0.dist-info/RECORD +33 -0
- {argenta-0.5.0b0.dist-info → argenta-1.0.0a0.dist-info}/WHEEL +1 -1
- argenta/router/command_handlers/__init__.py +0 -0
- argenta/router/command_handlers/entity.py +0 -21
- argenta-0.5.0b0.dist-info/METADATA +0 -603
- argenta-0.5.0b0.dist-info/RECORD +0 -29
- {argenta-0.5.0b0.dist-info → argenta-1.0.0a0.dist-info/licenses}/LICENSE +0 -0
argenta/router/entity.py
CHANGED
@@ -1,31 +1,37 @@
|
|
1
|
-
from typing import Callable
|
1
|
+
from typing import Callable
|
2
2
|
from inspect import getfullargspec
|
3
|
-
|
4
|
-
from argenta.command import
|
5
|
-
from argenta.
|
6
|
-
from argenta.
|
7
|
-
from argenta.router.
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
IncorrectNumberOfHandlerArgsException,
|
13
|
-
TriggerCannotContainSpacesException)
|
3
|
+
from src.argenta.command import Command
|
4
|
+
from src.argenta.command.models import InputCommand
|
5
|
+
from src.argenta.router.command_handler.entity import CommandHandlers, CommandHandler
|
6
|
+
from src.argenta.command.flag.models import Flag, Flags, InputFlags
|
7
|
+
from src.argenta.router.exceptions import (RepeatedFlagNameException,
|
8
|
+
TooManyTransferredArgsException,
|
9
|
+
RequiredArgumentNotPassedException,
|
10
|
+
IncorrectNumberOfHandlerArgsException,
|
11
|
+
TriggerContainSpacesException)
|
14
12
|
|
15
13
|
|
16
14
|
class Router:
|
17
15
|
def __init__(self,
|
18
|
-
title: str = None
|
19
|
-
|
16
|
+
title: str = None):
|
17
|
+
"""
|
18
|
+
Public. Directly configures and manages handlers
|
19
|
+
:param title: the title of the router, displayed when displaying the available commands
|
20
|
+
:return: None
|
21
|
+
"""
|
20
22
|
self._title = title
|
21
|
-
self._name = name
|
22
23
|
|
23
24
|
self._command_handlers: CommandHandlers = CommandHandlers()
|
24
25
|
self._ignore_command_register: bool = False
|
25
26
|
self._not_valid_flag_handler: Callable[[Flag], None] = lambda flag: print(f"Undefined or incorrect input flag: {flag.get_string_entity()}{(' '+flag.get_value()) if flag.get_value() else ''}")
|
26
27
|
|
27
28
|
|
28
|
-
def command(self, command: Command) -> Callable
|
29
|
+
def command(self, command: Command) -> Callable:
|
30
|
+
"""
|
31
|
+
Public. Registers handler
|
32
|
+
:param command: Registered command
|
33
|
+
:return: decorated handler as Callable[[Any], Any]
|
34
|
+
"""
|
29
35
|
self._validate_command(command)
|
30
36
|
|
31
37
|
def command_decorator(func):
|
@@ -39,7 +45,12 @@ class Router:
|
|
39
45
|
return command_decorator
|
40
46
|
|
41
47
|
|
42
|
-
def set_invalid_input_flag_handler(self, func):
|
48
|
+
def set_invalid_input_flag_handler(self, func) -> None:
|
49
|
+
"""
|
50
|
+
Public. Registers handler for invalid input flag
|
51
|
+
:param func: registered handler
|
52
|
+
:return: None
|
53
|
+
"""
|
43
54
|
processed_args = getfullargspec(func).args
|
44
55
|
if len(processed_args) != 1:
|
45
56
|
raise IncorrectNumberOfHandlerArgsException()
|
@@ -47,20 +58,30 @@ class Router:
|
|
47
58
|
self._not_valid_flag_handler = func
|
48
59
|
|
49
60
|
|
50
|
-
def
|
61
|
+
def finds_appropriate_handler(self, input_command: InputCommand) -> None:
|
62
|
+
"""
|
63
|
+
Private. Finds the appropriate handler for given input command and passes control to it
|
64
|
+
:param input_command: input command as InputCommand
|
65
|
+
:return: None
|
66
|
+
"""
|
51
67
|
input_command_name: str = input_command.get_trigger()
|
52
68
|
input_command_flags: InputFlags = input_command.get_input_flags()
|
53
69
|
|
54
70
|
for command_handler in self._command_handlers:
|
55
71
|
handle_command = command_handler.get_handled_command()
|
56
72
|
if input_command_name.lower() == handle_command.get_trigger().lower():
|
57
|
-
self.
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
73
|
+
self.process_input_command(input_command_flags, command_handler)
|
74
|
+
if input_command_name.lower() in handle_command.get_aliases():
|
75
|
+
self.process_input_command(input_command_flags, command_handler)
|
76
|
+
|
77
|
+
|
78
|
+
def process_input_command(self, input_command_flags: InputFlags, command_handler: CommandHandler) -> None:
|
79
|
+
"""
|
80
|
+
Private. Processes input command with the appropriate handler
|
81
|
+
:param input_command_flags: input command flags as InputFlags
|
82
|
+
:param command_handler: command handler for input command as CommandHandler
|
83
|
+
:return: None
|
84
|
+
"""
|
64
85
|
handle_command = command_handler.get_handled_command()
|
65
86
|
if handle_command.get_registered_flags().get_flags():
|
66
87
|
if input_command_flags.get_flags():
|
@@ -79,9 +100,15 @@ class Router:
|
|
79
100
|
return
|
80
101
|
|
81
102
|
|
82
|
-
def _validate_input_flags(self,
|
103
|
+
def _validate_input_flags(self, handled_command: Command, input_flags: InputFlags) -> bool:
|
104
|
+
"""
|
105
|
+
Private. Validates flags of input command
|
106
|
+
:param handled_command: entity of the handled command
|
107
|
+
:param input_flags:
|
108
|
+
:return: is flags of input command valid as bool
|
109
|
+
"""
|
83
110
|
for flag in input_flags:
|
84
|
-
is_valid =
|
111
|
+
is_valid: bool = handled_command.validate_input_flag(flag)
|
85
112
|
if not is_valid:
|
86
113
|
self._not_valid_flag_handler(flag)
|
87
114
|
return False
|
@@ -89,10 +116,15 @@ class Router:
|
|
89
116
|
|
90
117
|
|
91
118
|
@staticmethod
|
92
|
-
def _validate_command(command: Command):
|
119
|
+
def _validate_command(command: Command) -> None:
|
120
|
+
"""
|
121
|
+
Private. Validates the command registered in handler
|
122
|
+
:param command: validated command
|
123
|
+
:return: None if command is valid else raise exception
|
124
|
+
"""
|
93
125
|
command_name: str = command.get_trigger()
|
94
126
|
if command_name.find(' ') != -1:
|
95
|
-
raise
|
127
|
+
raise TriggerContainSpacesException()
|
96
128
|
|
97
129
|
flags: Flags = command.get_registered_flags()
|
98
130
|
if flags:
|
@@ -102,7 +134,13 @@ class Router:
|
|
102
134
|
|
103
135
|
|
104
136
|
@staticmethod
|
105
|
-
def _validate_func_args(command: Command, func: Callable):
|
137
|
+
def _validate_func_args(command: Command, func: Callable) -> None:
|
138
|
+
"""
|
139
|
+
Private. Validates the arguments of the handler
|
140
|
+
:param command: registered command in handler
|
141
|
+
:param func: entity of the handler func
|
142
|
+
:return: None if func is valid else raise exception
|
143
|
+
"""
|
106
144
|
registered_args = command.get_registered_flags()
|
107
145
|
transferred_args = getfullargspec(func).args
|
108
146
|
if registered_args.get_flags() and transferred_args:
|
@@ -114,18 +152,31 @@ class Router:
|
|
114
152
|
raise TooManyTransferredArgsException()
|
115
153
|
|
116
154
|
|
117
|
-
def
|
118
|
-
|
155
|
+
def set_command_register_ignore(self, _: bool) -> None:
|
156
|
+
"""
|
157
|
+
Private. Sets the router behavior on the input commands register
|
158
|
+
:param _: is command register ignore
|
159
|
+
:return: None
|
160
|
+
"""
|
161
|
+
self._ignore_command_register = _
|
119
162
|
|
120
163
|
|
121
|
-
def get_triggers(self):
|
164
|
+
def get_triggers(self) -> list[str]:
|
165
|
+
"""
|
166
|
+
Public. Gets registered triggers
|
167
|
+
:return: registered in router triggers as list[str]
|
168
|
+
"""
|
122
169
|
all_triggers: list[str] = []
|
123
170
|
for command_handler in self._command_handlers:
|
124
171
|
all_triggers.append(command_handler.get_handled_command().get_trigger())
|
125
172
|
return all_triggers
|
126
173
|
|
127
174
|
|
128
|
-
def get_aliases(self):
|
175
|
+
def get_aliases(self) -> list[str]:
|
176
|
+
"""
|
177
|
+
Public. Gets registered aliases
|
178
|
+
:return: registered in router aliases as list[str]
|
179
|
+
"""
|
129
180
|
all_aliases: list[str] = []
|
130
181
|
for command_handler in self._command_handlers:
|
131
182
|
if command_handler.get_handled_command().get_aliases():
|
@@ -134,16 +185,25 @@ class Router:
|
|
134
185
|
|
135
186
|
|
136
187
|
def get_command_handlers(self) -> CommandHandlers:
|
188
|
+
"""
|
189
|
+
Private. Gets registered command handlers
|
190
|
+
:return: registered command handlers as CommandHandlers
|
191
|
+
"""
|
137
192
|
return self._command_handlers
|
138
193
|
|
139
194
|
|
140
|
-
def get_name(self) -> str:
|
141
|
-
return self._name
|
142
|
-
|
143
|
-
|
144
195
|
def get_title(self) -> str | None:
|
196
|
+
"""
|
197
|
+
Public. Gets title of the router
|
198
|
+
:return: the title of the router as str or None
|
199
|
+
"""
|
145
200
|
return self._title
|
146
201
|
|
147
202
|
|
148
|
-
def set_title(self, title: str):
|
203
|
+
def set_title(self, title: str) -> None:
|
204
|
+
"""
|
205
|
+
Public. Sets the title of the router
|
206
|
+
:param title: title that will be setted
|
207
|
+
:return: None
|
208
|
+
"""
|
149
209
|
self._title = title
|
argenta/router/exceptions.py
CHANGED
@@ -1,23 +1,38 @@
|
|
1
1
|
class RepeatedFlagNameException(Exception):
|
2
|
+
"""
|
3
|
+
Private. Raised when a repeated flag name is registered
|
4
|
+
"""
|
2
5
|
def __str__(self):
|
3
6
|
return "Repeated registered_flag name in register command"
|
4
7
|
|
5
8
|
|
6
9
|
class TooManyTransferredArgsException(Exception):
|
10
|
+
"""
|
11
|
+
Private. Raised when too many arguments are passed
|
12
|
+
"""
|
7
13
|
def __str__(self):
|
8
14
|
return "Too many transferred arguments"
|
9
15
|
|
10
16
|
|
11
17
|
class RequiredArgumentNotPassedException(Exception):
|
18
|
+
"""
|
19
|
+
Private. Raised when a required argument is not passed
|
20
|
+
"""
|
12
21
|
def __str__(self):
|
13
22
|
return "Required argument not passed"
|
14
23
|
|
15
24
|
|
16
25
|
class IncorrectNumberOfHandlerArgsException(Exception):
|
26
|
+
"""
|
27
|
+
Private. Raised when incorrect number of arguments are passed
|
28
|
+
"""
|
17
29
|
def __str__(self):
|
18
30
|
return "Handler has incorrect number of arguments"
|
19
31
|
|
20
32
|
|
21
|
-
class
|
33
|
+
class TriggerContainSpacesException(Exception):
|
34
|
+
"""
|
35
|
+
Private. Raised when there is a space in the trigger being registered
|
36
|
+
"""
|
22
37
|
def __str__(self):
|
23
38
|
return "Command trigger cannot contain spaces"
|