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

Function http_multi_server

Lib/test/test_xmlrpc.py:676–744  ·  view source on GitHub ↗
(evt, numrequests, requestHandler=None)

Source from the content-addressed store, hash-verified

674 evt.set()
675
676def http_multi_server(evt, numrequests, requestHandler=None):
677 class TestInstanceClass:
678 def div(self, x, y):
679 return x // y
680
681 def _methodHelp(self, name):
682 if name == 'div':
683 return 'This is the div function'
684
685 def my_function():
686 '''This is my function'''
687 return True
688
689 class MyXMLRPCServer(xmlrpc.server.MultiPathXMLRPCServer):
690 def get_request(self):
691 # Ensure the socket is always non-blocking. On Linux, socket
692 # attributes are not inherited like they are on *BSD and Windows.
693 s, port = self.socket.accept()
694 s.setblocking(True)
695 return s, port
696
697 if not requestHandler:
698 requestHandler = xmlrpc.server.SimpleXMLRPCRequestHandler
699 class MyRequestHandler(requestHandler):
700 rpc_paths = []
701
702 class BrokenDispatcher:
703 def _marshaled_dispatch(self, data, dispatch_method=None, path=None):
704 raise RuntimeError("broken dispatcher")
705
706 serv = MyXMLRPCServer(("localhost", 0), MyRequestHandler,
707 logRequests=False, bind_and_activate=False)
708 serv.socket.settimeout(3)
709 serv.server_bind()
710 try:
711 global ADDR, PORT, URL
712 ADDR, PORT = serv.socket.getsockname()
713 #connect to IP address directly. This avoids socket.create_connection()
714 #trying to connect to "localhost" using all address families, which
715 #causes slowdown e.g. on vista which supports AF_INET6. The server listens
716 #on AF_INET only.
717 URL = "http://%s:%d"%(ADDR, PORT)
718 serv.server_activate()
719 paths = [
720 "/foo", "/foo/bar",
721 "/foo?k=v", "/foo#frag", "/foo?k=v#frag",
722 "", "/", "/RPC2", "?k=v", "#frag",
723 ]
724 for path in paths:
725 d = serv.add_dispatcher(path, xmlrpc.server.SimpleXMLRPCDispatcher())
726 d.register_introspection_functions()
727 d.register_multicall_functions()
728 d.register_function(lambda p=path: p, 'test')
729 serv.get_dispatcher(paths[0]).register_function(pow)
730 serv.get_dispatcher(paths[1]).register_function(lambda x,y: x+y, 'add')
731 serv.add_dispatcher("/is/broken", BrokenDispatcher())
732 evt.set()
733

Callers

nothing calls this directly

Calls 14

MyXMLRPCServerClass · 0.85
BrokenDispatcherClass · 0.85
add_dispatcherMethod · 0.80
register_functionMethod · 0.80
get_dispatcherMethod · 0.80
settimeoutMethod · 0.45
server_bindMethod · 0.45
getsocknameMethod · 0.45
server_activateMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…