diff MoinMoin/support/werkzeug/test.py @ 4670:06a744121699

updated werkzeug
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 30 Mar 2009 00:07:59 +0200
parents c404a1295318
children bd3f5ccf6fb6
line wrap: on
line diff
--- a/MoinMoin/support/werkzeug/test.py	Sun Mar 29 16:47:54 2009 +0200
+++ b/MoinMoin/support/werkzeug/test.py	Mon Mar 30 00:07:59 2009 +0200
@@ -595,15 +595,20 @@
            `mimetype`.  This change was made for consistency with
            :class:`werkzeug.FileWrapper`.
 
+            The `follow_redirects` parameter was added to :func:`open`.
+
         Additional parameters:
 
         :param as_tuple: Returns a tuple in the form ``(environ, result)``
-        :param buffered: set this to true to buffer the application run.
+        :param buffered: Set this to true to buffer the application run.
                          This will automatically close the application for
                          you as well.
+        :param follow_redirects: Set this to True if the `Client` should
+                                 follow HTTP redirects.
         """
         as_tuple = kwargs.pop('as_tuple', False)
         buffered = kwargs.pop('buffered', False)
+        follow_redirects = kwargs.pop('follow_redirects', False)
         environ = None
         if not kwargs and len(args) == 1:
             if isinstance(args[0], EnvironBuilder):
@@ -622,6 +627,18 @@
         rv = run_wsgi_app(self.application, environ, buffered=buffered)
         if self.cookie_jar is not None:
             self.cookie_jar.extract_wsgi(environ, rv[2])
+
+        if rv[0].status_code in (301, 302, 303, 305, 307) and follow_redirects:
+            redirect = urlparse.urlunsplit(urlparse.urlsplit(
+                dict(rv[2])['Location'])[:-2] + ('', ''))
+            kwargs.update({
+                'base_url':         redirect,
+                'as_tuple':         as_tuple,
+                'buffered':         buffered,
+                'follow_redirects': True
+            })
+            return self.open(*args, **kwargs)
+
         response = self.response_wrapper(*rv)
         if as_tuple:
             return environ, response