From 19eb14489e13f3deb6529cb8994782e078b75fb4 Mon Sep 17 00:00:00 2001 From: Jacob Daniel Bennett Date: Tue, 29 Sep 2020 09:56:15 -0400 Subject: [PATCH] Section parsing accounts for nested delimiters (and ignores them) in replies from users --- api/ECNQueue.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/api/ECNQueue.py b/api/ECNQueue.py index 77b4d50..ca934d6 100644 --- a/api/ECNQueue.py +++ b/api/ECNQueue.py @@ -189,13 +189,13 @@ def __parseSections(self) -> list: if self.__rawItem[contentStart] == "\n" and self.__rawItem[contentStart + 1].startswith("\tName:"): # List of lines in the directory info - rawDirectoryInfo = self.__rawItem[contentStart + 1: contentStart + 13] + # rawDirectoryInfo = self.__rawItem[contentStart + 1: contentStart + 13] # Parses the directory information and returns a dictionary of directory values directoryInfo["content"] = self.__directoryParsing(contentStart + 1) # Sets the initial message start to the next line after all directory lines and newlines - contentStart = contentStart + 14 + contentStart = contentStart + len(directoryInfo["content"]) + 2 else: @@ -208,6 +208,9 @@ def __parseSections(self) -> list: # Find line numbers where sections start sectionBoundaries = [ {"start": contentStart} ] + # Used for checking nested reply from user and other delimiters + replyFromUserNum = 0 + # Parses the entire contents of the message, stores everything before any delimiter as the initial message for lineNumber in range(contentStart, contentEnd + 1): @@ -218,8 +221,23 @@ def __parseSections(self) -> list: # Signifies that the inital message has been copletely parsed endInitialMessage = True - # Stores what line every delimeter starts/ends - sectionBoundaries.append({"start": lineNumber}) + if replyFromUserNum == 0 and line.startswith("===") and not line.startswith("===="): + + # Stores what line every delimeter starts/ends + sectionBoundaries.append({"start": lineNumber}) + + replyFromUserNum = replyFromUserNum + 1 + + elif replyFromUserNum != 0 and line.startswith("===") and not line.startswith("===="): + replyFromUserNum = replyFromUserNum + 1 + + elif replyFromUserNum == 0: + + sectionBoundaries.append({"start": lineNumber}) + + elif line.startswith("===="): + + replyFromUserNum = replyFromUserNum - 1 elif endInitialMessage == False: @@ -454,6 +472,7 @@ def __directoryParsing(self, directoryStartLine: int) -> dict: key, value = strippedInfo.split(":") directoryInformation[key] = value + directoryEndingLine = directoryEndingLine + 1 return directoryInformation @@ -806,9 +825,3 @@ def getQueues() -> list: return queues -if __name__ == "__main__": - item = Item("ce", 100) - print() -# for queue in getQueues(): -# for item in queue.items: -# print(f"${item.queue} ${item.number}") \ No newline at end of file