def webserver(func):
    """Runs the given function as a webserver.

    Function should take one argument, the path of the request. Should
    return tuple (status, content_type, content) or Nothing if there is no
    response.
    """
    class HandlerClass(BaseHTTPServer.BaseHTTPRequestHandler):
        def do_GET(self):
            output = func(self.path)
            if output:
                code, content_type, result = output
            else:
                code, content_type, result = 404, 'text/plain', 'Not found!'

            self.send_response(code)
            self.send_header('Content-Type', content_type)
            self.end_headers()
            if result:
                self.wfile.write(result)

    server = BaseHTTPServer.HTTPServer(('', 0), HandlerClass)
    thread = threading.Thread(target=server.serve_forever)
    thread.daemon = True
    thread.start()
    server.server_prefix = 'http://localhost:%d' % server.server_address[1]
    logging.info('Test server started on %s', server.server_prefix)
    return server
dataset/ETHPy150Open bslatkin/dpxdt/tests/site_diff_test.py/webserver/original