<commit_before>__author__ = 'Isaac'
from multiprocessing.queues import Empty


class Router:
    def __init__(self, response_queue, command_queue):
        self.response_queue = response_queue
        self.command_queue = command_queue
        self.routes = {}

    def handle(self):
        try:
            command = self.command_queue.get(block=False)
            if command is not None:
                url = None
                try:
                    url = command["url"]
                    self.response_queue.put({"url": url, "body": self.routes[url](command["body"])})
                except KeyError:
                    print("could not handle " + str(url))
        except Empty:
            pass

    def route(self, url):
        def decorator(function):
            self.routes[url] = function
            return function
        return decorator

    def __getitem__(self, item):
        return self.routes[item]<commit_msg>Maybe Better<commit_after>__author__ = 'Isaac'
from multiprocessing.queues import Empty


class Router:
    def __init__(self, response_queue, command_queue):
        self.response_queue = response_queue
        self.command_queue = command_queue
        self.routes = {}

    def handle(self):
        try:
            command = self.command_queue.get(block=False)
            if command is not None:
                url = None
                try:
                    url = command["url"]
                    self.response_queue.put({"url": url, "body": self[url](command["body"])})
                except KeyError:
                    print("could not handle " + str(url))
        except Empty:
            pass

    def route(self, url):
        def decorator(function):
            self.routes[url] = function
            return function
        return decorator

    def __getitem__(self, item):
        return self.routes[item]
{'fraction_non_alphanumeric': 0.09328358208955224, 'fraction_numerical': 0.0, 'mean_word_length': 1.7973174366616989, 'pattern_counts': {'":': 4, '<': 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': '574196', 'n_tokens_mistral': 509, 'n_tokens_neox': 489, 'n_words': 122}