<commit_before>from rapidsms.conf import settings
from rapidsms.router import Router as LegacyRouter


class Router(LegacyRouter):
    """ RapidSMS router with the threading and Queue parts removed """

    def __init__(self):
        super(Router, self).__init__()
        self.start()

    def start(self):
        self.info("starting router")
        for name in settings.INSTALLED_APPS:
            try:
                self.add_app(name)
            except Exception as e:
                self.exception(e)
        for name, conf in settings.INSTALLED_BACKENDS.items():
            self.add_backend(name, conf.get("ENGINE"), conf)
        self._start_all_apps()
        self.running = True

    def stop(self, graceful=False):
        self.info("stopping router")
        self._stop_all_apps()
        self.running = False

    def incoming(self, msg):
        # disable IncomingMessage.flush_responses
        msg.flush_responses = lambda: None
        # process incoming phases as usual
        super(Router, self).incoming(msg)
        # handle message responses from within router
        for response in msg.responses:
            self.outgoing(response)

    def outgoing(self, msg):
        # disable OutgoingMessage.send_now
        msg.send_now = lambda: None
        # process outgoing phase as usual
        super(Router, self).outgoing(msg)
        # send message from within router
        self.backends[msg.connection.backend.name].send(msg)<commit_msg>remove ENGINE from conf before creating backend<commit_after>import copy

from rapidsms.conf import settings
from rapidsms.router import Router as LegacyRouter


class Router(LegacyRouter):
    """ RapidSMS router with the threading and Queue parts removed """

    def __init__(self):
        super(Router, self).__init__()
        self.start()

    def start(self):
        self.info("starting router")
        for name in settings.INSTALLED_APPS:
            try:
                self.add_app(name)
            except Exception as e:
                self.exception(e)
        for name, conf in settings.INSTALLED_BACKENDS.items():
            parsed_conf = copy.copy(conf)
            engine = parsed_conf.pop('ENGINE')
            self.add_backend(name, engine, parsed_conf)
        self._start_all_apps()
        self.running = True

    def stop(self, graceful=False):
        self.info("stopping router")
        self._stop_all_apps()
        self.running = False

    def incoming(self, msg):
        # disable IncomingMessage.flush_responses
        msg.flush_responses = lambda: None
        # process incoming phases as usual
        super(Router, self).incoming(msg)
        # handle message responses from within router
        for response in msg.responses:
            self.outgoing(response)

    def outgoing(self, msg):
        # disable OutgoingMessage.send_now
        msg.send_now = lambda: None
        # process outgoing phase as usual
        super(Router, self).outgoing(msg)
        # send message from within router
        self.backends[msg.connection.backend.name].send(msg)
{'fraction_non_alphanumeric': 0.08487804878048781, 'fraction_numerical': 0.0, 'mean_word_length': 2.376509330406147, 'pattern_counts': {'":': 0, '<': 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': '7362783', 'n_tokens_mistral': 855, 'n_tokens_neox': 819, 'n_words': 225}