comparison 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
comparison
equal deleted inserted replaced
4669:d9f18ecbb2c4 4670:06a744121699
593 If a dict is provided as file in the dict for the `data` parameter 593 If a dict is provided as file in the dict for the `data` parameter
594 the content type has to be called `content_type` now instead of 594 the content type has to be called `content_type` now instead of
595 `mimetype`. This change was made for consistency with 595 `mimetype`. This change was made for consistency with
596 :class:`werkzeug.FileWrapper`. 596 :class:`werkzeug.FileWrapper`.
597 597
598 The `follow_redirects` parameter was added to :func:`open`.
599
598 Additional parameters: 600 Additional parameters:
599 601
600 :param as_tuple: Returns a tuple in the form ``(environ, result)`` 602 :param as_tuple: Returns a tuple in the form ``(environ, result)``
601 :param buffered: set this to true to buffer the application run. 603 :param buffered: Set this to true to buffer the application run.
602 This will automatically close the application for 604 This will automatically close the application for
603 you as well. 605 you as well.
606 :param follow_redirects: Set this to True if the `Client` should
607 follow HTTP redirects.
604 """ 608 """
605 as_tuple = kwargs.pop('as_tuple', False) 609 as_tuple = kwargs.pop('as_tuple', False)
606 buffered = kwargs.pop('buffered', False) 610 buffered = kwargs.pop('buffered', False)
611 follow_redirects = kwargs.pop('follow_redirects', False)
607 environ = None 612 environ = None
608 if not kwargs and len(args) == 1: 613 if not kwargs and len(args) == 1:
609 if isinstance(args[0], EnvironBuilder): 614 if isinstance(args[0], EnvironBuilder):
610 environ = args[0].get_environ() 615 environ = args[0].get_environ()
611 elif isinstance(args[0], dict): 616 elif isinstance(args[0], dict):
620 if self.cookie_jar is not None: 625 if self.cookie_jar is not None:
621 self.cookie_jar.inject_wsgi(environ) 626 self.cookie_jar.inject_wsgi(environ)
622 rv = run_wsgi_app(self.application, environ, buffered=buffered) 627 rv = run_wsgi_app(self.application, environ, buffered=buffered)
623 if self.cookie_jar is not None: 628 if self.cookie_jar is not None:
624 self.cookie_jar.extract_wsgi(environ, rv[2]) 629 self.cookie_jar.extract_wsgi(environ, rv[2])
630
631 if rv[0].status_code in (301, 302, 303, 305, 307) and follow_redirects:
632 redirect = urlparse.urlunsplit(urlparse.urlsplit(
633 dict(rv[2])['Location'])[:-2] + ('', ''))
634 kwargs.update({
635 'base_url': redirect,
636 'as_tuple': as_tuple,
637 'buffered': buffered,
638 'follow_redirects': True
639 })
640 return self.open(*args, **kwargs)
641
625 response = self.response_wrapper(*rv) 642 response = self.response_wrapper(*rv)
626 if as_tuple: 643 if as_tuple:
627 return environ, response 644 return environ, response
628 return response 645 return response
629 646