<commit_before># coding: utf-8


import json
import sys
import code

from io import BytesIO
from tornado import ioloop, web, template, gen

@gen.coroutine
def _eval(request):
    ns = {}
    to_eval = json.loads(request.body)['toEval']
    out, err = sys.stdout, sys.stderr
    fake_stdout, fake_stderr = BytesIO(), BytesIO()
    sys.stdout, sys.stderr = fake_stdout, fake_stderr
    console = code.InteractiveConsole(locals=ns)
    for statement in to_eval.split("\n"):
        if statement:
            console.push(statement)
        else:
            console.push('\n')
    sys.stdout, sys.stderr = out, err

    out_result, err_result = fake_stdout.getvalue(), fake_stderr.getvalue()

    return {"out": out_result,
           "err": err_result
           }


loader = template.Loader('templates')

class MainHandler(web.RequestHandler):
    def get(self):
        self.write(loader.load("main.html").generate())


class EvalHandler(web.RequestHandler):

    @gen.coroutine
    def post(self):
        response = yield _eval(self.request)
        self.write(response)


def make_app():
    return web.Application([
        (r"/", MainHandler),
        (r"/eval", EvalHandler),
        (r'/static/(.*)', web.StaticFileHandler, {'path': 'static/'}),
    ])

if __name__ == "__main__":
    app = make_app()
    app.listen(8080)
    ioloop.IOLoop.current().start()
<commit_msg>fix things that broke on python3<commit_after># coding: utf-8


import json
import sys
import code

from io import BytesIO, StringIO
from tornado import ioloop, web, template, gen

@gen.coroutine
def _eval(request):
    ns = {}
    to_eval = json.loads(request.body.decode('utf-8'))['toEval']
    out, err = sys.stdout, sys.stderr
    fake_stdout, fake_stderr = StringIO(), StringIO()
    sys.stdout, sys.stderr = fake_stdout, fake_stderr
    console = code.InteractiveConsole(locals=ns)
    for statement in to_eval.split("\n"):
        if statement:
            console.push(statement)
        else:
            console.push('\n')
    sys.stdout, sys.stderr = out, err

    out_result, err_result = fake_stdout.getvalue(), fake_stderr.getvalue()

    return {"out": out_result,
           "err": err_result
           }


loader = template.Loader('templates')

class MainHandler(web.RequestHandler):
    def get(self):
        self.write(loader.load("main.html").generate())


class EvalHandler(web.RequestHandler):

    @gen.coroutine
    def post(self):
        response = yield _eval(self.request)
        self.write(response)


def make_app():
    return web.Application([
        (r"/", MainHandler),
        (r"/eval", EvalHandler),
        (r'/static/(.*)', web.StaticFileHandler, {'path': 'static/'}),
    ])

if __name__ == "__main__":
    app = make_app()
    app.listen(8080)
    ioloop.IOLoop.current().start()

{'fraction_non_alphanumeric': 0.13949339992864787, 'fraction_numerical': 0.004281127363539065, 'mean_word_length': 2.966053748231966, 'pattern_counts': {'":': 6, '<': 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': '7066151', 'n_tokens_mistral': 904, 'n_tokens_neox': 887, 'n_words': 200}