changeset 4134:719256a8db51

Initial code to track down the use of request objects in MoinMoin
author Florian Krupicka <florian.krupicka@googlemail.com>
date Wed, 28 May 2008 15:19:20 +0200
parents 251827af7ddc
children 0fd8fd9979f8
files MoinMoin/web/__init__.py MoinMoin/web/request.py MoinMoin/wsgiapp.py
diffstat 3 files changed, 100 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/web/__init__.py	Wed May 28 15:19:20 2008 +0200
@@ -0,0 +1,10 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - This package contains the interface between webserver
+               and application. This is meant to become a replacement
+               and/or port of code currently scattered in MoinMoin.request
+               and MoinMoin.server.
+
+    @copyright: 2008-2008 MoinMoin:FlorianKrupicka
+    @license: GNU GPL, see COPYING for details.
+"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/web/request.py	Wed May 28 15:19:20 2008 +0200
@@ -0,0 +1,57 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - New slimmed down WSGI Request.
+
+    @copyright: 2008-2008 MoinMoin:FlorianKrupicka
+    @license: GNU GPL, see COPYING for details.
+"""
+
+from werkzeug import wrappers as werkzeug
+from werkzeug.utils import cached_property
+
+from MoinMoin.request import RequestBase
+
+from MoinMoin import log
+logging = log.getLogger(__name__)
+
+class Request(werkzeug.Request, RequestBase):
+    def __init__(self, environ):
+        werkzeug.Request.__init__(self, environ)
+        RequestBase.__init__(self, {})
+
+    def __getattribute__(self, name):
+        logging.error("UR DOING IT WRONG! (attribute '%s' requested)", name)
+        return RequestBase.__getattribute__(self, name)
+
+    def __setattr__(self, name, value):
+        logging.error("UR DOING IT WRONG! (attribute '%s' changed to '%r')", name, value)
+        return RequestBase.__setattr__(self, name, value)
+
+    def __delattr__(self, name):
+        logging.error("UR DOING IT WRONG! (attribute '%s' deleted)", name)
+        return Request.__delattr__(self, name)        
+
+    def decodePagename(self, name):
+        return name
+
+    def request_uri(self):
+        answer = self.script_root + self.path
+        qs = self.query_string
+        if qs:
+            answer = answer + '?' + qs
+        return answer
+    request_uri = cached_property(request_uri)
+
+    def http_user_agent(self):
+        return str(self.user_agent)
+    http_user_agent = cached_property(http_user_agent)
+
+for moinname, werkname in [('path_info', 'path'),
+                           ('request_method', 'method')]:
+    method =  getattr(werkzeug.Request, werkname)
+    setattr(Request, moinname, method)
+del moinname, werkname
+        
+
+    
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/wsgiapp.py	Wed May 28 15:19:20 2008 +0200
@@ -0,0 +1,33 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - WSGI application
+
+
+    @copyright: 2001-2003 Juergen Hermann <jh@web.de>,
+                2003-2006 MoinMoin:ThomasWaldmann,
+                2008-2008 MoinMoin:FlorianKrupicka
+    @license: GNU GPL, see COPYING for details.
+"""
+
+from werkzeug.wrappers import Response
+from werkzeug.debug import DebuggedApplication
+
+from MoinMoin.web.request import Request
+
+
+def application(request):
+    request.run()
+    response = Response(status=request.status,
+                        headers=request.headers)
+    if request._send_file is not None:
+        # moin wants to send a file (e.g. AttachFile.do_get)
+        def simple_wrapper(fileobj, bufsize):
+            return iter(lambda: fileobj.read(bufsize), '')
+        file_wrapper = environ.get('wsgi.file_wrapper', simple_wrapper)
+        response.response = file_wrapper(request._send_file, request._send_bufsize)
+    else:
+        response.response = request.output()
+    return response
+
+application = Request.application(application)
+application = DebuggedApplication(application)