changeset 4179:00a4837da41a

Consolidate Request and Response into single object
author Florian Krupicka <florian.krupicka@googlemail.com>
date Thu, 19 Jun 2008 17:37:53 +0200
parents e24aa7996f9f
children 8f3914a83410
files MoinMoin/web/request.py
diffstat 1 files changed, 32 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/web/request.py	Wed Jun 18 16:14:42 2008 +0200
+++ b/MoinMoin/web/request.py	Thu Jun 19 17:37:53 2008 +0200
@@ -10,17 +10,44 @@
 
 from werkzeug.wrappers import Request as WerkzeugRequest
 from werkzeug.wrappers import Response as WerkzeugResponse
+from werkzeug.utils import EnvironHeaders, cached_property
 
 from MoinMoin import config
 
 from MoinMoin import log
 logging = log.getLogger(__name__)
 
-class Request(WerkzeugRequest):
+class Request(WerkzeugRequest, WerkzeugResponse):
+    """ A full featured Request/Response object.
+
+    To better distinguish incoming and outgoing data/headers,
+    incoming versions are prefixed with 'in_' in contrast to
+    original Werkzeug implementation.
+    """
     charset = config.charset
     encoding_errors = 'replace'
+    default_mimetype = 'text/html'
 
-class Response(WerkzeugResponse):
-    charset = config.charset
-    default_mimetype = 'text/html'
-    
+    def __init__(self, environ, populate_request=True, shallow=False,
+                 response=None, status=None, headers=None, mimetype=None,
+                 content_type=None):
+        WerkzeugRequest.__init__(self, environ, populate_request, shallow)
+        WerkzeugResponse.__init__(self, response, status, headers,
+                                  mimetype, content_type)
+
+    data = WerkzeugResponse.data
+    stream = WerkzeugResponse.stream
+
+    def in_headers(self):
+        return EnvironHeaders(self.environ)
+    in_headers = cached_property(in_headers, doc=WerkzeugRequest.headers.__doc__)
+
+    def in_stream(self):
+        if self._data_stream is None:
+            self._load_form_data()
+        return self._data_stream
+    in_stream = property(in_stream, doc=WerkzeugRequest.stream.__doc__)
+
+    def in_data(self):
+        return self.in_stream.read()
+    in_data = cached_property(in_data, doc=WerkzeugRequest.data.__doc__)