<commit_before>import os.path
from contextlib import contextmanager
import socket
import socketserver
import threading
from http.server import SimpleHTTPRequestHandler
import json
from urllib.request import urlopen

import h11

@contextmanager
def socket_server(handler):
    httpd = socketserver.TCPServer(("127.0.0.1", 0), handler)
    thread = threading.Thread(target=httpd.serve_forever,
                              kwargs={"poll_interval": 0.01},
                              daemon=True)
    try:
        thread.start()
        yield httpd
    finally:
        httpd.shutdown()

test_file_path = os.path.join(os.path.dirname(__file__), "data/test-file")
with open(test_file_path, "rb") as f:
    test_file_data = f.read()

class SingleMindedRequestHandler(SimpleHTTPRequestHandler):
    def translate_path(self, path):
        return test_file_path<commit_msg>Conditional Python 2 imports.<commit_after>import os.path
from contextlib import contextmanager
import socket
import threading
import json

try:
    from urllib.request import urlopen
except ImportError:  # version specific: Python 2
    from urllib2 import urlopen

try:
    import socketserver
except ImportError:  # version specific: Python 2
    import SocketServer as socketserver

try:
    from http.server import SimpleHTTPRequestHandler
except ImportError:  # version specific: Python 2
    from SimpleHTTPServer import SimpleHTTPRequestHandler

import h11

@contextmanager
def socket_server(handler):
    httpd = socketserver.TCPServer(("127.0.0.1", 0), handler)
    thread = threading.Thread(target=httpd.serve_forever,
                              kwargs={"poll_interval": 0.01},
                              daemon=True)
    try:
        thread.start()
        yield httpd
    finally:
        httpd.shutdown()

test_file_path = os.path.join(os.path.dirname(__file__), "data/test-file")
with open(test_file_path, "rb") as f:
    test_file_data = f.read()

class SingleMindedRequestHandler(SimpleHTTPRequestHandler):
    def translate_path(self, path):
        return test_file_path
{'fraction_non_alphanumeric': 0.08187984496124032, 'fraction_numerical': 0.014050387596899225, 'mean_word_length': 3.365750528541226, 'pattern_counts': {'":': 2, '<': 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': '7133979', 'n_tokens_mistral': 612, 'n_tokens_neox': 598, 'n_words': 153}