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

Class TestHTTPServer

Lib/test/test_logging.py:998–1037  ·  view source on GitHub ↗

An HTTP server which is controllable using :class:`ControlMixin`. :param addr: A tuple with the IP address and port to listen on. :param handler: A handler callable which will be called with a single parameter - the request - in order to process

Source from the content-addressed store, hash-verified

996 self.ready.clear()
997
998class TestHTTPServer(ControlMixin, HTTPServer):
999 """
1000 An HTTP server which is controllable using :class:`ControlMixin`.
1001
1002 :param addr: A tuple with the IP address and port to listen on.
1003 :param handler: A handler callable which will be called with a
1004 single parameter - the request - in order to
1005 process the request.
1006 :param poll_interval: The polling interval in seconds.
1007 :param log: Pass ``True`` to enable log messages.
1008 """
1009 def __init__(self, addr, handler, poll_interval=0.5,
1010 log=False, sslctx=None):
1011 class DelegatingHTTPRequestHandler(BaseHTTPRequestHandler):
1012 def __getattr__(self, name, default=None):
1013 if name.startswith('do_'):
1014 return self.process_request
1015 raise AttributeError(name)
1016
1017 def process_request(self):
1018 self.server._handler(self)
1019
1020 def log_message(self, format, *args):
1021 if log:
1022 super(DelegatingHTTPRequestHandler,
1023 self).log_message(format, *args)
1024 HTTPServer.__init__(self, addr, DelegatingHTTPRequestHandler)
1025 ControlMixin.__init__(self, handler, poll_interval)
1026 self.sslctx = sslctx
1027
1028 def get_request(self):
1029 try:
1030 sock, addr = self.socket.accept()
1031 if self.sslctx:
1032 sock = self.sslctx.wrap_socket(sock, server_side=True)
1033 except OSError as e:
1034 # socket errors are silenced by the caller, print them here
1035 sys.stderr.write("Got an error:\n%s\n" % e)
1036 raise
1037 return sock, addr
1038
1039class TestTCPServer(ControlMixin, ThreadingTCPServer):
1040 """

Callers 1

test_outputMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_outputMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…