MCPcopy Index your code
hub / github.com/RustPython/RustPython / http_multi_server

Function http_multi_server

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

Source from the content-addressed store, hash-verified

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

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