helper_msgcoding pylint fixes
This commit is contained in:
parent
f4c7ac5604
commit
05cda087d6
|
@ -25,19 +25,24 @@ BITMESSAGE_ENCODING_EXTENDED = 3
|
|||
|
||||
|
||||
class MsgEncodeException(Exception):
|
||||
"""Exception during message encoding"""
|
||||
pass
|
||||
|
||||
|
||||
class MsgDecodeException(Exception):
|
||||
"""Exception during message decoding"""
|
||||
pass
|
||||
|
||||
|
||||
class DecompressionSizeException(MsgDecodeException):
|
||||
# pylint: disable=super-init-not-called
|
||||
"""Decompression resulted in too much data (attack protection)"""
|
||||
def __init__(self, size):
|
||||
self.size = size
|
||||
|
||||
|
||||
class MsgEncode(object):
|
||||
"""Message encoder class"""
|
||||
def __init__(self, message, encoding=BITMESSAGE_ENCODING_SIMPLE):
|
||||
self.data = None
|
||||
self.encoding = encoding
|
||||
|
@ -52,6 +57,7 @@ class MsgEncode(object):
|
|||
raise MsgEncodeException("Unknown encoding %i" % (encoding))
|
||||
|
||||
def encodeExtended(self, message):
|
||||
"""Handle extended encoding"""
|
||||
try:
|
||||
msgObj = messagetypes.message.Message()
|
||||
self.data = zlib.compress(msgpack.dumps(msgObj.encode(message)), 9)
|
||||
|
@ -64,15 +70,18 @@ class MsgEncode(object):
|
|||
self.length = len(self.data)
|
||||
|
||||
def encodeSimple(self, message):
|
||||
"""Handle simple encoding"""
|
||||
self.data = 'Subject:%(subject)s\nBody:%(body)s' % message
|
||||
self.length = len(self.data)
|
||||
|
||||
def encodeTrivial(self, message):
|
||||
"""Handle trivial encoding"""
|
||||
self.data = message['body']
|
||||
self.length = len(self.data)
|
||||
|
||||
|
||||
class MsgDecode(object):
|
||||
"""Message decoder class"""
|
||||
def __init__(self, encoding, data):
|
||||
self.encoding = encoding
|
||||
if self.encoding == BITMESSAGE_ENCODING_EXTENDED:
|
||||
|
@ -88,6 +97,7 @@ class MsgDecode(object):
|
|||
self.subject = _translate("MsgDecode", "Unknown encoding")
|
||||
|
||||
def decodeExtended(self, data):
|
||||
"""Handle extended encoding"""
|
||||
dc = zlib.decompressobj()
|
||||
tmp = ""
|
||||
while len(tmp) <= BMConfigParser().safeGetInt("zlib", "maxsize"):
|
||||
|
@ -131,6 +141,7 @@ class MsgDecode(object):
|
|||
self.body = msgObj.body
|
||||
|
||||
def decodeSimple(self, data):
|
||||
"""Handle simple encoding"""
|
||||
bodyPositionIndex = string.find(data, '\nBody:')
|
||||
if bodyPositionIndex > 1:
|
||||
subject = data[8:bodyPositionIndex]
|
||||
|
|
Reference in New Issue
Block a user