[Twisted-web] xmlrpc question
lotek at softhome.net
lotek at softhome.net
Tue Nov 30 13:19:00 MST 2004
How can i do this in twisted?
from SimpleXMLRPCServer import SimpleXMLRPCServer,
SimpleXMLRPCRequestHandler
class ExtendedXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
def do_GET(self):
#only allow a request for the crossdomain file
#this can be changed to support GETs of any file if needed
if self.path != '/crossdomain.xml':
self.send_response(403)
self.log_request(403)
return
#open the crossdomain file and read its contents
f = file('crossdomain.xml', 'r')
msg = f.read()
f.close()
#write the data to the socket along with valid HTTP headers
res = 'HTTP/1.0 200 OK\r\nDate: %s\r\n\r\n%s' % \
(self.date_time_string(),msg)
self.wfile.write(res)
self.log_request(200)
class EchoClass:
def echo(self, data):
return data
#create an instance of the class
s = EchoClass()
#create the server on localhost
server = SimpleXMLRPCServer(('', 8000), ExtendedXMLRPCRequestHandler)
#register the instance as a web service
server.register_instance(s)
#start accepting requests
server.serve_forever()
More information about the Twisted-web
mailing list