argenta 0.1.2__py3-none-any.whl → 0.1.3__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/entity.py +35 -35
- argenta/router/entity.py +9 -8
- {argenta-0.1.2.dist-info → argenta-0.1.3.dist-info}/METADATA +1 -1
- {argenta-0.1.2.dist-info → argenta-0.1.3.dist-info}/RECORD +6 -6
- {argenta-0.1.2.dist-info → argenta-0.1.3.dist-info}/LICENSE +0 -0
- {argenta-0.1.2.dist-info → argenta-0.1.3.dist-info}/WHEEL +0 -0
argenta/app/entity.py
CHANGED
@@ -13,56 +13,56 @@ class App:
|
|
13
13
|
prompt: str = 'Enter a command',
|
14
14
|
exit_command: str = 'q',
|
15
15
|
ignore_exit_command_register: bool = True,
|
16
|
-
initial_greeting: str = '
|
17
|
-
|
18
|
-
line_separate: str = '
|
19
|
-
command_group_description_separate: str = '
|
16
|
+
initial_greeting: str = '\nHello, I am Argenta\n',
|
17
|
+
farewell_message: str = 'GoodBye',
|
18
|
+
line_separate: str = '',
|
19
|
+
command_group_description_separate: str = '',
|
20
20
|
print_func: Callable[[str], None] = print) -> None:
|
21
21
|
self.prompt = prompt
|
22
22
|
self.print_func = print_func
|
23
23
|
self.exit_command = exit_command
|
24
24
|
self.ignore_exit_command_register = ignore_exit_command_register
|
25
|
-
self.
|
25
|
+
self.farewell_message = farewell_message
|
26
26
|
self.initial_greeting = initial_greeting
|
27
27
|
self.line_separate = line_separate
|
28
28
|
self.command_group_description_separate = command_group_description_separate
|
29
29
|
|
30
|
-
self.
|
31
|
-
self.
|
32
|
-
self.
|
33
|
-
self._description_message_pattern = '[{command}] *=*=* {description}'
|
30
|
+
self._routers: list[Router] = []
|
31
|
+
self._registered_commands: list[dict[str, str | list[dict[str, Callable[[], None] | str]] | Router]] = []
|
32
|
+
self._main_app_router: Router | None = None
|
33
|
+
self._description_message_pattern: str = '[{command}] *=*=* {description}'
|
34
34
|
|
35
35
|
|
36
36
|
def start_polling(self) -> None:
|
37
37
|
self.print_func(self.initial_greeting)
|
38
|
-
self.
|
38
|
+
self._validate_main_router()
|
39
39
|
|
40
40
|
while True:
|
41
|
-
self.
|
41
|
+
self._print_command_group_description()
|
42
42
|
self.print_func(self.prompt)
|
43
43
|
|
44
44
|
command: str = input()
|
45
45
|
|
46
|
-
self.
|
46
|
+
self._checking_command_for_exit_command(command)
|
47
47
|
self.print_func(self.line_separate)
|
48
48
|
|
49
|
-
is_unknown_command: bool = self.
|
49
|
+
is_unknown_command: bool = self._check_is_command_unknown(command)
|
50
50
|
|
51
51
|
if is_unknown_command:
|
52
52
|
continue
|
53
53
|
|
54
|
-
for router in self.
|
54
|
+
for router in self._routers:
|
55
55
|
router.input_command_handler(command)
|
56
56
|
self.print_func(self.line_separate)
|
57
57
|
self.print_func(self.command_group_description_separate)
|
58
58
|
|
59
59
|
|
60
60
|
def set_initial_greeting(self, greeting: str) -> None:
|
61
|
-
self.initial_greeting = greeting
|
61
|
+
self.initial_greeting: str = greeting
|
62
62
|
|
63
63
|
|
64
|
-
def
|
65
|
-
self.
|
64
|
+
def set_farewell_message(self, message: str) -> None:
|
65
|
+
self.farewell_message: str = message
|
66
66
|
|
67
67
|
|
68
68
|
def set_description_message_pattern(self, pattern: str) -> None:
|
@@ -71,34 +71,34 @@ class App:
|
|
71
71
|
description='description')
|
72
72
|
except KeyError:
|
73
73
|
raise InvalidDescriptionMessagePatternException(pattern)
|
74
|
-
self._description_message_pattern = pattern
|
74
|
+
self._description_message_pattern: str = pattern
|
75
75
|
|
76
76
|
|
77
|
-
def
|
78
|
-
if not self.
|
77
|
+
def _validate_main_router(self):
|
78
|
+
if not self._main_app_router:
|
79
79
|
raise MissingMainRouterException()
|
80
80
|
|
81
|
-
if not self.
|
81
|
+
if not self._main_app_router.unknown_command_func:
|
82
82
|
raise MissingHandlersForUnknownCommandsOnMainRouterException()
|
83
83
|
|
84
|
-
for router in self.
|
85
|
-
if router.unknown_command_func and self.
|
84
|
+
for router in self._routers:
|
85
|
+
if router.unknown_command_func and self._main_app_router is not router:
|
86
86
|
raise HandlerForUnknownCommandsCanOnlyBeDeclaredForMainRouterException()
|
87
87
|
|
88
88
|
|
89
|
-
def
|
89
|
+
def _checking_command_for_exit_command(self, command: str):
|
90
90
|
if command.lower() == self.exit_command.lower():
|
91
91
|
if self.ignore_exit_command_register:
|
92
|
-
self.print_func(self.
|
92
|
+
self.print_func(self.farewell_message)
|
93
93
|
exit(0)
|
94
94
|
else:
|
95
95
|
if command == self.exit_command:
|
96
|
-
self.print_func(self.
|
96
|
+
self.print_func(self.farewell_message)
|
97
97
|
exit(0)
|
98
98
|
|
99
99
|
|
100
|
-
def
|
101
|
-
registered_commands = self.
|
100
|
+
def _check_is_command_unknown(self, command: str):
|
101
|
+
registered_commands: list[dict[str, str | list[dict[str, Callable[[], None] | str]] | Router]] = self._registered_commands
|
102
102
|
for router in registered_commands:
|
103
103
|
for command_entity in router['commands']:
|
104
104
|
if command_entity['command'].lower() == command.lower():
|
@@ -107,14 +107,14 @@ class App:
|
|
107
107
|
else:
|
108
108
|
if command_entity['command'] == command:
|
109
109
|
return False
|
110
|
-
self.
|
110
|
+
self._main_app_router.unknown_command_handler(command)
|
111
111
|
self.print_func(self.line_separate)
|
112
112
|
self.print_func(self.command_group_description_separate)
|
113
113
|
return True
|
114
114
|
|
115
115
|
|
116
|
-
def
|
117
|
-
for router in self.
|
116
|
+
def _print_command_group_description(self):
|
117
|
+
for router in self._registered_commands:
|
118
118
|
self.print_func(router['name'])
|
119
119
|
for command_entity in router['commands']:
|
120
120
|
self.print_func(self._description_message_pattern.format(
|
@@ -130,16 +130,16 @@ class App:
|
|
130
130
|
raise InvalidRouterInstanceException()
|
131
131
|
|
132
132
|
if is_main:
|
133
|
-
if not self.
|
134
|
-
self.
|
133
|
+
if not self._main_app_router:
|
134
|
+
self._main_app_router = router
|
135
135
|
router.set_router_as_main()
|
136
136
|
else:
|
137
137
|
raise OnlyOneMainRouterIsAllowedException(router)
|
138
138
|
|
139
|
-
self.
|
139
|
+
self._routers.append(router)
|
140
140
|
|
141
141
|
registered_commands: list[dict[str, Callable[[], None] | str]] = router.get_registered_commands()
|
142
|
-
self.
|
142
|
+
self._registered_commands.append({'name': router.get_name(),
|
143
143
|
'router': router,
|
144
144
|
'commands': registered_commands})
|
145
145
|
|
argenta/router/entity.py
CHANGED
@@ -9,10 +9,10 @@ class Router:
|
|
9
9
|
name: str,
|
10
10
|
ignore_command_register: bool = False):
|
11
11
|
|
12
|
-
self.ignore_command_register
|
13
|
-
self.
|
12
|
+
self.ignore_command_register = ignore_command_register
|
13
|
+
self.name = name
|
14
14
|
|
15
|
-
self.
|
15
|
+
self._processed_commands: list[dict[str, Callable[[], None] | str]] = []
|
16
16
|
self.unknown_command_func: Callable[[str], None] | None = None
|
17
17
|
self._is_main_router: bool = False
|
18
18
|
|
@@ -24,7 +24,7 @@ class Router:
|
|
24
24
|
raise InvalidDescriptionInstanceException()
|
25
25
|
else:
|
26
26
|
def command_decorator(func):
|
27
|
-
self.
|
27
|
+
self._processed_commands.append({'func': func,
|
28
28
|
'command': command,
|
29
29
|
'description': description})
|
30
30
|
def wrapper(*args, **kwargs):
|
@@ -37,7 +37,7 @@ class Router:
|
|
37
37
|
if self.unknown_command_func is not None:
|
38
38
|
raise UnknownCommandHandlerHasAlreadyBeenCreatedException()
|
39
39
|
|
40
|
-
self.unknown_command_func = func
|
40
|
+
self.unknown_command_func: Callable = func
|
41
41
|
|
42
42
|
def wrapper(*args, **kwargs):
|
43
43
|
return func(*args, **kwargs)
|
@@ -45,7 +45,7 @@ class Router:
|
|
45
45
|
|
46
46
|
|
47
47
|
def input_command_handler(self, input_command):
|
48
|
-
for command_entity in self.
|
48
|
+
for command_entity in self._processed_commands:
|
49
49
|
if input_command.lower() == command_entity['command'].lower():
|
50
50
|
if self.ignore_command_register:
|
51
51
|
return command_entity['func']()
|
@@ -53,6 +53,7 @@ class Router:
|
|
53
53
|
if input_command == command_entity['command']:
|
54
54
|
return command_entity['func']()
|
55
55
|
|
56
|
+
|
56
57
|
def unknown_command_handler(self, unknown_command):
|
57
58
|
self.unknown_command_func(unknown_command)
|
58
59
|
|
@@ -62,9 +63,9 @@ class Router:
|
|
62
63
|
|
63
64
|
|
64
65
|
def get_registered_commands(self) -> list[dict[str, Callable[[], None] | str]]:
|
65
|
-
return self.
|
66
|
+
return self._processed_commands
|
66
67
|
|
67
68
|
|
68
69
|
def get_name(self) -> str:
|
69
|
-
return self.
|
70
|
+
return self.name
|
70
71
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
argenta/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
2
|
argenta/app/__init__.py,sha256=WGPNy7LzkE6vjgRIITFYuJIB96vgDMFPRLOh4SV3R3E,443
|
3
|
-
argenta/app/entity.py,sha256=
|
3
|
+
argenta/app/entity.py,sha256=TTkVvQ2TBRDGacMAbT0R9gUsr6UHYajVrZYnvAIObUU,6008
|
4
4
|
argenta/app/exceptions.py,sha256=IW_o0hfAbsj4aeWifzT7tL3BL-6tBCqm0R9MwMXTIRE,1551
|
5
5
|
argenta/router/__init__.py,sha256=gjneUFVbKVgwil8TbHRvCN89wT_U9CaakSbFmMC_fxk,227
|
6
|
-
argenta/router/entity.py,sha256=
|
6
|
+
argenta/router/entity.py,sha256=_o3jT5RkD5XGDGOlN2LGnHQ3entopr8xVtlWuSBvayw,2549
|
7
7
|
argenta/router/exceptions.py,sha256=iNZIM84oTdiowF-r4RRlfxkN4pjZuGlg8k3vouOZCT0,414
|
8
|
-
argenta-0.1.
|
9
|
-
argenta-0.1.
|
10
|
-
argenta-0.1.
|
11
|
-
argenta-0.1.
|
8
|
+
argenta-0.1.3.dist-info/LICENSE,sha256=zmqoGh2n5rReBv4s8wPxF_gZEZDgauJYSPMuPczgOiU,1082
|
9
|
+
argenta-0.1.3.dist-info/METADATA,sha256=Ts3DIjwtLi7uyiFQ4j9nJ96EsGsIHCBFKpGM17sJtfk,525
|
10
|
+
argenta-0.1.3.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
11
|
+
argenta-0.1.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|