changeset 4608:3a79d3ca5a83

changed code to support werkzeug 0.5 (thanks to mitsuhiko for the patch)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 27 Feb 2009 23:30:37 +0100
parents d8e5e9cfadf1
children 246ba4eecab2
files MoinMoin/web/contexts.py MoinMoin/web/request.py
diffstat 2 files changed, 25 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/web/contexts.py	Mon Feb 23 22:39:32 2009 +0100
+++ b/MoinMoin/web/contexts.py	Fri Feb 27 23:30:37 2009 +0100
@@ -229,7 +229,7 @@
         if n is None:
             return self.request.in_data
         else:
-            return self.request.input_stream.read(n)
+            return self.request.in_stream.read(n)
 
     def makeForbidden(self, resultcode, msg):
         status = {401: Unauthorized,
@@ -305,6 +305,7 @@
         def simple_wrapper(fileobj, bufsize):
             return iter(lambda: fileobj.read(bufsize), '')
         file_wrapper = self.environ.get('wsgi.file_wrapper', simple_wrapper)
+        self.request.direct_passthrough = True
         self.request.response = file_wrapper(fileobj, bufsize)
         raise MoinMoinFinish('sent file')
 
--- a/MoinMoin/web/request.py	Mon Feb 23 22:39:32 2009 +0100
+++ b/MoinMoin/web/request.py	Fri Feb 27 23:30:37 2009 +0100
@@ -9,10 +9,11 @@
 import re
 from StringIO import StringIO
 
-from werkzeug import Request as WerkzeugRequest
-from werkzeug import Response as WerkzeugResponse
-from werkzeug import EnvironHeaders, cached_property, Href, create_environ
-from werkzeug import parse_cache_control_header, HeaderSet, url_encode, Client
+from werkzeug import Request as RequestBase
+from werkzeug import Response as ResponseBase
+from werkzeug import EnvironHeaders, Headers, HeaderSet
+from werkzeug import Href, create_environ, url_encode, cached_property
+from werkzeug import Client # used by tests
 
 from MoinMoin import config
 
@@ -22,7 +23,7 @@
 class MoinMoinFinish(Exception):
     """ Raised to jump directly to end of run() function, where finish is called """
 
-class Request(WerkzeugRequest, WerkzeugResponse):
+class Request(ResponseBase, RequestBase):
     """ A full featured Request/Response object.
 
     To better distinguish incoming and outgoing data/headers,
@@ -34,51 +35,28 @@
     default_mimetype = 'text/html'
     given_config = None # if None, load wiki config from disk
 
-    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)
-        if self.script_root:
-            self.href = Href(self.script_root, self.charset)
-        else:
-            self.href = Href('/', self.charset)
-        self.abs_href = Href(self.url_root, self.charset)
-
-    data = WerkzeugResponse.data
-    stream = WerkzeugResponse.stream
-    cache_control = WerkzeugResponse.cache_control
-
-    def in_cache_control(self):
-        """A `CacheControl` object for the incoming cache control headers."""
-        cache_control = self.environ.get('HTTP_CACHE_CONTROL')
-        return parse_cache_control_header(cache_control)
-    in_cache_control = cached_property(in_cache_control)
+    # get rid of some inherited descriptors
+    headers = None
 
-    def in_headers(self):
-        """The headers from the WSGI environ as immutable `EnvironHeaders`."""
-        return EnvironHeaders(self.environ)
-    in_headers = cached_property(in_headers, doc=WerkzeugRequest.headers.__doc__)
+    def __init__(self, environ, populate_request=True, shallow=False):
+        ResponseBase.__init__(self)
+        RequestBase.__init__(self, environ, populate_request, shallow)
+        self.href = Href(self.script_root or '/', self.charset)
+        self.abs_href = Href(self.url_root, self.charset)
+        self.headers = Headers([('Content-Type', 'text/html')])
+        self.response = []
+        self.status_code = 200
 
-    def in_stream(self):
-        """The parsed stream if the submitted data was not multipart or
-        urlencoded form data.  This stream is the stream left by the CGI
-        module after parsing.  This is *not* the WSGI input stream.
-        """
-        if self._data_stream is None:
-            self._load_form_data()
-        return self._data_stream
-    in_stream = property(in_stream, doc=WerkzeugRequest.stream.__doc__)
+    in_stream = RequestBase.stream
 
+    @cached_property
     def in_data(self):
-        """This reads the buffered incoming data from the client into the
-        string.  Usually it's a bad idea to access `data` because a client
-        could send dozens of megabytes or more to cause memory problems on the
-        server.
-        """
         return self.in_stream.read()
-    in_data = cached_property(in_data, doc=WerkzeugRequest.data.__doc__)
+
+    @cached_property
+    def in_headers(self):
+        return EnvironHeaders(self.environ)
+
 
 class TestRequest(Request):
     """ Request with customized `environ` for test purposes. """