From 8e150c081531291984af4fb7222abb863c462dfd Mon Sep 17 00:00:00 2001 From: Jacob Daniel Bennett Date: Fri, 2 Oct 2020 10:59:26 -0400 Subject: [PATCH] preliminary Errorparse: returns an error dictionary upon encountering nested delimiter. --- api/ECNQueue.py | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/api/ECNQueue.py b/api/ECNQueue.py index 8272ea4..8df35cf 100644 --- a/api/ECNQueue.py +++ b/api/ECNQueue.py @@ -188,9 +188,6 @@ def __parseSections(self) -> list: # Checks for Directory Identifiers 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] - # Parses the directory information and returns a dictionary of directory values directoryInfo["content"] = self.__directoryParsing(contentStart + 1) @@ -208,8 +205,8 @@ 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 + # Set to true if a reply-from-user begining delimiter is parsed. Set to false if the ending delimiter is encountered + replyFromUserDelimiter = False # Parses the entire contents of the message, stores everything before any delimiter as the initial message for lineNumber in range(contentStart, contentEnd + 1): @@ -221,23 +218,40 @@ def __parseSections(self) -> list: # Signifies that the inital message has been copletely parsed endInitialMessage = True - if replyFromUserNum == 0 and line.startswith("===") and not line.startswith("===="): + if replyFromUserDelimiter == False and line.startswith("===") and not line.startswith("===="): # Stores what line every delimeter starts/ends sectionBoundaries.append({"start": lineNumber}) - replyFromUserNum = replyFromUserNum + 1 + replyFromUserDelimiter = True - elif replyFromUserNum != 0 and line.startswith("===") and not line.startswith("===="): - replyFromUserNum = replyFromUserNum + 1 + # Checks for nesteded delimiters within the reply from user + elif replyFromUserDelimiter == True and (line.startswith("===") or line.startswith("***")) and not line.startswith("===="): + + parseErrorMessage = ("Nested delimiter encountered on line " + + str(lineNumber) + ":\n" + + "\t " + line) + + # Creates a dictionary with information regarding to the nested delimiter + errorDictionary = { + "type": "parseError", + "datetime": self.__getFormattedDate(str(datetime.datetime.now())), + "content": parseErrorMessage + } - elif replyFromUserNum == 0: + # Appends the error dictionary to sections + sections.append(errorDictionary) + + # Immediately exits the section parsing function because item content needs to be edited from the cli + return sections + + elif replyFromUserDelimiter == False: sectionBoundaries.append({"start": lineNumber}) elif line.startswith("===="): - replyFromUserNum = replyFromUserNum - 1 + replyFromUserDelimiter = False elif endInitialMessage == False: @@ -865,11 +879,4 @@ def getQueues() -> list: if isDirectory and isValid: queues.append(Queue(file)) - return queues - -if __name__ == "__main__": - item = Item("aae", 2) - print() -# for queue in getQueues(): -# for item in queue.items: -# print(f"${item.queue} ${item.number}") \ No newline at end of file + return queues \ No newline at end of file