helper_msgcoding formating

This commit is contained in:
Mahendra 2018-04-07 17:48:54 +05:30
parent c5462a00cc
commit 1f5659d6ce
No known key found for this signature in database
GPG Key ID: A672D8FAAEE398B3

View File

@ -1,3 +1,4 @@
"""Helper msgcoding for checking validations."""
# !/usr/bin/python2.7
try:
@ -75,7 +76,8 @@ class MsgDecode(object):
self.encoding = encoding
if self.encoding == BITMESSAGE_ENCODING_EXTENDED:
self.decodeExtended(data)
elif self.encoding in [BITMESSAGE_ENCODING_SIMPLE, BITMESSAGE_ENCODING_TRIVIAL]:
elif self.encoding in [BITMESSAGE_ENCODING_SIMPLE,
BITMESSAGE_ENCODING_TRIVIAL]:
self.decodeSimple(data)
else:
self.body = _translate("MsgDecode", "The message has an unknown encoding.\nPerhaps you should upgrade Bitmessage.")
@ -140,7 +142,6 @@ class MsgDecode(object):
self.body = body
if __name__ == '__main__':
import random
messageData = {
"subject": ''.join(helper_random.randomchoice(string.ascii_lowercase + string.digits) for _ in range(40)),
"body": ''.join(helper_random.randomchoice(string.ascii_lowercase + string.digits) for _ in range(10000))
@ -152,10 +153,15 @@ if __name__ == '__main__':
obj1e = MsgDecode(1, obj1.data)
# no subject in trivial encoding
assert messageData["body"] == obj1e.body
if not messageData.get("body") == obj1e.body:
raise AssertionError()
obj2e = MsgDecode(2, obj2.data)
assert messageData["subject"] == obj2e.subject
assert messageData["body"] == obj2e.body
if not messageData["subject"] == obj2e.subject:
raise AssertionError()
if not messageData["body"] == obj2e.body:
raise AssertionError()
obj3e = MsgDecode(3, obj3.data)
assert messageData["subject"] == obj3e.subject
assert messageData["body"] == obj3e.body
if not messageData["subject"] == obj3e.subject:
raise AssertionError()
if not messageData["body"] == obj3e.body:
raise AssertionError()