Merge branch 'v0.6' of https://github.com/Bitmessage/PyBitmessage into UiChanges

This commit is contained in:
surbhi 2019-09-30 19:02:59 +05:30
commit a1a735ac40
No known key found for this signature in database
GPG Key ID: 88928762974D3618
3 changed files with 33 additions and 11 deletions

View File

@ -1,3 +1,7 @@
"""
src/messagetypes/__init__.py
============================
"""
from importlib import import_module from importlib import import_module
from os import path, listdir from os import path, listdir
from string import lower from string import lower
@ -9,12 +13,15 @@ from debug import logger
import messagetypes import messagetypes
import paths 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__)} self.data = {"": lower(type(self).__name__)}
def constructObject(data): def constructObject(data):
"""Constructing an object"""
whitelist = ["message"] whitelist = ["message"]
if data[""] not in whitelist: if data[""] not in whitelist:
return None return None

View File

@ -1,24 +1,30 @@
"""
src/messagetypes/message.py
===========================
"""
from debug import logger from debug import logger
from messagetypes import MsgBase from messagetypes import MsgBase
class Message(MsgBase): class Message(MsgBase):
def __init__(self): """Encapsulate a message"""
return # pylint: disable=attribute-defined-outside-init
def decode(self, data): def decode(self, data):
"""Decode a message"""
# UTF-8 and variable type validator # 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') self.subject = unicode(data["subject"], 'utf-8', 'replace')
else: else:
self.subject = unicode(str(data["subject"]), 'utf-8', 'replace') 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') self.body = unicode(data["body"], 'utf-8', 'replace')
else: else:
self.body = unicode(str(data["body"]), 'utf-8', 'replace') self.body = unicode(str(data["body"]), 'utf-8', 'replace')
def encode(self, data): def encode(self, data):
super(Message, self).encode() """Encode a message"""
super(Message, self).__init__()
try: try:
self.data["subject"] = data["subject"] self.data["subject"] = data["subject"]
self.data["body"] = data["body"] self.data["body"] = data["body"]
@ -27,5 +33,6 @@ class Message(MsgBase):
return self.data return self.data
def process(self): def process(self):
"""Process a message"""
logger.debug("Subject: %i bytes", len(self.subject)) logger.debug("Subject: %i bytes", len(self.subject))
logger.debug("Body: %i bytes", len(self.body)) logger.debug("Body: %i bytes", len(self.body))

View File

@ -1,23 +1,31 @@
"""
src/messagetypes/vote.py
========================
"""
from debug import logger from debug import logger
from messagetypes import MsgBase from messagetypes import MsgBase
class Vote(MsgBase): class Vote(MsgBase):
def __init__(self): """Module used to vote"""
return
def decode(self, data): def decode(self, data):
"""decode a vote"""
# pylint: disable=attribute-defined-outside-init
self.msgid = data["msgid"] self.msgid = data["msgid"]
self.vote = data["vote"] self.vote = data["vote"]
def encode(self, data): def encode(self, data):
super(Vote, self).encode() """Encode a vote"""
super(Vote, self).__init__()
try: try:
self.data["msgid"] = data["msgid"] self.data["msgid"] = data["msgid"]
self.data["vote"] = data["vote"] self.data["vote"] = data["vote"]
except KeyError as e: except KeyError as e:
logger.error("Missing key %s", e.name) logger.error("Missing key %s", e)
return self.data return self.data
def process(self): def process(self):
"""Encode a vote"""
logger.debug("msgid: %s", self.msgid) logger.debug("msgid: %s", self.msgid)
logger.debug("vote: %s", self.vote) logger.debug("vote: %s", self.vote)