Python xmlrpc servers?
ted holden
uwbear at verizon.net
Wed Dec 1 14:17:30 EST 2004
Skip Montanaro wrote:
> ted> I don't see what "lambda" is or how a lambda function is supposed
> ted> to be construed as adding two numbers together.
>
> Lambda is a keyword in Python used to create and return very simple
> (single-expression) functions. Lambda expressions can be used anywhere
> you'd normally use a function object. See:
>
> http://www.python.org/doc/current/ref/lambdas.html
>
> The line containing the lambda expression:
>
> server.register_function(lambda x,y: x+y, 'add')
>
> could be recast as:
>
> def add(x, y):
> return x+y
>
> server.register_function(add, 'add')
That's a whole lot easier to digest. I'd have assumed lambda was some sort
of stat function...
> The server listens to "localhost" on port 8888. To allow it to listen for
> external connections change "localhost" to the name or IP address of the
> server. Before you do that make sure you understand the ramifications of
> exposing your XML-RPC server to a broader class of potential clients, some
> of which are bound to be malicious.
>
> Skip
Many thanks, that's the part I was missing in the case of standalone
servers. The only other real question is what about the cgi servers? I'd
assume I'd take the example given:
class MyFuncs:
def div(self, x, y) : return div(x,y)
handler = CGIXMLRPCRequestHandler()
handler.register_function(pow)
handler.register_function(lambda x,y: x+y, 'add')
handler.register_introspection_functions()
handler.register_instance(MyFuncs())
handler.handle_request()
Stuff that into a file in the cgi-bin dir on the server, and then try to use
something like:
server = xmlrpclib.Server("http://192.168.1.102/testserver.py")
or
server = xmlrpclib.Server("http://192.168.1.102/cgi-bin/testserver.py")
That still hasn't worked, so far at least.
More information about the Python-list
mailing list