comparison MoinMoin/support/werkzeug/test.py @ 4689:bd3f5ccf6fb6

updated werkzeug
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 19 Apr 2009 00:46:15 +0200
parents 06a744121699
children 7cb92118a93e
comparison
equal deleted inserted replaced
4688:3e4e67bcbedd 4689:bd3f5ccf6fb6
20 from urllib2 import Request as U2Request 20 from urllib2 import Request as U2Request
21 21
22 from werkzeug._internal import _empty_stream 22 from werkzeug._internal import _empty_stream
23 from werkzeug.wrappers import BaseRequest 23 from werkzeug.wrappers import BaseRequest
24 from werkzeug.utils import create_environ, run_wsgi_app, get_current_url, \ 24 from werkzeug.utils import create_environ, run_wsgi_app, get_current_url, \
25 url_encode, url_decode, FileStorage 25 url_encode, url_decode, FileStorage, get_host
26 from werkzeug.datastructures import FileMultiDict, MultiDict, \ 26 from werkzeug.datastructures import FileMultiDict, MultiDict, \
27 CombinedMultiDict, Headers 27 CombinedMultiDict, Headers
28 28
29 29
30 def stream_encode_multipart(values, use_tempfile=True, threshold=1024 * 500, 30 def stream_encode_multipart(values, use_tempfile=True, threshold=1024 * 500,
626 self.cookie_jar.inject_wsgi(environ) 626 self.cookie_jar.inject_wsgi(environ)
627 rv = run_wsgi_app(self.application, environ, buffered=buffered) 627 rv = run_wsgi_app(self.application, environ, buffered=buffered)
628 if self.cookie_jar is not None: 628 if self.cookie_jar is not None:
629 self.cookie_jar.extract_wsgi(environ, rv[2]) 629 self.cookie_jar.extract_wsgi(environ, rv[2])
630 630
631 if rv[0].status_code in (301, 302, 303, 305, 307) and follow_redirects: 631 # handle redirects
632 redirect = urlparse.urlunsplit(urlparse.urlsplit( 632 redirect_chain = []
633 dict(rv[2])['Location'])[:-2] + ('', '')) 633 status_code = int(rv[1].split(None, 1)[0])
634 while status_code in (301, 302, 303, 305, 307) and follow_redirects:
635 redirect = dict(rv[2])['Location']
636 host = get_host(create_environ('/', redirect))
637 if get_host(environ).split(':', 1)[0] != host:
638 raise RuntimeError('%r does not support redirect to '
639 'external targets' % self.__class__)
640
641 scheme, netloc, script_root, qs, anchor = urlparse.urlsplit(redirect)
642 redirect_chain.append((redirect, status_code))
643
634 kwargs.update({ 644 kwargs.update({
635 'base_url': redirect, 645 'base_url': urlparse.urlunsplit((scheme, host,
646 script_root, '', '')).rstrip('/') + '/',
647 'query_string': qs,
636 'as_tuple': as_tuple, 648 'as_tuple': as_tuple,
637 'buffered': buffered, 649 'buffered': buffered,
638 'follow_redirects': True 650 'follow_redirects': False
639 }) 651 })
640 return self.open(*args, **kwargs) 652 rv = self.open(*args, **kwargs)
653 status_code = int(rv[1].split(None, 1)[0])
654
655 # Prevent loops
656 if redirect_chain[-1] in redirect_chain[0:-1]:
657 break
641 658
642 response = self.response_wrapper(*rv) 659 response = self.response_wrapper(*rv)
643 if as_tuple: 660 if as_tuple:
644 return environ, response 661 return environ, response
645 return response 662 return response