From 966b4382d89103d950d68d7a38406431ab00ab80 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Mon, 14 Nov 2016 20:22:10 +0100 Subject: [PATCH] Add handler for unknown encoding --- src/helper_msgcoding.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/helper_msgcoding.py b/src/helper_msgcoding.py index 99d617f8..ad26cbcb 100644 --- a/src/helper_msgcoding.py +++ b/src/helper_msgcoding.py @@ -6,6 +6,7 @@ import zlib import shared import messagetypes +from tr import _translate BITMESSAGE_ENCODING_IGNORE = 0 BITMESSAGE_ENCODING_TRIVIAL = 1 @@ -23,6 +24,8 @@ class MsgEncode(object): self.encodeSimple(message) elif self.encoding == BITMESSAGE_ENCODING_TRIVIAL: self.encodeTrivial(message) + else: + raise ValueError("Unknown encoding %i" % (encoding)) def encodeExtended(self, message): try: @@ -44,6 +47,7 @@ class MsgEncode(object): self.data = message['body'] self.length = len(self.data) + class MsgDecode(object): def __init__(self, encoding, data): self.encoding = encoding @@ -51,7 +55,9 @@ class MsgDecode(object): self.decodeExtended(data) elif self.encoding in [BITMESSAGE_ENCODING_SIMPLE, BITMESSAGE_ENCODING_TRIVIAL]: self.decodeSimple(data) - return + else: + self.body = _translate("MsgDecode", "The message has an unknown encoding.\nPerhaps you should upgrade Bitmessage.") + self.subject = _translate("MsgDecode", "Unknown encoding") def decodeExtended(self, data): try: