def _startOfSubFile(self, match, line): """ for start of the sub file, we need to add a list element to the current record if it not there reset _curRecord to be a new one, and push old one into the stack """ subFile = match.group("name") logger.debug("Start parsing subFile: %s, %s", subFile, line) while len(self._curStack) > 0: # we are in subfile mode prevSubFile = self._curStack[-1][1] if prevSubFile == subFile: # just continue with more of the same subfile self._curStack[-1][0].setdefault(subFile, []).append(self._curRecord) # append the previous result logger.debug("append previous record the current stack") break else: # this is a different subfile # now check if it is a nested subfile if isSubFileField(prevSubFile, subFile): # this is a nested subFile, push to stack logger.debug("Nested subFile, push to the stack") self._curStack.append((self._curRecord, subFile)) logger.debug("Nested subFile, stack is %s", self._curStack) break else: # this is a different subFile now: logger.debug("different subFile") preStack = self._curStack.pop() logger.debug("Pop stack") preStack[0].setdefault(preStack[1], []).append(self._curRecord) self._curRecord = preStack[0] logger.debug("different subFile, stack is %s", self._curStack) if len(self._curStack) == 0: self._curStack.append( (self._curRecord, subFile) ) # push a tuple, the first is the record, the second is the subFile field # logger.debug('push to stack: %s', self._curStack) self._curRecord = {} self._findKeyValueInLine(match, line, self._curRecord)
def _startOfSubFile(self, match, line): """ for start of the sub file, we need to add a list element to the current record if it not there reset _curRecord to be a new one, and push old one into the stack """ subFile = match.group('name') while self._curStack: # we are in subfile mode prevSubFile = self._curStack[-1][1] if prevSubFile == subFile: # just continue with more of the same subfile # append the previous result self._curStack[-1][0].setdefault(subFile, []).append(self._curRecord) break else: # this is a different subfile, now check if it is a nested subfile if isSubFileField(prevSubFile, subFile): # this is a nested subFile, push to stack self._curStack.append((self._curRecord, subFile)) break else: # this is a different subFile now: preStack = self._curStack.pop() preStack[0].setdefault(preStack[1], []).append(self._curRecord) self._curRecord = preStack[0] if not self._curStack: # push a tuple, the first is the record, the second is the subFile field self._curStack.append((self._curRecord, subFile)) self._curRecord = {} self._findKeyValueInLine(match, line)
def _startOfSubFile(self, match, line): """ for start of the sub file, we need to add a list element to the current record if it not there reset _curRecord to be a new one, and push old one into the stack """ subFile = match.group('name') logger.debug('Start parsing subFile: %s, %s', subFile, line) while len(self._curStack) > 0: # we are in subfile mode prevSubFile = self._curStack[-1][1] if prevSubFile == subFile: # just continue with more of the same subfile self._curStack[-1][0].setdefault(subFile, []).append(self._curRecord) # append the previous result logger.debug('append previous record the current stack') break; else: # this is a different subfile # now check if it is a nested subfile if isSubFileField(prevSubFile, subFile): # this is a nested subFile, push to stack logger.debug('Nested subFile, push to the stack') self._curStack.append((self._curRecord, subFile)) logger.debug('Nested subFile, stack is %s', self._curStack) break; else: # this is a different subFile now: logger.debug('different subFile') preStack = self._curStack.pop() logger.debug('Pop stack') preStack[0].setdefault(preStack[1], []).append(self._curRecord) self._curRecord = preStack[0] logger.debug('different subFile, stack is %s', self._curStack) if len(self._curStack) == 0: self._curStack.append((self._curRecord, subFile)) # push a tuple, the first is the record, the second is the subFile field # logger.debug('push to stack: %s', self._curStack) self._curRecord = {} self._findKeyValueInLine(match, line, self._curRecord)
def _startOfSubFile(self, match, line): """ for start of the sub file, we need to add a list element to the current record if it not there reset _curRecord to be a new one, and push old one into the stack """ subFile = match.group('name') while self._curStack: # we are in subfile mode prevSubFile = self._curStack[-1][1] if prevSubFile == subFile: # just continue with more of the same subfile # append the previous result self._curStack[-1][0].setdefault(subFile, []).append(self._curRecord) break; else: # this is a different subfile, now check if it is a nested subfile if isSubFileField(prevSubFile, subFile): # this is a nested subFile, push to stack self._curStack.append((self._curRecord, subFile)) break else: # this is a different subFile now: preStack = self._curStack.pop() preStack[0].setdefault(preStack[1], []).append(self._curRecord) self._curRecord = preStack[0] if not self._curStack: # push a tuple, the first is the record, the second is the subFile field self._curStack.append((self._curRecord, subFile)) self._curRecord = {} self._findKeyValueInLine(match, line)
def _rewindStack(self): while self._curStack: # we are in subFile Mode if not isSubFileField(self._curStack[-1][1], self._curField): preStack = self._curStack.pop() preStack[0].setdefault(preStack[1], []).append(self._curRecord) self._curRecord = preStack[0] else: break
def _rewindStack(self): while self._curStack: # we are in subFile Mode if not isSubFileField(self._curStack[-1][1], self._curField): preStack = self._curStack.pop() preStack[0].setdefault(preStack[1],[]).append(self._curRecord) self._curRecord = preStack[0] else: break
def _rewindStack(self): logger.debug("rewindStack is called") while len(self._curStack) > 0: # we are in subFile Mode if not isSubFileField(self._curStack[-1][1], self._curField): preStack = self._curStack.pop() # logger.debug('pop previous stack item: %s', preStack) preStack[0].setdefault(preStack[1], []).append(self._curRecord) # logger.debug('reset current record: %s', preStack) self._curRecord = preStack[0] else: logger.debug("in subFile Fields: %s, record: %s", self._curField, self._curRecord) break
def _rewindStack(self): logger.debug('rewindStack is called') while len(self._curStack) > 0: # we are in subFile Mode if not isSubFileField(self._curStack[-1][1], self._curField): preStack = self._curStack.pop() # logger.debug('pop previous stack item: %s', preStack) preStack[0].setdefault(preStack[1],[]).append(self._curRecord) # logger.debug('reset current record: %s', preStack) self._curRecord = preStack[0] else: logger.debug('in subFile Fields: %s, record: %s', self._curField, self._curRecord) break