This repository has been archived on 2024-12-06. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2024-12-06/src/messagetypes/message.py
Peter Surda 2cc4435cfc
Imports, typos, syntax errors
- remove obsolete imports
- add missing imports
- fix typos
- fix syntax errors
- thanks to landscape.io for report
2017-02-08 14:19:02 +01:00

32 lines
1011 B
Python

from debug import logger
from messagetypes import MsgBase
class Message(MsgBase):
def __init__(self):
return
def decode(self, data):
# UTF-8 and variable type validator
if type(data["subject"]) is 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:
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()
try:
self.data["subject"] = data["subject"]
self.data["body"] = data["body"]
except KeyError as e:
logger.error("Missing key %s", e.name)
return self.data
def process(self):
logger.debug("Subject: %i bytes", len(self.subject))
logger.debug("Body: %i bytes", len(self.body))