From 9ad77eaed8653d7bcc9ebfd3d9e366a27d7e6d4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Mon, 6 May 2019 17:11:56 +0200 Subject: [PATCH] Allow passing an iterable with keys to subscribe to in EventHandlerBase.__init__() --- lib/tfw/event_handler_base.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/tfw/event_handler_base.py b/lib/tfw/event_handler_base.py index 6f9819b..beb79a4 100644 --- a/lib/tfw/event_handler_base.py +++ b/lib/tfw/event_handler_base.py @@ -3,6 +3,7 @@ from abc import ABC, abstractmethod from inspect import currentframe +from typing import Iterable from tfw.networking.event_handlers import ServerConnector from tfw.crypto import message_checksum, KeyManager, verify_message @@ -20,7 +21,12 @@ class EventHandlerBase(ABC): """ def __init__(self, key): self.server_connector = ServerConnector() - self.keys = [key] + self.keys = [] + if isinstance(key, str): + self.keys.append(key) + elif isinstance(key, Iterable): + self.keys = list(key) + self.subscribe(*self.keys) self.server_connector.register_callback(self.event_handler_callback)