mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 23:21:32 +00:00
Rework MessageSender to conform defined API
This commit is contained in:
parent
c99630172b
commit
91d5e560eb
@ -7,15 +7,18 @@ from .networking.server_connector import ServerUplinkConnector
|
|||||||
class MessageSender:
|
class MessageSender:
|
||||||
def __init__(self, custom_anchor=None):
|
def __init__(self, custom_anchor=None):
|
||||||
self.server_connector = ServerUplinkConnector()
|
self.server_connector = ServerUplinkConnector()
|
||||||
if isinstance(custom_anchor, str):
|
if isinstance(custom_anchor, bytes):
|
||||||
custom_anchor = custom_anchor.encode('utf-8')
|
custom_anchor = custom_anchor.decode('utf-8')
|
||||||
self.anchor = custom_anchor or b'message'
|
self.anchor = custom_anchor or 'message'
|
||||||
|
|
||||||
def send(self, originator, message):
|
def send(self, originator, message):
|
||||||
response = {
|
data = {
|
||||||
'originator': originator,
|
'originator': originator,
|
||||||
'timestamp': datetime.now().isoformat(),
|
'timestamp': datetime.now().isoformat(),
|
||||||
'message': message
|
'message': message
|
||||||
}
|
}
|
||||||
encoded_response = json.dumps(response).encode('utf-8')
|
response = {
|
||||||
self.server_connector.send(self.anchor, encoded_response)
|
'anchor': self.anchor,
|
||||||
|
'data': data
|
||||||
|
}
|
||||||
|
self.server_connector.send(*[frame.encode('utf-8') for frame in (self.anchor, json.dumps(response))])
|
||||||
|
Loading…
Reference in New Issue
Block a user