Skip to content

Commit

Permalink
Remove unecessary newlines from the begining and end of initial messa…
Browse files Browse the repository at this point in the history
…ge section
  • Loading branch information
Jacob Daniel Bennett committed Sep 20, 2020
1 parent 04484ad commit e45ce20
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions api/ECNQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,49 @@ def __parseSections(self) -> list:
# Adds the contents of the line to the directory info
directoryInfo.append(lineContents)

# allows to move to the next iteration of the parent for loop, no need to continue parsing directory delimiters
break

# Increment the line counter by after each line
lineCounter = lineCounter + 1

# Parses the initial message to remove directory information
for lineNumber in sorted(directoryLinesToRemove, reverse=True):

# Remove the directory line from the intital message
initialMessageContent.pop(lineNumber)

# Removes unecessary newlines from the begining and the end of the initial message

newLinebegining = True
newLineEnd = True

while newLinebegining or newLineEnd:
# Initializes the Length of Message content each iteration of the loop
initialmessagecontentLength = len(initialMessageContent)

# Checks if the last line is a newline
if initialMessageContent[initialmessagecontentLength -1] == "\n":

# Deletes the last line if it is a newline
initialMessageContent.pop(initialmessagecontentLength - 1)

# If the previous condition failed, then set the new line end to False if it isn't false already
elif newLineEnd == True:

newLineEnd = False

# Checks if the first line in message content is a newline
if initialMessageContent[0] == "\n":

# Removes the first line in message content if it is a newline
initialMessageContent.pop(0)

# If the previous condition failed, then set the new line begining to False if it isn't false already
elif newLinebegining == True:

newLinebegining = False

# Appends Directory Information into the sections array
sections.append(
{"type": "directoryInformation",
Expand Down Expand Up @@ -767,5 +802,4 @@ def getQueues() -> list:
if isDirectory and isValid:
queues.append(Queue(file))

return queues

return queues

0 comments on commit e45ce20

Please sign in to comment.