2 from jsonrpc import ServiceHandler
4 class CGIServiceHandler(ServiceHandler):
5 def __init__(self, service):
7 import __main__ as service
9 ServiceHandler.__init__(self, service)
11 def handleRequest(self, fin=None, fout=None, env=None):
20 contLen=int(env['CONTENT_LENGTH'])
21 data = fin.read(contLen)
25 resultData = ServiceHandler.handleRequest(self, data)
27 response = "Content-Type: text/plain\n"
28 response += "Content-Length: %d\n\n" % len(resultData)
29 response += resultData
31 #on windows all \n are converted to \r\n if stdout is a terminal and is not set to binary mode :(
32 #this will then cause an incorrect Content-length.
33 #I have only experienced this problem with apache on Win so far.
34 if sys.platform == "win32":
37 msvcrt.setmode(fout.fileno(), os.O_BINARY)
44 def handleCGI(service=None, fin=None, fout=None, env=None):
45 CGIServiceHandler(service).handleRequest(fin, fout, env)