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 os import path, listdir
from string import lower
@ -9,12 +13,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

View File

@ -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))

View File

@ -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)