get_procedures() can now return Python function objects as well.

This means that the JSON encoder must act accordingly and parse
the function object into an encodable string.
This commit is contained in:
Fabio Manganiello 2020-04-12 22:56:12 +02:00
parent 124269776d
commit f7d644c32d
2 changed files with 4 additions and 1 deletions

View file

@ -8,6 +8,7 @@ from platypush.backend.http.app.utils import authenticate, get_websocket_port
from platypush.backend.http.utils import HttpUtils from platypush.backend.http.utils import HttpUtils
from platypush.config import Config from platypush.config import Config
from platypush.message import Message
index = Blueprint('index', __name__, template_folder=template_folder) index = Blueprint('index', __name__, template_folder=template_folder)
@ -70,7 +71,7 @@ def index():
websocket_port=get_websocket_port(), websocket_port=get_websocket_port(),
template_folder=template_folder, static_folder=static_folder, template_folder=template_folder, static_folder=static_folder,
plugins=Config.get_plugins(), backends=Config.get_backends(), plugins=Config.get_plugins(), backends=Config.get_backends(),
procedures=json.dumps(Config.get_procedures()), procedures=json.dumps(Config.get_procedures(), cls=Message.Encoder),
has_ssl=http_conf.get('ssl_cert') is not None) has_ssl=http_conf.get('ssl_cert') is not None)

View file

@ -24,6 +24,8 @@ class Message(object):
return int(obj) return int(obj)
if isinstance(obj, np.ndarray): if isinstance(obj, np.ndarray):
return obj.tolist() return obj.tolist()
if callable(obj):
return '<function at {}.{}>'.format(obj.__module__, obj.__name__)
return return