Merge pull request #36 from hubertmis/fix-token

Fix token handling
This commit is contained in:
Giacomo Tanganelli 2021-01-17 12:01:30 +01:00 committed by GitHub
commit 8e0704e706
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 8 deletions

View file

@ -119,17 +119,16 @@ class Message(object):
""" """
Set the Token of the message. Set the Token of the message.
:type value: String :type value: Bytes
:param value: the Token :param value: the Token
:raise AttributeError: if value is longer than 256 :raise AttributeError: if value is longer than 256
""" """
if value is None: if value is None:
self._token = value self._token = value
return return
if isinstance(value, int):
value = bytes([value])
if not isinstance(value, bytes): if not isinstance(value, bytes):
value = bytes(value, "utf-8") value = bytes(value)
if len(value) > 256: if len(value) > 256:
raise AttributeError raise AttributeError
self._token = value self._token = value

View file

@ -157,10 +157,8 @@ class Serializer(object):
values = [tmp, message.code, message.mid] values = [tmp, message.code, message.mid]
if message.token is not None and tkl > 0: if message.token is not None and tkl > 0:
fmt += "%ss" % tkl
for b in message.token: values.append(message.token)
fmt += "B"
values.append(b)
options = Serializer.as_sorted_list(message.options) # already sorted options = Serializer.as_sorted_list(message.options) # already sorted
lastoptionnumber = 0 lastoptionnumber = 0