<commit_before>from .blueprint import root_blueprint as root_route
from ...core.node import node
from ...core.task_handler import executor

# syft absolute
from syft.core.common.message import SignedImmediateSyftMessageWithReply
from syft.core.common.message import SignedImmediateSyftMessageWithoutReply
from syft.core.common.serde.deserialize import _deserialize

from flask import request, Response
import json

executor_running = False


@root_route.route("/pysyft", methods=["POST"])
def root_route():
    global executor_running
    if not executor_running:
        executor.submit(node.run_handlers_thread)
        executor_running = True

    data = request.get_data()
    obj_msg = _deserialize(blob=data, from_bytes=True)
    if isinstance(obj_msg, SignedImmediateSyftMessageWithReply):
        reply = node.recv_immediate_msg_with_reply(msg=obj_msg)
        r = Response(response=reply.serialize(to_bytes=True), status=200)
        r.headers["Content-Type"] = "application/octet-stream"
        return r
    elif isinstance(obj_msg, SignedImmediateSyftMessageWithoutReply):<commit_msg>Add metadata route<commit_after>from .blueprint import root_blueprint as root_route
from ...core.node import node
from ...core.task_handler import executor

# syft absolute
from syft.core.common.message import SignedImmediateSyftMessageWithReply
from syft.core.common.message import SignedImmediateSyftMessageWithoutReply
from syft.core.common.serde.deserialize import _deserialize

from flask import request, Response
import json
from nacl.encoding import HexEncoder

executor_running = False


@root_route.route("/metadata", methods=["GET"])
def metadata_route():
    response_body = {
        "metadata": node.get_metadata_for_client()
        .serialize()
        .SerializeToString()
        .decode("ISO-8859-1"),
    }
    return Response(json.dumps(response_body), status=200, mimetype="application/json")


@root_route.route("/pysyft", methods=["POST"])
def root_route():
    data = request.get_data()
    obj_msg = _deserialize(blob=data, from_bytes=True)
    if isinstance(obj_msg, SignedImmediateSyftMessageWithReply):
        reply = node.recv_immediate_msg_with_reply(msg=obj_msg)
        r = Response(response=reply.serialize(to_bytes=True), status=200)
        r.headers["Content-Type"] = "application/octet-stream"
        return r
    elif isinstance(obj_msg, SignedImmediateSyftMessageWithoutReply):
{'fraction_non_alphanumeric': 0.09444904722452362, 'fraction_numerical': 0.00579950289975145, 'mean_word_length': 4.8474576271186445, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '404648', 'n_tokens_mistral': 723, 'n_tokens_neox': 714, 'n_words': 149}