Skip to content

Commit

Permalink
preliminary Errorparse: returns an error dictionary upon encountering…
Browse files Browse the repository at this point in the history
… nested delimiter.
  • Loading branch information
Jacob Daniel Bennett committed Oct 2, 2020
1 parent 0b3ed98 commit 8e150c0
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions api/ECNQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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):
Expand All @@ -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:

Expand Down Expand Up @@ -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}")
return queues

0 comments on commit 8e150c0

Please sign in to comment.