# Path: harpoon/container_manager.py
# def make_server(manager, address):
#     class RequestHandler(BaseHTTPRequestHandler):
#         def handle(self):
#             try:
#                 super().handle()
#             except KeyboardInterrupt:
#                 raise
#             except Exception as error:
#                 self.send_response(500)
#                 self.send_header("Content-Type", "application/json")
#                 self.end_headers()
# 
#                 if isinstance(error, DelfickError):
#                     asdct = error.as_dict()
#                 else:
#                     log.exception("Unexpected error")
#                     asdct = {"message": str(error)}
# 
#                 e = {"error": asdct, "error_code": error.__class__.__name__}
#                 self.wfile.write(json.dumps(e, default=lambda o: repr(o)).encode())
# 
#         def do_GET(self):
#             if self.path == "/version":
#                 manager.version(self)
#             elif self.path == "/shutdown":
#                 if manager.shutting_down:
#                     self.send_response(204)
#                     self.end_headers()
#                 else:
#                     manager.shutdown(self)
#             else:
#                 self.send_response(404)
#                 self.end_headers()
#                 self.wfile.write("Unknown path: {0}".format(self.path).encode())
# 
#         def do_POST(self):
#             if self.path == "/stop_container":
#                 manager.stop_container(self)
#             elif self.path == "/start_container":
#                 manager.start_container(self)
#             elif self.path == "/unlock_container":
#                 manager.unlock_container(self)
#             else:
#                 self.send_response(404)
#                 self.end_headers()
#                 self.wfile.write("Unknown path: {0}".format(self.path).encode())
# 
#         def log_message(self, format, *args):
#             log.info("%s - %s", self.address_string(), format % args)
# 
#     class Server(socketserver.ThreadingMixIn, HTTPServer):
#         pass
# 
#     return Server(address, RequestHandler)


from harpoon.container_manager import make_server
from contextlib import contextmanager
import subprocess
import threading
import requests
import tempfile
import socket
import psutil
import signal
import pytest
import time
import sys
import os
                if os.path.exists(filename):
                    return
                time.sleep(0.1)

            if not os.path.exists(filename):
                assert False, "Failed to wait for filename: {0}".format(filename)

        def wait_for_port(self, port, timeout=2):
            start = time.time()
            while time.time() - start < timeout:
                if self.port_connected(port):
                    return
                time.sleep(0.1)

            assert self.port_connected(port)

        def assertForks(self, info, timeout=1):
            start = time.time()
            while time.time() - start < timeout:
                if info["done"]:
                    return

            if not info["done"]:
                assert False, "The process should have forked, but it hasn't within timeout"

        def version(self, info):
            return requests.get(self.local(info["port"], "/version")).content.decode()

        def start_inprocess(self, manager):
            port = self.free_port()

# Path: harpoon/container_manager.py
# def make_server(manager, address):
#     class RequestHandler(BaseHTTPRequestHandler):
#         def handle(self):
#             try:
#                 super().handle()
#             except KeyboardInterrupt:
#                 raise
#             except Exception as error:
#                 self.send_response(500)
#                 self.send_header("Content-Type", "application/json")
#                 self.end_headers()
# 
#                 if isinstance(error, DelfickError):
#                     asdct = error.as_dict()
#                 else:
#                     log.exception("Unexpected error")
#                     asdct = {"message": str(error)}
# 
#                 e = {"error": asdct, "error_code": error.__class__.__name__}
#                 self.wfile.write(json.dumps(e, default=lambda o: repr(o)).encode())
# 
#         def do_GET(self):
#             if self.path == "/version":
#                 manager.version(self)
#             elif self.path == "/shutdown":
#                 if manager.shutting_down:
#                     self.send_response(204)
#                     self.end_headers()
#                 else:
#                     manager.shutdown(self)
#             else:
#                 self.send_response(404)
#                 self.end_headers()
#                 self.wfile.write("Unknown path: {0}".format(self.path).encode())
# 
#         def do_POST(self):
#             if self.path == "/stop_container":
#                 manager.stop_container(self)
#             elif self.path == "/start_container":
#                 manager.start_container(self)
#             elif self.path == "/unlock_container":
#                 manager.unlock_container(self)
#             else:
#                 self.send_response(404)
#                 self.end_headers()
#                 self.wfile.write("Unknown path: {0}".format(self.path).encode())
# 
#         def log_message(self, format, *args):
#             log.info("%s - %s", self.address_string(), format % args)
# 
#     class Server(socketserver.ThreadingMixIn, HTTPServer):
#         pass
# 
#     return Server(address, RequestHandler)


# Path: tests/helpers/mixins/container_manager.py
from harpoon.container_manager import make_server
from contextlib import contextmanager
import subprocess
import threading
import requests
import tempfile
import socket
import psutil
import signal
import pytest
import time
import sys
import os

                if os.path.exists(filename):
                    return
                time.sleep(0.1)

            if not os.path.exists(filename):
                assert False, "Failed to wait for filename: {0}".format(filename)

        def wait_for_port(self, port, timeout=2):
            start = time.time()
            while time.time() - start < timeout:
                if self.port_connected(port):
                    return
                time.sleep(0.1)

            assert self.port_connected(port)

        def assertForks(self, info, timeout=1):
            start = time.time()
            while time.time() - start < timeout:
                if info["done"]:
                    return

            if not info["done"]:
                assert False, "The process should have forked, but it hasn't within timeout"

        def version(self, info):
            return requests.get(self.local(info["port"], "/version")).content.decode()

        def start_inprocess(self, manager):
            port = self.free_port()

            server = make_server(manager, ("127.0.0.1", port))