<commit_before># -*- coding: utf-8 -*-
import json
import logging
import tornado.gen
import tornado.ioloop
import tornado.web
import tornado.websocket
import tornadoredis
from concurrent.futures import ThreadPoolExecutor
from django.utils.module_loading import import_by_path

from .settings import SUBSCRIBER_CLASS_PATH, REDIS_HOST, REDIS_PORT
from .settings import REDIS_CHANNELS, MAX_WORKERS
from .registry import registry, autodiscover

autodiscover()

__all__ = ('WebSocketServer',)
LOGGER = logging.getLogger('mease.websocket_server')


class WebSocketHandler(tornado.websocket.WebSocketHandler):

    def open(self):
        # Init storage
        self.storage = {}

        # Call openers callbacks
        for func in self.application.registry.openers:
            self.application.executor.submit(func, self, self.application.clients)

        # Append client to clients list
        if self not in self.application.clients:
            self.application.clients.append(self)

    def on_close(self):
        # Call closer callbacks
        for func in self.application.registry.closers:
            self.application.executor.submit(func, self, self.application.clients)

        # Remove client from clients list
        if self in self.application.clients:
            self.application.clients.remove(self)

    def on_message(self, message):
        # Call receiver callbacks
        for func, to_json in self.application.registry.receivers:

            if to_json:
                try:
                    message = json.loads(message)
                except ValueError:
                    continue

            self.application.executor.submit(
                func, self, message, self.application.clients)

<commit_msg>Added `send` method on websocket client<commit_after># -*- coding: utf-8 -*-
import json
import logging
import tornado.gen
import tornado.ioloop
import tornado.web
import tornado.websocket
import tornadoredis
from concurrent.futures import ThreadPoolExecutor
from django.utils.module_loading import import_by_path

from .settings import SUBSCRIBER_CLASS_PATH, REDIS_HOST, REDIS_PORT
from .settings import REDIS_CHANNELS, MAX_WORKERS
from .registry import registry, autodiscover

autodiscover()

__all__ = ('WebSocketServer',)
LOGGER = logging.getLogger('mease.websocket_server')


class WebSocketHandler(tornado.websocket.WebSocketHandler):

    def open(self):
        # Init storage
        self.storage = {}

        # Call openers callbacks
        for func in self.application.registry.openers:
            self.application.executor.submit(func, self, self.application.clients)

        # Append client to clients list
        if self not in self.application.clients:
            self.application.clients.append(self)

    def on_close(self):
        # Call closer callbacks
        for func in self.application.registry.closers:
            self.application.executor.submit(func, self, self.application.clients)

        # Remove client from clients list
        if self in self.application.clients:
            self.application.clients.remove(self)

    def on_message(self, message):
        # Call receiver callbacks
        for func, to_json in self.application.registry.receivers:

            if to_json:
                try:
                    message = json.loads(message)
                except ValueError:
                    continue

            self.application.executor.submit(
                func, self, message, self.application.clients)

    def send(self, *args, **kwargs):
        self.write_message(*args, **kwargs)


{'fraction_non_alphanumeric': 0.07733109994416527, 'fraction_numerical': 0.0005583472920156337, 'mean_word_length': 2.709109730848861, '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': '2589763', 'n_tokens_mistral': 1002, 'n_tokens_neox': 955, 'n_words': 251}