From 7ae8328899d6c9e6b01b630319c5a2422292878e Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 6 Sep 2018 12:31:47 +0200 Subject: [PATCH] Adding method merge to class ModuleInfoDict --- lib/webhooks/module_list.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/webhooks/module_list.py b/lib/webhooks/module_list.py index b07d236..499e015 100644 --- a/lib/webhooks/module_list.py +++ b/lib/webhooks/module_list.py @@ -32,7 +32,7 @@ from .obj import BaseObject from .module_info import ModuleInfo -__version__ = '0.1.2' +__version__ = '0.1.3' LOG = logging.getLogger(__name__) @@ -131,6 +131,22 @@ class ModuleInfoDict(MutableMapping, BaseObject): del self._map[full_name] + # ------------------------------------------------------------------------- + def merge(self, item): + + if not isinstance(item, ModuleInfo): + raise TypeError(self.msg_invalid_modinfo_type.format(item.__class__.__name__)) + + full_name = item.full_name + if full_name in self._map.keys(): + if self.verbose > 2: + LOG.debug("Merging module {!r}.".format(full_name)) + self._map[full_name].merge_in(item) + else: + if self.verbose > 2: + LOG.debug("New module {!r}.".format(full_name)) + self._set_item(full_name, item) + # ------------------------------------------------------------------------- # The next five methods are requirements of the ABC. def __setitem__(self, key, value): @@ -169,6 +185,9 @@ class ModuleInfoDict(MutableMapping, BaseObject): if full_name == '': raise ValueError(self.msg_empty_key_error.format(key)) + if self.verbose > 4: + LOG.debug("Searching for key {!r} ...".format(key)) + return full_name in self._map # ------------------------------------------------------------------------- -- 2.39.5