<commit_before>import os
from tornado.ioloop import IOLoop
from tornado.web import Application, StaticFileHandler
from snorky.server.message_handler import MessageHandler

from snorky.server.request_handlers.http import BackendHTTPHandler
from snorky.server.request_handlers.websocket import SnorkyWebSocketHandler

from snorky.server.services.pubsub import PubSubService, PubSubBackend

# Adapted from http://stackoverflow.com/a/23818878/1777162
class IndexAwareStaticFileHandler(StaticFileHandler):
    def parse_url_path(self, url_path):
        if not url_path or url_path.endswith('/'):
            url_path += 'index.html'

        return StaticFileHandler.parse_url_path(self, url_path)

class PrivatePubSub(PubSubService):
    def can_publish(self, client, channel):
        # Publishing is only allowed from the backend
        return False

if __name__ == "__main__":
    io_loop = IOLoop.instance()
    message_handler = MessageHandler()

    pubsub = PubSubService("pubsub")
    pubsub_backend = PubSubBackend("pubsub_backend", pubsub)
    message_handler.register_service(pubsub)
    message_handler.register_service(pubsub_backend)

    dirname = os.path.dirname(__file__)
    application = Application([
        SnorkyWebSocketHandler.get_route(message_handler, "/ws"),
        (r"/backend", BackendHTTPHandler, {
            "message_handler": message_handler,
            "api_key": "swordfish"
        }),
        (r"/(.*)", IndexAwareStaticFileHandler, {"path": dirname}),
    ])
    application.listen(5800)

    try:
        print("Snorky running...")
        IOLoop.instance().start()
    except KeyboardInterrupt:
        pass
<commit_msg>Use PrivatePubSub<commit_after>import os
from tornado.ioloop import IOLoop
from tornado.web import Application, StaticFileHandler
from snorky.server.message_handler import MessageHandler

from snorky.server.request_handlers.http import BackendHTTPHandler
from snorky.server.request_handlers.websocket import SnorkyWebSocketHandler

from snorky.server.services.pubsub import PubSubService, PubSubBackend

# Adapted from http://stackoverflow.com/a/23818878/1777162
class IndexAwareStaticFileHandler(StaticFileHandler):
    def parse_url_path(self, url_path):
        if not url_path or url_path.endswith('/'):
            url_path += 'index.html'

        return StaticFileHandler.parse_url_path(self, url_path)

class PrivatePubSub(PubSubService):
    def can_publish(self, client, channel):
        # Publishing is only allowed from the backend
        return False

if __name__ == "__main__":
    io_loop = IOLoop.instance()
    message_handler = MessageHandler()

    pubsub = PrivatePubSub("pubsub")
    pubsub_backend = PubSubBackend("pubsub_backend", pubsub)
    message_handler.register_service(pubsub)
    message_handler.register_service(pubsub_backend)

    dirname = os.path.dirname(__file__)
    application = Application([
        SnorkyWebSocketHandler.get_route(message_handler, "/ws"),
        (r"/backend", BackendHTTPHandler, {
            "message_handler": message_handler,
            "api_key": "swordfish"
        }),
        (r"/(.*)", IndexAwareStaticFileHandler, {"path": dirname}),
    ])
    application.listen(5800)

    try:
        print("Snorky running...")
        IOLoop.instance().start()
    except KeyboardInterrupt:
        pass

{'fraction_non_alphanumeric': 0.09555288461538461, 'fraction_numerical': 0.01141826923076923, 'mean_word_length': 3.8812316715542523, 'pattern_counts': {'":': 8, '<': 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': '4424719', 'n_tokens_mistral': 1014, 'n_tokens_neox': 969, 'n_words': 199}