Mercurial > libervia-backend
diff libervia/backend/tools/trigger.py @ 4270:0d7bb4df2343
Reformatted code base using black.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 19 Jun 2024 18:44:57 +0200 |
parents | 4dc00e848961 |
children |
line wrap: on
line diff
--- a/libervia/backend/tools/trigger.py Tue Jun 18 12:06:45 2024 +0200 +++ b/libervia/backend/tools/trigger.py Wed Jun 19 18:44:57 2024 +0200 @@ -33,7 +33,7 @@ class SkipOtherTriggers(Exception): - """ Exception to raise if normal behaviour must be followed instead of following triggers list """ + """Exception to raise if normal behaviour must be followed instead of following triggers list""" pass @@ -62,7 +62,6 @@ # plugins are always avaialble for normal clients return True - def add(self, point_name, callback: Callable, priority=0): """Add a trigger to a point @@ -89,11 +88,7 @@ ) def add_with_check( - self, - point_name: str, - plugin, - callback: Callable, - priority: int=0 + self, point_name: str, plugin, callback: Callable, priority: int = 0 ) -> None: """Like [Add], but check session before running the trigger @@ -109,20 +104,24 @@ @param priority: callback will be called in priority order, biggest first """ if inspect.iscoroutinefunction(callback): + async def async_wrapper(client: SatXMPPEntity, *args, **kwargs): if client.is_component and plugin not in client.plugins: log.debug(f"Ignoring {callback} as parent plugin is not available") return True else: return await callback(client, *args, **kwargs) + self.add(point_name, async_wrapper, priority) else: + def sync_wrapper(client: SatXMPPEntity, *args, **kwargs): if client.is_component and plugin not in client.plugins: log.debug(f"Ignoring {callback} as parent plugin is not available") return True else: return callback(client, *args, **kwargs) + self.add(point_name, sync_wrapper, priority) def remove(self, point_name, callback): @@ -152,7 +151,7 @@ if point_name not in self.__triggers: return True - can_cancel = not kwargs.pop('triggers_no_cancel', False) + can_cancel = not kwargs.pop("triggers_no_cancel", False) for priority, trigger in self.__triggers[point_name]: try: