From 40e15579fdeee55352a28545f664fc7bc8b602c6 Mon Sep 17 00:00:00 2001 From: lakshyacis Date: Fri, 27 Sep 2019 19:31:55 +0530 Subject: [PATCH 1/3] messagetypes init flake and pylint fixes --- src/messagetypes/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/messagetypes/__init__.py b/src/messagetypes/__init__.py index 06783eac..7319dfd5 100644 --- a/src/messagetypes/__init__.py +++ b/src/messagetypes/__init__.py @@ -1,3 +1,7 @@ +""" +src/messagetypes/__init__.py +============================ +""" from importlib import import_module from os import path, listdir from string import lower @@ -6,12 +10,15 @@ from debug import logger import messagetypes import paths -class MsgBase(object): - def encode(self): + +class MsgBase(object): # pylint: disable=too-few-public-methods + """Base class for message types""" + def __init__(self): self.data = {"": lower(type(self).__name__)} def constructObject(data): + """Constructing an object""" whitelist = ["message"] if data[""] not in whitelist: return None @@ -32,6 +39,7 @@ def constructObject(data): else: return returnObj + if paths.frozen is not None: import messagetypes.message import messagetypes.vote From 9aa7dd9d78d4eda83f78f577af7b47ccd8694fa2 Mon Sep 17 00:00:00 2001 From: lakshyacis Date: Mon, 30 Sep 2019 18:42:36 +0530 Subject: [PATCH 2/3] message pylint fixes --- src/messagetypes/message.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/messagetypes/message.py b/src/messagetypes/message.py index f52c6b35..cd5bf762 100644 --- a/src/messagetypes/message.py +++ b/src/messagetypes/message.py @@ -1,24 +1,30 @@ +""" +src/messagetypes/message.py +=========================== +""" from debug import logger from messagetypes import MsgBase class Message(MsgBase): - def __init__(self): - return + """Encapsulate a message""" + # pylint: disable=attribute-defined-outside-init def decode(self, data): + """Decode a message""" # UTF-8 and variable type validator - if type(data["subject"]) is str: + if isinstance(data["subject"], str): self.subject = unicode(data["subject"], 'utf-8', 'replace') else: self.subject = unicode(str(data["subject"]), 'utf-8', 'replace') - if type(data["body"]) is str: + if isinstance(data["body"], str): self.body = unicode(data["body"], 'utf-8', 'replace') else: self.body = unicode(str(data["body"]), 'utf-8', 'replace') def encode(self, data): - super(Message, self).encode() + """Encode a message""" + super(Message, self).__init__() try: self.data["subject"] = data["subject"] self.data["body"] = data["body"] @@ -27,5 +33,6 @@ class Message(MsgBase): return self.data def process(self): + """Process a message""" logger.debug("Subject: %i bytes", len(self.subject)) logger.debug("Body: %i bytes", len(self.body)) From e5b92e29a2d62a5549bd36786db2fa7c7af4eb2e Mon Sep 17 00:00:00 2001 From: lakshyacis Date: Mon, 30 Sep 2019 18:42:50 +0530 Subject: [PATCH 3/3] vote pylint fixes --- src/messagetypes/vote.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/messagetypes/vote.py b/src/messagetypes/vote.py index df8d267f..e128e9ba 100644 --- a/src/messagetypes/vote.py +++ b/src/messagetypes/vote.py @@ -1,23 +1,31 @@ +""" +src/messagetypes/vote.py +======================== +""" from debug import logger from messagetypes import MsgBase + class Vote(MsgBase): - def __init__(self): - return + """Module used to vote""" def decode(self, data): + """decode a vote""" + # pylint: disable=attribute-defined-outside-init self.msgid = data["msgid"] self.vote = data["vote"] def encode(self, data): - super(Vote, self).encode() + """Encode a vote""" + super(Vote, self).__init__() try: self.data["msgid"] = data["msgid"] self.data["vote"] = data["vote"] except KeyError as e: - logger.error("Missing key %s", e.name) + logger.error("Missing key %s", e) return self.data def process(self): + """Encode a vote""" logger.debug("msgid: %s", self.msgid) logger.debug("vote: %s", self.vote)