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

Function http_server

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

Source from the content-addressed store, hash-verified

610# Second when the server has been shutdown. The user must clear
611# the event after it has been set the first time to catch the second set.
612def http_server(evt, numrequests, requestHandler=None, encoding=None):
613 class TestInstanceClass:
614 def div(self, x, y):
615 return x // y
616
617 def _methodHelp(self, name):
618 if name == 'div':
619 return 'This is the div function'
620
621 class Fixture:
622 @staticmethod
623 def getData():
624 return '42'
625
626 class MyXMLRPCServer(xmlrpc.server.SimpleXMLRPCServer):
627 def get_request(self):
628 # Ensure the socket is always non-blocking. On Linux, socket
629 # attributes are not inherited like they are on *BSD and Windows.
630 s, port = self.socket.accept()
631 s.setblocking(True)
632 return s, port
633
634 if not requestHandler:
635 requestHandler = xmlrpc.server.SimpleXMLRPCRequestHandler
636 serv = MyXMLRPCServer(("localhost", 0), requestHandler,
637 encoding=encoding,
638 logRequests=False, bind_and_activate=False)
639 try:
640 serv.server_bind()
641 global ADDR, PORT, URL
642 ADDR, PORT = serv.socket.getsockname()
643 #connect to IP address directly. This avoids socket.create_connection()
644 #trying to connect to "localhost" using all address families, which
645 #causes slowdown e.g. on vista which supports AF_INET6. The server listens
646 #on AF_INET only.
647 URL = "http://%s:%d"%(ADDR, PORT)
648 serv.server_activate()
649 serv.register_introspection_functions()
650 serv.register_multicall_functions()
651 serv.register_function(pow)
652 serv.register_function(lambda x: x, 'têšt')
653 @serv.register_function
654 def my_function():
655 '''This is my function'''
656 return True
657 @serv.register_function(name='add')
658 def _(x, y):
659 return x + y
660 testInstance = TestInstanceClass()
661 serv.register_instance(testInstance, allow_dotted_names=True)
662 evt.set()
663
664 # handle up to 'numrequests' requests
665 while numrequests > 0:
666 serv.handle_request()
667 numrequests -= 1
668
669 except TimeoutError:

Callers 1

threadFuncMethod · 0.85

Calls 12

MyXMLRPCServerClass · 0.85
TestInstanceClassClass · 0.85
register_functionMethod · 0.80
register_instanceMethod · 0.80
server_bindMethod · 0.45
getsocknameMethod · 0.45
server_activateMethod · 0.45
setMethod · 0.45
handle_requestMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…