From 4e8504bd1d4c3aac6f95ab4091a664131e08dfbc Mon Sep 17 00:00:00 2001 From: nemunaire Date: Fri, 14 Jul 2017 12:20:04 +0200 Subject: [PATCH] xmlparser: Implement update method, as in dict --- nemubot/tools/xmlparser/node.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/nemubot/tools/xmlparser/node.py b/nemubot/tools/xmlparser/node.py index 7df255e..8523771 100644 --- a/nemubot/tools/xmlparser/node.py +++ b/nemubot/tools/xmlparser/node.py @@ -124,9 +124,12 @@ class ModuleState: def setIndex(self, fieldname="name", tagname=None): """Defines an hash table to accelerate childs search. You have just to define a common attribute""" - self.index = self.tmpIndex(fieldname, tagname) self.index_fieldname = fieldname self.index_tagname = tagname + self._updateIndex() + + def _updateIndex(self): + self.index = self.tmpIndex(self.index_fieldname, self.index_tagname) def __contains__(self, i): """Return true if i is found in the index""" @@ -135,6 +138,10 @@ class ModuleState: else: return self.hasAttribute(i) + def update(self, *args, **kwargs): + self.attributes.update(*args, **kwargs) + self._updateIndex() + def hasAttribute(self, name): """DOM like method""" return (name in self.attributes)