From f7d644c32dd46da6befeeeaed72e28f96aafd782 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 12 Apr 2020 22:56:12 +0200 Subject: [PATCH] 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. --- platypush/backend/http/app/routes/index.py | 3 ++- platypush/message/__init__.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/platypush/backend/http/app/routes/index.py b/platypush/backend/http/app/routes/index.py index ea3e6424..f9ee147d 100644 --- a/platypush/backend/http/app/routes/index.py +++ b/platypush/backend/http/app/routes/index.py @@ -8,6 +8,7 @@ from platypush.backend.http.app.utils import authenticate, get_websocket_port from platypush.backend.http.utils import HttpUtils from platypush.config import Config +from platypush.message import Message index = Blueprint('index', __name__, template_folder=template_folder) @@ -70,7 +71,7 @@ def index(): websocket_port=get_websocket_port(), template_folder=template_folder, static_folder=static_folder, 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) diff --git a/platypush/message/__init__.py b/platypush/message/__init__.py index d55d45a4..270ec0ba 100644 --- a/platypush/message/__init__.py +++ b/platypush/message/__init__.py @@ -24,6 +24,8 @@ class Message(object): return int(obj) if isinstance(obj, np.ndarray): return obj.tolist() + if callable(obj): + return ''.format(obj.__module__, obj.__name__) return