import cgi import logging import wsgiref.handlers from google.appengine.api import users from google.appengine.ext import webapp from rpc_functions import * class XMLRPC(webapp.RequestHandler): def post(self): import xmlrpclib p, m = xmlrpclib.loads(self.request.body) try: f = globals().get(m) if f and callable(f): result = f(*p) xml = xmlrpclib.dumps((result,), methodresponse=1) else: xml = xmlrpclib.dumps(xmlrpclib.Fault(-32400, 'system error: Cannot find or call %s' % m), methodresponse=1) except Exception, e: xml = xmlrpclib.dumps(xmlrpclib.Fault(-32400, 'system error: %s' % e), methodresponse=1) self.response.headers['Content-Type'] = 'text/xml; charset=utf-8' self.response.out.write(xml) def main(): application = webapp.WSGIApplication( [('/XMLRPC', XMLRPC)], debug=True) wsgiref.handlers.CGIHandler().run(application) if __name__ == "__main__": main()