From 02d1ca018882e38c1fdfdb764dd2f02709bdde59 Mon Sep 17 00:00:00 2001 From: Tomas Smetana Date: Sun, 16 Jun 2019 08:34:33 +0200 Subject: [PATCH] Accept also bytearray type for message (#29) --- pylgbst/messages.py | 2 +- pylgbst/utilities.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pylgbst/messages.py b/pylgbst/messages.py index 09e5d68..7236a36 100644 --- a/pylgbst/messages.py +++ b/pylgbst/messages.py @@ -58,7 +58,7 @@ class UpstreamMsg(Message): assert hub_id == 0 msg_type = msg._byte() assert cls.TYPE == msg_type, "Message type does not match: %x!=%x" % (cls.TYPE, msg_type) - assert isinstance(msg.payload, bytes) + assert isinstance(msg.payload, (bytes, bytearray)) return msg def __shift(self, vtype, vlen): diff --git a/pylgbst/utilities.py b/pylgbst/utilities.py index e479ea3..faf8a4d 100644 --- a/pylgbst/utilities.py +++ b/pylgbst/utilities.py @@ -30,7 +30,7 @@ def usint(seq, index): def str2hex(data): # we need it for python 2+3 compatibility # if sys.version_info[0] == 3: # data = bytes(data, 'ascii') - if not isinstance(data, bytes): + if not isinstance(data, (bytes, bytearray)): data = bytes(data, 'ascii') hexed = binascii.hexlify(data) return hexed