MCPcopy Index your code
hub / github.com/python/cpython / test

Function test

Lib/http/server.py:975–1005  ·  view source on GitHub ↗

Test the HTTP request handler class. This runs an HTTP server on port 8000 (or the port argument).

(HandlerClass=BaseHTTPRequestHandler,
         ServerClass=ThreadingHTTPServer,
         protocol="HTTP/1.0", port=8000, bind=None,
         tls_cert=None, tls_key=None, tls_password=None)

Source from the content-addressed store, hash-verified

973
974
975def test(HandlerClass=BaseHTTPRequestHandler,
976 ServerClass=ThreadingHTTPServer,
977 protocol="HTTP/1.0", port=8000, bind=None,
978 tls_cert=None, tls_key=None, tls_password=None):
979 """Test the HTTP request handler class.
980
981 This runs an HTTP server on port 8000 (or the port argument).
982
983 """
984 ServerClass.address_family, addr = _get_best_family(bind, port)
985 HandlerClass.protocol_version = protocol
986
987 if tls_cert:
988 server = ServerClass(addr, HandlerClass, certfile=tls_cert,
989 keyfile=tls_key, password=tls_password)
990 else:
991 server = ServerClass(addr, HandlerClass)
992
993 with server as httpd:
994 host, port = httpd.socket.getsockname()[:2]
995 url_host = f'[{host}]' if ':' in host else host
996 protocol = 'HTTPS' if tls_cert else 'HTTP'
997 print(
998 f"Serving {protocol} on {host} port {port} "
999 f"({protocol.lower()}://{url_host}:{port}/) ..."
1000 )
1001 try:
1002 httpd.serve_forever()
1003 except KeyboardInterrupt:
1004 print("\nKeyboard interrupt received, exiting.")
1005 sys.exit(0)
1006
1007
1008def _main(args=None):

Callers 1

_mainFunction · 0.70

Calls 5

_get_best_familyFunction · 0.85
getsocknameMethod · 0.45
lowerMethod · 0.45
serve_foreverMethod · 0.45
exitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…