First, please don’t shoot me if this has already been asked – I have looked around but to no avail.
I have a python file (named rpc.py) containing many functions serving AJAX requests. For example:
def test(self, vars):
return vars['id']
def test2(self, vars):
return vars['id']+1
And it is called with a URL like:
rpc.py?fnc=test2&id=4
I want to call the function that matches the 'fnc' query parameter and pass the whole query string into 'vars'.
So something like the following “pseudocode” is what I am after:
vars = cgi.FieldStorage()
print "Content-Type: text/html\n\n"
print eval('vars["fnc"].value(vars)')
Any ideas?
You can use
but I’d also suggest adding a prefix to the service names (e.g. “do_test”) to avoid malicious code that would be able to call any of the methods of the server object simply by passing their names (including ones you think it shouldn’t). In this case it would be