<commit_before>import json
from copy import deepcopy


def chain_event(chain, obj):
    if "success" in chain:
        if chain["success"]["type"] == "$render":
            chain["success"] = obj
            obj["success"] = {"type": "$render"}
            obj["error"] = {
                "type": "$util.banner",
                "options": {
                    "title": "Error",
                    "description": "Uh oh, something went wrong."
                }
            }
        else:
            chain_event(chain["success"], obj)
    else:
        chain.update(obj)
        chain["success"] = {"type": "$render"}
        chain["error"] = {
            "type": "$util.banner",
            "options": {
                "title": "Error",
                "description": "Uh oh, something went wrong."
            }
        }

class ModuleProcessor(object):
    def __init__(self, modules):
        self.modules = modules

    def process(self, template, params):
        module_id = params["module_id"]
        if module_id in self.modules:
            self.insert_module_data(template, module_id)
            self.insert_module_ui(template, module_id)

    def insert_module_data(self, template, module_id):
        res = sorted(self.modules.values(), key=lambda x: x["name"])
        for mod in res:
            mod["active"] = mod["id"] == module_id
        template["$jason"]["head"]["data"]["posts"] = res

    def insert_module_ui(self, template, module_id):
        sections = template["$jason"]["head"]["templates"]["body"]["sections"]
        sections.append(self.modules[module_id]["view"])


class RPCProcessor(object):
    def __init__(self, rpcs):
        self.rpcs = rpcs

    def process(self, template, params):
        method = "com.srivatsaniyer.weaveremote.jasonette.Messaging.rpc"
        actions = template["$jason"]["head"]["actions"]
        for rpc_obj in self.rpcs.values():
            actions["rpc-" + rpc_obj["name"]] = {
                "type": "$external.invoke",
                "method": method,
                "data": {
                    "request_schema": rpc_obj["request_schema"],
                    "response_schema": rpc_obj["response_schema"],
                    "request_queue": rpc_obj["request_queue"],
                    "response_queue": rpc_obj["response_queue"],
                }
            }


class RootView(object):
    def __init__(self, path, content):
        with open(path) as f:
            self.template = json.load(f)
        self.processors = [
            ModuleProcessor(content["modules"]),
            RPCProcessor(content["rpcs"])
        ]

    def data(self, params):<commit_msg>Remove request and response schema. Push apis and queues info within options object.<commit_after>import json
from copy import deepcopy


def chain_event(chain, obj):
    if "success" in chain:
        if chain["success"]["type"] == "$render":
            chain["success"] = obj
            obj["success"] = {"type": "$render"}
            obj["error"] = {
                "type": "$util.banner",
                "options": {
                    "title": "Error",
                    "description": "Uh oh, something went wrong."
                }
            }
        else:
            chain_event(chain["success"], obj)
    else:
        chain.update(obj)
        chain["success"] = {"type": "$render"}
        chain["error"] = {
            "type": "$util.banner",
            "options": {
                "title": "Error",
                "description": "Uh oh, something went wrong."
            }
        }


class ModuleProcessor(object):
    def __init__(self, modules):
        self.modules = modules

    def process(self, template, params):
        module_id = params["module_id"]
        if module_id in self.modules:
            self.insert_module_data(template, module_id)
            self.insert_module_ui(template, module_id)

    def insert_module_data(self, template, module_id):
        res = sorted(self.modules.values(), key=lambda x: x["name"])
        for mod in res:
            mod["active"] = mod["id"] == module_id
        template["$jason"]["head"]["data"]["posts"] = res

    def insert_module_ui(self, template, module_id):
        sections = template["$jason"]["head"]["templates"]["body"]["sections"]
        sections.append(self.modules[module_id]["view"])


class RPCProcessor(object):
    def __init__(self, rpcs):
        self.rpcs = rpcs

    def process(self, template, params):
        method = "com.srivatsaniyer.weaveremote.jasonette.Messaging.rpc"
        actions = template["$jason"]["head"]["actions"]
        for rpc_obj in self.rpcs.values():
            actions["rpc-" + rpc_obj["name"]] = {
                "type": "$external.invoke",
                "options": {
                    "method": method,
                    "data": {
                        "request_queue": rpc_obj["request_queue"],
                        "response_queue": rpc_obj["response_queue"],
                        "apis": rpc_obj["apis"],
                    }
                }
            }


class RootView(object):
    def __init__(self, path, content):
        with open(path) as f:
            self.template = json.load(f)
        self.processors = [
            ModuleProcessor(content["modules"]),
            RPCProcessor(content["rpcs"])
        ]

    def data(self, params):
{'fraction_non_alphanumeric': 0.14432029795158285, 'fraction_numerical': 0.0, 'mean_word_length': 1.943013698630137, 'pattern_counts': {'":': 36, '<': 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': '2483812', 'n_tokens_mistral': 1512, 'n_tokens_neox': 1490, 'n_words': 312}