1
0
mirror of https://github.com/undera/pylgbst.git synced 2020-11-18 19:37:26 -08:00

Accept also bytearray type for message (#29)

This commit is contained in:
Tomas Smetana 2019-06-16 08:34:33 +02:00 committed by Andrey Pokhilko
parent 32eecac1a6
commit 02d1ca0188
2 changed files with 2 additions and 2 deletions

View File

@ -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):

View File

@ -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