changeset 4148:78e6deeadc7e

Make XML-RPC action call into own WSGI app (draft)
author Florian Krupicka <florian.krupicka@googlemail.com>
date Sun, 08 Jun 2008 00:32:31 +0200
parents 95e9e24da409
children 769850545997
files MoinMoin/web/apps.py MoinMoin/web/contexts.py
diffstat 2 files changed, 43 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/web/apps.py	Sun Jun 08 00:32:31 2008 +0200
@@ -0,0 +1,29 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - WSGI apps and middlewares
+
+    @copyright: 2003-2008 MoinMoin:ThomasWaldmann,
+                2008-2008 MoinMoin:FlorianKrupicka
+    @license: GNU GPL, see COPYING for details.
+"""
+from MoinMoin.web.request import Request
+from MoinMoin.web.contexts import XMLRPCContext
+
+class XMLRPCApp(object):
+    """ Handles XML-RPC method calls or dispatches to next layer """
+    
+    def __init__(self, app):
+        self.app = app
+        
+    def __call__(self, environ, start_response):
+        request = Request(environ)
+        action = Request.args.get('action')
+        
+        from MoinMoin import xmlrpc
+
+        if action == 'xmlrpc':
+            return xmlrpc.xmlrpc(XMLRPCContext(environ))
+        elif action == 'xmlrpc2':
+            return xmlrpc.xmlrpc2(XMLRPCContext(environ))
+        else:
+            return self.app(environ, start_response)
--- a/MoinMoin/web/contexts.py	Sun Jun 08 00:23:56 2008 +0200
+++ b/MoinMoin/web/contexts.py	Sun Jun 08 00:32:31 2008 +0200
@@ -23,7 +23,19 @@
 class Context(object):
     pass
 
-class HTTPContext(Context, RequestBase):
+class EnvironContext(Context):
+    def __init__(self, environ):
+        request = environ.get('werkzeug.request')
+        if request and isinstance(request, Request):
+            self._wsgirequest = request
+        else:
+            self._wsgirequest = Request(environ)
+        self.environ = environ
+
+class XMLRPCContext(EnvironContext):
+    pass
+
+class HTTPContext(EnvironContext, RequestBase):
     """ Lowermost context for MoinMoin.
 
     Contains code related to manipulation of HTTP related data like:
@@ -32,11 +44,9 @@
     * GET/POST/PUT/etc data
     """
     def __init__(self, environ):
-        self._wsgirequest = Request(environ)
-        self.environ = environ
+        EnvironContext.__init__(self, environ)
         self.__output = []
         self.headers = Headers()
-
         self.status = 200
 
         # compat properties (remove when not necessary anymore)