def processInput(self, textData): parent = DataObject() tempKey = "" tempValue = "" tracker = "" #tracker options include "", creatingKey, creatingValue tempGroupKey = self.groupKey tempListKey = "" i = 0 while i < len(textData): if textData[i] in self.specialCharacters: if textData[i] == '<': if tracker == "": if textData[i:i + 2] == '</': if textData[i:(i + len(tempListKey) + 3)] == "</" + tempListKey + ">": parent.kind = "list" parent.name = tempListKey i = i + len( tempListKey ) + 2 #there is an i increment by 1 at the bottom self.counter = i return parent elif textData[i:(i + len(tempGroupKey) + 3)] == "</" + tempGroupKey + ">": parent.kind = "group" parent.name = tempGroupKey i = i + len( tempGroupKey ) + 2 #there is an i increment by 1 at the bottom self.counter = i return parent else: tracker = "creatingKey" elif tracker == "creatingValue": if textData[i:i + 2] == '</': if textData[i:(i + len(tempKey) + 3)] == "</" + tempKey + ">": tracker = "" parent.addKeyValue(tempKey, tempValue) i = i + len( tempKey ) + 2 #there is an i increment by 1 at the bottom tempKey = "" tempValue = "" elif textData[i:i + 2] != '</' and tempGroupKey != "": childObject = InputXML(textData[i:], tempKey) child = childObject.processedInput tempKey = "" tracker = "" if child.kind == "group": if self.previousGroupKey != "" and self.previousGroupKey != child.name: self.previousGroupKey = child.name elif self.previousGroupKey == "": self.previousGroupKey = child.name elif self.previousGroupKey == child.name: tempListKey = tempGroupKey i = i + childObject.counter parent.addPair(child) elif textData[i:i + 2] != '</': tempGroupKey = tempKey tempKey = "" tempValue = "" tracker = "" i -= 1 #this is to reset the count so the < is looked at again if textData[i] == '>': if tracker == "creatingKey": tracker = "creatingValue" else: if tracker == "creatingKey": tempKey = tempKey + textData[i] elif tracker == "creatingValue": tempValue = tempValue + textData[i] #+ "*" i += 1 self.counter = i return parent
def processInput(self, textData, tracker = "", tempKey = ""): parent = DataObject() tempValue = "" #tracker options include "", creatingKey, completedKey, creatingValue, creatingList groupListEndTracker = None for i in range (1, len(textData)): if groupListEndTracker == "group": #this is to allow skipping through the part of the input text that is called recursively if textData[i] == "}": groupListEndTracker = None elif groupListEndTracker == "list": #this is to allow skipping through the part of the input text that is called recursively if textData[i] == "]": groupListEndTracker = None elif textData[i] in self.specialCharacters: if textData[i] == '"': if tracker == "": tracker = "creatingKey" elif tracker == "creatingKey": tracker = "completedKey" elif tracker == "completedKey": tracker = "creatingValue" elif tracker == "creatingValue": tracker = "" parent.addKeyValue(tempKey, tempValue) tempKey = "" tempValue = "" else: print('ERROR: Invalid "') elif textData[i] == ",": if tracker == "creatingValue": tracker = "" parent.addKeyValue(tempKey, tempValue) tempKey = "" tempValue = "" elif textData[i] == "{": groupListEndTracker = "group" child = self.processInput(textData[i:]) child.kind = "group" if tracker == "completedKey": tracker = "" child.name = tempKey tempKey = "" parent.addPair(child) elif tracker == "creatingList": groupName = tempKey + "_item" child.name = groupName parent.addPair(child) elif textData[i] == "}": if tracker == "creatingValue": tracker = "" parent.addKeyValue(tempKey, tempValue) tempKey = "" tempValue = "" return parent elif textData[i] == "[": groupListEndTracker = "list" child = self.processInput(textData[i:], "creatingList", tempKey) child.kind = "list" if tracker == "completedKey": tracker = "" child.name = tempKey tempKey = "" parent.addPair(child) elif textData[i] == "]": return parent else: if tracker == "creatingKey": tempKey = tempKey + textData[i] elif tracker == "completedKey": if textData[i] != " ": tracker = "creatingValue" tempValue = tempValue + textData[i] elif tracker == "creatingValue": tempValue = tempValue + textData[i] #+ "*" return parent
def processInput(self, textData): parent = DataObject() tempKey = "" tempValue = "" tracker = "" #tracker options include "", creatingKey, creatingValue tempGroupKey = self.groupKey tempListKey = "" i = 0 while i < len(textData): if textData[i] in self.specialCharacters: if textData[i] == '<': if tracker == "": if textData[i:i+2] == '</': if textData[i:(i+len(tempListKey)+3)] == "</"+ tempListKey +">": parent.kind = "list" parent.name = tempListKey i= i + len(tempListKey) + 2 #there is an i increment by 1 at the bottom self.counter = i return parent elif textData[i:(i+len(tempGroupKey)+3)] == "</"+ tempGroupKey +">": parent.kind = "group" parent.name = tempGroupKey i= i + len(tempGroupKey) + 2 #there is an i increment by 1 at the bottom self.counter = i return parent else: tracker = "creatingKey" elif tracker == "creatingValue": if textData[i:i+2] == '</': if textData[i:(i+len(tempKey)+3)] == "</"+ tempKey +">": tracker = "" parent.addKeyValue(tempKey, tempValue) i = i + len(tempKey) + 2 #there is an i increment by 1 at the bottom tempKey = "" tempValue = "" elif textData[i:i+2] != '</' and tempGroupKey != "": childObject = InputXML(textData[i:], tempKey) child = childObject.processedInput tempKey = "" tracker = "" if child.kind == "group": if self.previousGroupKey != "" and self.previousGroupKey != child.name: self.previousGroupKey = child.name elif self.previousGroupKey == "": self.previousGroupKey = child.name elif self.previousGroupKey == child.name: tempListKey = tempGroupKey i = i + childObject.counter parent.addPair(child) elif textData[i:i+2] != '</': tempGroupKey = tempKey tempKey = "" tempValue = "" tracker = "" i -= 1 #this is to reset the count so the < is looked at again if textData[i] == '>': if tracker == "creatingKey": tracker = "creatingValue" else: if tracker == "creatingKey": tempKey = tempKey + textData[i] elif tracker == "creatingValue": tempValue = tempValue + textData[i] #+ "*" i += 1 self.counter = i return parent