<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-

from Tkinter import Tk, BOTH, Frame
from Queue import Queue, Empty
from threading import Thread
import BaseHTTPServer
import Tkinter as tk
import json

try:
    import winsound
except ImportError:
    pass

HOST = '127.0.0.1'
PORT = 5000

ServerClass = BaseHTTPServer.HTTPServer
Protocol = "HTTP/1.0"

queue = Queue()


class HandlerClass(BaseHTTPServer.BaseHTTPRequestHandler):
    app = None

    def do_POST(s):
        if s.path == '/':
            try:
                content_lenght = int(s.headers['Content-Length'])
                post_data = json.loads(s.rfile.read(content_lenght))
                HandlerClass.app.display(post_data['display'])
            except:
                s.send_response(500)
                s.send_header("Content-type", "application/json")
                s.end_headers()
                s.wfile.write(json.dumps({'status': 'KO'}))

            s.send_response(200)
            s.send_header("Content-type", "application/json")
            s.end_headers()
            s.wfile.write(json.dumps({'status': 'OK'}))
        else:
            s.send_response(404)


    def do_GET(s):
        if s.path == '/':
            s.send_response(200)
            s.send_header("Content-type", "application/json")
            s.end_headers()
            try:
                barcode = queue.get(timeout=2)
                s.wfile.write(json.dumps({'status': 'OK', 'barcode': barcode}))
                queue.task_done()
            except Empty:
                s.wfile.write(json.dumps({'status': 'Empty'}))
        else:
            s.send_response(404)


class WebserverThread(Thread):
    def __init__(self, app):
        Thread.__init__(self)
        self.server_address = (HOST, PORT)
        HandlerClass.protocol_version = Protocol
        HandlerClass.app = app
        self.httpd = ServerClass(self.server_address, HandlerClass)

    def run(self):
        sa = self.httpd.socket.getsockname()
        print "Serving HTTP on", sa[0], "port", sa[1], "..."
        self.httpd.serve_forever()

<commit_msg>add a TIMEOUT constant setted to 1<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-

from Tkinter import Tk, BOTH, Frame
from Queue import Queue, Empty
from threading import Thread
import BaseHTTPServer
import Tkinter as tk
import json
try:
    import winsound
except ImportError:
    pass

TIMEOUT = 1
HOST = '127.0.0.1'
PORT = 5000

ServerClass = BaseHTTPServer.HTTPServer
Protocol = "HTTP/1.0"

queue = Queue()


class HandlerClass(BaseHTTPServer.BaseHTTPRequestHandler):
    app = None

    def do_POST(s):
        if s.path == '/':
            try:
                content_lenght = int(s.headers['Content-Length'])
                post_data = json.loads(s.rfile.read(content_lenght))
                HandlerClass.app.display(post_data['display'])
            except:
                s.send_response(500)
                s.send_header("Content-type", "application/json")
                s.end_headers()
                s.wfile.write(json.dumps({'status': 'KO'}))

            s.send_response(200)
            s.send_header("Content-type", "application/json")
            s.end_headers()
            s.wfile.write(json.dumps({'status': 'OK'}))
        else:
            s.send_response(404)


    def do_GET(s):
        if s.path == '/':
            s.send_response(200)
            s.send_header("Content-type", "application/json")
            s.end_headers()
            try:
                barcode = queue.get(timeout=TIMEOUT)
                s.wfile.write(json.dumps({'status': 'OK', 'barcode': barcode}))
                queue.task_done()
            except Empty:
                s.wfile.write(json.dumps({'status': 'Empty'}))
        else:
            s.send_response(404)


class WebserverThread(Thread):
    def __init__(self, app):
        Thread.__init__(self)
        self.server_address = (HOST, PORT)
        HandlerClass.protocol_version = Protocol
        HandlerClass.app = app
        self.httpd = ServerClass(self.server_address, HandlerClass)

    def run(self):
        sa = self.httpd.socket.getsockname()
        print "Serving HTTP on", sa[0], "port", sa[1], "..."
        self.httpd.serve_forever()


{'fraction_non_alphanumeric': 0.12878071833648394, 'fraction_numerical': 0.014886578449905482, 'mean_word_length': 2.069615663524293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4372596', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1300, 'n_words': 250}