changeset 5582:ca98db50efac

request: fix for werkzeug 0.6 and 0.5.1 compatibility
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 25 Feb 2010 01:35:06 +0100
parents af56baebf4d1
children ea0b35b54bbf
files MoinMoin/web/contexts.py MoinMoin/web/request.py
diffstat 2 files changed, 19 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/web/contexts.py	Tue Feb 23 23:45:09 2010 +0100
+++ b/MoinMoin/web/contexts.py	Thu Feb 25 01:35:06 2010 +0100
@@ -281,7 +281,7 @@
     # the output related methods
     def write(self, *data):
         """ Write to output stream. """
-        self.request.stream.writelines(data)
+        self.request.out_stream.writelines(data)
 
     def redirectedOutput(self, function, *args, **kw):
         """ Redirect output during function, return redirected output """
--- a/MoinMoin/web/request.py	Tue Feb 23 23:45:09 2010 +0100
+++ b/MoinMoin/web/request.py	Thu Feb 25 01:35:06 2010 +0100
@@ -47,7 +47,24 @@
         self.response = []
         self.status_code = 200
 
-    in_stream = RequestBase.stream
+    # XXX ugly hack begin - works by sheer luck
+    # TODO keep request and response separate, don't mix them together
+    stream = property() # protect inherited .stream attr from accessing
+    
+    try:
+        # for werkzeug 0.6
+        in_stream = cached_property(RequestBase.stream.func, 'in_stream')
+    except AttributeError:
+        # no .func -> werkzeug 0.5
+        in_stream = RequestBase.stream
+
+    try:
+        # for werkzeug 0.6
+        out_stream = cached_property(ResponseBase.stream.func, 'out_stream')
+    except AttributeError:
+        # no .func -> werkzeug 0.5
+        out_stream = ResponseBase.stream
+    # XXX ugly hack end
 
     @cached_property
     def in_data(self):