Skip to content

Commit

Permalink
Section parsing accounts for nested delimiters (and ignores them) in …
Browse files Browse the repository at this point in the history
…replies from users
  • Loading branch information
Jacob Daniel Bennett committed Sep 29, 2020
1 parent 3129730 commit 19eb144
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions api/ECNQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

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

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

Expand Down Expand Up @@ -454,6 +472,7 @@ def __directoryParsing(self, directoryStartLine: int) -> dict:
key, value = strippedInfo.split(":")

directoryInformation[key] = value

directoryEndingLine = directoryEndingLine + 1

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

0 comments on commit 19eb144

Please sign in to comment.