diff options
author | Santhosh Thottingal <santhosh.thottingal@gmail.com> | 2009-07-19 18:32:04 +0530 |
---|---|---|
committer | Santhosh Thottingal <santhosh.thottingal@gmail.com> | 2009-07-19 18:32:04 +0530 |
commit | c8a17ee264a269a59651936b34a960f4d40a9074 (patch) | |
tree | 3b2b21be4668f50a5c5f307c89e42323b8a8c292 /silpa/jsonrpc/modpywrapper.py | |
parent | 05f7f938168f9b3195c9b101f4b98f298ab2e981 (diff) | |
download | AnjaliOldLipi.git-c8a17ee264a269a59651936b34a960f4d40a9074.tar.gz AnjaliOldLipi.git-c8a17ee264a269a59651936b34a960f4d40a9074.tar.xz AnjaliOldLipi.git-c8a17ee264a269a59651936b34a960f4d40a9074.zip |
JSON RPC Based new architecture and corresponding changes
Diffstat (limited to 'silpa/jsonrpc/modpywrapper.py')
-rw-r--r-- | silpa/jsonrpc/modpywrapper.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/silpa/jsonrpc/modpywrapper.py b/silpa/jsonrpc/modpywrapper.py new file mode 100644 index 0000000..3e61017 --- /dev/null +++ b/silpa/jsonrpc/modpywrapper.py @@ -0,0 +1,52 @@ +import sys, os +from jsonrpc import ServiceHandler, ServiceException + + +class ServiceImplementaionNotFound(ServiceException): + pass + + +class ModPyServiceHandler(ServiceHandler): + def __init__(self, req): + self.req = req + ServiceHandler.__init__(self, None) + + + def findServiceEndpoint(self, name): + req = self.req + + (modulePath, fileName) = os.path.split(req.filename) + (moduleName, ext) = os.path.splitext(fileName) + + if not os.path.exists(os.path.join(modulePath, moduleName + ".py")): + raise ServiceImplementaionNotFound() + else: + if not modulePath in sys.path: + sys.path.insert(0, modulePath) + + from mod_python import apache + module = apache.import_module(moduleName, log=1) + + if hasattr(module, "service"): + self.service = module.service + elif hasattr(module, "Service"): + self.service = module.Service() + else: + self.service = module + + return ServiceHandler.findServiceEndpoint(self, name) + + + def handleRequest(self, data): + self.req.content_type = "text/plain" + data = self.req.read() + resultData = ServiceHandler.handleRequest(self, data) + self.req.write(resultData) + self.req.flush() + +def handler(req): + from mod_python import apache + ModPyServiceHandler(req).handleRequest(req) + return apache.OK + + |