From 7d05f70fe12013ec64e5a426ada63a5c2b6864cc Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 1 Dec 2020 14:27:39 +0000 Subject: [PATCH] Fix mosq_test.py to_string() on Python 3 --- test/mosq_test.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/mosq_test.py b/test/mosq_test.py index 66c63c71..901ece55 100644 --- a/test/mosq_test.py +++ b/test/mosq_test.py @@ -201,7 +201,7 @@ def to_string(packet): if len(packet) == 0: return "" - packet0 = struct.unpack("!B", bytes(packet[0])) + packet0 = struct.unpack("!B%ds" % (len(packet)-1), bytes(packet)) packet0 = packet0[0] cmd = packet0 & 0xF0 if cmd == 0x00: @@ -214,7 +214,7 @@ def to_string(packet): (slen, packet) = struct.unpack(pack_format, packet) pack_format = "!" + str(slen)+'sBBH' + str(len(packet)-slen-4) + 's' (protocol, proto_ver, flags, keepalive, packet) = struct.unpack(pack_format, packet) - s = "CONNECT, proto="+protocol+str(proto_ver)+", keepalive="+str(keepalive) + s = "CONNECT, proto="+str(protocol)+str(proto_ver)+", keepalive="+str(keepalive) if flags&2: s = s+", clean-session" else: @@ -224,14 +224,14 @@ def to_string(packet): (slen, packet) = struct.unpack(pack_format, packet) pack_format = "!" + str(slen)+'s' + str(len(packet)-slen) + 's' (client_id, packet) = struct.unpack(pack_format, packet) - s = s+", id="+client_id + s = s+", id="+str(client_id) if flags&4: pack_format = "!H" + str(len(packet)-2) + 's' (slen, packet) = struct.unpack(pack_format, packet) pack_format = "!" + str(slen)+'s' + str(len(packet)-slen) + 's' (will_topic, packet) = struct.unpack(pack_format, packet) - s = s+", will-topic="+will_topic + s = s+", will-topic="+str(will_topic) pack_format = "!H" + str(len(packet)-2) + 's' (slen, packet) = struct.unpack(pack_format, packet) @@ -247,14 +247,14 @@ def to_string(packet): (slen, packet) = struct.unpack(pack_format, packet) pack_format = "!" + str(slen)+'s' + str(len(packet)-slen) + 's' (username, packet) = struct.unpack(pack_format, packet) - s = s+", username="+username + s = s+", username="+str(username) if flags&64: pack_format = "!H" + str(len(packet)-2) + 's' (slen, packet) = struct.unpack(pack_format, packet) pack_format = "!" + str(slen)+'s' + str(len(packet)-slen) + 's' (password, packet) = struct.unpack(pack_format, packet) - s = s+", password="+password + s = s+", password="+str(password) if flags&1: s = s+", reserved=1" @@ -274,13 +274,13 @@ def to_string(packet): (tlen, packet) = struct.unpack(pack_format, packet) pack_format = "!" + str(tlen)+'s' + str(len(packet)-tlen) + 's' (topic, packet) = struct.unpack(pack_format, packet) - s = "PUBLISH, rl="+str(rl)+", topic="+topic+", qos="+str(qos)+", retain="+str(retain)+", dup="+str(dup) + s = "PUBLISH, rl="+str(rl)+", topic="+str(topic)+", qos="+str(qos)+", retain="+str(retain)+", dup="+str(dup) if qos > 0: pack_format = "!H" + str(len(packet)-2) + 's' (mid, packet) = struct.unpack(pack_format, packet) s = s + ", mid="+str(mid) - s = s + ", payload="+packet + s = s + ", payload="+str(packet) return s elif cmd == 0x40: # PUBACK @@ -311,7 +311,7 @@ def to_string(packet): (tlen, packet) = struct.unpack(pack_format, packet) pack_format = "!" + str(tlen)+'sB' + str(len(packet)-tlen-1) + 's' (topic, qos, packet) = struct.unpack(pack_format, packet) - s = s + ", topic"+str(topic_index)+"="+topic+","+str(qos) + s = s + ", topic"+str(topic_index)+"="+str(topic)+","+str(qos) return s elif cmd == 0x90: # SUBACK @@ -337,7 +337,7 @@ def to_string(packet): (tlen, packet) = struct.unpack(pack_format, packet) pack_format = "!" + str(tlen)+'s' + str(len(packet)-tlen) + 's' (topic, packet) = struct.unpack(pack_format, packet) - s = s + ", topic"+str(topic_index)+"="+topic + s = s + ", topic"+str(topic_index)+"="+str(topic) return s elif cmd == 0xB0: # UNSUBACK