tags:

views:

34

answers:

2

I want to do a very simple webserver in python able to receive XML document over HTTP and then to send as response XML document.

Do you have any example?

just to understand How arrange the work...

many thanks!

UPDATE:

I need something like this:

a client do a post with an xml document: < request > < name>plus< /name> < param>2< /param> < param>3< /param> < /request>'

the python server answers: < response> < result>OK< /result> < outcome>5< /outcome> < /response >

Do you have an example for such kind of things??

A: 

Example with standard library:

Or use some lightweight web framework:

The MYYN
+1  A: 

You can use XMLRPC :

SimpleXMLRPCServer Example (from the Python Docs)

Server code:

from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler

# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
    rpc_paths = ('/RPC2',)

# Create server
server = SimpleXMLRPCServer(("localhost", 8000),
                            requestHandler=RequestHandler)
server.register_introspection_functions()

# Register pow() function; this will use the value of
# pow.__name__ as the name, which is just 'pow'.
server.register_function(pow)

# Register a function under a different name
def adder_function(x,y):
    return x + y
server.register_function(adder_function, 'add')

# Register an instance; all the methods of the instance are
# published as XML-RPC methods (in this case, just 'div').
class MyFuncs:
    def div(self, x, y):
        return x // y

server.register_instance(MyFuncs())

# Run the server's main loop
server.serve_forever()

The following client code will call the methods made available by the preceding server:

import xmlrpclib

s = xmlrpclib.ServerProxy('http://localhost:8000')
print s.pow(2,3)  # Returns 2**3 = 8
print s.add(2,3)  # Returns 5
print s.div(5,2)  # Returns 5//2 = 2

# Print list of available methods
print s.system.listMethods()
Blauohr