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
parent 068c8172
......@@ -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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment