From 326fb2d7a5ccb05f6c07c71b05224376060f2f79 Mon Sep 17 00:00:00 2001 From: Justin Campbell Date: Sun, 26 Jul 2020 20:23:14 -0400 Subject: [PATCH] Replaced all instances of returning None with returning empty values --- api/ECNQueue.py | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/api/ECNQueue.py b/api/ECNQueue.py index b34db59..5bfa26a 100644 --- a/api/ECNQueue.py +++ b/api/ECNQueue.py @@ -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. @@ -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. @@ -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)