Skip to content

Commit

Permalink
Directory Parsing now checks for a \tName delimiter before assuming a…
Browse files Browse the repository at this point in the history
… newline after header info denotes directory info
  • Loading branch information
Jacob Daniel Bennett committed Sep 28, 2020
1 parent ee0edac commit 0da7774
Showing 1 changed file with 44 additions and 11 deletions.
55 changes: 44 additions & 11 deletions api/ECNQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,23 @@ def __parseSections(self) -> list:
initialMessageContent = []
endInitialMessage = False

if self.__rawItem[contentStart] == "\n" :
# 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]
directoryInfo["content"] = self.__directoryParsing(rawDirectoryInfo)

# 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

else:

# Initialize an empty dictionary for content
directoryInfo["content"] = {}

# Appends Directory Information into the sections array
sections.append(directoryInfo)

Expand Down Expand Up @@ -355,6 +367,9 @@ def __parseSections(self) -> list:
# Returns a dictionary with edit information
editInfo = self.__editParsing(line)

# Remove the delimiter String
sectionContent.remove(line)

# Appends content of the edit message to the dictionary
editInfo["content"] = sectionContent

Expand Down Expand Up @@ -403,7 +418,7 @@ def __parseSections(self) -> list:

return sections

def __directoryParsing(self, directoryContent: list) -> dict:
def __directoryParsing(self, directoryStartLine: int) -> dict:
"""Returns a dictionary with directory information
Returns: dictionary:
Expand All @@ -421,17 +436,28 @@ def __directoryParsing(self, directoryContent: list) -> dict:
"Subject": subject
"""
directoryInformation = {}

directoryEndingLine = directoryStartLine
while directoryEndingLine - directoryStartLine <= 11:

info = self.__rawItem[directoryEndingLine]

for info in directoryContent:
strippedInfo = info.strip()
try:
key, value = strippedInfo.split(": ")
except:
key, value = strippedInfo.split(":")
if info == "\n":

break

directoryInformation[key] = value
else:
strippedInfo = info.strip()
try:
key, value = strippedInfo.split(": ")
except:
key, value = strippedInfo.split(":")

directoryInformation[key] = value
directoryEndingLine = directoryEndingLine + 1

return directoryInformation

def __editParsing(self, line: str) -> dict:
"""Returns a dictionary with edit information
Expand Down Expand Up @@ -778,4 +804,11 @@ def getQueues() -> list:
if isDirectory and isValid:
queues.append(Queue(file))

return queues
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 0da7774

Please sign in to comment.