summaryrefslogtreecommitdiffstats
path: root/silpa/jsonrpc/cgiwrapper.py
diff options
context:
space:
mode:
authorSanthosh Thottingal <santhosh.thottingal@gmail.com>2009-07-19 18:32:04 +0530
committerSanthosh Thottingal <santhosh.thottingal@gmail.com>2009-07-19 18:32:04 +0530
commitc8a17ee264a269a59651936b34a960f4d40a9074 (patch)
tree3b2b21be4668f50a5c5f307c89e42323b8a8c292 /silpa/jsonrpc/cgiwrapper.py
parent05f7f938168f9b3195c9b101f4b98f298ab2e981 (diff)
downloadRachana.git-c8a17ee264a269a59651936b34a960f4d40a9074.tar.gz
Rachana.git-c8a17ee264a269a59651936b34a960f4d40a9074.tar.xz
Rachana.git-c8a17ee264a269a59651936b34a960f4d40a9074.zip
JSON RPC Based new architecture and corresponding changes
Diffstat (limited to 'silpa/jsonrpc/cgiwrapper.py')
-rw-r--r--silpa/jsonrpc/cgiwrapper.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/silpa/jsonrpc/cgiwrapper.py b/silpa/jsonrpc/cgiwrapper.py
new file mode 100644
index 0000000..a5bc2b0
--- /dev/null
+++ b/silpa/jsonrpc/cgiwrapper.py
@@ -0,0 +1,45 @@
+import sys, os
+from jsonrpc import ServiceHandler
+
+class CGIServiceHandler(ServiceHandler):
+ def __init__(self, service):
+ if service == None:
+ import __main__ as service
+
+ ServiceHandler.__init__(self, service)
+
+ def handleRequest(self, fin=None, fout=None, env=None):
+ if fin==None:
+ fin = sys.stdin
+ if fout==None:
+ fout = sys.stdout
+ if env == None:
+ env = os.environ
+
+ try:
+ contLen=int(env['CONTENT_LENGTH'])
+ data = fin.read(contLen)
+ except Exception, e:
+ data = ""
+
+ resultData = ServiceHandler.handleRequest(self, data)
+
+ response = "Content-Type: text/plain\n"
+ response += "Content-Length: %d\n\n" % len(resultData)
+ response += resultData
+
+ #on windows all \n are converted to \r\n if stdout is a terminal and is not set to binary mode :(
+ #this will then cause an incorrect Content-length.
+ #I have only experienced this problem with apache on Win so far.
+ if sys.platform == "win32":
+ try:
+ import msvcrt
+ msvcrt.setmode(fout.fileno(), os.O_BINARY)
+ except:
+ pass
+ #put out the response
+ fout.write(response)
+ fout.flush()
+
+def handleCGI(service=None, fin=None, fout=None, env=None):
+ CGIServiceHandler(service).handleRequest(fin, fout, env) \ No newline at end of file