Allow passing an iterable with keys to subscribe to in EventHandlerBase.__init__()

This commit is contained in:
Kristóf Tóth 2019-05-06 17:11:56 +02:00
parent 90b780a5c0
commit 9ad77eaed8
1 changed files with 7 additions and 1 deletions

View File

@ -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)