From 25f63cfb30b4171e0286e63bafb78378c5c6dfe4 Mon Sep 17 00:00:00 2001 From: Arvid Ihrig <ihrig@fhi-berlin.mpg.de> Date: Mon, 20 Nov 2017 15:23:58 +0100 Subject: [PATCH] reversed execution order of the free callbacks in the previous commit -onOpen now executes the callback associated with key None AFTER all sections have been opened and section-bound callbacks are executed -onClose now executes the callback associated with key None BEFORE all sections have been closed and section-bound callbacks are executed --- common/python/nomadcore/simple_parser.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/common/python/nomadcore/simple_parser.py b/common/python/nomadcore/simple_parser.py index 3c46500..4d116dc 100644 --- a/common/python/nomadcore/simple_parser.py +++ b/common/python/nomadcore/simple_parser.py @@ -1132,12 +1132,6 @@ class SimpleParser(object): compiledMatcher = self.parserBuilder.compiledMatchers[stateIndex] sects = OrderedDict() - # call the not section-bound onOpen function of the specific matcher - if compiledMatcher.matcher.onOpen: - callback = compiledMatcher.matcher.onOpen.get(None) - if callback: - callback(self.backend, None, None) - for s in compiledMatcher.matcher.sections: gIndex = self.backend.openSection(s) sects[s] = gIndex @@ -1150,11 +1144,23 @@ class SimpleParser(object): section = section_manager.openSections[gIndex] callback(self.backend, gIndex, section) + # call the not section-bound onOpen function of the specific matcher + if compiledMatcher.matcher.onOpen: + callback = compiledMatcher.matcher.onOpen.get(None) + if callback: + callback(self.backend, None, None) + self.context.append(ParsingContext(stateIndex, sects, compiledMatcher, ParsingContext.Start)) def contextClose(self, cNow): if cNow.startEnd == ParsingContext.Start: + # call the not section-bound onClose function of the specific matcher + if cNow.compiledMatcher.matcher.onClose: + callback = cNow.compiledMatcher.matcher.onClose.get(None) + if callback: + callback(self.backend, None, None) + for s, gIndex in reversed(list(cNow.sections.items())): # Call the matcher specific onClose callbacks @@ -1168,12 +1174,6 @@ class SimpleParser(object): # Call the global onClose callbacks self.backend.closeSection(s, gIndex) - # call the not section-bound onClose function of the specific matcher - if cNow.compiledMatcher.matcher.onClose: - callback = cNow.compiledMatcher.matcher.onClose.get(None) - if callback: - callback(self.backend, None, None) - cNow.startEnd = ParsingContext.End return True else: -- GitLab