MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / _loopback_server

Function _loopback_server

pkg/pypi/tests/test_cli.py:1043–1071  ·  view source on GitHub ↗

Serve `routes` ({path: bytes}) on 127.0.0.1; any other path redirects.

(routes)

Source from the content-addressed store, hash-verified

1041
1042@contextlib.contextmanager
1043def _loopback_server(routes):
1044 """Serve `routes` ({path: bytes}) on 127.0.0.1; any other path redirects."""
1045
1046 class Handler(http.server.BaseHTTPRequestHandler):
1047 def do_GET(self):
1048 body = routes.get(self.path)
1049 if body is None:
1050 self.send_response(302)
1051 self.send_header("Location", "https://example.invalid/elsewhere")
1052 self.send_header("Content-Length", "0")
1053 self.end_headers()
1054 return
1055 self.send_response(200)
1056 self.send_header("Content-Length", str(len(body)))
1057 self.end_headers()
1058 self.wfile.write(body)
1059
1060 def log_message(self, *args):
1061 pass
1062
1063 server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), Handler)
1064 thread = threading.Thread(target=server.serve_forever, daemon=True)
1065 thread.start()
1066 try:
1067 yield f"http://127.0.0.1:{server.server_address[1]}"
1068 finally:
1069 server.shutdown()
1070 server.server_close()
1071 thread.join()
1072
1073
1074class DownloadBaseTests(unittest.TestCase):

Calls 1

startMethod · 0.80

Tested by

no test coverage detected