changeset 4670:06a744121699

updated werkzeug
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 30 Mar 2009 00:07:59 +0200
parents d9f18ecbb2c4
children 2b7e69ce6a05
files MoinMoin/support/werkzeug/http.py MoinMoin/support/werkzeug/script.py MoinMoin/support/werkzeug/test.py
diffstat 3 files changed, 27 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/support/werkzeug/http.py	Sun Mar 29 16:47:54 2009 +0200
+++ b/MoinMoin/support/werkzeug/http.py	Mon Mar 30 00:07:59 2009 +0200
@@ -18,7 +18,10 @@
 """
 import re
 import inspect
-from email.utils import parsedate_tz, mktime_tz
+try:
+    from email.utils import parsedate_tz, mktime_tz
+except ImportError:
+    from email.Utils import parsedate_tz, mktime_tz
 from cStringIO import StringIO
 from tempfile import TemporaryFile
 from urllib2 import parse_http_list as _parse_list_header
--- a/MoinMoin/support/werkzeug/script.py	Sun Mar 29 16:47:54 2009 +0200
+++ b/MoinMoin/support/werkzeug/script.py	Mon Mar 30 00:07:59 2009 +0200
@@ -270,11 +270,12 @@
 
 def make_runserver(app_factory, hostname='localhost', port=5000,
                    use_reloader=False, use_debugger=False, use_evalex=True,
-                   threaded=False, processes=1, static_files=None):
+                   threaded=False, processes=1, static_files=None,
+                   extra_files=None):
     """Returns an action callback that spawns a new development server.
 
     .. versionadded:: 0.5
-       `static_files` was added.
+       `static_files` and `extra_files` was added.
 
     :param app_factory: a function that returns a new WSGI application.
     :param hostname: the default hostname the server should listen on.
@@ -284,6 +285,7 @@
     :param threaded: the default threading setting.
     :param processes: the default number of processes to start.
     :param static_files: optionally a dict of static files.
+    :param extra_files: optionally a list of extra files to track for reloading.
     """
     def action(hostname=('h', hostname), port=('p', port),
                reloader=use_reloader, debugger=use_debugger,
@@ -292,5 +294,5 @@
         from werkzeug.serving import run_simple
         app = app_factory()
         run_simple(hostname, port, app, reloader, debugger, evalex,
-                   None, 1, threaded, processes, static_files)
+                   extra_files, 1, threaded, processes, static_files)
     return action
--- 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