mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 19:31:33 +00:00
Mark old serialization methods as module internal
This commit is contained in:
parent
499b575adf
commit
3c12b5503e
@ -1,10 +1,9 @@
|
||||
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
||||
# All Rights Reserved. See LICENSE file for details.
|
||||
|
||||
from .serialization import decode_if_needed, encode_if_needed, serialize_all, deserialize_all
|
||||
from .serialization import serialize_tfw_msg, deserialize_tfw_msg
|
||||
from .zmq_connector_base import ZMQConnectorBase
|
||||
from .controller_connector import ControllerConnector
|
||||
# from .controller_connector import ControllerConnector # TODO: readd once controller stuff is resolved
|
||||
from .message_sender import MessageSender
|
||||
from .event_handlers.server_connector import ServerUplinkConnector as TFWServerConnector
|
||||
from .server.tfw_server import TFWServer
|
||||
|
@ -25,41 +25,41 @@ import json
|
||||
|
||||
|
||||
def serialize_tfw_msg(message):
|
||||
return serialize_all(message['key'], message)
|
||||
return _serialize_all(message['key'], message)
|
||||
|
||||
|
||||
def deserialize_tfw_msg(*args):
|
||||
return deserialize_all(*args)[1]
|
||||
return _deserialize_all(*args)[1]
|
||||
|
||||
|
||||
def serialize_all(*args):
|
||||
def _serialize_all(*args):
|
||||
return tuple(_serialize_single(arg) for arg in args)
|
||||
|
||||
|
||||
def deserialize_all(*args):
|
||||
def _deserialize_all(*args):
|
||||
return tuple(_deserialize_single(arg) for arg in args)
|
||||
|
||||
|
||||
def _serialize_single(data):
|
||||
if not isinstance(data, str):
|
||||
data = json.dumps(data)
|
||||
return encode_if_needed(data)
|
||||
return _encode_if_needed(data)
|
||||
|
||||
|
||||
def _deserialize_single(data):
|
||||
try:
|
||||
return json.loads(data)
|
||||
except ValueError:
|
||||
return decode_if_needed(data)
|
||||
return _decode_if_needed(data)
|
||||
|
||||
|
||||
def encode_if_needed(value):
|
||||
def _encode_if_needed(value):
|
||||
if isinstance(value, str):
|
||||
value = value.encode('utf-8')
|
||||
return value
|
||||
|
||||
|
||||
def decode_if_needed(value):
|
||||
def _decode_if_needed(value):
|
||||
if isinstance(value, (bytes, bytearray)):
|
||||
value = value.decode('utf-8')
|
||||
return value
|
||||
|
@ -4,4 +4,4 @@
|
||||
from .event_handler_connector import EventHandlerConnector, EventHandlerUplinkConnector, EventHandlerDownlinkConnector
|
||||
from .tfw_server import TFWServer
|
||||
from .zmq_websocket_handler import ZMQWebSocketProxy
|
||||
from .controller_responder import ControllerResponder
|
||||
# from .controller_responder import ControllerResponder # TODO: readd once controller stuff is resolved
|
||||
|
Loading…
Reference in New Issue
Block a user