<commit_before>import copy

from django.conf import settings

from .base import BaseRouter


class BlockingRouter(BaseRouter):
    """ Simple router that blocks while sending and receiving messages """

    def __init__(self, *args, **kwargs):
        """
        Apps and backends are added manually to the blocking backend.
        """
        apps = kwargs.pop('apps', settings.INSTALLED_APPS)
        backends = kwargs.pop('backends', settings.INSTALLED_BACKENDS)
        super(BlockingRouter, self).__init__(*args, **kwargs)
        for name in apps:
            try:
                self.add_app(name)
            except Exception as e:
                self.exception(e)
        for name, conf in backends.iteritems():
            parsed_conf = copy.copy(conf)
            engine = parsed_conf.pop('ENGINE')
            self.add_backend(name, engine, parsed_conf)
        self.start()  # legacy

    def receive_incoming(self, msg):
        # process incoming phases
        super(BlockingRouter, self).receive_incoming(msg)
        # handle message responses from within router
        for response in msg.responses:
            self.send_outgoing(response)<commit_msg>use send API when sending responses to ensure settings.RAPIDSMS_ROUTER is used<commit_after>import copy

from django.conf import settings

from rapidsms.router.base import BaseRouter


class BlockingRouter(BaseRouter):
    """ Simple router that blocks while sending and receiving messages """

    def __init__(self, *args, **kwargs):
        """
        Apps and backends are added manually to the blocking backend.
        """
        apps = kwargs.pop('apps', settings.INSTALLED_APPS)
        backends = kwargs.pop('backends', settings.INSTALLED_BACKENDS)
        super(BlockingRouter, self).__init__(*args, **kwargs)
        for name in apps:
            try:
                self.add_app(name)
            except Exception as e:
                self.exception(e)
        for name, conf in backends.iteritems():
            parsed_conf = copy.copy(conf)
            engine = parsed_conf.pop('ENGINE')
            self.add_backend(name, engine, parsed_conf)
        self.start()  # legacy

    def receive_incoming(self, msg):
        from rapidsms.router import send
        # process incoming phases
        super(BlockingRouter, self).receive_incoming(msg)
        # handle message responses from within router
        for response in msg.responses:
            send(response.text, response.connections)
{'fraction_non_alphanumeric': 0.08648431214802896, 'fraction_numerical': 0.0, 'mean_word_length': 2.4831932773109244, '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': '7630497', 'n_tokens_mistral': 667, 'n_tokens_neox': 652, 'n_words': 190}