explicit-python 2.3.0__py3-none-any.whl → 2.3.1__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.
@@ -10,6 +10,8 @@ from pydantic.main import BaseModel
10
10
 
11
11
  from explicit.domain import HasUnsetValues
12
12
 
13
+ from .exceptions import NoHandlerError
14
+
13
15
 
14
16
  class Command(HasUnsetValues, BaseModel):
15
17
 
@@ -78,6 +80,7 @@ class CommandBusMixin(ABC):
78
80
 
79
81
  def add_command_handler(self, command: Type[Command], handler: CommandHandler) -> None:
80
82
  """Регистрация обработчика команды."""
83
+
81
84
  assert issubclass(command, Command)
82
85
  assert callable(handler)
83
86
  self._command_handlers[command] = handler
@@ -87,14 +90,16 @@ class CommandBusMixin(ABC):
87
90
  *handlers: Tuple[Type[Command], CommandHandler]
88
91
  ) -> None:
89
92
  """Регистрация обработчиков команд."""
93
+
90
94
  for command, handler in handlers:
91
95
  self.add_command_handler(command, handler)
92
96
 
93
97
  def handle_command(self, command: Command):
94
- """Передача запроса обработчику типа данного команды."""
98
+ """Передача запроса обработчику типа данной команды."""
95
99
 
96
100
  assert isinstance(command, Command)
97
- try:
98
- return self._command_handlers[type(command)](command)
99
- except KeyError as e:
100
- raise ValueError(f'No handler for {type(command)}') from e
101
+ handler = self._command_handlers.get(type(command))
102
+ if handler is None:
103
+ raise NoHandlerError(type(command))
104
+
105
+ return handler(command)
@@ -0,0 +1,8 @@
1
+ from typing import Any
2
+
3
+
4
+ class NoHandlerError(ValueError):
5
+ """Обработчик для данного сообщения не зарегистрирован."""
6
+
7
+ def __init__(self, message_cls: type[Any], *args, **kwargs):
8
+ super().__init__(f'No handler for {message_cls}', *args, **kwargs)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: explicit-python
3
- Version: 2.3.0
3
+ Version: 2.3.1
4
4
  Summary: Набор компонентов для построения многослойной архитектуры
5
5
  Author: BARS Group
6
6
  Author-email: education_dev@bars-open.ru
@@ -18,13 +18,14 @@ explicit/domain/types.py,sha256=CTC-CV4aRXQvJ1hy0LOAOtkDnJA7MTTMEw6UHBFKGL0,994
18
18
  explicit/domain/validation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  explicit/domain/validation/exceptions.py,sha256=qHmLuFnsrweNDXGTkG2baPmMYcjkDdgQefANrq1xwx8,5055
20
20
  explicit/messagebus/__init__.py,sha256=u5D-bx-IqhG1LFv-78RGK9Tgbv-uPQL_bQgDr586GsM,126
21
- explicit/messagebus/commands.py,sha256=5kEoL23ZaYLRuUdwrurNBmwZL7Ss5TgQaulbn0he8Mc,3147
21
+ explicit/messagebus/commands.py,sha256=418gVurePuNbzZyE91wtitmhwgWMKRo--r6qL-HHiO4,3176
22
22
  explicit/messagebus/dependency_injection.py,sha256=wOYcixyW-8bn4Bd0IZfdahPWUkF8UACG0wm3PN9S95o,2578
23
23
  explicit/messagebus/events.py,sha256=BKAqEqIC_V6sYMeHZQpAZBsigf9NanSgGZVTJlKX3-I,3487
24
+ explicit/messagebus/exceptions.py,sha256=fIOKFd-YAN5j3UA555W4dFjYwU4pmUa_HlqOX2Z8haM,309
24
25
  explicit/messagebus/messagebus.py,sha256=Yc55SCvCQjS1F5fZtLpjjDOFes7P6gXb5uFo7xeXRw4,3071
25
26
  explicit/messagebus/queries.py,sha256=kMtT8Bm2YeZbrORAIqq0unou1V2XBz8hvLPXmmzHP_4,1616
26
- explicit_python-2.3.0.dist-info/METADATA,sha256=Do8drNf2qwpsYdfkmxP3ziTN2UZ_3IjEEaTk7wQBp1s,13004
27
- explicit_python-2.3.0.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
28
- explicit_python-2.3.0.dist-info/dependency_links.txt,sha256=z2Fi-sEElLMsunjPT4vpjRUYQ4oGu_tX_9NeLaEKlgo,44
29
- explicit_python-2.3.0.dist-info/top_level.txt,sha256=tt6T8l4Yji4ww87qZQcD4CbcwTIHy7NAPmU7QAfMcpY,9
30
- explicit_python-2.3.0.dist-info/RECORD,,
27
+ explicit_python-2.3.1.dist-info/METADATA,sha256=THSd0qsC7o6VqOJpCd6GKwTzRunJ2Q_h9FVsOu8RnS8,13004
28
+ explicit_python-2.3.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
29
+ explicit_python-2.3.1.dist-info/dependency_links.txt,sha256=z2Fi-sEElLMsunjPT4vpjRUYQ4oGu_tX_9NeLaEKlgo,44
30
+ explicit_python-2.3.1.dist-info/top_level.txt,sha256=tt6T8l4Yji4ww87qZQcD4CbcwTIHy7NAPmU7QAfMcpY,9
31
+ explicit_python-2.3.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (77.0.3)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5