# 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
        def assertPIDGoneWithin(self, pid, timeout):
            start = time.time()
            while time.time() - start < timeout:
                if not self.pid_running(pid):
                    return
                time.sleep(0.1)

            assert not self.pid_running(pid)

        def free_port(self):
            with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
                s.bind(("0.0.0.0", 0))
                return s.getsockname()[1]

        def local(self, port, path):
            return "http://localhost:{0}{1}".format(port, path)

        def wait_for_pid(self, pid, timeout=5):
            start = time.time()
            while time.time() - start < timeout:
                if self.pid_running(pid):
                    return
                os.kill(pid, signal.SIGTERM)
                time.sleep(0.1)

            if self.pid_running(pid):
                os.kill(pid, signal.SIGKILL)

        def wait_for_file(self, filename, timeout=5):
            start = time.time()

# 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

        def assertPIDGoneWithin(self, pid, timeout):
            start = time.time()
            while time.time() - start < timeout:
                if not self.pid_running(pid):
                    return
                time.sleep(0.1)

            assert not self.pid_running(pid)

        def free_port(self):
            with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
                s.bind(("0.0.0.0", 0))
                return s.getsockname()[1]

        def local(self, port, path):
            return "http://localhost:{0}{1}".format(port, path)

        def wait_for_pid(self, pid, timeout=5):
            start = time.time()
            while time.time() - start < timeout:
                if self.pid_running(pid):
                    return
                os.kill(pid, signal.SIGTERM)
                time.sleep(0.1)

            if self.pid_running(pid):
                os.kill(pid, signal.SIGKILL)

        def wait_for_file(self, filename, timeout=5):
            start = time.time()

            while time.time() - start < timeout: