Ejemplo n.º 1
0
def server(evt, numrequests):
    serv = DocXMLRPCServer(("localhost", 0), logRequests=False)

    try:
        global PORT
        PORT = serv.socket.getsockname()[1]

        # Add some documentation
        serv.set_server_title("DocXMLRPCServer Test Documentation")
        serv.set_server_name("DocXMLRPCServer Test Docs")
        serv.set_server_documentation(
            "This is an XML-RPC server's documentation, but the server "
            "can be used by POSTing to /RPC2. Try self.add, too."
        )

        # Create and register classes and functions
        class TestClass(object):
            def test_method(self, arg):
                """Test method's docs. This method truly does very little."""
                self.arg = arg

        serv.register_introspection_functions()
        serv.register_instance(TestClass())

        def add(x, y):
            """Add two instances together. This follows PEP008, but has nothing
            to do with RFC1952. Case should matter: pEp008 and rFC1952.  Things
            that start with http and ftp should be auto-linked, too:
            http://google.com.
            """
            return x + y

        def annotation(x: int):
            """ Use function annotations. """
            return x

        class ClassWithAnnotation:
            def method_annotation(self, x: bytes):
                return x.decode()

        serv.register_function(add)
        serv.register_function(lambda x, y: x - y)
        serv.register_function(annotation)
        serv.register_instance(ClassWithAnnotation())

        while numrequests > 0:
            serv.handle_request()
            numrequests -= 1
    except socket.timeout:
        pass
    finally:
        serv.server_close()
        PORT = None
        evt.set()
Ejemplo n.º 2
0
def server(evt, numrequests):
    serv = DocXMLRPCServer(("localhost", 0), logRequests=False)

    try:
        global PORT
        PORT = serv.socket.getsockname()[1]

        # Add some documentation
        serv.set_server_title("DocXMLRPCServer Test Documentation")
        serv.set_server_name("DocXMLRPCServer Test Docs")
        serv.set_server_documentation(
            "This is an XML-RPC server's documentation, but the server "
            "can be used by POSTing to /RPC2. Try self.add, too.")

        # Create and register classes and functions
        class TestClass(object):
            def test_method(self, arg):
                """Test method's docs. This method truly does very little."""
                self.arg = arg

        serv.register_introspection_functions()
        serv.register_instance(TestClass())

        def add(x, y):
            """Add two instances together. This follows PEP008, but has nothing
            to do with RFC1952. Case should matter: pEp008 and rFC1952.  Things
            that start with http and ftp should be auto-linked, too:
            http://google.com.
            """
            return x + y

        def annotation(x: int):
            """ Use function annotations. """
            return x

        class ClassWithAnnotation:
            def method_annotation(self, x: bytes):
                return x.decode()

        serv.register_function(add)
        serv.register_function(lambda x, y: x-y)
        serv.register_function(annotation)
        serv.register_instance(ClassWithAnnotation())

        while numrequests > 0:
            serv.handle_request()
            numrequests -= 1
    except socket.timeout:
        pass
    finally:
        serv.server_close()
        PORT = None
        evt.set()
Ejemplo n.º 3
0
def docxmlrpcserver(title, name, documentation):
    p = int(os.environ['INITIAL_PORT']
            )  # avoid starting the server on the same port by PyExZ3
    serv = DocXMLRPCServer(("localhost", p), logRequests=False)
    serv.set_server_title(title)  #"DocXMLRPCServer Test Documentation")
    serv.set_server_name(name)  #"DocXMLRPCServer Test Docs")
    serv.set_server_documentation(
        documentation)  #"This is an XML-RPC server's documentation")
    serv.register_introspection_functions()
    serv.register_multicall_functions()
    serv.register_function(lambda x, y: x + y)
    serv.register_instance(DocXMLRPCServer(("localhost", p + 1)))
    generated = serv.generate_html_documentation()
    os.environ["INITIAL_PORT"] = str(p + 2)
    if '<script>' in generated:
        return 'dangerous'
    else:
        return 'safe'
Ejemplo n.º 4
0
def make_server():
    serv = DocXMLRPCServer(('localhost', 0), logRequests=False)
    try:
        serv.set_server_title('DocXMLRPCServer Test Documentation')
        serv.set_server_name('DocXMLRPCServer Test Docs')
        serv.set_server_documentation(
            "This is an XML-RPC server's documentation, but the server can be used by POSTing to /RPC2. Try self.add, too."
        )

        class TestClass(object):
            def test_method(self, arg):
                """Test method's docs. This method truly does very little."""
                self.arg = arg

        serv.register_introspection_functions()
        serv.register_instance(TestClass())

        def add(x, y):
            """Add two instances together. This follows PEP008, but has nothing
            to do with RFC1952. Case should matter: pEp008 and rFC1952.  Things
            that start with http and ftp should be auto-linked, too:
            http://google.com.
            """
            return x + y

        def annotation(x: int):
            """ Use function annotations. """
            return x

        class ClassWithAnnotation:
            def method_annotation(self, x: bytes):
                return x.decode()

        serv.register_function(add)
        serv.register_function(lambda x, y: x - y)
        serv.register_function(annotation)
        serv.register_instance(ClassWithAnnotation())
        return serv
    except:
        serv.server_close()
        raise
Ejemplo n.º 5
0
	def register_instance(self, inst):
		DocXMLRPCServer.register_instance(self, _KeywordInstance(inst))