Skip to content

Commit

Permalink
Replaced all instances of returning None with returning empty values
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Campbell committed Jul 27, 2020
1 parent 72e4f7a commit 326fb2d
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions api/ECNQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def __init__(self, queue: str, number: int) -> None:
self.userName = self.__getUserName()
self.userAlias = self.__getUserAlias()
self.assignedTo = self.__getAssignedTo()
self.subject = self.__getMostRecentHeaderByType("Subject")["content"]
self.status = self.__getMostRecentHeaderByType("Status")["content"]

def __getLastUpdated(self) -> float:
"""Returns last modified time of item reported by the filesystem in mm-dd-yy hh:mm am/pm format.
Expand Down Expand Up @@ -160,19 +162,35 @@ def __isLocked(self) -> Union[str, bool]:
else:
return False

def __getMostRecentHeaderByType(self, headerType: str) -> Union[dict, None]:
def __getMostRecentHeaderByType(self, headerType: str) -> dict:
"""Return most recent header of the given type.
If no header of that type exists, returns None.
If no header of that type exists, return a header with the type requests and empty content.
Example: Requesting a Status header that does exist
__getMostRecentHeaderByType("Status")
becomes
{
"type": "Status",
"content": "Waiting for Reply"
}
Example: Requesting a Status header that doesn't exist
__getMostRecentHeaderByType("Status")
becomes
{
"type": "Status",
"content": ""
}
Args:
headerType (str): Type of header to return.
Returns:
Union[dict, None]: dict of header if it exists or None
dict: dict of header if it exists or dict of requested type with empty content.
"""
for header in self.headers:
if header["type"] == headerType: return header
return None
return { "type": headerType, "content": "" }

def __parseFromData(self, data: str) -> str:
"""Parse From header and return requested data.
Expand All @@ -195,37 +213,38 @@ def __parseFromData(self, data: str) -> str:
elif data == "userEmail": return userEmail
else: raise ValueError("data='" + str(data) + "' is not a valid option. data must be \"userName\" or \"userEmail\".")

def __getUserName(self, data="userName") -> Union[str, None]:
def __getUserName(self, data="userName") -> str:
return self.__parseFromData(data)

def __getUserEmail(self, data="userEmail") -> str:
return self.__parseFromData(data)

def __getUserAlias(self) -> Union[str, None]:
def __getUserAlias(self) -> str:
"""Returns user's Career Account alias if present.
If Career Account alias isn't present, returns none.
If Career Account alias isn't present, returns empty string.
Example: Email from campb303@purdue.edu
userAlias = 'campb303'
userAlias = "campb303"
Example: Email from spam@spammer.net
userAlias = None
userAlias = ""
Returns:
Union[str, None]: User's Career Account alias if present or None
str: User's Career Account alias if present or empty string
"""
emailUser, emailDomain = self.userEmail.split("@")
return emailUser if emailDomain.endswith("purdue.edu") else None
return emailUser if emailDomain.endswith("purdue.edu") else ""

def __getAssignedTo(self) -> Union[str, None]:
def __getAssignedTo(self) -> str:
"""Returns the alias of the person this item was most recently assigned to.
Returns None if this item isn't assigned.
Returns empty string if this item isn't assigned.
Returns:
Union[str, None]: Alias of the person item is assigned to or None
str: Alias of the person item is assigned to or empty string.
"""
assignedToHeader = self.__getMostRecentHeaderByType("Assigned-To")
return assignedToHeader["content"] if assignedToHeader != None else None
assignedTo = assignedToHeader["content"]
return assignedTo

def __repr__(self) -> str:
return self.queue + str(self.number)
Expand Down

0 comments on commit 326fb2d

Please sign in to comment.