<commit_before>import tornado.httpserver
import tornado.websocket
import tornado.ioloop
import tornado.web
import zlib
import json
import datetime
import time
import logging

websockets = set()

class WSHandler(tornado.websocket.WebSocketHandler):

    def allow_draft76(self):
        # for iOS 5.0 Safari
        return True

    def open(self):
        websockets.add(self)

    def on_close(self):
        websockets.remove(self)

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.set_header("Content-Type", "application/json")
        self.write([])
    def post(self):
        try:
            if 'Content-Encoding' in self.request.headers and self.request.headers['Content-Encoding'] == 'deflate':
                message = zlib.decompress(self.request.body)
                for waiter in websockets:
                    waiter.write_message(message)
            else:
                message = self.request.body
            json_object = json.loads(message)
            print(json_object)
        except Exception as e:
            print(e)
            logging.error("Error sending message", exc_info=True)


application = tornado.web.Application([
    (r'/ws', WSHandler),
    (r"/post", MainHandler),
])


if __name__ == "__main__":
    try:
        http_server = tornado.httpserver.HTTPServer(application)
        http_server.listen(8080)
        main_loop = tornado.ioloop.IOLoop.instance().start()
    except:
        raise
<commit_msg>Try to load imput string as a json object before sharing<commit_after>import tornado.httpserver
import tornado.websocket
import tornado.ioloop
import tornado.web
import zlib
import json
import datetime
import time
import logging

websockets = set()

class WSHandler(tornado.websocket.WebSocketHandler):

    def allow_draft76(self):
        # for iOS 5.0 Safari
        return True

    def open(self):
        websockets.add(self)

    def on_close(self):
        websockets.remove(self)

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.set_header("Content-Type", "application/json")
        self.write([])
    def post(self):
        try:
            if 'Content-Encoding' in self.request.headers and self.request.headers['Content-Encoding'] == 'deflate':
                message = json.loads(zlib.decompress(self.request.body))
                for waiter in websockets:
                    waiter.write_message(message)
            else:
                message = self.request.body
            json_object = json.loads(message)
        except Exception as e:
            print(e)
            logging.error("Error sending message", exc_info=True)


application = tornado.web.Application([
    (r'/ws', WSHandler),
    (r"/post", MainHandler),
])


if __name__ == "__main__":
    try:
        http_server = tornado.httpserver.HTTPServer(application)
        http_server.listen(9999)
        main_loop = tornado.ioloop.IOLoop.instance().start()
    except:
        raise

{'fraction_non_alphanumeric': 0.10167785234899329, 'fraction_numerical': 0.005369127516778523, 'mean_word_length': 2.5111896348645466, 'pattern_counts': {'":': 2, '<': 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': '5476335', 'n_tokens_mistral': 896, 'n_tokens_neox': 846, 'n_words': 193}